简体   繁体   English

加权中值引导

[英]Weighted Median bootstrap

Currently I am obtaining 95% CI on the median by using this目前我通过使用这个获得了中位数的 95% CI

x<-rnorm(100)
        bootmed = apply(matrix(sample(x, rep=TRUE, 10^4*length(x)), nrow=10^4), 1, median)
    quantile(bootmed, c(.025, 0.975))[1]->a1
    quantile(bootmed, c(.025, 0.975))[2]->a2

the problem now is that i need to do this for a weighted Median.现在的问题是我需要为加权中位数执行此操作。 I use the weightedMedian function in the matrixStats package: matrixStats::weightedMedian我在matrixStats包中使用了weightedMedian函数: matrixStats::weightedMedian

so I do not only have x with the numbers but also y with the weights (runif(100)) - so now I calculate所以我不仅有带数字的 x,还有带权重的 y (runif(100)) - 所以现在我计算

weightedMedian(x,runif(100))

but how does the equivalent for the above bootstrap go?但是上述引导程序的等效项如何?

The ... argument of the apply() function allows you to pass optional arguments to your function. apply()函数的...参数允许您将可选参数传递给您的函数。 Alternatively, you can also define a custom function.或者,您也可以定义自定义函数。 Assuming that your median weights are identical for all rows, the answer to your question looks like this:假设所有行的中位数权重都相同,您的问题的答案如下所示:

x <- rnorm(100)
y <- rnorm(100)
M <- matrix(sample(x, rep=TRUE, 10^4*length(x)), nrow=10^4)

bootmed = apply(M, 1, weightedMedian, w=y)
# Or, alternatively..
bootmed = apply(M, 1, function(x) weightedMedian(x,y))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM