pcr {analogue}  R Documentation 
Fits a palaeoecological transfer function model using principal component regression, using an optional transformation of the matrix of predictor variables when these are species abundance data.
## Default S3 method: pcr(x, y, ncomp, tranFun, ...) ## S3 method for class 'formula' pcr(formula, data, subset, na.action, ..., model = FALSE) Hellinger(x, ...) ChiSquare(x, apply = FALSE, parms) ## S3 method for class 'pcr' performance(object, ...) ## S3 method for class 'pcr' residuals(object, comps = NULL, ...) ## S3 method for class 'pcr' fitted(object, comps = NULL, ...) ## S3 method for class 'pcr' coef(object, comps = NULL, ...) ## S3 method for class 'pcr' screeplot(x, restrict = NULL, display = c("RMSE","avgBias","maxBias","R2"), xlab = NULL, ylab = NULL, main = NULL, sub = NULL, ...) ## S3 method for class 'pcr' eigenvals(x, ...)
x 
Matrix or data frame of predictor variables. Usually species
composition or abundance data for transfer function models. For

y 
Numeric vector; the response variable to be modelled. 
ncomp 
numeric; number of principal components to build models for. If not supplied the largest possible number of components is determined. 
tranFun 
function; a function or name of a function that
performs a transformation of the predictor variables 
formula 
a model formula. 
data 
an optional data frame, list or environment (or object
coercible by 
subset 
an optional vector specifying a subset of observations to be used in the fitting process. 
na.action 
a function which indicates what should happen when
the data contain 
model 
logical; If 
apply 
logical; should an existing tranformation, using precomputed metaparameters, be applied? 
parms 
list; a named list of parameters computed during model fitting that can be used to apply the transformation during prediction. 
object 
an object of class 
comps 
numeric; which components to return. 
restrict 
numeric; limit the number of components on the screeplot. 
display 
character; which model performance statistic should be drawn on the screeplot? 
xlab, ylab, main, sub 
character; labels for the plot. 
... 
Arguments passed to other methods. 
When applying crossvalidation (CV) to transfer function models, any transformation of the predictors must be applied separately during each iteration of the CV procedure to the part of the data used in fitting the model. In the same way, any samples to be predicted from the model must use any metaparameters derived from the training data only. For examle, centring is appled to the training data only and the variables means used to centre the training data are used to centre the test samples. The variable means should not be computed on a combination of the training and test samples.
When using PCR, we might wish to apply a transformation to the species data predictor variables such that the PCA of those data preserves a dissimilarity coefficient other than the Euclidean distance. This transformation is applied to allow PCA to better describe patterns in the species data (Legendre & Gallagher 2001).
How this is handled in pcr
is to take a usersupplied function
that takes a single argument, the matrix of predictor variables. The
function should return a matrix of the same dimension as the input. If
any metaparameters are required for subsequent use in prediction,
these should be returned as attribute "parms"
, attached to the
matrix.
Two example transformation functions are provided implementing the
Hellinger and Chi Square transformations of Legendre & Gallagher
(2001). Users can base their transformation functions on
these. ChiSquare()
illustrates how metaparameters should be
returned as the attribute "parms"
.
Returns an object of class "pcr"
, a list with the
following components:
fitted.values 
matrix; the PCR estimates of the response. The columns contain fitted values using C components, where C is the Cth column of the matrix. 
coefficients 
matrix; regression coefficients for the
PCR. Columns as per 
residuals 
matrix; residuals, where the Cth column represents a PCR model using C components. 
scores 

loadings 

Yloadings 

xMeans 
numeric; means of the predictor variables in the training data. 
yMean 
numeric; mean of the response variable in the training data. 
varExpl 
numeric; variance explained by the PCR model. These are the squares of the singular values. 
totvar 
numeric; total variance in the training data 
call 
the matched call. 
tranFun 
transformation function used. 
tranParms 
list; meta parameters used to computed the transformed training data. 
performance 
data frame; crossvalidation performance statistics for the model. 
ncomp 
numeric; number of principal components computed 
Gavin L. Simpson
## Load the Imbrie & Kipp data and ## summer seasurface temperatures data(ImbrieKipp) data(SumSST) ## normal interface and apply Hellinger transformation mod < pcr(ImbrieKipp, SumSST, tranFun = Hellinger) mod ## formula interface, but as above mod2 < pcr(SumSST ~ ., data = ImbrieKipp, tranFun = Hellinger) mod2 ## Several standard methods are available fitted(mod, comps = 1:4) resid(mod, comps = 1:4) coef(mod, comps = 1:4) ## Eigenvalues can be extracted eigenvals(mod) ## screeplot method screeplot(mod)