Extract Information From a Fitted PLSR or PCR Model
Functions to extract information from
mvr objects: Regression
coefficients, fitted values, residuals, the model frame, the model
matrix, names of the variables and components, and the X
variance explained by the components.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
## S3 method for class 'mvr' coef(object, ncomp = object$ncomp, comps, intercept = FALSE, ...) ## S3 method for class 'mvr' fitted(object, ...) ## S3 method for class 'mvr' residuals(object, ...) ## S3 method for class 'mvr' model.matrix(object, ...) ## S3 method for class 'mvr' model.frame(formula, ...) prednames(object, intercept = FALSE) respnames(object) compnames(object, comps, explvar = FALSE, ...) explvar(object)
vector of positive integers. The components to include in the coefficients or to extract the names of. See below.
logical. Whether coefficients for the intercept should
be included. Ignored if
logical. Whether the explained X variance should be appended to the component names.
other arguments sent to underlying functions. Currently
only used for
These functions are mostly used inside other functions. (Functions
usually called through their generic functions
coef.mvr is used to extract the regression coefficients of a
model, i.e. the B in y = XB (for the Q in y = TQ
where T is the scores, see
Yloadings). An array of
c(nxvar, nyvar, length(ncomp)) or
length(comps)) is returned.
comps is missing (or is
coef()[,,ncomp[i]] are the coefficients for models with
ncomp[i] components, for i = 1, …, length(ncomp).
intercept = TRUE, the first dimension is nxvar +
1, with the intercept coefficients as the first row.
comps is given, however,
the coefficients for a model with only the component
i.e. the contribution of the component
comps[i] on the
residuals.mvr return the fitted values
and residuals, respectively. If the model was fitted with
na.action = na.exclude (or after setting the default
the fitted values (or residuals) corresponding to excluded
observations are returned as
NA; otherwise, they are omitted.
model.frame.mvr returns the model frame; i.e. a data frame with
all variables neccessary to generate the model matrix. See
model.frame for details.
model.matrix.mvr returns the (possibly coded) matrix used as
X in the fitting. See
compnames extract the
names of the X variables, responses and components,
intercept = TRUE in
the name of the intercept variable (i.e.
returned as well.
compnames can also extract component names
from score and loading matrices. If
explvar = TRUE in
explained variance for each component (if available) is appended to the component
names. For optimal formatting of the explained variances when not all
components are to be used, one should specify the desired components
with the argument
explvar extracts the amount of X variance (in per cent)
explained by for each component in the model. It can also handle
score and loading matrices returned by
coef.mvr returns an array of regression coefficients.
fitted.mvr returns an array with fitted values.
residuals.mvr returns an array with residuals.
model.frame.mvr returns a data frame.
model.matrix.mvr returns the X matrix.
compnames return a
character vector with the corresponding names.
explvar returns a numeric vector with the explained variances,
NULL if not available.
Ron Wehrens and Bjørn-Helge Mevik
1 2 3 4 5 6 7 8 9 10 11
data(yarn) mod <- pcr(density ~ NIR, data = yarn[yarn$train,], ncomp = 5) B <- coef(mod, ncomp = 3, intercept = TRUE) ## A manual predict method: stopifnot(drop(B[1,,] + yarn$NIR[!yarn$train,] %*% B[-1,,]) == drop(predict(mod, ncomp = 3, newdata = yarn[!yarn$train,]))) ## Note the difference in formatting: mod2 <- pcr(density ~ NIR, data = yarn[yarn$train,]) compnames(mod2, explvar = TRUE)[1:3] compnames(mod2, comps = 1:3, explvar = TRUE)
Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.