source("http://myweb.uiowa.edu/pbreheny/7600/s16/notes/fun.R")

# Slide 16 ------------------------------------------------------------------
# Requires running the code in sim.R first

n <- 50
load("sim-a.RData")
a <- apply(res, 2:3, mean)
load("sim-b.RData")
b <- apply(res, 2:3, mean)

rho <- as.numeric(rownames(a))
R <- length(rho)
oMSE <- numeric(R)
for (j in 1:R) {
  S <- rho[j]*matrix(1, 5, 5) + (1-rho[j])*diag(5)
  oMSE[j] <- sum(diag(solve(S)))/n
}

labs <- c("Lasso", "Elastic Net")
par(mfrow=c(1,2), mar=c(5,5,2,0.5), oma=c(0,0,2,0))
matplot(rho, a, type='l', lty=1, lwd=3, col=pal(2), bty='n', las=1, xlab=expression(rho), ylab="MSE")
mtext('Compound symmetric')
matplot(rho, b, type='l', lty=1, lwd=3, col=pal(2), bty='n', las=1, xlab=expression(rho), ylab="MSE")
mtext('Block diagonal')
toplegend(legend=labs, lwd=3, col=pal(2))
