Re: [R] R quadreg

From: Petr Savicky <>
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?


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. mailing list PLEASE do read the posting guide 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 Please read the posting guide before posting to the list.

list of date sections of archive