How does glmnet compute the maximal lambda value?

前端 未结 4 1255
迷失自我
迷失自我 2020-12-29 14:15

The glmnet package uses a range of LASSO tuning parameters lambda scaled from the maximal lambda_max under which no predi

4条回答
  •  情歌与酒
    2020-12-29 14:47

    To get the same result you need to standardize the variables using a standard deviation with n instead of n-1 denominator.

    mysd <- function(y) sqrt(sum((y-mean(y))^2)/length(y))
    sx <- scale(x,scale=apply(x, 2, mysd))
    sx <- as.matrix(sx, ncol=20, nrow=100)
    sy <- as.vector(scale(y, scale=mysd(y)))
    max(abs(colSums(sx*sy)))/100
    ## [1] 0.1758808
    fitGLM <- glmnet(sx,sy)
    max(fitGLM$lambda)
    ## [1] 0.1758808
    

提交回复
热议问题