I'm a little bit puzzled by the default standardization of the lasso/elastic net/ridge regression algorithms implemented in the (great!) glmnet package.
In most other applications, people would standardize a data matrix $X$ by centering all columns $j$ around the mean ($\sum_{i=1}^n x_{ij}=0$) and scaling columns to unit variance, meaning:
$\frac{1}{n-1}\sum_{i=1}^nx_{ij}^2=1$. (a)
In the original glmnet and lasso papers, they state instead a normalization with factor $\frac{1}{n}$, that is, the biased estimator of the variance:
$\frac{1}{n}\sum_{i=1}^nx_{ij}^2=1$. (b)
The original ridge regression paper, on the other hand, states that $X^TX$ should have $1$s on the diagonal like a correlation matrix, leading to
$\sum_{i=1}^nx_{ij}^2=1$, (c)
without any multiplying factor. Now comes the most puzzling part, checking the Fortran code of the glmnet package in R (see lines 116 to 140), I cannot shake the feeling that they are actually standardizing such that:
$\frac{n}{n-1}\sum_{i=1}^nx_{ij}^2=1$, (d)
leading to the entries of the diagonal of $X^TX$ being just a little bit below $1$.
Now, I'm not fit in Fortran and I might read something wrong, but I've got two open questions now:
- Why do they use the biased estimate of the variance/standard deviation for standardization in glmnet?
- Or do they actually use the standardization with $\frac{n}{n-1}$?
The standardization in 2.) would actually make sense, since the diagonal of $X^TX$ would not depend on the number of observations anymore.
glmnet
package? Is it to mimic the MLE of the variance? If I usescale()
function inR
to standardize the variables by the 1/(N-1) formula, input the standadized data and use optionstandardize=FALSE
, the de-standardized coefficients will be slight different from what the default method (input data in original scale withstandardize=TRUE
) would produce. I'm wondering if it is theoretically okay to usescale
to standardize the data first and use them as the inputs. Could anyone help? $\endgroup$