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
1) 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) 2) set x2,x3 and x4 to and mean value that you understand as rasonable for your purpose] and 3) 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 <[EMAIL PROTECTED]> Para: r-help@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@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@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.