Skip to content

Commit 0eb9ed6

Browse files
authored
use StatsModels.isnested instead of defining new issubmodel func (#462)
* use StatsModels.isnested instead of defining new issubmodel func * fix kwarg syntax in new expr for 1.0 compat * codereview: no docstring (use statsmodels default), API alphabetizin
1 parent 8da427b commit 0eb9ed6

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

docs/src/api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ StatsBase.deviance
6565
GLM.dispersion
6666
GLM.ftest
6767
GLM.installbeta!
68-
GLM.issubmodel
6968
StatsBase.nobs
7069
StatsBase.nulldeviance
7170
StatsBase.predict
71+
StatsModels.isnested
7272
```
7373

7474
## Links and methods applied to them

src/ftest.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ mutable struct FTestResult{N}
1414
pval::NTuple{N, Float64}
1515
end
1616

17-
"""A helper function to determine if mod1 is nested in mod2"""
18-
function issubmodel(mod1::LinPredModel, mod2::LinPredModel; atol::Real=0.0)
17+
@deprecate issubmodel(mod1::LinPredModel, mod2::LinPredModel; atol::Real=0.0) StatsModels.isnested(mod1, mod2; atol=atol)
18+
19+
function StatsModels.isnested(mod1::LinPredModel, mod2::LinPredModel; atol::Real=0.0)
1920
mod1.rr.y != mod2.rr.y && return false # Response variables must be equal
2021

2122
# Test that models are nested
@@ -136,13 +137,13 @@ function ftest(mods::LinearModel...; atol::Real=0.0)
136137
forward = length(mods) == 1 || dof(mods[1]) <= dof(mods[2])
137138
if forward
138139
for i in 2:length(mods)
139-
if dof(mods[i-1]) >= dof(mods[i]) || !issubmodel(mods[i-1], mods[i], atol=atol)
140+
if dof(mods[i-1]) >= dof(mods[i]) || !StatsModels.isnested(mods[i-1], mods[i], atol=atol)
140141
throw(ArgumentError("F test is only valid for nested models"))
141142
end
142143
end
143144
else
144145
for i in 2:length(mods)
145-
if dof(mods[i]) >= dof(mods[i-1]) || !issubmodel(mods[i], mods[i-1], atol=atol)
146+
if dof(mods[i]) >= dof(mods[i-1]) || !StatsModels.isnested(mods[i], mods[i-1], atol=atol)
146147
throw(ArgumentError("F test is only valid for nested models"))
147148
end
148149
end

test/runtests.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -708,15 +708,15 @@ end
708708
othermod = lm(@formula(Result~Other), d).model
709709
nullmod = lm(@formula(Result~1), d).model
710710
bothmod = lm(@formula(Result~Other+Treatment), d).model
711-
@test GLM.issubmodel(nullmod, mod)
712-
@test !GLM.issubmodel(othermod, mod)
713-
@test GLM.issubmodel(mod, bothmod)
714-
@test !GLM.issubmodel(bothmod, mod)
715-
@test GLM.issubmodel(othermod, bothmod)
711+
@test StatsModels.isnested(nullmod, mod)
712+
@test !StatsModels.isnested(othermod, mod)
713+
@test StatsModels.isnested(mod, bothmod)
714+
@test !StatsModels.isnested(bothmod, mod)
715+
@test StatsModels.isnested(othermod, bothmod)
716716

717717
d.Sum = d.Treatment + (d.Other .== 1)
718718
summod = lm(@formula(Result~Sum), d).model
719-
@test GLM.issubmodel(summod, bothmod)
719+
@test StatsModels.isnested(summod, bothmod)
720720

721721
ft1a = ftest(mod, nullmod)
722722
@test isnan(ft1a.pval[1])
@@ -851,7 +851,7 @@ end
851851
# Fit 2 (both)
852852
Xc2 = RL\X
853853
mod2 = lm(Xc2, Yc)
854-
@test GLM.issubmodel(mod1, mod2)
854+
@test StatsModels.isnested(mod1, mod2)
855855
end
856856

857857
@testset "coeftable" begin

0 commit comments

Comments
 (0)