统计学(五):非参数检验

1.单样本资料与已知总体参数的非参数检验

# 总体中位数为2.15
x = 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.adj
p.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) 

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值