Hi, I'm wondering about some logics behind the following simplifications: y ~ 1:x simplifies to y ~ 1 y ~ x:1 simplifies to y ~ 1 y ~ x*1 simplifies to y ~ x y ~ 1*x simplifies to y ~ 1 Mainly I would have expected y ~ 1:x to simplify to y ~ x and the cross operator to be invariant to order. I have some further surprising cases below that I'd also like to know more about but just above will also be great. https://rpubs.com/emitanaka/unexpected-formula-eval Best, Emi *Dr. Emi Tanaka* | Lecturer in Statistics Faculty of Science, School of Mathematics and Statistics Secretary, NSW Branch, Statistical Society of Australia <https://www.meetup.com/NSW-Branch-of-the-Statistics-Society-of-Australia/> Social Media Coordinator, Central, International Biometrics Society <https://twitter.com/IBSstats> *THE UNIVERSITY OF SYDNEY* 827, Carslaw F07 | The University of Sydney | NSW | 2006 *Phone:* +61 2 9351 3039 *Website:* * <http://sydney.edu.au/>*https://emitanaka.github.io/ *Twitter: *@statsgen CRICOS 00026A This email plus any attachments to it are confidential. Any unauthorised use is strictly prohibited. If you receive this email in error, please delete it and any attachments. Please think of our environment and only print this e-mail if necessary. [[alternative HTML version deleted]]
Richard M. Heiberger
2019-Oct-11 17:58 UTC
[R] Surprising Symbolic Model Formula Evaluations
I can't duplicate your examples This is what I see> y ~ 1:xy ~ 1:x Please try again in a vanilla R session, and send a reproducible example. vanilla means start R from the operating system command line with R --vanilla this prevents any of your initialization files from being loaded. See ?Startup for details. On Fri, Oct 11, 2019 at 1:05 PM Emi Tanaka <dr.emi.tanaka at gmail.com> wrote:> > Hi, > > I'm wondering about some logics behind the following simplifications: > > y ~ 1:x simplifies to y ~ 1 > y ~ x:1 simplifies to y ~ 1 > y ~ x*1 simplifies to y ~ x > y ~ 1*x simplifies to y ~ 1 > > Mainly I would have expected y ~ 1:x to simplify to y ~ x and the cross > operator to be invariant to order. > > I have some further surprising cases below that I'd also like to know more > about but just above will also be great. > > https://rpubs.com/emitanaka/unexpected-formula-eval > > Best, > > Emi > > *Dr. Emi Tanaka* | Lecturer in Statistics > > Faculty of Science, School of Mathematics and Statistics > > > Secretary, NSW Branch, Statistical Society of Australia > <https://www.meetup.com/NSW-Branch-of-the-Statistics-Society-of-Australia/> > > Social Media Coordinator, Central, International Biometrics Society > <https://twitter.com/IBSstats> > > > *THE UNIVERSITY OF SYDNEY* > 827, Carslaw F07 | The University of Sydney | NSW | 2006 > *Phone:* +61 2 9351 3039 > *Website:* * <http://sydney.edu.au/>*https://emitanaka.github.io/ > *Twitter: *@statsgen > > CRICOS 00026A > This email plus any attachments to it are confidential. > Any unauthorised use is strictly prohibited. If you receive this email in > error, please delete it and any attachments. Please think of our > environment and only print this e-mail if necessary. > > [[alternative HTML version deleted]] > > ______________________________________________ > 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.
Rich:> x <- 1:10 > y <- runif(10) > lm(y ~ 1:x)Call: lm(formula = y ~ 1:x) Coefficients: (Intercept) 0.477> lm(y ~ x:1)Call: lm(formula = y ~ x:1) Coefficients: (Intercept) 0.477> lm(y ~ 1*x)Call: lm(formula = y ~ 1 * x) Coefficients: (Intercept) 0.477> lm(y ~ x*1)Call: lm(formula = y ~ x * 1) Coefficients: (Intercept) x 0.493927 -0.003079 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 Fri, Oct 11, 2019 at 10:59 AM Richard M. Heiberger <rmh at temple.edu> wrote:> I can't duplicate your examples > This is what I see > > y ~ 1:x > y ~ 1:x > > Please try again in a vanilla R session, and send a reproducible example. > vanilla means start R from the operating system command line with > R --vanilla > > this prevents any of your initialization files from being loaded. See > ?Startup > for details. > > On Fri, Oct 11, 2019 at 1:05 PM Emi Tanaka <dr.emi.tanaka at gmail.com> > wrote: > > > > Hi, > > > > I'm wondering about some logics behind the following simplifications: > > > > y ~ 1:x simplifies to y ~ 1 > > y ~ x:1 simplifies to y ~ 1 > > y ~ x*1 simplifies to y ~ x > > y ~ 1*x simplifies to y ~ 1 > > > > Mainly I would have expected y ~ 1:x to simplify to y ~ x and the cross > > operator to be invariant to order. > > > > I have some further surprising cases below that I'd also like to know > more > > about but just above will also be great. > > > > https://rpubs.com/emitanaka/unexpected-formula-eval > > > > Best, > > > > Emi > > > > *Dr. Emi Tanaka* | Lecturer in Statistics > > > > Faculty of Science, School of Mathematics and Statistics > > > > > > Secretary, NSW Branch, Statistical Society of Australia > > < > https://www.meetup.com/NSW-Branch-of-the-Statistics-Society-of-Australia/> > > > > Social Media Coordinator, Central, International Biometrics Society > > <https://twitter.com/IBSstats> > > > > > > *THE UNIVERSITY OF SYDNEY* > > 827, Carslaw F07 | The University of Sydney | NSW | 2006 > > *Phone:* +61 2 9351 3039 > > *Website:* * <http://sydney.edu.au/>*https://emitanaka.github.io/ > > *Twitter: *@statsgen > > > > CRICOS 00026A > > This email plus any attachments to it are confidential. > > Any unauthorised use is strictly prohibited. If you receive this email in > > error, please delete it and any attachments. Please think of our > > environment and only print this e-mail if necessary. > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > 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. > > ______________________________________________ > 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. >[[alternative HTML version deleted]]
Look at what terms() (hence lm()) does with such formulae:> str(terms(y~1*x))Classes 'terms', 'formula' language y ~ 1 * x ..- attr(*, "variables")= language list(y, x) ..- attr(*, "factors")= int(0) ..- attr(*, "term.labels")= chr(0) ..- attr(*, "order")= int(0) ..- attr(*, "intercept")= int 1 ..- attr(*, "response")= int 1 ..- attr(*, ".Environment")=<environment: R_GlobalEnv>> coef(lm(y~1*x, data=data.frame(y=1:10,x=log2(1:10))))(Intercept) 5.5 Bill Dunlap TIBCO Software wdunlap tibco.com On Fri, Oct 11, 2019 at 10:59 AM Richard M. Heiberger <rmh at temple.edu> wrote:> I can't duplicate your examples > This is what I see > > y ~ 1:x > y ~ 1:x > > Please try again in a vanilla R session, and send a reproducible example. > vanilla means start R from the operating system command line with > R --vanilla > > this prevents any of your initialization files from being loaded. See > ?Startup > for details. > > On Fri, Oct 11, 2019 at 1:05 PM Emi Tanaka <dr.emi.tanaka at gmail.com> > wrote: > > > > Hi, > > > > I'm wondering about some logics behind the following simplifications: > > > > y ~ 1:x simplifies to y ~ 1 > > y ~ x:1 simplifies to y ~ 1 > > y ~ x*1 simplifies to y ~ x > > y ~ 1*x simplifies to y ~ 1 > > > > Mainly I would have expected y ~ 1:x to simplify to y ~ x and the cross > > operator to be invariant to order. > > > > I have some further surprising cases below that I'd also like to know > more > > about but just above will also be great. > > > > https://rpubs.com/emitanaka/unexpected-formula-eval > > > > Best, > > > > Emi > > > > *Dr. Emi Tanaka* | Lecturer in Statistics > > > > Faculty of Science, School of Mathematics and Statistics > > > > > > Secretary, NSW Branch, Statistical Society of Australia > > < > https://www.meetup.com/NSW-Branch-of-the-Statistics-Society-of-Australia/> > > > > Social Media Coordinator, Central, International Biometrics Society > > <https://twitter.com/IBSstats> > > > > > > *THE UNIVERSITY OF SYDNEY* > > 827, Carslaw F07 | The University of Sydney | NSW | 2006 > > *Phone:* +61 2 9351 3039 > > *Website:* * <http://sydney.edu.au/>*https://emitanaka.github.io/ > > *Twitter: *@statsgen > > > > CRICOS 00026A > > This email plus any attachments to it are confidential. > > Any unauthorised use is strictly prohibited. If you receive this email in > > error, please delete it and any attachments. Please think of our > > environment and only print this e-mail if necessary. > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > 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. > > ______________________________________________ > 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. >[[alternative HTML version deleted]]