[R] predicting values from multiple regression

Ista Zahn izahn at psych.rochester.edu
Mon Mar 21 00:01:53 CET 2011


Hi Anna,
Maybe you can start again and tell us what you are trying to
accomplish. If you are trying to calculate predicted values for the
cases in the data set used to fit the model you don't need the newdata
argument at all. Just do

predict(model9)

If you are trying to do something else, please describe what that
something else is and I'm sure someone will help.

Best,
Ista

On Sun, Mar 20, 2011 at 7:56 PM, Anna Lee <ana-lee at web.de> wrote:
> Dear Ista!
>
> Thank you for replying. The point you made is exactly what's the
> problem: I want to predict the values at different points in space.
> calP stands for the water content at each sampling point (n=90) but I
> don't quite understand what R does. calP is my vector of measured data
> and I thought with the predict function the programm would calculate a
> value from the model function for every value of calP... ?
>
> 2011/3/20 Ista Zahn <izahn at psych.rochester.edu>:
>> Hi Anna,
>>
>> On Sun, Mar 20, 2011 at 2:54 PM, Anna Lee <ana-lee at web.de> wrote:
>>> Hey List,
>>>
>>> I did a multiple regression and my final model looks as follows:
>>>
>>> model9<-lm(calP ~ nsP + I(st^2) + distPr + I(distPr^2))
>>>
>>> Now I tried to predict the values for calP from this model using the
>>> following function:
>>>
>>> xv<-seq(0,89,by=1)
>>> yv<-predict(model9,list(distPr=xv,st=xv,nsP=xv))
>>
>> The second argument to predict.lm is newdata, which should be a
>> data.frame. see ?predict.lm.
>>
>> Beyond that though, I'm not sure what you are trying to accomplish.
>> The way you've set this up you would get predicted values for cases
>> like
>>
>> distPr     st     nsp
>> 0            0      0
>> 1            1      1
>> 2            2      2
>> .             .       .
>> 89          89     89
>>
>>
>> Is that really what you want?
>>
>> Best,
>> Ista
>>>
>>> The predicted values are however strange. Now I do not know weather
>>> just the model does not fit the data (actually all coefficiets are
>>> significant and the plot(model) shows a good shape) or wether I did
>>> something wrong with my prediction command. Does anyone have an
>>> idea???
>>>
>>> --
>>>
>>>
>>> Thanks a lot, Anna
>>>
>>> ______________________________________________
>>> 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.
>>>
>>
>>
>>
>> --
>> Ista Zahn
>> Graduate student
>> University of Rochester
>> Department of Clinical and Social Psychology
>> http://yourpsyche.org
>>
>
>
>
> --
>
>
>
> Der Inhalt dieser E-Mail ist vertraulich. Sollte Ihnen die E-Mail
> irrtümlich zugesandt worden sein, bitte ich Sie, mich unverzüglich zu
> benachrichtigen und die E-Mail zu löschen.
>
> This e-mail is confidential. If you have received it in error, please
> notify me immediately and delete it from your system.
>



-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org



More information about the R-help mailing list