【发布时间】:2020-09-06 03:29:34
【问题描述】:
假设我们有以下密度:
bvtnorm <- function(x, y, mu_x = 10, mu_y = 5, sigma_x = 3, sigma_y = 7, rho = 0.4) {
function(x, y)
1 / (2 * pi * sigma_x * sigma_y * sqrt(1 - rho ^ 2)) *
exp(- 1 / (2 * (1 - rho ^ 2)) * (((x - mu_x) / sigma_x) ^ 2 +
((y - mu_y) / sigma_y) ^ 2 - 2 * rho * (x - mu_x) * (y - mu_y) /
(sigma_x * sigma_y)))
}
f2 <- bvtnorm(x, y)
我想计算以下积分:
integral_1=1-adaptIntegrate(f2, lowerLimit = c(-Inf,0), upperLimit = c(+Inf,+Inf))
不幸的是,它提供了这个错误:
Error in f(tan(x), ...) : argument "y" is missing, with no default
我不知道如何解决这个问题。 提前感谢您的帮助!
【问题讨论】:
-
bvtnorm产生的函数f2有两个参数,x 和 y,但是adaptIntegrate需要一个单变量函数,所以它不能用于这边 -
@AllanCameron,我应该用 c(x,y) 更改 x,y 吗?
-
double integral in R 可能会有所帮助。
标签: r