Learn R Programming

rchemo (version 0.1-3)

xfit: Matrix fitting from a PCA or PLS model

Description

Function xfit calculates an approximate of matrix \(X\) (\(X_fit\)) from a PCA or PLS fitted on \(X\).

Function xresid calculates the residual matrix \(E = X - X_fit\).

Usage

xfit(object, X, ...)

# S3 method for Pca xfit(object, X, ..., nlv = NULL)

# S3 method for Plsr xfit(object, X, ..., nlv = NULL)

xresid(object, X, ..., nlv = NULL)

Value

For xfit:matrix of fitted values.

For xresid:matrix of residuals.

Arguments

object

A fitted model, output of a call to a fitting function.

X

The X-data that was used to fit the model object.

nlv

Number of components (PCs or LVs) to consider.

...

Optional arguments.

Examples

Run this code

n <- 6 ; p <- 4
X <- matrix(rnorm(n * p), ncol = p)
y <- rnorm(n)

nlv <- 3
fm <- pcasvd(X, nlv = nlv)
xfit(fm, X)
xfit(fm, X, nlv = 1)
xfit(fm, X, nlv = 0)

X - xfit(fm, X)
xresid(fm, X)

X - xfit(fm, X, nlv = 1)
xresid(fm, X, nlv = 1)

Run the code above in your browser using DataLab