princomp(x, ...) ## S3 method for class 'formula': princomp(formula, data = NULL, subset, na.action, ...) ## Default S3 method: princomp(x, cor = FALSE, scores = TRUE, covmat = NULL, subset = rep(TRUE, nrow(as.matrix(x))), ...)
x, formula | a matrix, data frame, or formula. If you specify a matrix, the columns should correspond to variables and the rows to observations. If you specify a formula, do not place any variables on the left (response) side. |
data | a data frame or matrix. This argument is usually used only when you provide a formula. |
covmat | a list or matrix. You can specify a list of the form returned by cov.wt and cov.mve. Components must include center and cov. A cor component will not be used, however, an n.obs component, if present, will be used. If you specify a matrix, x is ignored. |
scores | a logical value, or an integer. If scores is TRUE, the function returns a matrix of scores for all of the components. If scores is numeric, then scores and loadings for the first scores components are returned. If scores is FALSE, scores are not computed. |
cor | a logical value. If TRUE, then the principal components are based on the correlation matrix rather than the covariance matrix. That is, the variables are scaled to have unit variance. |
na.action | a character string that specifies how to handle missing values (NAs). By default, an error is returned if missing values (NAs) are present. |
subset | the subset of the observations to use. |
... | other arguments passed in or from function. |
sdev | a vector of standard deviations of the principal components. |
loadings | an orthogonal matrix of class loadings that specifies the loadings. The first column is the linear combination of columns of x that define the first principal component, and so on. If argument scores is numeric, then this contains that number of columns. |
n.obs | number of observations on which the estimates are based. This may not be present if covmat was used. |
scores | scores of some or all of the principal components for the observations. |
center | vector of centers for the variables. |
scale | vector of numbers by which the variables are scaled. If cor = FALSE, these are all 1. If cor = TRUE, then scales is the square roots of the diagonal of the cov component of covmat, if present, and otherwise it is the standard deviations of the input data variables. |
terms | terms object of the formula. This is not present if a formula was not used. |
call | an image of the call to princomp. |
princomp(Sdatasets::prim4) # Use a robust estimate of the covariances and scale the variables prim4.pcr <- princomp(Sdatasets::prim4, covmat=cov.wt(Sdatasets::prim4), cor=TRUE) print(loadings(prim4.pcr), cutoff=.5)princomp(~ pre.mean + post.mean + pre.dev + post.dev, data=Sdatasets::wafer)
princomp(~ Unemployed + Employed, data=Sdatasets::longley, subset=Year >1956)