1. Generate your own vector p which will represent the probability masses?
of a random variable X with values 1, 2, . . . , length(p). You will use this
random variable below. Some examples of possible ways to generate p:
> p <- rep(1/42, 42)
> p <- runif(21); p <- p/sum(p)
> p <- scan(``myProbabilities.txt'')
> p <- dbinom(0:9, 9, 0.1)
2. Compute the mean and variance of X, and illustrate it with a barplot.
3. Create a matrix A with 1000 rows and 1000 columns, where each entry
is an independent draw from X.
4. Based on A, create 1000 independent draws of the mean of 1000 draws
from X. (Hint: R functions _apply_ and _mean_). Compare the histo-
gram of these 1000 numbers with the barplot above, and comment.
1
5. Repeat the previous point using only the _rst column, the 2 _rst co-
lumns, the 10 _rst columns, and the 100 _rst columns of A. Comment
on the di_erences. (Hint: You may want to use the extra parameter
_nclass_ or _breaks_ in the _hist_ function to change the appearance of
some of the histograms, to make them more comparable).
6. Investigate and illustrate the distribution of the _ve sets of 1000 num-
bers generated above, using the R function _qqnorm_. Comment.
7. Using the results above, do the following, for n = 1, 2, 10, 100, 1000:
(a) Compute the mean of the 1000 independent draws of the mean of
the n draws from X.
(b) Compute the sample variance of the 1000 independent draws of
the mean of the n draws from X, and compare it with the variance
found in part 2 divided by n.
Comment on the result.
8. Repeat parts 3,4,5 and 6 above, but now generate the draws from
a standard Cauchy distribution (so, to generate 100000 samples, use
the R command _rcauchy(100000)_). Optional: Discuss why the results
seem to differ from those you got before.
Answers:
hmmm it seems to me you have generated a textbook answer. Well done.