Sasha Pustota
2008-Sep-30 22:48 UTC
[R] integrate: can pass numbers but not variables as additional arguments
I'm trying to integrate one dimension of a bivariate normal. It works when additional parameters are passed explicitly: library(mvtnorm) bivInt <- function(x,y,mx,my,r) { dmvnorm(c(x, y), mean=c(mx, my), sigma=rbind(c(1, r), c(r, 1))) } integrate(Vectorize(bivInt), lower=-Inf, upper=2, 1, 2, 2, .5)$value # [1] 0.1737709 How to make it work when the additional parameters are passed as variables? I'm getting errors: y<-1; mx<-2; my<-2; r<-.5 integrate(Vectorize(bivInt), lower=-Inf, upper=2, y, mx, my, r) # Error in eval(expr, envir, enclos) : # ..1 used in an incorrect context, no ... to look in> integrate(Vectorize(bivInt), lower=-Inf, upper=2, y=y, mx=mx, my=my, r=r)Error in eval(expr, envir, enclos) : ..1 used in an incorrect context, no ... to look in