Re: [R] R squared for lm prediction

2010-10-04 Thread Jeff Newmiller
Or use the summary function on the lm object. "Thomas Stewart" wrote: >I'm not sure I understand what you want, but here is a guess. > >Let y be the hold out response values. Let y.hat be the model predictions >for the corresponding ys. > >The key is to remember that R^2 = cor( y , y.hat )^2. >

Re: [R] R squared for lm prediction

2010-10-04 Thread Thomas Stewart
I'm not sure I understand what you want, but here is a guess. Let y be the hold out response values. Let y.hat be the model predictions for the corresponding ys. The key is to remember that R^2 = cor( y , y.hat )^2. So, cor( cbind(y,y.hat))[1,2]^2 should give you a measure you want. -tgs On

Re: [R] R squared for lm prediction

2010-10-04 Thread Joshua Wiley
Hi Brima, # Fit model model.lm <- lm(Sepal.Length ~ Petal.Length, data = iris[1:75,]) # Predict data for some new data pred.dat <- predict(model.lm, newdata = iris[76:150,]) # Calculate correlation between predicted values for new data # and actual values, then square cor(iris[1:75,"Sepal.Lengt