方法R实现函数描述
T-testt.test()比较两组(参数检验)
Wilcoxon testwilcox.test()比较两组(非参数检验)
ANOVAaov()或anova()比较多组(参数检验)
Kruskal-Walliskruskal.test()比较多组(非参数检验)

wilcox

wilcox.test(as.numeric(expression)~group,data=rt)

图片alt

图片alt

fisher

两分类变量相关性描述

tableStat <- table(cluster_clinical[,c("T","cluster")])
pStat <- fisher.test(tableStat)

图片alt

图片alt


pStat <- chisq.test(tableStat)

多个分组变量统计检验

图片alt

图片alt

library(ggplot2)
library(ggpubr)
plot_df_reshape <- reshape2::melt(expr_data_anno_13,id.vars="group",variable.name="genes")
plot_df_reshape$group <- factor(plot_df_reshape$group,levels = c("Tumor","Normal"),ordered = T)
compare_means <- compare_means(value ~ group, data = plot_df_reshape, 
              group.by = "genes")
write.csv(compare_means,file = "result/compare_means.csv",row.names = F,quote = F)
genes.y.group1group2pp.adjp.formatp.signifmethod
METTL3valueTumorNormal5.93E-084.20E-075.90E-08****Wilcoxon
METTL14valueTumorNormal3.48E-184.20E-17< 2e-16****Wilcoxon
WTAPvalueTumorNormal8.89E-085.30E-078.90E-08****Wilcoxon
RBM15valueTumorNormal0.58854967710.5885nsWilcoxon
ZC3H13valueTumorNormal0.91057658910.9106nsWilcoxon
ggplot(plot_df_reshape, aes(x= genes, y = value,fill=group)) +
  geom_violin(aes(fill = group),position = position_dodge(width = 0.8)) + #最大的不同
  geom_boxplot(show.legend = F,width=0.1,position = position_dodge(width = 0.8),outlier.colour = NA) +
  scale_fill_manual(values = c(brewer.pal(7, "Set2")[c(1, 2, 5)])) +#调颜色
  theme_classic() +#选主题
  theme(panel.background = element_rect(fill = "white", #框线
                                        colour = "black",
                                        size = 0.25),
        axis.line = element_line(colour = "black", size = 0.25),# x轴的轴线
        axis.title = element_text(size = 13, face = "plain", color = "black"),#x轴的标题
        axis.text = element_text(size = 12, face = "plain", color = "black"),
        axis.text.x= element_text(angle=90,hjust=0),
        ) +#图例位置
  xlab("") +#把group去掉
  ylab(paste0("Gene Expression"))+
  stat_compare_means(label = "p.format")

图片alt

图片alt

案例

化妆15(55)95(55)110
不化妆85(45)5(45)90
100100200
cluster1cluster2
<=659281
>65149133

参考