[R] problem with predict(...,type="terms")

Antonio.Gasparrini at lshtm.ac.uk Antonio.Gasparrini at lshtm.ac.uk
Mon Aug 3 17:18:31 CEST 2009


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
http://www.lshtm.ac.uk/people/gasparrini.antonio ( http://www.lshtm.ac.uk/pehru/ )




More information about the R-help mailing list