Cliff Clive
2011-Oct-16 19:55 UTC
[R] Suppressing the Intercept in lm() when using a dataframe for the model
It's easy to run a linear regression on a simple model without an intercept just by doing this: lm(y ~ x1 + x2 -1) Is there a similar trick to suppress the intercept when your model is in a large dataframe and you don't want to write out the names of individual columns? -- View this message in context: http://r.789695.n4.nabble.com/Suppressing-the-Intercept-in-lm-when-using-a-dataframe-for-the-model-tp3910327p3910327.html Sent from the R help mailing list archive at Nabble.com.
Joshua Wiley
2011-Oct-16 20:19 UTC
[R] Suppressing the Intercept in lm() when using a dataframe for the model
On Sun, Oct 16, 2011 at 12:55 PM, Cliff Clive <cliffclive at gmail.com> wrote:> It's easy to run a linear regression on a simple model without an intercept > just by doing this: > > lm(y ~ x1 + x2 -1) > > > Is there a similar trick to suppress the intercept when your model is in a > large dataframe and you don't want to write out the names of individual > columns?Yep...same trick.> > -- > View this message in context: http://r.789695.n4.nabble.com/Suppressing-the-Intercept-in-lm-when-using-a-dataframe-for-the-model-tp3910327p3910327.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at 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. >-- Joshua Wiley Ph.D. Student, Health Psychology Programmer Analyst II, ATS Statistical Consulting Group University of California, Los Angeles https://joshuawiley.com/
David Winsemius
2011-Oct-16 22:23 UTC
[R] Suppressing the Intercept in lm() when using a dataframe for the model
On Oct 16, 2011, at 3:55 PM, Cliff Clive wrote:> It's easy to run a linear regression on a simple model without an > intercept > just by doing this: > > lm(y ~ x1 + x2 -1) > > > Is there a similar trick to suppress the intercept when your model > is in a > large dataframe and you don't want to write out the names of > individual > columns?Something along the lines of: lm(y ~ . -1, data=dfrm) But you do need to offer specific examples to get specific answers. (Hence the usual advice to read the Posting Guide.)>-- David Winsemius, MD Heritage Laboratories West Hartford, CT