
Calculates predicted values from a fitted principal components regression model. Leave-one-out, bootstrap or n k-fold crossvalidated predictions are also implemented.
# S3 method for pcr
predict(object, newdata, ncomp = object$ncomp,
CV = c("none", "LOO", "bootstrap", "kfold"),
verbose = FALSE, nboot = 100, kfold = 10, folds = 5,
...)
A matrix of predicted values with rows representing samples in
newdata
and columns, the PCR components requested via
ncomp
.
a fitted model of class "pcr"
, the result of a
call to pcr
.
data frame of new observations for which predictions are sought.
numeric; the PCR components for which predictions are
sought. If ncomp = c
, predictions for components 1:c
are produced.
character; the type of crossvalidation required. Currently, no crossvalidation methods are implemented.
logical; should progress on crossvalidation be printed to the console?
numeric; the number of bootstrap samples to draw.
numeric; the number of folds to split data into.
numeric; the number of repetitions of k-fold CV.
arguments passed to other methods.
Gavin L. Simpson
predict.pcr
arranges for any transformation applied to the
training data to be applied to the newdata
prior to
prediction.
pcr
## Load the Imbrie & Kipp data and
## summer sea-surface temperatures
data(ImbrieKipp)
data(SumSST)
## choose 10 samples to act as a test set, for illustration
take <- c(5,58,31,51,42,28,30,57,8,50)
## normal interface and apply Hellinger transformation
mod <- pcr(ImbrieKipp[-take, ], SumSST[-take], tranFun = Hellinger)
## predictions
predict(mod, ImbrieKipp[take, ], ncomp = 4)
## predictions
set.seed(123)
predict(mod, ImbrieKipp[take, ], ncomp = 4, CV = "bootstrap",
nboot = 100)
Run the code above in your browser using DataLab