Problem sheet 2 -- Distributions and Sampling
Sampling from Distributions
Write a computer program that generates random variables distributed according to the given probability distributions, create a sample of these random variables and plot histograms and compare to the given probability density distributions:
P(x)=1 for x in [0,1] and x in [3,5].
P(x)=exp(x) for x in [0,1]
P(x)= cos(x) for x in [0, pi/2].
Sampling and the CLT
Consider the distribution in the first example of the first problem. Generate samples of various sizes and
Explore the change in shape of the distribution of sample means (by plotting the distributions of sample means for various sample sizes)
Calculate the mean of the distribution and explore the convergence of sample means depending on sample size by plotting the standard deviation of sample means vs sample size.
Estimating PI
A (not very accurate) method to estimate PI is via Monte Carlo sampling as follows. Consider points distributed uniformly at random in the square of unit length and count all occurances in which points are found in the quarter circle inscribed into the unit square. This way the area of the quarter circle can be estimated via "Monte Carlo integration" which in turn allows to estimate PI.
Write a computer program that allows to estimate PI in this way and explore the relationship between sample size (i.e. number of points simulated) and the accuracy of the Monte Carlo estimate.
How large does your sample have to be to estimate PI with error bounds smaller than 10^-9 ?