1 Simulation Exercise

Assume mean function \(E(y|x)= 5 + 1.2*x_1 +3*x_2\)

#sample code for hw2 p3
#monte carlo simulation
n <- 200 #sample size
m <- 100 #number of simulation iterations
#part i) simulate predictors X

#part ii)
for(j in 1:m){
  #simulate the error term m=100 times...
  #generate response vector y with error term per iteration
  lm.out <- ?? #fit linear regression
  betaMatrix[j,] <- lm.out$coefficients
  mysummary <- summary(lm.out)
  listMSE[j] <- mysummary$sigma^2 #get MSE per iteration
  }
#part iii) compute MSE bias etc
beta_mean <- apply(betaMatrix,2,mean)
beta_var <- apply(betaMatrix,2,var)

go to top