Skip to content
Prev 39295 / 63424 Next

Anomaly in [.terms

I've wondered about how to deal with terms objects
whose formula and attributes disagreed with each
other.  In your case the intercept attribute was 0
but there was no -1 in the formula and you (and others)
complained that [.terms respected the formula and not
the attributes.  In another case you can set the response
attribute to 0 but leave the response term in the formula.
Then [.terms alters the formula to drop the response term.
  > t <- terms(y ~ x1 + x2)
  > attr(t, "response")
  [1] 1
  > attr(t, "response") <- 0
  > t[1]
  ~x1
  attr(,"variables")
  list(x1)
  attr(,"factors")
     x1
  x1  1
  attr(,"term.labels")
  [1] "x1"
  attr(,"order")
  [1] 1
  attr(,"intercept")
  [1] 1
  attr(,"response")
  [1] 0
  attr(,".Environment")
  <environment: R_GlobalEnv>
  > version$version.string
  [1] "R version 2.12.1 (2010-12-16)"
Is altering the formula to match the attributes desirable?

I suspect you would be displeased if [.terms added
a -1 to the formula if the intercept term were 0.

If you have a terms object without a response in
the formula and you set the response attribute to
1 then [.terms just gets mixed up.  Altering most
other attributes of a terms object risks confusing
lots of functions.

Should R have a function to set the intercept term
to a legal value so we could say that directly altering
the attributes of a terms object should never be done?

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com