Importance Sampling is a Monte Carlo integration technique for getting (very accurate) approximations to integrals. Consider the integral
and suppose we wish to approximate this without doing any calculus. Statistically speaking we want to compute the normalizing constant for a standard normal, which we know to be
We can rewrite the above integral as
because this is just multiplying the integrand by 1. One can now make the observation that
and realise that
where
.
The code below in R performs this summation.
N=10000 cumsum=rep(0,N) for(i in 2:N){ x=rt(1,3) cumsum[i]=cumsum[i-1]+((exp((-0.5)*(x^2)))/dt(x,3)) } for(i in 1:N) cumsum[i]=cumsum[i]/i plot(cumsum[50:N],type="l")
At n=10000 the normalizing constant given by importance sampling is 2.516303. Increasing n to n=100000 the normalizing constant is 2.505983