On 29/09/10 11.13, peter dalgaard wrote:
On Sep 29, 2010, at 10:29 , Niels Richard Hansen wrote:
The functions drop.terms and [.terms ignores if the intercept has been
explicitly removed. Is that a deliberate feature?
Perhaps rather an unimplemented one. The root cause is that both functions
use reformulate() on the "term.labels" attribute, and there is no way to
specify that you want to reformulate into a no-intercept formula. On the
other hand, the modeling code will happily proceed with a no-intercept model
even if there is no "-1" in formula part of a terms object, e.g.
x<- terms(y~a+b) attr(x,"intercept")<- 0 lm(x)
Call: lm(formula = x)
Coefficients: a b 0.2263 0.4178
formula(x)
y ~ a + b
so I suppose that there is no really good excuse not to carry the "intercept"
attribute over. As usual, with code as old as this, there is always the risk
that something actually relies on current behavior.
Thanks Peter. I expected something like that.
As I see it, the intercept (or more often, removal of the intercept)
is treated differently from other terms, and information on the presence
of an intercept is stored in an attribute of the terms object rather
than the formula. This attribute is not copied when using drop.terms
or [.terms. I believe it should be, but as you say Peter, some may rely
on the way the functions behave now.
So basically, you should use code like
x <- terms(y~a+b-1)
z <- x[2]
attr(z, "intercept") <- attr(x, "intercept")
to make sure that the intercept information is preserved.
- Niels
--
Niels Richard Hansen Web: www.math.ku.dk/~richard
Associate Professor Email: niels.r.han...@math.ku.dk
Department of Mathematical Sciences nielsrichardhan...@gmail.com
University of Copenhagen Skype: nielsrichardhansen.dk
Universitetsparken 5 Phone: +45 353 20783 (office)
2100 Copenhagen Ø +45 2859 0765 (mobile)
Denmark
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.