JuliaStats / GLMNet.jl

Julia wrapper for fitting Lasso/ElasticNet GLM models using glmnet
Other
95 stars 35 forks source link

Incorrect `null_dev`s #39

Closed dpmerrell closed 3 years ago

dpmerrell commented 4 years ago

The null deviations seem to be incorrect when I run GLMNet.glmnet -- I'm getting absurdly small numbers.

Example: this code

# Simulated data set
X_sim = randn((100,10));
beta_sim = randn(10);
y_sim = randn(100) .+ (X_sim * beta_sim  .+ 3.14)

sim_path = GLMNet.glmnet(X_sim, y_sim)

Produces the output:

Least Squares GLMNet Solution Path (64 solutions for 10 predictors in 266 passes):
───────────────────────────────
      df    pct_dev           λ
───────────────────────────────
 [1]   0  0.0        3.15936   
 [2]   1  0.0716368  2.87869   
 [3]   1  0.131111   2.62295   
 [4]   1  0.180487   2.38994   
 [5]   1  0.221481   2.17762   
 [6]   2  0.270351   1.98417   
.
.
.

Which seems fine -- but then when I run

sim_path.null_dev

I get an absurdly small number:

6.240013019814641e-34

In contrast, when I compute the null deviance (sum of squares) myself:

size(X_sim, 1) * var(y_sim)

I get

2389.5611952108716

Have I misunderstood something? It's easy enough to compute the null deviance on my own, but it seems like GLMNet.jl isn't computing it as advertised.

And I don't see it covered in your unit tests. So maybe this was a small blind spot.