makeDat: makeDat: creates simulated data based on a sparse PCA model

Description Usage Arguments Value Examples

View source: R/makeData.R

Description

A function that generates a realistic dataset based on a sparse PCA model X = XWP^T, with a sparse W and with W = P and W^T W = I

Usage

1
makeDat(n, comdis, variances)

Arguments

n

The number of objects the data should have

comdis

A matrix specifying the zero structure of W, the data will have ncomp = ncol(comdis) "important components" and J = nrow(comdis) variables

variances

specifying the variances of the J components these are the J eigenvalues of X^T X

ncomp

The number of components that are of interest

Value

A list with the following items:
X A data matrix generated from MASS::mvrnorm() with a zero mean structure and Sigma = P %*% diag(variances) %*% t(P), empirical is set FALSE
P A matrix of dimension J x J, with the loadings/weights the first Q columns have the sparsity structure specified in comdis, the other Q-J columns are non-sparse.
Sigma The covariance matrix that is used to generate the data from Sigma = P %*% diag(variances) %*% t(P)
In case of failure the function returns NA. The function can fail if the comdis structure specified in P is not possible, i.e. linear dependency

Examples

1
2
3
4
5
6
7
ncomp <- 3 
J <- 30
comdis <- matrix(1, J, ncomp)
comdis <- sparsify(comdis, 0.7) #set 70% of the 1's to zero
variances <- makeVariance(varianceOfComps = c(100, 80, 70), J = J, error = 0.05) #create realistic eigenvalues
dat <- makeDat(n = 100, comdis = comdis, variances = variances)
 

trbKnl/sparseWeightBasedPCA documentation built on July 22, 2020, 10:29 p.m.