in order to understand the output of one of my lme models I produced a little simpler example using lm (so no random factor). I noticed that my fitted model does not seem to fit the data correctly, as the predicted y-values deviate strongly from the given values when using predict(lm).
My data set is:
a = c(rep(1:10, 4)) b = c(10,20,30,40,50,60,70,80,90,100, 5,8,10,14,17,22,27,35,42,50, 90,82,73,64,56,48,40,33,25,18, 5,6,8,10,12,14,17,20,23,26) c = c(rep("male", 10), rep("female", 10), rep("male", 10), rep("female", 10)) d = c(rep("low", 20), rep("high", 20)) e = data.frame(yval = b, xval = a, sex = c, education = d)
Graphically it looks like this:
library(car) scatterplot(yval~xval | education, smooth = F, grid = T, spread = F, reg.line = T, data = e, xlab = "x", ylab = "y") scatterplot(yval~xval | sex, smooth = F, grid = T, spread = F, reg.line = T, data = e, xlab = "x", ylab = "y")
and the linear model is:
lm2 = lm(yval~xval+sex+xval:sex+education+xval:education, data = e) summary(lm2)
e_pred = e e_pred$pred = predict(lm2)
I get the predicted values which do not match the real data at all:
e = cbind(e,e_pred$pred)
Is this due to the fact, that there is more than one significant interaction?
Thanks a lot (in advance) for reading and perhaps answering!!