I believe I can manually compute response values from coefficients obtained using 'raw' polynomial predictor variables.
Example R code is
x <- seq(-2,2,length=100) # true function y <- 1.2*x^2 + 2.3*x + 3.4 # add noise eps <- rnorm(100, 0, 1) y <- y + eps df <- data.frame(x=x, y=y) # fit quadratic to noisy data points qfit <- lm(y ~ x + I(x^2), data=df) # manual predictions xmat <- cbind(1, x, x^2) yhat <- xmat %*% qfit$coeff
This yields the coefficients:
Coefficients: (Intercept) x I(x^2) 3.385 2.362 1.277
I could port that manual calculation to another programming language.
However, it appears using the function 'poly' is preferred on account of the correlation between x and x^2 in the above model, leading to the new fit
newfit <- lm( y ~ poly(x, degree=2), data=df)
and this yields different coefficients:
(Intercept) poly(x, degree = 2)1 poly(x, degree = 2)2 5.122729 27.549886 15.536953
The first question is whether it is really better or even necessary that poly with its orthogonal polynomials is used instead of raw predictors?
The second question is how to manually compute responses using the coefficients from the regression using the poly function? I need to do this because the model will be implemented in another program in another language.