Dear all, May I do multiple integration using R? I was looking adapt but it is saying it integrates a scalar function over a multidimensional rectangle. I have integrand of several variable and upper, lower limit too variable. I wanted to see the result using adapt (though it is not for this purpose, I suppose) Func<-function(x){(x[1]*x[2])} adapt(2, lo=c(0,1), up=c(1,x[1]), functn=Func) it is not giving any error(it should, if it is not the correct way of putting up) but also not giving correct result. Is there any package to handle multiple integration in R?? Thanking you, with best regards, N. Dey
Have you considered Monte Carlo integration? If the function is bounded on the rectangular region of integration (or if its square is integrable), then you can generate N random points inside the rectangle, and evaluate the function at each point. Their mean is the integral, and from their sample variance, you can get a confidence interval on that estimate. With modern computers, you can get any degree of accuracy you want just by waiting longer. You can improve on this using kernals, but I'm not familiar with those methods. hope this helps. spencer graves N Dey wrote:> Dear all, > > May I do multiple integration using R? I was looking > adapt but it is saying it integrates a scalar function > over a multidimensional rectangle. I have integrand of > several variable and upper, lower limit too variable. > > I wanted to see the result using adapt (though it is > not for this purpose, I suppose) > > Func<-function(x){(x[1]*x[2])} > adapt(2, lo=c(0,1), up=c(1,x[1]), functn=Func) > > it is not giving any error(it should, if it is not the > correct way of putting up) but also not giving correct > result. > > Is there any package to handle multiple integration in > R?? > > Thanking you, > with best regards, > N. Dey > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help
You should get an error message from "adapt" since it doesn't understand what value to use for x[1]. However, in your case you are not getting an error message probably because you already have an object named "x" somewhere in your current working directory. This may explain the error. If you want to use "adapt", your integration region must be "rectangular", which is not the case in your problem. But using indicator function, it is easy to turn your region into a rectangular region and then use "adapt". Hope this helps, Ravi. ----- Original Message ----- From: N Dey <ndey00 at yahoo.com> Date: Saturday, April 26, 2003 8:56 am Subject: [R] Multiple Integration> Dear all, > > May I do multiple integration using R? I was looking > adapt but it is saying it integrates a scalar function > over a multidimensional rectangle. I have integrand of > several variable and upper, lower limit too variable. > > I wanted to see the result using adapt (though it is > not for this purpose, I suppose) > > Func<-function(x){(x[1]*x[2])} > adapt(2, lo=c(0,1), up=c(1,x[1]), functn=Func) > > it is not giving any error(it should, if it is not the > correct way of putting up) but also not giving correct > result. > > Is there any package to handle multiple integration in > R?? > > Thanking you, > with best regards, > N. Dey > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help >