createPCAmodelmatrix: Create Principal Component Analysis (PCA) scores matrix

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/functions_aux.R

Description

Wrapper function for creating PCA scores to be used in a regression analysis.

Usage

1
2
3
4
5
6
7
8
createPCAmodelmatrix(
  data,
  ncomps,
  covarnames = colnames(data),
  center = TRUE,
  scale = TRUE,
  matrixonly = TRUE
)

Arguments

data

Matrix or data frame of data

ncomps

Number of PCA components to return.

covarnames

Names of variables or column numbers in data on which the PCA is to be run.

center

Logical indicator of whether data should be centered. Passed to prcomp.

scale

Logical indicator of whether data should be scaled. Passed to prcomp.

matrixonly

Logical indicator of whether only the model matrix should be returned, or the full output from prcomp.

Details

This is a wrapper around prcomp, which does the necessary computation.

Value

If matrixonly=TRUE, a matrix of PCA scores. Otherwise a list containing two elements: X, a matrix of scores, and pca, the output from prcomp.

Author(s)

Joshua Keller

See Also

createTPRSmodelmatrix, predkmeansCVest

Examples

1
2
3
4
5
n <- 100
d <- 15
X <- matrix(rnorm(n*d), ncol=d, nrow=n)
X <- as.data.frame(X)
mx <- createPCAmodelmatrix(data=X, ncomps=2)

predkmeans documentation built on Jan. 11, 2020, 9:29 a.m.