princmp: princmp

View source: R/princmp.r

princmpR Documentation

princmp

Description

Enhanced Output for Principal and Sparse Principal Components

Usage

princmp(
  formula,
  data = environment(formula),
  method = c("regular", "sparse"),
  k = min(5, p - 1),
  kapprox = min(5, k),
  cor = TRUE,
  sw = FALSE,
  nvmax = 5
)

Arguments

formula

a formula with no left hand side, or a numeric matrix

data

a data frame or table. By default variables come from the calling environment.

method

specifies whether to use regular or sparse principal components are computed

k

the number of components to plot, display, and return

kapprox

the number of components to approximate with stepwise regression when sw=TRUE

cor

set to FALSE to compute PCs on the original data scale, which is useful if all variables have the same units of measurement

sw

set to TRUE to run stepwise regression PC prediction/approximation

nvmax

maximum number of predictors to allow in stepwise regression PC approximations

Details

Expands any categorical predictors into indicator variables, and calls princomp (if method='regular' (the default)) or sPCAgrid in the pcaPP package (method='sparse') to compute lasso-penalized sparse principal components. By default all variables are first scaled by their standard deviation after observations with any NAs on any variables in formula are removed. Loadings of standardized variables, and if orig=TRUE loadings on the original data scale are printed. If pl=TRUE a scree plot is drawn with text added to indicate cumulative proportions of variance explained. If sw=TRUE, the leaps package regsubsets function is used to approximate the PCs using forward stepwise regression with the original variables as individual predictors.

A print method prints the results and a plot method plots the scree plot of variance explained.

Value

a list of class princmp with elements scores, a k-column matrix with principal component scores, with NAs when the input data had an NA, and other components useful for printing and plotting. If k=1 scores is a vector. Other components include vars (vector of variances explained), method, k.

Author(s)

Frank Harrell


Hmisc documentation built on June 22, 2024, 12:19 p.m.