Learn R Programming

analogue (version 0.17-7)

predict.pcr: Predicted values from a principal components regression

Description

Calculates predicted values from a fitted principal components regression model. Leave-one-out, bootstrap or n k-fold crossvalidated predictions are also implemented.

Usage

# S3 method for pcr
predict(object, newdata, ncomp = object$ncomp,
        CV = c("none", "LOO", "bootstrap", "kfold"),
        verbose = FALSE, nboot = 100, kfold = 10, folds = 5,
        ...)

Value

A matrix of predicted values with rows representing samples in

newdata and columns, the PCR components requested via

ncomp.

Arguments

object

a fitted model of class "pcr", the result of a call to pcr.

newdata

data frame of new observations for which predictions are sought.

ncomp

numeric; the PCR components for which predictions are sought. If ncomp = c, predictions for components 1:c are produced.

CV

character; the type of crossvalidation required. Currently, no crossvalidation methods are implemented.

verbose

logical; should progress on crossvalidation be printed to the console?

nboot

numeric; the number of bootstrap samples to draw.

kfold

numeric; the number of folds to split data into.

folds

numeric; the number of repetitions of k-fold CV.

...

arguments passed to other methods.

Author

Gavin L. Simpson

Details

predict.pcr arranges for any transformation applied to the training data to be applied to the newdata prior to prediction.

See Also

pcr

Examples

Run this code
## 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