Monte Carlo Integration Method

118 Views Asked by At

$$q = \int_{-1}^{\infty} xe^{-x-1}\sin{x} \,dx$$

How can I use the Monte Carlo integration method to find out the estimate of q and its standard error, using n iid samples generated from Exp(1) ?

1

There are 1 best solutions below

1
On BEST ANSWER

Suggestion

Using $u=x+1$ gives

$$ q=\int^\infty_{-1}x e^{-(x+1)}\sin(x)\,dx =\int^\infty_0(x-1)e^{-x}\sin(x-1)\,dx$$

Try $$\hat{q}_n=\Big(\frac{1}{n}\sum^n_{k=1}(X_k-1)\sin(X_k-1)\Big)$$ as an estimate for $q$, and $$ \frac{1}{n-1}\sum^n_{k=1}((X_k-1)\sin(X_k-1)-\hat{q}_n)^2 $$ as an estimate of its variance. If you do the whole integration by parts (or do some numerical integration other than MC), the variance can be estimated by $$ \frac{1}{n}\sum^n_{k=1}((X_k-1)\sin(X_k-1)-q)^2 $$

Here us an short R code:

N <- 100
x<- rexp(100000)

q.true <- ntegrate(function(x){(x-1)*sin(x-1)*exp(-x)},
                   lower = 0,upper = Inf)$value
q <-numeric(length = N)
sq <-numeric(length = N)
for(n in 1:N){
  p <- x[1:(n*1000)]
  q[n] <- mean((p-1)*sin(p-1))
  sq[n] <- sum( ((p-1)*sin(p-1) - q[n])^2)/(n*1000 -1)
}


data.frame(n=(1:100)*1000,q_n=q,sn = sq, true_q = q.true)