In: Statistics and Probability
from monte carlo methods, use importance sampling to estimate P(X > 3)
where e^(-sqrt(x)) [sin(x)]^2 and x > 0
>
> set.seed(0)
>
> ## proposal density as exponential function is given hence
exponential
>
> x = rexp(1000)
> head(x)
[1] 0.1840366 0.1457067 0.1397953 0.4360686 2.8949685
1.2295621
>
> ## Target density that is the given density funcition
>
> f = function(x) exp(-sqrt(x))*sin(x)*sin(x)
>
> targ_den = f(x)
> head(targ_den)
[1] 0.02180668 0.01439152 0.01335902 0.09217575 0.01087209
0.29298628
>
> ## importance weights of the sample
>
> w = f(x) / dexp(x)
> head(w)
[1] 0.02621293 0.01664893 0.01536339 0.14256039 0.19659928
1.00193441
>
> target_Sampl = w * x
> head(target_Sampl)
[1] 0.004824139 0.002425861 0.002147729 0.062166114 0.569148740
1.231940533
>
> event_X = length(which(target_Sampl >3))
>
> PX = event_X/length(target_Sampl)
> PX
[1] 0.03
>
Hence, P(X>3) = 0.03