Skip to content

Using predicted() in R

2 messages · flokke, David Winsemius

#
Dear all, 
I am a R user since about 3 weeks now and still struggeling with things that
must be very 
easy for you...
This week I am struggling with the function predict()

I want to use this function to get a 95% interval. 
I understand that you have to use it in such a way as: 

lm_examplemodel<- lm(y~x1 + x2 + x3)
newdata <- data.frame(x1 = ???, x2 = ???, x3 = ???)
predict(lm_examplemodel, newdata, interval = 'confidence')

 And here comes my questions. As you maybe already have guessed its about
the questions marks/
the values for the new data frame you have to use. 

I read in help(predict.lm) that you have to use a new data frame to be able
to use the predict 
function, but I dont know what values I have to assign to x1 and x2 ... to
create the new data set.
In the help function it says that you can use the fitted values, but when I
use the function: 

fitted(lm_examplemodel)
or fitted.values(lm_examplemodel)

I get many many columns. I think that the function gives a fitted value for
every Yi and Xi. 
SO how do I get those values? Do i have to use another function than fitted?
Or not the fitted 
values at all?


Thanks already so much!
Cheers,maria

--
View this message in context: http://r.789695.n4.nabble.com/Using-predicted-in-R-tp3934150p3934150.html
Sent from the R help mailing list archive at Nabble.com.
#
On Oct 24, 2011, at 2:45 PM, flokke wrote:

            
Many times the x1,x2,and x3 will be irregularly spaced.
You might want to create predictions on a regular grid for plotting  
functions htat require such. Obviously you would want to keep the  
values within the ranges of original values so you don't extrapolate  
beyond the range of measurements.
And you might be plotting the estimated and 95% ranges.
Perhaps:

x1=seq(range(x1)[1]:range(x1)[2], by=diff(range(x1))/10

... und so weiter.
That looks wrong. `fitted` should be one per record. You have not  
followed the advice to post real data so it is not possible to  
diagnose your error. Please read the Posting Guide.
David Winsemius, MD
West Hartford, CT