Re: [R] R quadreg

From: Petr Savicky <savicky_at_praha1.ff.cuni.cz>
Date: Mon, 28 Feb 2011 21:36:48 +0100

On Mon, Feb 28, 2011 at 08:41:02AM -0800, knut-o wrote:
> Hi
> I have a x-list and a y-list and I'm trying to make a line that goes ca.
> through the dots. I want to find a, b and c in ax^2 + bx + c.
> How to do?

Hi.

Try the following

  x <- rnorm(100)
  y <- 4*x^2 + 3*x + 2 + 0.2*rnorm(100)
  z <- poly(x, degree=2, raw=TRUE)

  lm(y ~ z)$coefficients
  (Intercept)          z1          z2 
     2.000131    3.013591    4.000884 

or also

  x2 <- x^2
  lm(y ~ x + x2)$coefficients

with the same result.

Hope this helps.

Petr Savicky.



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. Received on Mon 28 Feb 2011 - 20:38:43 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 28 Feb 2011 - 22:10:17 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive