I'm currently trying to develop my understanding of ordered factors in R and using them as dependent variables in a linear model. I understand the outputs .L ,.Q and .C represent linear, quadratic and cubic but I'm wondering what is the "newx" that can be used the equations below to derive estimates for each level of my ordered factor.
I thought the "newx" was derived from the contr.poly() function but using this leads to a mismatch between my equation and the results derived from the predict() function. Can anyone help me understand what "newx" should be?
set.seed(101)
d <- data.frame(x=sample(1:4,size=30,replace=TRUE))
d$y <- rnorm(30,1+2*d$x,sd=0.01)
d$x = factor(d$x, labels=c("none", "some", "more", "a lot"))
Coefs <- coef(lm(y~ordered(x), d))
newx <- contr.poly(4)
predict(lm(y~ordered(x), d), newdata = data.frame(x = as.factor(c("none", "some", "more", "a lot"))))
Coefs[1]+(Coefs[2]*newx[1,1])+(Coefs[3]*newx[1,2]^2)+(Coefs[4]*newx[1,3]^3)
Coefs[1]+(Coefs[2]*newx[2,1])+(Coefs[3]*newx[2,2]^2)+(Coefs[4]*newx[2,3]^3)
Coefs[1]+(Coefs[2]*newx[3,1])+(Coefs[3]*newx[3,2]^2)+(Coefs[4]*newx[3,3]^3)
Coefs[1]+(Coefs[2]*newx[4,1])+(Coefs[3]*newx[4,2]^2)+(Coefs[4]*newx[4,3]^3)