title: R-squared on test data
body: <p>I fit a linear regression model on 75% of my data set that includes ~11000 observations and 143 variables:</p>
  
  <pre><code>gl.fit &lt;- lm(y[1:ceiling(length(y)*(3/4))] ~ ., data= x[1:ceiling(length(y)*(3/4)),]) #3/4 for training
  </code></pre>
  
  <p>and I got an R^2 of 0.43. I then tried predicting on my test data using the rest of the data:</p>
  
  <pre><code>ytest=y[(ceiling(length(y)*(3/4))+1):length(y)]
  x.test &lt;- cbind(1,x[(ceiling(length(y)*(3/4))+1):length(y),]) #The rest for test
  yhat &lt;- as.matrix(x.test)%*%gl.fit$coefficients  #Calculate the predicted values
  </code></pre>
  
  <p>I now would like to calculate the R^2 value on my test data. Is there any easy way to calculate that?</p>
  
  <p>Thank you</p>