khliland / pls

The pls R package
36 stars 3 forks source link

writing a loop for partial least square regression used for Test-Set-Calibration #11

Closed RJulianneR closed 5 years ago

RJulianneR commented 5 years ago

I am calculating predictions on Test-Set-Data (Calibration 70%, Validation 30%). As i have several different input datasets, i like to create a loop for the prediction. This doesnt work yet on my newdata (Validation-Set), so i would like to know how the code behind plsr is, as the output is a 'large mvr' and it is not really clear to me which parameters are taken when i use predict(x, newdata = y) or RMSEP(x, newdata = y)...

Thank you very much in advance.

bhmevik commented 5 years ago

You can view the code of the plsr function by simply typing plsr and hitting return. However, since plsr is simply a wrapper around mvr, it is probably more useful to look at that one. Also, viewing the code this way doesn't show you any comments in the code, so the best is probably to download the source code from CRAN or from the github repo, and look at the files in the R directory (for instance mvr.R). Also, the help files help(plsr) will tell you what the function is returning. To see the code for the predict method in the pls package, you would have to type pls:::predict.mvr, and for the RMSEP, pls:::RMSEP.mvr, since these functions are not exported. Since RMSEP is a wrapper for MSEP it is probably better to look at pls:::MSEP.mvr. Or again: look at the source code files instead.