Skip to content
Prev 304675 / 398506 Next

predict.lm(...,type="terms") question

On Sep 2, 2012, at 03:38 , David Winsemius wrote:

            
Yes. Lots of confusion going on here. 

First, data= is _always_ used as the _first_ place to look for variables, if things are not in it, search continues into the formula's environment. To be slightly perverse, notice that even this works:
Call:
lm(formula = y ~ x, data = d)

Coefficients:
(Intercept)            x  
    -0.2760       0.2328  

Secondly, what is predict(..., type="terms") supposed to have to do with inverting a regression equation? That's just not what it does, it only splits the prediction formula into its constituent terms.

Thirdly; no, you do not invert a regression equation by regressing y on x. That only works if you can be sure that your new (x, y) are sampled from the same population as the data, which is not going to be the case if you are fitting to data with, say, selected equispaced x values. There's a whole literature on how to do this properly, Google e.g. "inverse calibration" for enlightenment.