View source: R/pca.factor.analysis.R
pca.factor.analysis | R Documentation |
This function performs (1) a factor analysis on numeric data and PC loadings derived from said data, then subsequently (3) performs a hypergeometrix enrichment test to ask if a certain class of variables are enriched on a particular PC.
pca.factor.analysis( metabolitedata, pcloadings, sigthreshold = 0.3, feature_anno = feature_data$SUPER_PATHWAY )
metabolitedata |
a matrix or data frame of metabolite data |
pcloadings |
a matrix or data frame of pc loadings you wish to test |
sigthreshold |
Spearman's rho correlation threshold to declare an association between the numeric variable and a PC loading |
feature_anno |
a vector of variable annotations to perform the hypergeomtric enrichment on |
a list object of length 2: (1) a list object of enrichment_tables, and (2) the Spearman's correlation matrix between features and the PC loadings
## define a covariance matrix cmat = matrix(1, 4, 4 ) cmat[1,] = c(1, 0.8, 0.6, 0.2) cmat[2,] = c(0.8, 1, 0.7, 0.5) cmat[3,] = c(0.6, 0.7, 1, 0.6) cmat[4,] = c(0.2, 0.5, 0.6,1) ## simulate some correlated data (multivariable random normal) set.seed(1110) d1 = MASS::mvrnorm(n = 250, mu = c(5, 45, 25, 15), Sigma = cmat ) set.seed(1010) d2 = MASS::mvrnorm(n = 250, mu = c(5, 45, 25, 15), Sigma = cmat ) ## simulate some random data d3 = sapply(1:20, function(x){ rnorm(250, 40, 5) }) ex_data = cbind(d1,d2,d3) rownames(ex_data) = paste0("ind", 1:nrow(ex_data)) colnames(ex_data) = paste0("var", 1:ncol(ex_data)) ## annotation met_anno = c( rep("A", 10), rep("B", 10), rep("C", 8) ) ## PCA pca = prcomp(ex_data, center = TRUE, scale = TRUE) ## run pca.factor.analysis() ex_out = pca.factor.analysis(metabolitedata = ex_data, pcloadings = pca$x[,1:5], sigthreshold = 0.3, feature_anno = met_anno )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.