library(discreteRV)
X <- RV(c(0, 9), c(1/2, 1/2))
X ** (-2)
每当我尝试运行这个时,我都会得到以下错误:
Error in RV(as.numeric(outcomes(X))^Y, probs(X), fractions = attr(X, "fractions"), :
More probabilities/odds than outcomes provided
包来自GitHub:discreteRV
问题是您试图将零提升为负幂,这基本上相当于计算1/0(在本例中,您试图找到(1/0(^2(-一种不确定的形式。当用1
替换0
时,代码运行良好的
> X <- RV(c(1, 9), c(1/2, 1/2))
> X ** (-2)
Random variable with 2 outcomes
Outcomes 0.0123456790123457 1
Probs 1/2 1/2