From: Milton Cezar Ribeiro <milton_ruser_at_yahoo.com.br>

Date: Tue, 22 Jan 2008 09:28:46 -0800 (PST)

mod<-lm(y~x1+x2+x3+x3,data=df)

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.

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. Received on Tue 22 Jan 2008 - 17:30:28 GMT

Date: Tue, 22 Jan 2008 09:28:46 -0800 (PST)

Hi Franzi,

Up to I know you can´t predict values without you have x2,x3 and x4 parameters. So you have three possible solution

- set x2, x3 and x4 to Zero, *but* it will depend so much of what you want, because if you set them to zero, it means that you are adjusting something like mod<-lm(y~x1)
- set x2,x3 and x4 to and mean value that you understand as rasonable for your purpose] and
- build a set of for () looping, with the ranges of x2, x3 and x4, and see what happens with the y, for each combination of x1-x2-x3-x4.

y<-runif(101)

x1<-sample(seq(0, 100)) x2<-seq(from=0,to=100,by=1) x3<-seq(from=0,to=100,by=1)^2 x4<-exp(seq(from=0,to=100,by=1)) df<-data.frame(cbind(y,x1,x2,x3,x4))

mod<-lm(y~x1+x2+x3+x3,data=df)

df.complete<-NULL

for (x2 in seq(from=0,to=100,by=20)) { for (x3 in seq(from=0,to=100,by=20)) { for (x4 in seq(from=0,to=100,by=20)) {

x1<-seq(0, 100, by=10)

df.new<-data.frame(cbind(x1,x2,x3,x4)) df.new$pred<-predict(mod,new=df.new) df.complete<-rbind(df.complete,df.new)}}}

head(df.complete,50)

summary(df.complete)

But you have a problema. If you have four dimensions (x1-x4), it is so hard to graph. In the case of two dimensions (like x1 and x2) you can use the function interp() function of akima´s packge to generate a 3d plot of your response variavel y-pred as a surface.

Good luck,

miltinho

Brazil

- Mensagem original ---- De: Fränzi Korner <fraenzi.korner_at_oikostat.ch> Para: r-help_at_r-project.org Enviadas: Terça-feira, 22 de Janeiro de 2008 11:50:03 Assunto: [R] predict from a multiple regression model

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?

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]]

-----Anexo incorporado-----

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.

armazenamento!

[[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. Received on Tue 22 Jan 2008 - 17:30:28 GMT

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.2.0, at Tue 22 Jan 2008 - 18:30:07 GMT.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*