提问人:Anne 提问时间:5/29/2023 更新时间:5/29/2023 访问量:40
如何使用加权数据在引导中使用索引
How to use indices in bootstrapping using weighted data
问:
我正在尝试引导两个数据变量 x 和 y 之间的加权差:
DF_Difference = data.frame(
x_M = c(-0.3, 0.3, -0.18, 0.02, 0.07, 0.11, 0.20, 0.8, 0.3, -0.4), # data x
x_W = c(50, 40, 70, 5, 15, 30, 32, 13, 9, 19), # weights of x
y_M = c(-0.6, 0.25, 0.1, 0.3, 0.3, -0.05, -0.5, 1, 0.05, -0.6), #data y
y_W = c(70, 8, 10, 39, 9, 49, 90, 77, 23, 75) # weights of y
)
我使用以下函数来执行此操作:
weighteddifference = function(d,i){
DF_Difference = d[i,]
Difference = DF_Difference$x_M - DF_Difference$y_M
WeightsDifference = 1 / (1/DF_Difference$x_W + 1/DF_Difference$y_W)
MeanDiff = wtd.mean(x=Difference, weights=WeightsDifference)
return(MeanDiff)
}
bootstrap =
boot(data = DF_Difference[, , drop=F],
statistic = weighteddifference,
R = 1000)
这段代码有效,但我不确定该函数如何处理数据和权重:它们是否仍然链接在一起?那么,例如 x = -0.3 的权重是否仍然为 50?我试图通过使用 i 作为索引来实现这一点,但我怀疑这是否正确。
答: 暂无答案
评论
stype
i
statistic
weighteddifference