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? Thanks, Knut -- View this message in context: http://r.789695.n4.nabble.com/R-quadreg-tp3328275p3328275.html Sent from the R help mailing list archive at Nabble.com.
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.