FairyOnIce
FairyOnIce

Reputation: 2614

Update formula objects in R with offset function

I have an R formula object:

  R> formula.obj <- Y ~ 1 + X + offset(Z)

I want to get rid of offset(Z) and obtain:

  R> formula.obj.want <- Y ~ 1 + X

It seems that update function does NOT work in this scenario:

  R> update(formula.obj,.~.-offset(Z))
  Y ~ X + offset(Z)

Is there way to get formula.obj.want from formula.obj?

Upvotes: 1

Views: 275

Answers (2)

Rich Scriven
Rich Scriven

Reputation: 99331

You can use the list structure and the language

> formula.obj[[3]] <- quote(1 + X)
> formula.obj
Y ~ 1 + X
> class(formula.obj)
[1] "formula"

Note that I did try update, and it did not want to include the 1

> update(formula.obj, .~ 1 + X)
Y ~ X

Upvotes: 1

Igor Barinov
Igor Barinov

Reputation: 25580

You can't do this in update. "-" is not supported for offset formulas http://stat.ethz.ch/R-manual/R-patched/library/stats/html/offset.html Define another function as u did

Upvotes: 1

Related Questions