-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[G]VIF #548
[G]VIF #548
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -362,7 +362,7 @@ fitted(m::LinPredModel) = m.rr.mu | |
predict(mm::LinPredModel) = fitted(mm) | ||
residuals(obj::LinPredModel) = residuals(obj.rr) | ||
|
||
function formula(obj::LinPredModel) | ||
function StatsModels.formula(obj::LinPredModel) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While we are at it. When is it called. When I do:
other methods are called. Do we have tests for different cases when formula is not present? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm, will investigate. I thought we caught this when Milan removed TableRegressionModel. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On current master: julia> formula(lm(ones(10, 1), randn(10)))
ERROR: ArgumentError: model was fitted without a formula
Stacktrace:
[1] formula(obj::LinearModel{GLM.LmResp{Vector{Float64}}, GLM.DensePredChol{Float64, LinearAlgebra.CholeskyPivoted{Float64, Matrix{Float64}, Vector{Int64}}}})
@ GLM ~/Code/GLM.jl/src/linpred.jl:366
[2] top-level scope
@ REPL[13]:1
julia> formula(glm(ones(10, 1), randn(10), Normal()))
ERROR: ArgumentError: model was fitted without a formula
Stacktrace:
[1] formula(obj::GeneralizedLinearModel{GLM.GlmResp{Vector{Float64}, Normal{Float64}, IdentityLink}, GLM.DensePredChol{Float64, LinearAlgebra.CholeskyPivoted{Float64, Matrix{Float64}, Vector{Int64}}}})
@ GLM ~/Code/GLM.jl/src/linpred.jl:366
[2] top-level scope
@ REPL[14]:1 (will have to keep this in mind for the backport to 1.x where we still have TableRegressionModel) |
||
obj.formula === nothing && throw(ArgumentError("model was fitted without a formula")) | ||
return obj.formula | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2011,3 +2011,12 @@ end | |
@test_throws ArgumentError lm(@formula(OptDen ~ Carb), form; method=:pr) | ||
@test_throws ArgumentError glm(@formula(OptDen ~ Carb), form, Normal(); method=:pr) | ||
end | ||
|
||
@testset "[G]VIF" begin | ||
duncan = RDatasets.dataset("car", "Duncan") | ||
lm1 = lm(@formula(Prestige ~ 1 + Income + Education), duncan) | ||
@test termnames(lm1)[2] == coefnames(lm1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So what should a user do to perform VIF analysis for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
@test vif(lm1) ≈ gvif(lm1) | ||
lm2 = lm(@formula(Prestige ~ 1 + Income + Education + Type), duncan) | ||
@test gvif(lm2; scale=true) ≈ [1.486330, 2.301648, 1.502666] atol=1e-4 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are just the StatsModels tests carried forward to models actually fitted here. 😄 But I can add a cross reference. |
||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should just reexport StatsModels? That sounds natural.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only "problem" is that breaking changes in StatsModels necessarily become breaking changes in GLM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah but there shouldn't be breaking changes in StatsModels minor releases, and anyway users who need these functions will do
using StatsModels
.