Hi, I'm new in WGCNA, and trying to learn. I'm using the second tutorial (female vs male), but in the third section of the tutorial (Relating the consensus modules to female set-specific modules) when I try to execute all pairwaise comparisons using the code chunk 4:
for (fmod in 1:nFemMods) for (cmod in 1:nConsMods) { femMembers = (femaleColors == femModules[fmod]); consMembers = (moduleColors == consModules[cmod]); pTable[fmod, cmod] = -log10(fisher.test(femMembers, consMembers, alternative = "greater")$p.value); CountTbl[fmod, cmod] = sum(femaleColors == femModules[fmod] & moduleColors == consModules[cmod]) }
I get an error saying that in fisher test, x and y should be same length. I don't know why I am getting this error, and after trying different things, the only reason that comes to my mind is maybe because gsg function removed different number of genes from my female and male groups (58 genes removed from female data, but 17 genes removed from male data). Can this be a reason for the error? If yes, what do I need to do about it? If not, what might be the reason? Thanks for any help/advice,
It worked. Thank you very much
Hi, I am also new to WGCNA. I am also getting the same error i.e. "Error in fisher.test(femMembers, consMembers, alternative = "greater") : 'x' and 'y' must have at least 2 levels". I tried the above solution but it could not solve the error as my femaleColors and moduleColors have same number of genes, if this was creating issue. The script says
for (fmod in 1:nFemMods) for (cmod in 1:nConsMods) { femMembers = (femaleColors.common == femModuleLabels[fmod]); consMembers = (moduleColors.common == consModules[cmod]); pTable[fmod, cmod] = -log10(fisher.test(femMembers, consMembers, alternative = "greater")$p.value); CountTbl[fmod, cmod] = sum(femaleColors.common == femModules[fmod] & moduleColors.common == consModules[cmod]) }
femMembers and consMembers in my case are logicals having TRUE and FALSE. Is it okay? How can fisher.test be applied on logicals?
Please help. Thanks in advance.
I am having the same error as in the first post. I applied the code from Peter and after running the code I get:
In my case femMembers and conMembers are logicals but empty....
EDIT: I solved the problem, maybe it will be useful for someone else - my error was because of loading not the right file! I forgot to load the Input data first.
Here is my code corrected: