方法 | R实现函数 | 描述 |
T-test | t.test() | 比较两组(参数检验) |
Wilcoxon test | wilcox.test() | 比较两组(非参数检验) |
ANOVA | aov()或anova() | 比较多组(参数检验) |
Kruskal-Wallis | kruskal.test() | 比较多组(非参数检验) |
wilcox
wilcox.test(as.numeric(expression)~group,data=rt)
fisher
两分类变量相关性描述
tableStat <- table(cluster_clinical[,c("T","cluster")])
pStat <- fisher.test(tableStat)
pStat <- chisq.test(tableStat)
多个分组变量统计检验
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. | group1 | group2 | p | p.adj | p.format | p.signif | method |
METTL3 | value | Tumor | Normal | 5.93E-08 | 4.20E-07 | 5.90E-08 | **** | Wilcoxon |
METTL14 | value | Tumor | Normal | 3.48E-18 | 4.20E-17 | < 2e-16 | **** | Wilcoxon |
WTAP | value | Tumor | Normal | 8.89E-08 | 5.30E-07 | 8.90E-08 | **** | Wilcoxon |
RBM15 | value | Tumor | Normal | 0.588549677 | 1 | 0.5885 | ns | Wilcoxon |
ZC3H13 | value | Tumor | Normal | 0.910576589 | 1 | 0.9106 | ns | Wilcoxon |
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")
案例
| 男 | 女 | |
化妆 | 15(55) | 95(55) | 110 |
不化妆 | 85(45) | 5(45) | 90 |
| 100 | 100 | 200 |
| cluster1 | cluster2 |
<=65 | 92 | 81 |
>65 | 149 | 133 |
参考