# WGCNA correcting p value for varying sample numbers in each of the trait columns

I am correcting a data frame of sample comparison using p value. However in some columns I have different sample numbers. Within the data frame I have 4 comparisons e.g B_R, R_C, B_C, C_C. They each have different sample numbers in the comparisons. I need to create a loop or change the code so I can vary the nSamples numbers for each of the comparisons. I have tried to do this for each comparison separately but to no avail. Does anyone have any suggestions? Thank you. I have tried..

nGenes = ncol(cells)
nSamples = nrow(cells)

MEs0 = moduleEigengenes(cells, moduleColors)$eigengenes MEs = orderMEs(MEs0) moduleTraitCor= cor(MEs, status, use="p") moduleTraitPvalue = corPvalueStudent(moduleTraitCor, nSamples) sizeGrWindow(10,6) textMatrix = paste(signif(moduleTraitCor, 2), "\n(", signif(moduleTraitPvalue, 1), ")", sep = "")  I have tried to code for the varying Sample numbers using: MEs0 = moduleEigengenes(cell, moduleColors)$$eigengenes MEs = orderMEs(MEs0) moduleTraitCor= cor(MEs, NR_status, use="p") moduleTraitPvalue$$B_R = corPvalueStudent(moduleTraitCor, 32) moduleTraitPvalue$$R_C = corPvalueStudent(moduleTraitCor, 31) moduleTraitPvalue$$B_C = corPvalueStudent(moduleTraitCor, 47) moduleTraitPvalue$C_C = corPvalueStudent(moduleTraitCor, 31)

sizeGrWindow(10,6)
textMatrix = paste(signif(moduleTraitCor, 2), "\n(",
signif(moduleTraitPvalue$$NR_R, moduleTraitPvalue$$R_C,
moduleTraitPvalue$$C_C, moduleTraitPvalue$$NR_C, 1), ")", sep = "")


## 1 Answer

You can use the function corAndPvalue. Simply replace the lines

moduleTraitCor= cor(MEs, status, use="p")
moduleTraitPvalue = corPvalueStudent(moduleTraitCor, nSamples)


by something like

cp = corAndPvalue(MEs, status)
moduleTraitCor = cp$$cor moduleTraitPvalue = cp$$p


corAndPvalue takes automatically into account the number of valid samples for each element of the resulting correlation matrix.

• Thank you so much, as always! Nov 21, 2019 at 13:21