[R] automated polynomial regression

Dieter Wirz didi.wirz at gmail.com
Thu May 14 18:03:46 CEST 2009


Dear all -
We perform some measurements with a machine that needs to be
recalibrated. The best calibration we get with polynomial regression.
The data might look like follows:

> true_y <- c(1:50)*.8
> # the real values
> m_y <- c((1:21)*1.1, 21.1, 22.2, 23.3 ,c(25:50)*.9)/0.3-5.2
> # the measured data
> x <- c(1:50)
> # and the x-axes
>
> # Now I do the following:
>
> m_y_2 <- m_y^2
> m_y_3 <- m_y^3
> mylm <- lm(true_y ~ m_y + m_y_2 + m_y_3) ; mylm

Call:
lm(formula = true_y ~ m_y + m_y_2 + m_y_3)

Coefficients:
(Intercept)          m_y        m_y_2        m_y_3
  1.646e+00    1.252e-01    2.340e-03   -9.638e-06

Now I can get the real result with
> calibration <- 1.646e+00 + 1.252e-01*m_y + 2.340e-03*m_y_2 - 9.638e-06* m_y_3
But I have to put the values "by hand" into the polynom.

Isn't there an easier, more direct way, or at least , is there a way
to access the coefficients of lm() for further calculations?

Thanks
Dieter




More information about the R-help mailing list