Skip to content

Commit

Permalink
Fix ftest printing
Browse files Browse the repository at this point in the history
And uncomment tests.

Also avoid using mod as an identifier since it can conflict with Base.mod
  • Loading branch information
nalimilan committed Sep 10, 2018
1 parent b5e5cb2 commit f588c90
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
13 changes: 6 additions & 7 deletions src/ftest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,18 @@ julia> dat = DataFrame(Treatment=[1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2.],
Result=[1.1, 1.2, 1, 2.2, 1.9, 2, .9, 1, 1, 2.2, 2, 2],
Other=[1, 1, 2, 1, 2, 1, 3, 1, 1, 2, 2, 1]);
julia> mod = lm(@formula(Result ~ 1 + Treatment), dat);
julia> model = lm(@formula(Result ~ 1 + Treatment), dat);
julia> nullmod = lm(@formula(Result ~ 1), dat);
julia> nullmodel = lm(@formula(Result ~ 1), dat);
julia> bigmod = lm(@formula(Result ~ 1 + Treatment + Other), dat);
julia> bigmodel = lm(@formula(Result ~ 1 + Treatment + Other), dat);
julia> ft = ftest(mod.model, nullmod.model)
julia> ft = ftest(model.model, nullmodel.model)
Res. DOF DOF ΔDOF SSR ΔSSR R² ΔR² F* p(>F)
Model 1 10 3 0.1283 0.9603
Model 2 11 2 -1 3.2292 -3.1008 0.0000 0.9603 241.6234 <1e-7
julia> ftest(bigmod.model, mod.model, nullmod.model)
julia> ftest(bigmodel.model, model.model, nullmodel.model)
Res. DOF DOF ΔDOF SSR ΔSSR R² ΔR² F* p(>F)
Model 1 9 4 0.1038 0.9678
Model 2 10 3 -1 0.1283 -0.0245 0.9603 0.0076 2.1236 0.1790
Expand Down Expand Up @@ -107,7 +106,7 @@ function show(io::IO, ftr::FTestResult{N}) where N

nc = 10
nr = N
outrows = Matrix{String}(nr+1, nc)
outrows = Matrix{String}(undef, nr+1, nc)

outrows[1, :] = ["", "Res. DOF", "DOF", "ΔDOF", "SSR", "ΔSSR",
"", "ΔR²", "F*", "p(>F)"]
Expand Down
27 changes: 13 additions & 14 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -487,25 +487,24 @@ end

ft = ftest(mod, nullmod)
@test isapprox(ft.pval[1].v, 2.481215056713184e-8)
# Test output - already covered in doctest
# @test sprint(show, ftest(mod, nullmod)) ==
# """
# Res. DOF DOF ΔDOF SSR ΔSSR R² ΔR² F* p(>F)
# Model 1 10 3 0.1283 0.9603
# Model 2 11 2 -1 3.2292 -3.1008 -0.0000 0.9603 241.6234 <1e-7
# """
@test sprint(show, ftest(mod, nullmod)) ==
"""
Res. DOF DOF ΔDOF SSR ΔSSR R² ΔR² F* p(>F)
Model 1 10 3 0.1283 0.9603
Model 2 11 2 -1 3.2292 -3.1008 -0.0000 0.9603 241.6234 <1e-7
"""

bigmod = lm(@formula(Result~Treatment+Other), d).model
ft2 = ftest(bigmod, mod, nullmod)
@test isapprox(ft2.pval[2].v, 2.481215056713184e-8)
@test isapprox(ft2.pval[1].v, 0.17903437900958952)
# @test sprint(show, ftest(bigmod, mod, nullmod)) ==
# """
# Res. DOF DOF ΔDOF SSR ΔSSR R² ΔR² F* p(>F)
# Model 1 9 4 0.1038 0.9678
# Model 2 10 3 -1 0.1283 -0.0245 0.9603 0.0076 2.1236 0.1790
# Model 3 11 2 -1 3.2292 -3.1008 -0.0000 0.9603 241.6234 <1e-7
# """
@test sprint(show, ftest(bigmod, mod, nullmod)) ==
"""
Res. DOF DOF ΔDOF SSR ΔSSR R² ΔR² F* p(>F)
Model 1 9 4 0.1038 0.9678
Model 2 10 3 -1 0.1283 -0.0245 0.9603 0.0076 2.1236 0.1790
Model 3 11 2 -1 3.2292 -3.1008 -0.0000 0.9603 241.6234 <1e-7
"""
end

@testset "F test rounding error" begin
Expand Down

0 comments on commit f588c90

Please sign in to comment.