Skip to content
antagomir edited this page Apr 5, 2015 · 81 revisions

Correlation analysis

Cross-correlate input variables between two data sets (samples x features matrices; matched samples assumed; correlations calculated between features). For instance, between phylotypes and environmental variables:

# Determine sample size
N <- ncol(l2.log10.simulated)
## Error in ncol(l2.log10.simulated): error in evaluating the argument 'x' in selecting a method for function 'ncol': Error: object 'l2.log10.simulated' not found
# Create some random sample information for the metadata
metadata.simulated <- data.frame(list(
              sampleID = colnames(l2.log10.simulated),
	      subjectID = paste("subjectID", rep(1:4, 5)),
	      group = sample(paste("group", rep(1:4, 5))),
	      time = paste("group", rep(1:4, 5)),
              age = runif(N, 0, 100),
              gender = sample(c("M", "F"), N, replace = TRUE),
              diet = sample(c("Apricots", "Beverages", "Carrots"), 
	      N, replace = TRUE)))
## Error in colnames(l2.log10.simulated): error in evaluating the argument 'x' in selecting a method for function 'colnames': Error: object 'l2.log10.simulated' not found
# Calculate correlations between metadata and profiling data
cc <- cross.correlate(metadata.simulated, t(l2.log10.simulated), 
      			mode = "table", p.adj.method = "BY")
## Error in t(l2.log10.simulated): error in evaluating the argument 'x' in selecting a method for function 't': Error: object 'l2.log10.simulated' not found
print(head(cc))
## Error in head(cc): error in evaluating the argument 'x' in selecting a method for function 'head': Error: object 'cc' not found

Matrix mode plus visualization for the similarity matrix:

cc <- cross.correlate(metadata.simulated, t(l2.log10.simulated), mode = "matrix")
## Error in t(l2.log10.simulated): error in evaluating the argument 'x' in selecting a method for function 't': Error: object 'l2.log10.simulated' not found
tmp <- PlotMatrix(t(cc$cor), type = "twoway")
## Error in eval(expr, envir, enclos): could not find function "PlotMatrix"

Clone this wiki locally