![](/img/trans.png)
[英]Bootstrapping sample means in R using boot Package, Creating the Statistic Function for boot() Function
[英]Bootstrapping in R Not Displaying Relevant Statistic
我已经为我所在的班级启动了一个项目,在尝试显示我想要的特定统计数据时,我遇到了错误。 我正在使用 R 编程语言对 R 工作室中的统计进行编码。 这是我的代码:
boot = do(20)*
{
horizon = 20
totalwealth = 10000
pweights = c(0.5, 0, 0, 0, 0.5)
holdings = pweights * totalwealth
wealthtracker = rep(0, horizon) # Set up a placeholder to track total wealth
for(today in 1:horizon) {
return.today = resample(myreturns, 1, orig.ids=FALSE)
holdings = holdings*(1+return.today)
totalwealth = sum(holdings)
wealthtracker[today] = totalwealth
}
VaR = unname(quantile(wealthtracker, p=0.05))
VaR
}
hist(boot$VaR)
当我尝试从我的样本统计数据中获取数据或构建直方图(在本例中为 VaR)时,会发生我遇到的错误。
每当我输入“boot$”时,接下来出现的应该是“VaR”和我的引导模型中的其他统计数据,但唯一显示的是“结果”。 当我输入命令以在引导程序 (bootstrap$VaR) 的上下文中返回任何带有 VaR 的内容时,我返回此错误 - 'x' 必须是数字。 这里的问题是我已经通过应用 unname 函数确保 'x' 是数字。 非常感谢这里的任何帮助。
谢谢。
当您使用镶嵌包的do()
函数时,结果始终位于名为result
的列中。 您在这些括号内调用什么变量并不重要。
不要尝试访问boot$VaR
,只需使用boot$result
,例如
hist(boot$result)
它包含您想要的数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.