【问题标题】:distr package: two random variable multiplication operation errordistr 包:两个随机变量乘法运算错误
【发布时间】:2019-05-23 18:58:30
【问题描述】:

我一直在研究一个大型财务模型,并试图对数据中的不确定性进行建模。为此,我一直将变量建模为正态分布(我知道,我可能应该使用 Weibull 或其他什么,但鉴于我的时间限制,目前这只是最简单的。

我找到了distr 包,它是统计对象数学的绝妙实现,但我不知道如何让乘法起作用,因为我正在处理数百万美元。我认为我重载了包中的一些函数,因为它们旨在处理 X ~ [0,1] 而不是 X_mean = 70000, X_sd = 250 之类的数据,这些数据代表财务不确定性。

代码如下:

```{r one more thing}
library(distr)
library(tidyverse)

distroptions("DefaultNrFFTGridPointsExponent" = 50)
distroptions("DefaultNrGridPoints" = 2^50)

Containers <- Norm(mean=71000, sd=250)     
# Containers is how many containers we own in the wild
Container_Unit_Cap_Cost <- Norm(mean=85,sd=2) 
# Container_Unit_Cap_Cost is the unit cost to acquire new containers
Container_Total_Cap_Cost <- Containers * Container_Unit_Cap_Cost            
# Container_Total_Cap_Cost is product distribution of the two previous uncertain variables

xlim_min <- Container_Total_Cap_Cost@gaps[1,2]
xlim_max <- Container_Total_Cap_Cost@gaps[2,2]

ggplot(tibble(x = c(xlim_min, xlim_max)), aes(x)) +
  stat_function(fun = conv@d, n = 101) +   
  scale_y_continuous() + 
  theme_dark()

```

这导致了错误

Grid for approxfun too wide, increase DefaultNrFFTGridPointsExponentError in seq.default(from = lower, to = upper, by = h) : 'by' argument is much too small

来自 RStudio 的以下回溯

14. stop("'by' argument is much too small")
13. seq.default(from = lower, to = upper, by = h)
12. seq(from = lower, to = upper, by = h)
11. .discretizeP(e1, lower, upper, h)
10. e10 + e20
9. e10 + e20
8. .class1(object)
7. as(e10 + e20, "UnivarLebDecDistribution")
6. log(e1DC$pos$D) + log(e2DC$pos$D)
5. log(e1DC$pos$D) + log(e2DC$pos$D)
4. .class1(object)
3. as(exp(log(e1DC$pos$D) + log(e2DC$pos$D)), "UnivarLebDecDistribution")
2. Containers * Container_Unit_Cap_Cost
1. Containers * Container_Unit_Cap_Cost

我在distr 的选项中搞砸了,但似乎无法找到一种方法让它以更大的时间间隔进行迭代。我增加了DefaultNrFFTGridPointsExponentError

有人有什么想法吗?

【问题讨论】:

    标签: r statistics distribution


    【解决方案1】:

    我发现通过从例程中清除我的两个选项更改,并将它们设置回默认值,这运行没有问题。我不知道为什么会出现提示我更改它们的原始错误,但是现在这个问题已经解决了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-27
      • 1970-01-01
      • 2013-09-05
      • 2013-02-19
      • 1970-01-01
      • 1970-01-01
      • 2017-09-08
      相关资源
      最近更新 更多