# Calculating RMSEC and RMSECV of PCA in R

I have been trying to calculate the root mean squares error of calibration (RMSEC) and the root mean squares error of cross validation (RMSECV) for a PCA model made in R using the mdatools package.

My dataset is too complex to upload, however I followed the same method as shown in the link below:

http://mdatools.com/mdatools/models-and-results.html

Am I right in saying that both RMSEC and RMSECV are calculated as the square root of the residuals^2 divided by the number of samples? From the cross validated model, I am given values for Q distance. Are these the data that I use as the residuals when calculating the RMSEC and RMSECV? If so, I would have Q residuals for the calibration model, and Q residuals for the cross validated model.

Thanks in advance

## 1 Answer

I'm trying to figure this out too, and it seems that RMSECV is related to PRESS as $$RMSECV = \sqrt\frac{PRESS}{n*p}$$ Where PRESS is the sum of Q-residuals of each sample against a cross validated model, n is your number of samples, and p, the number variables in the original dataset

Similarly, RESS is the sum of the Q-Residuals for each sample of the model against itself, so I imagine RMSEC is similarly defined using the model Q-residuals.