[R] integrate: can pass numbers but not variables as additional arguments
Sasha Pustota
popgen at gmail.com
Wed Oct 1 00:48:08 CEST 2008
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
More information about the R-help
mailing list