R 中的加权 Wilcoxon 检验 [英] Weighted Wilcoxon test in R

查看:31
本文介绍了R 中的加权 Wilcoxon 检验的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对两个样本 x 和 y 执行 Wilcoxon 检验,其中 x 和 y 是长度为 n 的数值向量.

I want to perform a Wilcoxon test on two samples x and y where x and y are numeric vectors of length n.

鉴于一些实验设计,我想给 x 中的一些条目一些权重.这些权重如何包含在 Wilcoxon 检验中?我找到了各种包:survey"、Hmisc"

Given some experimental design, I would like to give to some entries in x some weights. How can such weights be included in the Wilcoxon test? I found various packages: "survey", "Hmisc"

但是一个没有权重的简单测试并没有给我返回标准的 Wilcoxon 结果:例如:

but a simple test with no weights does not give me back the standard Wilcoxon result: for instance:

x=rnorm(n=100,mean=0,sd=1)
y=rnorm(n=100,mean=0.1,sd=1)
wilcox.test(x,y)
data:  x and y 
W = 4389, p-value = 0.1358

使用 WWest 函数:wwest(x,y)

with the WWest function: wwest(x,y)

Wald Test of H0: BETA1=0
TS: 0.0284 PVAL: 0.8665 

Drop Test of H0: BETA1=0
TS: 0.0406 PVAL: 0.8407 

我希望我说清楚了.

推荐答案

这是加权 Wilcox 检验的建议x 和 y 是要比较的向量,wx 是要应用于 x 的权重向量,

Here is a suggestion of a weighted Wilcox test x and y are the vectors to compare, wx is the vector of weights to be applied to x,

wwilcox = function( x, y, wx  ){

U = 0
## Loop over the selection branches
for( iy in y ){

## Neutral branches smaller or equal
smaller = which(  x < iy )
equal = which( x == iy )

## Count
sumSmaller = sum(wx[smaller])
sumEqual = sum(wx[equal]/2)
sumTot = sumSmaller + sumEqual

## Total rank
U = U + sumTot
}

## U statistics
nY = length(y)
nX = sum(wx)

## Large sample: U follows a Gaussian
mU = nY * nX / 2
sigU = sqrt( ( nY * nX * ( 1 + nY + nX ) ) / 12 )
zU = ( U - mU ) / sigU

## p-value, one-sided
pU = erfc( zU / sqrt(2) ) /2

return(pU)
}

## Complemantery error function
erfc = function(x) 2 * pnorm(x * sqrt(2), lower = FALSE)

欢迎任何评论!

这篇关于R 中的加权 Wilcoxon 检验的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆