Homework 4

Due: At the start of class on Monday, March 18. Please turn in a hard copy.

Textbook Questions: 7.7, 7.14, 7.17, 7.28 (parts (a)-(e) only)

Extra Question 1

Repeat part (a) of question 7.28 except compute standard errors using the bootstrap. Provide your code and a brief explanation of your results.

Extra Question 2

Monte Carlo simulations are a very useful way to study properties of different estimators. Basically, the idea is to use simulated data (where we know what the true model is) and check how well a particular estimator performs.

For this problem, we’ll use Monte Carlo simulations to assess the bias and sampling variance of \(\hat{\beta}\). Because we have never done this before, I am going to provide some code that is useful for this problem (though you will have to fill in some details).

For a particular simulation, do the following for \(i=1,...,n\) (for now, set \(n=100\), but we will try different values of \(n\) later)

The above steps give you a data set with observations of \(Y\) and \(X\). Using this data, run a regression of \(Y\) on \(X\) (make sure to include an intercept) and recover estimates \(\hat{\beta}_0\) and \(\hat{\beta}_1\).

  1. Do the above steps 1000 times and calculate (i) the average values of \(\hat{\beta}_1\) across simulations, and (ii) the variance of \(\hat{\beta}_1\) across simulations. What do these results suggest to you? In particular, are they consistent with the theory that we have derived in class? Explain.

  2. Try the same calculations with \(n=2\), \(n=10\), \(n=50\), and \(n=500\). What do you notice?

# function to run a single simulation
sim <- function() {
  # draw X1
  X1 <- rexp(n)
  
  # draw the error term
  e <- mixtools::rnormmix(n, lambda=c(.5,.5), mu=c(-2,2), sigma=c(1,1))
  
  ## TODO: construct Y
  

  ## TODO: use X1 and Y to estimate bet0 and bet1
  

  # TODO: return estimated value of bet1
  
}

# function to run many simulations
# @param n_sims is the number of simulations to run
run_mc <- function(n_sims=1000) {
  
  # run n_sims simulations and store in a vector
  mc_res <- sapply(1:n_sims, function(s) {
    sim()
  })
  
  # print the mean of b1
  cat("mean b1  : ", mean(mc_res), "\n")
  
  # print the variance of b1
  cat("var b1   : ", var(mc_res), "\n")
}
# run the simulations
# set values of parameters and number of observations
b0 <- 0
b1 <- 1
n <- 100

run_mc()

Extra Question 3

For this question, we will conduct more Monte Carlo simulations, building on the previous question. This time we will use Monte Carlo simulations to assess how well our asymptotic inference arguments work.

As in the previous question, for a particular simulation, do the following for \(i=1,...,n\) (for now, set \(n=100\), but we will try different values of \(n\) later)

The above steps give you a data set with observations of \(Y\) and \(X\). Construct a t-statistic for \(\mathbb{H}_0 : \beta_1 = 1\). For each Monte Carlo simulation, determine whether or not you reject \(\mathbb{H}_0\) at a 5% significance level.

  1. Given our theoretical results from class, can you tell what fraction of the time you should reject \(\mathbb{H}_0\) in this setup?

  2. Do the above steps 1000 times and calculate the fraction of times that you reject \(\mathbb{H}_0\). Are the results in line with the theory from class? Explain.

  3. Try the same calculations with \(n=10\), \(n=50\), \(n=500\), and \(n=1000\). What do you notice?

  4. Redo parts (a)-(c), but for \(\mathbb{H}_0 : \beta_1=0\). What patterns do you notice?