1.单样本资料与已知总体参数的非参数检验
# 总体中位数为2.15x = c(2.15,2.10,2.20,2.12,2.42,2.52,2.62,2.72,2.99,3.19,3.37,4.57)wilcox.test(x,mu = 2.15,conf.level = .95,alternative = 'greater')
2.配对设计资料的非参数检验
x1 = c(39,42,51,43,55,45,22,48,40,45,40,49)x2 = c(55,54,55,47,53,63,52,44,48,55,32,57)wilcox.test(x1,x2)
3.两组定量资料的非参数检验
统计检验data = data.frame(group = c(rep('A',9),rep('B',8)),value = c(11,15,10,18,11,20,24,22,25,13,14,10,8,16,9,17,21))wilcox.test(value~group,data = data)
可视化
p <- ggboxplot(data, x = "group", y = "value",fill = "group",palette = "jco", # 自动使用医学杂志配色xlab = 'group',ylab = 'value',add = 'jitter',width = 0.3,bxp.errorbar = T,bxp.errorbar.width = 0.3) p + geom_signif(xmin = 'A',xmax = 'B',y_position = 26,annotations = 'ns')
4.多组定量资料的非参数检验(类似单因子方差分析)
统计检验states <- data.frame(state.region, state.x77)kruskal.test(Illiteracy ~ state.region, data=states)
多重比较
p = pairwise.wilcox.test(states$Illiteracy, states$state.region,p.adjust.method = "BH")p = c(0.0071,0.0268,0.0268,0.0268)p.signif = ifelse(p < 0.05, ifelse(p < 0.01,ifelse(p < 0.001, '***', '**'),'*'),'ns')
可视化
annotation <- data.frame( start=c("Northeast", "Northeast","South","South"), end=c("South","North Central","West",'North Central'),y = c(3,3.2,3.4,3.6),label=p.signif)
p = ggboxplot(states, x = "state.region", y = "Illiteracy",fill = "state.region",bxp.errorbar = T,add = 'jitter',palette = 'jco', # 自定义色彩short.panel.labs = FALSE,xlab = '') +geom_signif(data = annotation,aes(xmin=start, xmax=end, annotations=label, y_position=y),manual=TRUE)
ggpar(p, x.text.angle = 45)
5.双因子非参数检验
多重比较stat.test <- compare_means(len ~ dose, data = ToothGrowth, group.by = "supp",method = "wilcox.test")p = stat.test$p.adjp.signif = ifelse(p < 0.05, ifelse(p < 0.01,ifelse(p < 0.001, '***', '**'),'*'),'ns')
可视化
annotation <- data.frame(supp= rep(c('VC','OJ'),each =3),start=c("0.5", "0.5",'1'), end=c('1','2','2'),y = c(34,38,36),label=unname(p.signif))
ggboxplot(ToothGrowth, x = "dose", y = "len",fill = "dose",bxp.errorbar = T,add = 'jitter',palette = c("#00AFBB", "#FC4E07",'#E7B800'), # 自定义色彩facet.by = "supp", short.panel.labs = FALSE,xlab = '') +geom_signif(data = annotation,aes(xmin=start, xmax=end, annotations=label, y_position=y),manual=TRUE)
如果觉得《统计学(五):非参数检验》对你有帮助,请点赞、收藏,并留下你的观点哦!