Antonio.Gasparrini at lshtm.ac.uk
2009-Aug-03 15:18 UTC
[R] problem with predict(...,type="terms")
Hello R users, I'm trying to understand the meaning of the results returned by the command 'predict' with type="terms". I thought it was the matrix with the fitted values for each term (value of predictor * related coef), but the calculation is different. I include an example below: y <- rnorm(10) x1 <- rnorm(10) x2 <- rnorm(10) model <- lm(y ~ x1 + x2) predict(model,type="terms")[1,] cbind(x1,x2)[1,] * t(coef(model)[2:3]) I guess the true result should be the second one. Maybe the command include some additional transformation? Any suggestion? Thanks for your time Antonio Gasparrini Public and Environmental Health Research Unit (PEHRU) London School of Hygiene & Tropical Medicine Keppel Street, London WC1E 7HT, UK Office: 0044 (0)20 79272406 - Mobile: 0044 (0)79 64925523 Skype contact: a.gasparrini lshtm.ac.uk/people/gasparrini.antonio ( lshtm.ac.uk/pehru )