[R] Convert Class "numeric" to class "lm

Vladimir Eremeev wl2776 at gmail.com
Wed Feb 7 10:52:54 CET 2007



Simon P. Kempf wrote:
> 
> Background: 
> I have five multiple imputed datasets. For each datasets I have run a
> regression analysis and combined the regression coefficients according to
> Rubin (1987) rule. 
> 

So, now you have two numeric values: slope and offset. Right?


Simon P. Kempf wrote:
> 
> Now I want to use these combined regression coefficients on a different
> dataset (with the same variable names but different values) and check how
> good they can predict my dependent variable. Normally, it would use the
> predict.lm function which requires an object of class "lm". But my
> combined
> regression coefficients are an object of class "numeric". Therefore, I
> need
> to know how to convert an object of class "numeric" to a class "lm". 
> 

Given numeric values above, I would use multiplication and addition
operations on them and new data.

Try to explore the structure of instances of these classes with str().
You will see that an object of class "lm" is a list with several components
(12 afair). 
One of them is "coefficients".

You can also construct this object manually from scratch and use
predict.lm(), however, you must correctly create all list elements used by
this function. 
Typing predict.lm in R console will show you the body of this function.
Don't forget to assign the attribute "class".

RSiteSearch("construct lm") will take you here: 
http://finzi.psych.upenn.edu/R/Rhelp02a/archive/32782.html

-- 
View this message in context: http://www.nabble.com/-R--Convert-Class-%22numeric%22-to-class-%22lm-tf3185677.html#a8842534
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list