## Problem 1 a <- 2 reps <- 10000 ## Generate a single N(0,1) random draw, 10000 times Z <- rnorm(reps) ## Find the variance of these draws var(Z) ## Find the variance of a times each draw var(a*Z) # Verify that the var(a*Z) = a^2 * var(Z) a^2*var(Z) ## Problem 2 n <- 4 reps <- 10000 ## Generate 4 iid N(0,1) random draws 10000 times Z <- array( rnorm(n*reps), c(n, reps) ) ## Find the variances of the 4 iid random draws fourVariances <- apply(Z, 1, var) ## Verify that the variance of the sum is roughly the sum of the variances varOfSum <- var( apply(Z, 2, sum) ) print(varOfSum) print(sum(fourVariances)) ## Problem 5 V <- NULL reps <- 10000 for (lambda in c(1,2,3,4)) { for (n in c(10,20,40,80)) { X <- array(rexp(n*reps, lambda), c(n,reps)) M <- apply(X, 2, mean) V <- rbind(V, c(lambda, n, var(M), 1/(n*lambda^2))) } } ## Problem 8 V <- NULL reps <- 10000 for (lambda in c(1,2,3,4)) { for (n in c(10,20,40,80)) { X <- array(rpois(n*reps, lambda), c(n,reps)) M <- apply(X, 2, mean) V <- rbind(V, c(lambda, n, var(M), lambda/n)) } }