问题描述
在R中,我可以使用boot
函数(来自here)来计算某种统计量的估计值。
如何从std.error
函数的输出中将boot
或该估计值读入R变量?
使用来自ISL book的Boston
数据集进行简单的示例
get_mean <- function(data,index) {
return(mean(data[index]))
}
bootstrap_res <- boot(Boston$medv,get_mean,1000)
bootstrap_res
此打印
ORDINARY NONParaMETRIC BOOTSTRAP
Call:
boot(data = Boston$medv,statistic = get_mean,R = 1000)
Bootstrap Statistics :
original bias std. error
t1* 22.53281 0.007650791 0.4106622
如何将0.4106622
值放入R代码中的变量中?
例如我可以使用
mean_original <- bootstrap_res$t0
要将22.53281
读入mean_original
变量中。
如何读取报告的std.error?
查看boot
返回中的其他字段,我看不出明显的方法
> summary(bootstrap_res)
Length Class Mode
t0 1 -none- numeric
t 1000 -none- numeric
R 1 -none- numeric
data 506 -none- numeric
seed 626 -none- numeric
statistic 1 -none- function
sim 1 -none- character
call 4 -none- call
stype 1 -none- character
strata 506 -none- numeric
weights 506 -none- numeric
解决方法
简单地计算:
bootstrap_res
#Bootstrap Statistics :
# original bias std. error
#t1* 22.53281 -0.008953755 0.399066
sd(bootstrap_res$t)
#[1] 0.399066