I have ussed lm to generate a basic line correlation: fit = lm(hours.of.sleep ~ ToSleep) Note: From "Bayesian Computation with R", Jim Albert, p. 7 I understand the simple y = mx + b line that this fits the data to. Now apparently I don't understand formulas. The documentation indicates that there is an implied "intercept" in the formula so now I want to try and fit the line to a second degree polynomial so I tried: ft = lm(hours.of.sleep ~ ToSleep ^ 2 + ToSleep) and I still seem to get results that indicate a slope intercept, y = mx + b, type of fit. Can anyone give me a short tutorial on the formula syntax? I would like to fit the data to 2nd and higher order polynomials, 1 / x, log(x), etc. I am sorry but I could not glean this information from the help page on lm. Thank you. Kevin
Hi Kevin,>> Can anyone give me a short tutorial on the formula syntax? ... I am sorry >> but I could not >> glean this information from the help page on lm.You can give yourself a very good tutorial by reading ?formula and Chapter 12 of file://localhost/C:/Program%20Files/R/R-2.7.1pat/doc/manual/R-intro.html Mark. rkevinburton wrote:> > I have ussed lm to generate a basic line correlation: > > fit = lm(hours.of.sleep ~ ToSleep) > > Note: From "Bayesian Computation with R", Jim Albert, p. 7 > > I understand the simple y = mx + b line that this fits the data to. Now > apparently I don't understand formulas. The documentation indicates that > there is an implied "intercept" in the formula so now I want to try and > fit the line to a second degree polynomial so I tried: > > ft = lm(hours.of.sleep ~ ToSleep ^ 2 + ToSleep) > > and I still seem to get results that indicate a slope intercept, y = mx + > b, type of fit. Can anyone give me a short tutorial on the formula syntax? > I would like to fit the data to 2nd and higher order polynomials, 1 / x, > log(x), etc. I am sorry but I could not glean this information from the > help page on lm. > > Thank you. > > Kevin > > ______________________________________________ > 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. > >-- View this message in context: http://www.nabble.com/Beginning-lm-tp18668114p18669143.html Sent from the R help mailing list archive at Nabble.com.
on 07/26/2008 10:37 AM rkevinburton at charter.net wrote:> I have ussed lm to generate a basic line correlation: > > fit = lm(hours.of.sleep ~ ToSleep) > > Note: From "Bayesian Computation with R", Jim Albert, p. 7 > > I understand the simple y = mx + b line that this fits the data to. > Now apparently I don't understand formulas. The documentation > indicates that there is an implied "intercept" in the formula so now > I want to try and fit the line to a second degree polynomial so I > tried: > > ft = lm(hours.of.sleep ~ ToSleep ^ 2 + ToSleep) > > and I still seem to get results that indicate a slope intercept, y > mx + b, type of fit. Can anyone give me a short tutorial on the > formula syntax? I would like to fit the data to 2nd and higher order > polynomials, 1 / x, log(x), etc. I am sorry but I could not glean > this information from the help page on lm.The help system is not intended to be a tutorial, but a reference showing the syntax of function calls, what they do, what they return, some potential gotchas, references/citations and a _limited_ number of common examples of use. The first place to start is to read "An Introduction to R", which is available with your R installation and online at: http://cran.r-project.org/doc/manuals/R-intro.html The apropos section in that document is "Statistical models in R": http://cran.r-project.org/doc/manuals/R-intro.html#Statistical-models-in-R which provides more in-depth examples, including your situation. There are also other books available for R listed here: http://www.r-project.org/doc/bib/R-books.html which will provide more generalized overviews of R, since subject focused books, such as Jim Albert's, will by necessity, have rather brief introductions to the language. There are also some contributed documents here: http://cran.r-project.org/other-docs.html HTH, Marc Schwartz