You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Why can I not manually specify an intercept like @formula(x ~ 1 + y)? The documentation ?@formula says:
1, 0, and -1 indicate the presence (for 1) or absence (for 0 and -1) of an intercept column.
So 1 is a valid intercept specification, like in R. This @formula also works in GLM.lm.
Code that works
If I write @formula(x ~ y), Lasso.jl will automatically fit a model with an intercept:
julia>fit(LassoModel, @formula(x ~ y), df)
StatsModels.TableRegressionModel{LassoModel{LinearModel{GLM.LmResp{Vector{Float64}}, GLM.DensePredChol{Float64, LinearAlgebra.CholeskyPivoted{Float64, Matrix{Float64}, Vector{Int64}}}}, MinAICc}, Matrix{Float64}}
x ~ y
Coefficients:
LassoModel usingMinAICc(2) segment of the regularization path.
Coefficients:
──────────────
Estimate
──────────────
x1 -0.132743
x2 0.0497596
──────────────
I assume the first coefficient is the intercept and the second one is multiplied by y, so the model is:
x = -0.132743 + 0.0497596 * y
So, intercepts are supported, but I can't manually specify that I want an intercept.
More code that doesn't work
Let's fit a model without an intercept. I specify this with the 0 in @formula(x ~ 0 + y).
julia>fit(LassoModel, @formula(x ~0+ y), df)
StatsModels.TableRegressionModel{LassoModel{LinearModel{GLM.LmResp{Vector{Float64}}, GLM.DensePredChol{Float64, LinearAlgebra.CholeskyPivoted{Float64, Matrix{Float64}, Vector{Int64}}}}, MinAICc}, Matrix{Float64}}
x ~0+ y
Coefficients:
LassoModel usingMinAICc(2) segment of the regularization path.
Coefficients:
──────────────
Estimate
──────────────
x1 -0.132743
x2 0.0497596
──────────────
It seems like the package ignored the zero in the formula, fitted an intercept -0.132743 anyway and produced the same model as above, even though the @formula is different. R's glmnetsupports fitting without an intercept since 2013.
It would be nice if it were possible to specify the intercept in the formula.
Versions
Julia v1.9-beta2
Lasso v0.7.0
The text was updated successfully, but these errors were encountered:
When using Lasso.jl, I noticed that to exclude the intercept, it needs to be specified as an argument in fit() as in fit(LassoModel,...; intercept=false) -- rather than in @formula(...) like with GLM.jl. I haven't stepped through the source code to understand why.
Code that doesn't work
Why can I not manually specify an intercept like
@formula(x ~ 1 + y)
? The documentation?@formula
says:So
1
is a valid intercept specification, like in R. This@formula
also works inGLM.lm
.Code that works
If I write
@formula(x ~ y)
, Lasso.jl will automatically fit a model with an intercept:I assume the first coefficient is the intercept and the second one is multiplied by
y
, so the model is:So, intercepts are supported, but I can't manually specify that I want an intercept.
More code that doesn't work
Let's fit a model without an intercept. I specify this with the
0
in@formula(x ~ 0 + y)
.It seems like the package ignored the zero in the formula, fitted an intercept
-0.132743
anyway and produced the same model as above, even though the@formula
is different. R'sglmnet
supports fitting without an intercept since 2013.It would be nice if it were possible to specify the intercept in the formula.
Versions
The text was updated successfully, but these errors were encountered: