Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 自举加权中值和置信区间_R - Fatal编程技术网

R 自举加权中值和置信区间

R 自举加权中值和置信区间,r,R,我使用下面的代码来引导中位数的置信区间,这很好 library(boot) data <- c(6, 11, 7, 8, 3, 9, 4, 1, 1, 8, 2, 2, 5, 3, 1) weight <- c(0.839432605459112, 0.774215027235327, 0.709256693551626, 0.809376516981207, 0.809698716683444, 0.880849581474519, 0.829263837448813, 1.803

我使用下面的代码来引导中位数的置信区间,这很好

library(boot)
data <- c(6, 11, 7, 8, 3, 9, 4, 1, 1, 8, 2, 2, 5, 3, 1)
weight <- c(0.839432605459112, 0.774215027235327, 0.709256693551626, 0.809376516981207, 0.809698716683444, 0.880849581474519, 0.829263837448813, 1.80390621483409, 1.12749447791778, 0.93389158146594, 1.07832286911631, 0.79541512406283, 1.06708509325217, 0.946752658104578, 0.968003233015867)
Mboot = boot(data, function(x,i) median(x[i]), R=10000)
boot.ci(Mboot, conf = 0.95,  type = c("norm", "basic" ,"perc"))
库(启动)

数据您只需将
数据
乘以
重量
,然后对产品进行引导

library(boot)
Mboot_w = boot(data * weight, function(x,i) median(x[i]), R=10000)
Mboot_w
boot.ci(Mboot_w, conf = 0.95,  type = c("norm", "basic" ,"perc"))

让我们来分析一下引导过程。基本上,
R=10000
生产了10000个样品,并更换了产品。 然后计算每个引导的中值。现在有了加权中间值的采样分布

df <- data * weight
weighted_medians <- replicate(10000, median(sample(df, length(df), replace = T)))
使用分位数,95%的置信区间为

quantile(boot_medians, c(.025, .975))

你能把
dput(数据)
放在你的问题里吗?此外,请指出您正在使用的重要软件包。请参阅更新的问题如果没有最小的可复制示例,则很难复制您的问题:。问题中指出的主要问题不是错误消息,而是如何使用置信区间引导加权中值,所以后面的部分可以忽略。好吧,如果我们不知道权重的话,我们就不能帮助你建立一个加权中值。你的数据只是一个向量,我们不知道向量中每个元素的权重。
quantile(boot_medians, c(.025, .975))