In this exercise we will again be using random number generators. When using random numbers, it is wise to always fix the random seed (the starting point of the number generation). This ensures that in the future we can exactly reproduce the chain of executions that led to the randomly generated results.
Start by setting a random seed. If you follow my random seed and reproduce the code below in exactly the same order, you will get the same results. If you do not follow the exact ordering (i.e. if you skip or rerun a question, or have different code), your results may be different due to random sampling. This is not a bad thing! It is just a result of the method and should be that way.
#set random seed, make things reproducible
set.seed(123)
av
. Compute the standard deviation of av
.av
.rnorm(20, 100, 10)
## [1] 94.39524 97.69823 115.58708 100.70508 101.29288 117.15065 104.60916
## [8] 87.34939 93.13147 95.54338 112.24082 103.59814 104.00771 101.10683
## [15] 94.44159 117.86913 104.97850 80.33383 107.01356 95.27209
mfrow
to set up the layout for a 3 by 4 array of plots. In the top 4 panels, show normal probability plots (‘QQ-plots’) for 4 separate “random” samples of size 10, all drawn from a normal distribution. In the middle 4 panels, display plots for samples of size 100. In the bottom 4 panels, display plots for samples of size 1000. Comment on how the appearance of the plots changes as the sample size changes.runif
instead of rnorm
.rexp()
to simulate 100 exponential random numbers with rate 0.2. Do the following on the simulated random numbers y1
predicted by x1
- stored in object fit1
y2
predicted by x2
- stored in object fit2
y3
predicted by x3
- stored in object fit3
y4
predicted by x4
- stored in object fit4
blue
, gray
, orange
and purple
, respectively. End of practical.