[R] variable names in lm formula ~.
Bert Gunter
bgunter.4567 at gmail.com
Tue Jan 30 17:12:09 CET 2018
Well...
?terms.formula says:
"data: a data frame from which the meaning of the special symbol . can
be inferred. It is unused if there is no . in the formula."
So this seems to me to be an obscure bug, as I have found no warning
against this admittedly confusing but still, I think, legal syntax.
Note:
> d <- data.frame(log = runif(10), x = 1:10)
> y <- rnorm(10,5)
> m1 <- lm(y ~ ., data = d)
> formula(m1)
y ~ log + x
> m2 <- update(m1, formula =log(y) ~.)
> formula(m2)
log(y) ~ log + x
> m3 = lm(log(y) ~., data =d)
> formula(m3)
log(y) ~ x
As always, correction appreciated if I'm wrong.
Cheers,
Bert
Bert Gunter
"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Tue, Jan 30, 2018 at 6:23 AM, Jeff Newmiller
<jdnewmil at dcn.davis.ca.us> wrote:
>
> Functions are first class objects, so some kind of collision is bound to happen if you do this... so don't.
> --
> Sent from my phone. Please excuse my brevity.
>
> On January 30, 2018 3:11:56 AM PST, "Vito M. R. Muggeo" <vito.muggeo at unipa.it> wrote:
> >dear all,
> >Is the following intentional? Am I missing anything in documentation?
> >
> >d<-data.frame(y=rnorm(10,5,.5),exp=rnorm(10), age=rnorm(10))
> >formula(lm(exp(y)~exp+age, data=d))
> >#--> exp(y) ~ exp + age
> >
> >formula(lm(exp(y)~., data=d))
> >#--> exp(y) ~ age
> >
> >variable 'exp' (maybe indicating "experience") is not included in the
> >model. The same happens with 'log' (and other function names, I
> >suppose..)
> >
> >best,
> >vito
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
More information about the R-help
mailing list