Learn R Programming

mdatools (version 0.5.3)

pcares: Results of PCA decomposition

Description

pcares is used to store results for PCA decomposition of data.

Usage

pcares(scores, loadings, residuals, totvar, tnorm = NULL, ncomp.selected = NULL, ...)

Arguments

scores
matrix with score values (nobj x ncomp).
loadings
matrix with loading values (nvar x ncomp).
residuals
matrix with data residuals.
totvar
total variance for data matrix.
tnorm
vector with singular values for scores normalization.
ncomp.selected
selected number of components for decomposition.
...
other arguments supported by ldecomp.

Value

  • Returns an object (list) of class pcares and ldecomp with following fields:
  • scoresmatrix with score values (nobj x ncomp).
  • residualsmatrix with data residuals (nobj x nvar).
  • T2matrix with T2 distances (nobj x ncomp).
  • Q2matrix with Q2 distances (nobj x ncomp).
  • tnormvector with singular values used for scores normalization.
  • ncomp.selectedselected number of components.
  • expvarexplained variance for each component.
  • cumexpvarcumulative explained variance.

Details

In fact pcares is a wrapper for ldecomp - general class for storing results for linear decomposition X = TP' + E. So, most of the methods, arguments and returned values are inherited from ldecomp.

There is no need to create a pcares object manually, it is created automatically when build a PCA model (see pca) or apply the model to a new data (see predict.pca). The object can be used to show summary and plots for the results.

See Also

Methods for pcares objects: ll{ print.pcares shows information about the object. summary.pcares shows statistics for the PCA results. }

Methods, inherited from ldecomp class: ll{ plotScores.ldecomp makes scores plot. plotVariance.ldecomp makes explained variance plot. plotCumVariance.ldecomp makes cumulative explained variance plot. plotResiduals.ldecomp makes Q2 vs. T2 residuals plot. } Check also pca and ldecomp.

Examples

Run this code
### Examples for PCA results class

library(mdatools)

## 1. Make a model for every odd row of People data
## and apply it to the objects from every even row

data(people)
x = people[seq(1, 32, 2), ]
x.new = people[seq(1, 32, 2), ]

model = pca(people, scale = TRUE, cv = 1, info = 'Simple PCA model')
model = selectCompNum(model, 4)

res = predict(model, x.new)
summary(res)
plot(res)

## 1. Make PCA model for People data with autoscaling
## and full cross-validation and get calibration results


data(people)
model = pca(people, scale = TRUE, cv = 1, info = 'Simple PCA model')
model = selectCompNum(model, 4)

res = model$calres
summary(res)
plot(res)

## 2. Show scores plots for the results
par(mfrow = c(2, 2))
plotScores(res)
plotScores(res, cgroup = people[, 'Beer'], show.labels = TRUE)
plotScores(res, comp = c(1, 3), show.labels = TRUE)
plotScores(res, comp = 2, type = 'h', show.labels = TRUE)
par(mfrow = c(1, 1))

## 3. Show residuals and variance plots for the results
par(mfrow = c(2, 2))
plotVariance(res, type = 'h')
plotCumVariance(res, show.labels = TRUE, legend.position = 'bottomright')
plotResiduals(res, show.labels = TRUE, cgroup = people[, 'Sex'])
plotResiduals(res, ncomp = 2, show.labels = TRUE)
par(mfrow = c(1, 1))

Run the code above in your browser using DataLab