[R] Multiple Integrals

Shant Ch sha1one at yahoo.com
Fri Aug 28 23:55:19 CEST 2015


Hello all,
For a study I want to find E|X1/3+X2/3+X3/3-X4| for variables following lognormal distribution. To get the value we need to use four integrals. This is the code which I is used

      fx<-function(x){
        dlnorm(x,meanlog=2.185,sdlog=0.562)
      }
U31<-integrate(function(y1) { sapply(y1, function(y1) { 
+              integrate(function(y2){  sapply(y2, function(y2) {
+              integrate(function(x1){  sapply(x1, function(x1) { 
+              integrate(function(x2)
+               abs(y1/3+y2/3+x1/3-x2)*fx(y1)*fx(y2)*fx(x1)*fx(x2),0, Inf)$value
+              })},0, Inf)$value })},0, Inf)$value})},0,Inf)$value
The error I received is the following:
Error in integrate(function(y2) { : 
  maximum number of subdivisions reached

I can understand the problem, but I am unable to figure out what can be done.. It would be great if you can let me know a solution to the problem so as to find a value for the integral.

Shant

	[[alternative HTML version deleted]]



More information about the R-help mailing list