R/rsq.R

Defines functions Fig2.9

Documented in Fig2.9

#' Reproduce Figure 2.9
#'
#' Reproduces Figure 2.9 from the book; if you specify any options, your results may look different.
#'
#' @examples
#' Fig2.9()
#'
#' # By hand
#' attachData(pollution)
#' cvfit <- cv.glmnet(std(X), y)   # Standardize design matrix
#' rsq <- 1-cvfit$cvm/var(y)
#'
#' @export

Fig2.9 <- function() {
  # Fit
  Data <- readData('pollution')
  X <- std(Data$X)
  y <- Data$y
  cvfit <- cv.ncvreg(X, y, penalty="lasso", nfolds=length(y))
  plot(cvfit, type="rsq", bty="n", xlab=expression(lambda), xaxt="n")
  at <- c(40, 4, 0.4, 0.04)
  axis(1, at=log(at), labels=at)
}
pbreheny/hdrm documentation built on Jan. 17, 2024, 8:53 p.m.