我将概率密度函数编码为:
myfunc <- function(x){
ifelse(x >= 0 & x < 0.5, 1,
ifelse (x >= 0.5 & x < 1, 0.2,
ifelse(x >= 1 & x < 2, 0.8*(x-1), 0)))
}
我知道 EV 是加权积分,但我正在努力编写计算代码。
另外:从长远来看,我如何模拟这个(0.867)结果?
有人可以帮忙吗?
最佳答案
这是一种使用集成
的解决方案:
integrate(function(x) x*myfunc(x),lower=0,upper=2)
0.866666666666667 with absolute error < 9.6e-15
关于r - 如何根据 R 中的概率密度计算自定义连续分布的平均值(期望值),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77202266/