Comp Assign
Comp Assign
Instructions: Complete this computer assignment, prepare a report including your code, and
any output, plots or comments required by the questions and submit it on the Assignment item
on Canvas. The file upload format is limited to pdf and html. We highly encourage you to knit
your report using R Markdown, but the report can be created any way that is convenient as
long as it includes all the required content.
1. In a gambling game, a player wins the game if they roll 10 fair, six-sided dice, and get a
sum of at least 40.
(a) Approximate the probability of winning by simulating the game 104 times. Use
set.seed(200) for this question. Output your approximate probability, but do not
print your simulated rolls.
(b) Compute the Central Limit Theorem approximation P (Y ≥ 40), where Y is the sum
of 10 dice, and compare it to the Monte Carlo approximation obtained above. You
can use the fact that E(Y ) = 35, Var(Y ) = 175/6.
Value 0 1 2 3 4
Freq 130 133 49 7 1
modelled as values taken by i.i.d. random variables with common Bin(4, p) distribution,
i.e.
4 x
P (X = x) = p (1 − p)4−x , for x = 0, 1, 2, 3, 4
x
for some unknown p.
(a) Generate a random sample of size 25 from a normal distribution with mean µ = 3
and standard deviation σ = 1.5. Assume σ is known and we want to estimate µ.
Using the sample generated, find a 95% confidence interval (CI) for µ.
(b) Repeat the process in (a) 20 times. Using your 20 samples, calculate 20 CIs for µ.
How many of these 20 intervals contain the true mean µ = 3? Output this number
from your code, but no need to print the 20 CIs themselves.
1
4. Use set.seed(100) to answer this question.
(a) Generate a random sample of size 30 from the exponential distribution with param-
eter λ = 2 and find the mean of your sample. Repeat this process 1000 times and
draw a histogram of these 1000 means (use prob=T in hist). (Do not print the 1000
means.)
(b) Next we check whether the Central Limit Theorem gives a good approximation for
the distribution of the means. Overlay the histogram with a normal density curve
with appropriate mean and variance. (You will need to use the mean and variance
of exponential distributions from lectures. No need to derive). Comment on the fit.