美文网首页想法心理简友广场
R语言:B-M中位数检验和WMW检验

R语言:B-M中位数检验和WMW检验

作者: Cache_wood | 来源:发表于2022-04-19 08:47 被阅读0次

@[toc]

B-W检验

Brown-Mood检验与符号检验的思想类似,仅比较了两组数据的符号;类似于单样本的Wilcoxon符号秩检验,利用更多信息构造检验



BM.test<-function(x,y,alt='two.sided')
{
  xy<-c(x,y)
  m<-length(x)
  n<-length(y)
  md.xy<-median(xy)
  t.val<-sum(xy>md.xy)
  A<-sum(x>md.xy)
  count.table<-matrix(c(A,m-A,m,t.val-A,n-(t.val-A),n,t.val,m+n-t.val,m+n),
                      nr=3,nc=3,byrow = F)
  colnames(count.table)<-c('X','Y','X+Y')
  row.names(count.table)<-c('>MXY','<MXY','TOTAL')
  if(alt=='two.sided'){p.value=2*min(phyper(A,m,n,t.val),
                                     phyper(A-1,m,n,t.val,lower.tail=F))}
  if(alt=='greater'){p.value=phyper(A-1,m,n,t.val,lower.tail = F)}
  if(alt=='less'){p.value=phyper(A,m,n,t.val)}
  list(count.table=count.table,p.value=p.value)
}
x<-c(698,688,675,656,655,648,640,639,620)
y<-c(780,754,740,712,693,680,621)
BM.test(x,y)
$count.table
      X Y X+Y
>MXY  2 6   8
<MXY  7 1   8
TOTAL 9 7  16

$p.value
[1] 0.04055944

在显著性水平𝜶=𝟎.𝟎𝟓时, 𝒑值< 𝜶,拒绝原假设,认为两个不同品牌显示器在不同商场的零售价格存在差异

同样可以使用package来直接调用mood.test函数

library('RVAideMemoire')
response<-c(x,y)
fact<-c(rep('A',length(x)),rep('B',length(y)))
fact<-as.factor(fact)
mood.medtest(response~fact)
    Mood's median test

data:  response by fact
p-value = 0.04056
library('coin')
median_test(response~fact,distribution='exact')
    Exact Two-Sample Brown-Mood Median Test

data:  response by fact (A, B)
Z = -2.4398, p-value = 0.04056
alternative hypothesis: true mu is not equal to 0

WMW检验

在原假设下, 𝑾_{𝑿𝒀}𝑾_{𝒀𝑿}同分布,称为Mann-Whitney统计量
Mann-Whitney检验(Mann-Whitney于1947年提出,不等样本)与两样本的Wilcoxon秩和检验(Wilcoxon于1945年提出,等样本)等价,因此也称为Wilcoxon-Mann-Whitney检验

weight.low<-c(134,146,104,119,124,161,107,83,113,129,97,123)
weight.high<-c(70,118,101,85,112,132,94)
wilcox.test(weight.high,weight.low)
wilcox.test(weight.high,weight.low,exact = F)

不带修正

    Wilcoxon rank sum exact test

data:  weight.high and weight.low
W = 22, p-value = 0.1003
alternative hypothesis: true location shift is not equal to 0

带修正

    Wilcoxon rank sum test with continuity
    correction

data:  weight.high and weight.low
W = 22, p-value = 0.09934
alternative hypothesis: true location shift is not equal to 0

Mood方差检验

从秩的角度很难区分样本是否分散的问题。

前提:Mood检验法假定两位置参数相等,所以在采用Mood检验之前需要进行两样本位置参数检验。

x<-c(4,5,6,5,7,10,12)
y<-c(6,7,2,8,9,9,8)
mood.test(x,y)
    Mood two-sample test of scale

data:  x and y
Z = 1.6514, p-value = 0.09865
alternative hypothesis: two.sided

Moses方差检验

Moses于1963年提出一种无需事先假定两分布位置参数相等的检验两总体方差相等的方法,应用较广。

x<-c(8.2,10.7,7.5,14.6,6.3,9.2,11.9,5.6,12.8,5.2,4.9,13.5)
y<-c(4.7,6.3,5.2,6.8,5.6,4.2,6.0,7.4,8.1,6.5)
VarRank<-function(x,y,K=3)
{
  m1<-floor(length(x)/K)
  m2<-floor(length(y)/K)
  x.VR<-NULL
  y.VR<-NULL
  x.temp<-x
  y.temp<-y
  for (r in 1:m1){
    x.index<-sample(1:length(x.temp),K)
    x.VR<-c(x.VR,var(x.temp[x.index])*(K-1))
    x.temp<-x.temp[-x.index]
  }
  for (s in 1:m2){
    y.index<-sample(1:length(y.temp),K)
    y.VR<-c(y.VR,var(y.temp[y.index])*(K-1))
    y.temp<-y.temp[-y.index]
  }
  list(m1=m1,m2=m2,x.VR=x.VR,y.VR=y.VR)
}
re<-VarRank(x,y)
wilcox.test(re$x.VR,re$y.VR)
    Wilcoxon rank sum exact test

data:  re$x.VR and re$y.VR
W = 12, p-value = 0.05714
alternative hypothesis: true location shift is not equal to 0

相关文章

  • R语言:B-M中位数检验和WMW检验

    @[toc] B-W检验 Brown-Mood检验与符号检验的思想类似,仅比较了两组数据的符号;类似于单样本的Wi...

  • R语言统计检验

    R语言的各种检验 1、W检验(Shapiro–Wilk (夏皮罗–威克尔 ) W统计量检验) 检验数据是否符合正态...

  • Fisher's exact test

    目录 适用实例 计算原理 计算实例3.1 解答过程3.2 R语言代码 Fisher精确检验和卡方检验的选择 1. ...

  • 非参检验

    总览 参数检验非参检验工具t检验、方差分析卡方检验、中位数检验特点正态分布、定距非正态、定类、定序 卡方检验是与期...

  • R语言T检验

    我们比较的对象是南方和非南方各州,因变量为监禁的概率。一个针对两组的独立样本t检验可以用于检验两个总体的均值相等的...

  • R语言-方差检验

    方差检验 对实验数据检验方差相等的正态分布总体均值是否相等。判断各因素对试验指标影响是否显著。根据影响实验指标条件...

  • R语言t检验

    本文首发于公众号:医学和生信笔记 医学和生信笔记,专注R语言在临床医学中的使用,R语言数据分析和可视化。主要分享R...

  • R语言ggstatsplot包做T检验

    R语言用ggstatsplot包做方差分析和绘图R语言ggstatsplot包做卡方检验 单样本均值比较 1、点图...

  • R语言与统计-3:卡方检验

    R语言与统计-1:t检验与秩和检验[https://www.jianshu.com/p/ba629f6ae85d]...

  • R语言与统计-5:Logistic回归

    R语言与统计-1:t检验与秩和检验[https://www.jianshu.com/p/ba629f6ae85d]...

网友评论

    本文标题:R语言:B-M中位数检验和WMW检验

    本文链接:https://www.haomeiwen.com/subject/rveosrtx.html