【问题标题】:Bootstrapping in R Not Displaying Relevant StatisticR中的自举不显示相关统计数据
【发布时间】:2017-05-03 23:41:58
【问题描述】:

我已经为我所在的课程启动了一个项目,当我尝试显示我想要的特定统计信息时,我遇到了错误。我正在使用 R 编程语言对 R Studio 中的统计数据进行编码。这是我的代码:

  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”是数字。非常感谢这里的任何帮助。

谢谢。

【问题讨论】:

  • 你使用什么包?像myreturns 这样的变量是如何定义的?如果您向reproducible example 提供示例输入数据,则最容易提供帮助。

标签: r statistics montecarlo statistics-bootstrap


【解决方案1】:

当您使用mosaic package 的do() 函数时,结果总是在名为result 的列中。您在这些括号中调用什么变量并不重要。

不要尝试访问boot$VaR,只需使用boot$result,例如

hist(boot$result)

它包含你想要的数据。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-16
    • 1970-01-01
    • 1970-01-01
    • 2020-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多