Exercises
Monte Carlo methods.
1. The density f (x, y) of bi-dimensional vector (X, Y ) is inversely proportional to the 1 + x2 + x2y2 + y2 on the square x, y ∈ [-2, 2], i.e.
f (x, y) = (c/(1 + x2 + x2y2 + y2)) , x, y ∈ [-2, 2].
1. Construct the algorithm for simulation of the vector (X, Y ). Plot the function f (x, y). Simulate 10000 points of (X, Y ) and construct the corresponding histogram. Compare the density profile with the histogram.
2. Using Monte Carlo method calculate the probability P(|X - Y| ≤ 0.5). Check empirically the convergence for the true value.
3. Using Monte Carlo method calculate the integral
I = 0∫2dx -2∫1 dy.(xy/(1 + x2 + x2y2 + y2))
Check empirically the convergence.
2. Consider the problem of comparing means of two populations: let (x1, . . . , xn) i.i.d samples from X ∼ U [-1, 1] distribution and suppose (y1, . . . , yn) are i.i.d. samples from Y ∼ U [-1 + θ, 1 + θ], where θ is positive. Let n = 10.
1. In order to test the hypothesis H0 : µx = µy versus H1 : µx ≠ µy use the t-Student statistics (variances are equals):
t = (x¯ - y¯)/(σP√(2/n)), with σP = √(σˆ2x(n - 1) + σˆ2y(n - 1))/(2n -2)
where
σˆ2x = 1/(n-1)Σi=1n(xi - x¯)2, σˆ2y = 1/(n-1)Σi=1n(yi - y¯)2,
Using simulation experiment construct the curve the power of the test based on the points of θ: t=seq(0,1,by=0.05), considering the α = 0.05:
(a) for any θi ∈ t simulate N times samples (x1, . . . , x10)j, (y1, . . . , y10)j, j = 1, . . . , N . For example choose N = 1000;
(b) for any (x1, . . . , x10)j, (y1, . . . , y10)j calculate tj statistics (1) and compare it with t1-α/2,2n-2 quantile of t-Student distribution with 2n - 2 degree of freedom;
(c) accept the estimation of error of type II as Mi/N , where Mi is the number of how many time we accept the H0, when H0 is wrong (because θi > 0) i.e. how many |tj| ≤ t1-α/2,2n-2; thus, the power will be 1 - Mi/N.
2. Suggest and describe the bootstrap test hypothesis for the same problem and the same α = 0.05 (use the same statistics (1)). Using simulation experiment construct the curve of the power of the test based on the points of θ: t=seq(0,1,by=0.05), considering the α = 0.05:
(a) for any θi ∈ t simulate N times samples (x1, . . . , x10)j, (y1, . . . , y10)j, j = 1, . . . , N . For example choose N = 1000;
(b) for any (x1, . . . , x10)j, (y1, . . . , y10)j calculate tj statistics (1) and then using the bootstrapping calculate pb-value: see slides how to estimate pb-value; here wee need to run the bootstrap; choose B as 1000, for example; remember, we accept H0 is pb-value is greater then α and reject H0 otherwise;
(c) accept the estimation of error of type II as Mi/N , where Mi is the number of how many time we accept the H0, when H0 is wrong (because θi > 0) i.e. how many |tj| ≤ t1-α/2,2n-2; thus, the power will be 1 - Mi/N.
Plot both power curves and compare.
3. Choose the instrumental function g(x) = e-x and evaluate the integral by importance sampling:
I = 0∫∞ 1/(1 + ex) dx.
1. Find the value of integral I.
2. Plot the convergence of importance sampling estimator Iˆn to the true value.
3. Is the variance of Iˆn finite?