Entering edit mode
Hello! I am doing a WGCNA and during the process of external trait matching I stumbled upon the problem, that in order to correlate the eigengenes I need numeric values. The problem is that I have categorical variables. Am I allowed to just convert them to numeric values, or does this mess up the statistic?
traitData <- read.table("sampleinfo_comb.txt", header = T)
Samples <- rownames(datExpr0)
nGenes = ncol(datExpr0)
nSamples = nrow(datExpr0)
#In Order to correlate traits to the eigengenes, we need numeric values (Am I allowed to do it like this, or do I need another correlation method??)
traitData$Treatment <- as.numeric(factor(traitData$Treatment, levels = c("no_challenge", "challenge")))
traitData$Setting <- as.numeric(factor(traitData$Setting, levels = c("group", "isolation"))) #converts group=1 and isolation=2
traitData$Caste <- as.numeric(factor(traitData$Caste, levels = c("worker", "queen"))) # converts worker=1 and queen=2
#########
module.trait.correlation = cor(mergedMEs, traitData, use = "p") #p for pearson correlation coefficient
module.trait.Pvalue = corPvalueStudent(module.trait.correlation, nSamples)
This code generated some pretty results for my data, I am just not sure whether it is the appropiate method for my categorical traits?
Thanks for any advice!
