[R] predict from a multiple regression model

Chuck Cleland ccleland at optonline.net
Tue Jan 22 16:07:13 CET 2008


On 1/22/2008 9:50 AM, Fränzi Korner wrote:
> Hello
> 
>  
> 
> how can I predict from a lm-object over a range of values of one explanatory
> variable without having to specify values for all the other explanatory
> variables? 
> 
>  
> 
> e.g. 
> 
>  
> 
> mod<-lm(y~x1+x2+x3+x4)
> 
>  
> 
> x1.new<-seq(0, 100)
> 
> predict(mod, new=list(x1=x1.new))
> 
>  
> 
>  
> 
> Here, predict() does not work, since values for x2, x3 and x4 are missing.
> Is there a function or argument that, in such a case, averages or weights
> over the other explanatory variables, how it is done in Genstat? 

   You might consider effect() in the effects package by John Fox.  For 
example:

library(effects)

mod.pres <- lm(prestige ~ log(income, 10) + poly(education, 3) +
poly(women, 2), data=Prestige)

effect("poly(women,2)", mod.pres, xlevels=list(women = seq(0,100,20)))

  poly(women,2) effect
women
        0       20       40       60       80      100
47.71028 45.12385 44.53749 45.95121 49.36499 54.77883

> Thanks
> 
> Fränzi
> 
>  
> 
>  
> 
> ************************************************************************
> 
> Dr. Fränzi Korner-Nievergelt
> 
> oikostat - Statistische Analysen und Beratung
> 
> Ausserdorf 43
> 
> CH - 6218 Ettiswil
> 
> Tel.: +41 (0) 41 980 49 22
> 
> www.oikostat.ch
> 
> 
> 
> *************************************************************************
> 
> 
> 
> Schweizerische Vogelwarte
> 
> CH - 6204 Sempach
> 
> 
> 
> www.vogelwarte.ch
> 
> *************************************************************************
> 
> 
> 
> 
> 	[[alternative HTML version deleted]]
> 
> 
> 
> ------------------------------------------------------------------------
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


-- 
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894



More information about the R-help mailing list