predict.mvr {pls} | R Documentation |
Prediction for mvr (PCR, PLSR) models. New responses or scores are predicted using a fitted model and a new matrix of observations.
## S3 method for class 'mvr': predict(object, newdata, comps = 1:object$ncomp, type = c("response", "scores"), cumulative = TRUE, ...)
object |
an mvr object. The fitted model |
newdata |
a data frame. The new data. If missing, the training data is used. |
comps |
vector of positive integers. The components to use in the prediction. See below. |
type |
character. Whether to predict scores or response values |
cumulative |
logical. How the elements of comps are
interpreted. Ignored if type is "scores" . See below |
... |
further arguments. Currently not used |
When type
is "response"
(default), predicted response
values are returned. If cumulative
is TRUE
, the
elements of comps
are interpreted cumulatively,
i.e. predictions for models with comps[1]
components,
comps[2]
components, etc., are returned. Otherwise, predicted
response values for a single model with the exact components in
comps
are returned.
When type
is "scores"
, predicted score values are
returned for the components given in comps
.
It is also possible to supply a matrix instead of a data frame as
newdata
, which is then assumed to be the X data matrix.
Note that the usual checks for the size and type of the data are then
omitted. Also note that this is
only possible with predict
; it will not work in
functions like predplot
, RMSEP
or
R2
, because they also need the response variable of the new
data.
When type
is "response"
, a three dimensional array of
predicted response values is returned. The dimensions correspond to
the observations, the response variables and the model sizes,
respectively.
When type
is "scores"
, a score matrix is returned.
A warning message like 'newdata' had 10 rows but variable(s)
found have 106 rows means that not all variables were found in the
newdata
data frame. This (usually) happens if the formula
contains terms like NIR$X
. Do not use such terms; use the
data
argument instead. See mvr
for details.
Ron Wehrens and Bjørn-Helge Mevik
mvr
, summary.mvr
,
coef.mvr
, plot.mvr
data(NIR) nir.mvr <- mvr(y ~ X, ncomp = 5, data = NIR[NIR$train,]) ## Predicted responses for models with 1, 2, 3 and 4 components pred.resp <- predict(nir.mvr, comps = 1:4, newdata = NIR[!NIR$train,]) ## Predicted responses for a single model with components 1, 2, 3, 4 predict(nir.mvr, comps = 1:4, cumulative = FALSE, newdata = NIR[!NIR$train,]) ## Predicted scores predict(nir.mvr, comps = 1:3, type = "scores", newdata = NIR[!NIR$train,])