Skip to content

Commit

Permalink
better test support for Julia <1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
palday committed Aug 19, 2023
1 parent ea08c3d commit 9a447a9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
3 changes: 3 additions & 0 deletions src/regressionmodel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ end
function _difference_method!(::Vector{T}, ::Vector{T},
::RegressionModel,
::AutoInvLink) where {T <: AbstractFloat}
@static if VERSION < v"1.9"
@error "AutoInvLink requires extensions and is thus not available on Julia < 1.9."
end
throw(ArgumentError("No appropriate extension is loaded for automatic " *
"determination of the inverse link for this model type"))
end
Expand Down
30 changes: 19 additions & 11 deletions test/delta_method.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ using Test
@test isapprox(only(eff_emm_trans.upper), 47.5; atol=0.05)

@testset "AutoInvLink fails gracefully" begin
# this should work even pre Julia 1.9 because by definition
# no extension is loaded
@test_throws ArgumentError effects(design, model; invlink=AutoInvLink())
end
end
Expand All @@ -52,7 +54,11 @@ end
:Neuroticism => [16])
X = [1.0 13.0 16.0 13 * 16]
iv = Base.Fix1(GLM.linkinv, Link(model.model))
invlinks = [iv, AutoInvLink()]
@static if VERSION >= v"1.9"
invlinks = [iv, AutoInvLink()]
else
invlinks = [iv]
end
@testset "invlink = $invlink" for invlink in invlinks
for level in [0.68, 0.95]
eff = effects(design, model; invlink, level)
Expand Down Expand Up @@ -95,17 +101,19 @@ end
end
end

@testset "link function in a MixedModel" begin
model = fit(MixedModel,
@formula(use ~ 1 + age + (1|urban)),
MixedModels.dataset(:contra),
Bernoulli(); progress=false)
design = Dict(:age => -10:10)
eff_manual = effects(design, model;
invlink=Base.Fix1(GLM.linkinv, Link(model)))
eff_auto = effects(design, model; invlink=AutoInvLink())
@static if VERSION >= v"1.9"
@testset "link function in a MixedModel" begin
model = fit(MixedModel,
@formula(use ~ 1 + age + (1|urban)),
MixedModels.dataset(:contra),
Bernoulli(); progress=false)
design = Dict(:age => -10:10)
eff_manual = effects(design, model;
invlink=Base.Fix1(GLM.linkinv, Link(model)))
eff_auto = effects(design, model; invlink=AutoInvLink())

@test all(isapprox.(Matrix(eff_manual), Matrix(eff_auto)))
@test all(isapprox.(Matrix(eff_manual), Matrix(eff_auto)))
end
end

@testset "identity by another name" begin
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using Effects
using Test

@testset "Aqua" begin
Aqua.test_all(Effects; ambiguities=false)
Aqua.test_all(Effects; ambiguities=false, project_toml_formatting)
end

@testset "TypicalTerm" begin
Expand Down

0 comments on commit 9a447a9

Please sign in to comment.