Learn R Programming

pls (version 1.1-0)

coef.mvr: Extract Information From a Fitted PLSR or PCR Model

Description

Functions to extract information from mvr objects: Regression coefficients, the model frame, the the model matrix, names of the variables and components, and the $X$ variance explained by the components.

Usage

## S3 method for class 'mvr':
coef(object, comps = object$ncomp, intercept = FALSE,
     cumulative = TRUE, \dots)
## S3 method for class 'mvr':
model.matrix(object, \dots)
## S3 method for class 'mvr':
model.frame(formula, \dots)
prednames(object, intercept = FALSE)
respnames(object)
compnames(object, comps = 1:object$ncomp, explvar = FALSE)
explvar(object)

Arguments

Value

  • coef.mvr returns an array of regression coefficients. model.frame.mvr returns a data frame. model.matrix.mvr returns the $X$ matrix.

    prednames, respnames and compnames return a character vector with the corresponding names.

    explvar returns a numeric vector with the explained variances.

encoding

latin1

Details

Except for coef.mvr, these functions are mostly used inside other functions. coef.mvr is used to extract the regression coefficients of a model, i.e. the $B$ in $y = XB$. An array of dimension c(nxvar, nyvar, length(comps)) is returned.

If cumulative = TRUE, coef()[,,comps[i]] are the coefficients for models with comps[i] components, for $i = 1, \ldots, length(comps)$. Also, if intercept = TRUE, the first dimension is $nxvar + 1$, with the intercept coefficients as the first row.

If cumulative = FALSE, however, coef()[,,comps[i]] are the coefficients for a model with only the component comps[i], i.e. the contribution of the component comps[i] on the regression coefficients.

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 model.matrix for details.

prednames, respnames and compnames extract the names of the $X$ variables, responses and components, respectively. With intercept = TRUE in prednames, the name of the intercept variable (i.e. "(Intercept)") is returned as well. If explvar = TRUE in compnames, the explained variance for each component 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 comps.

explvar extracts the amount of $X$ variance (in per cent) explained by for each component in the model.

See Also

mvr

Examples

Run this code
data(NIR)
mod <- pcr(y ~ X, data = NIR[NIR$train,], ncomp = 5)
B <- coef(mod, comps = 3, intercept = TRUE)
## A manual predict method:
stopifnot(drop(B[1,,] + NIR$X[!NIR$train,] %*% B[-1,,]) ==
          drop(predict(mod, comps = 3, newdata = NIR[!NIR$train,])))

## Note the difference in formatting:
mod2 <- pcr(y ~ X, data = NIR[NIR$train,])
compnames(mod2, explvar = TRUE)[1:3]
compnames(mod2, comps = 1:3, explvar = TRUE)

Run the code above in your browser using DataLab