MSEP and R2pred for Linear Model I have two set of data 1-Training (Calibrating) 2-Test. With these datasets, I


*

*Fit the model using first dataset.

*predict using the second dataset x-variables

*I have to test the closeness of the prediction

*In pls package, I can using following command to calculate RMSEP and R2,
predict(my.pls.model, newdata=my.new.data, nc=component.i.need)
However, I need the same thing for linear model. I found a package called mixlm, but this can only calculate RMSEP or R2pred for the first set, i.e. prediction made with calibration dataset not the test set. Is there some formula or function that I can use to calculate RMSE or R2pred for linear model.
 A: If you check the pls package documentation, you'll find that R2 and RMSEP are described (here). The documentation provides also a reference to Melvik and Rene (2004). Those two sources combined tell you that:
$$R^2 = 1 - \frac{SSE}{SST}$$
where $SST = \sum^n_{i=1} (y_i - \overline{y})^2 $ and $SSE = \sum^n_{i=1} (y_i - \hat{y}_i)^2 $. And MSEP is:
$$MSEP_{\text{test}} = \frac{1}{n_T} \sum^{n_T}_{i=1} \left( \hat{y}_{T,i} - y_{T,i} \right)^2 $$
that is computed over $T$ test sets, each of size $n_T$, where $\hat{y}_{T,i}$ an estimate computed on test set $T$.
In R that would be something like:
y_hat <- predict(model)
sst <- sum((y - mean(y))^2)
sse <- sum((y - y_hat)^2)
r_sq <- 1 - (sse/sst)
msep_T <- sum((y_hat - y)^2) / n

Reading Melvik and Rene (2004) paper would give you hints how to adapt this code to your needs (e.g. to apply it to different test-sets or cross-validation sets).
However, notice also what does authors of pls say about $R^2$:

For R2, this is the unadjusted $R^2$. It is overoptimistic and should
  not be used for assessing models.

