xfit: Matrix fitting from a PCA or PLS model

View source: R/xfit.R

xfitR Documentation

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 class 'Pca'
xfit(object, X, ..., nlv = NULL) 

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

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

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.

Value

For xfit:matrix of fitted values.

For xresid:matrix of residuals.

Examples


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)


rchemo documentation built on Sept. 11, 2024, 8:05 p.m.