|
643 | 643 | @test preds_delta.upper .- preds_delta.lower ≈ 2 .* 1.96 .* R_glm_se atol=1e-3 |
644 | 644 | @test_throws ArgumentError predict(gm, newX, interval=:confidence, interval_method=:undefined_method) |
645 | 645 | @test_throws ArgumentError predict(gm, newX, interval=:undefined) |
646 | | -end |
| 646 | +end |
| 647 | + |
| 648 | +@testset "F test comparing to null model" begin |
| 649 | + d = DataFrame(Treatment=[1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2.], |
| 650 | + Result=[1.1, 1.2, 1, 2.2, 1.9, 2, .9, 1, 1, 2.2, 2, 2], |
| 651 | + Other=categorical([1, 1, 2, 1, 2, 1, 3, 1, 1, 2, 2, 1])) |
| 652 | + mod = lm(@formula(Result~Treatment), d).model |
| 653 | + othermod = lm(@formula(Result~Other), d).model |
| 654 | + nullmod = lm(@formula(Result~1), d).model |
| 655 | + bothmod = lm(@formula(Result~Other+Treatment), d).model |
| 656 | + nointerceptmod = lm(reshape(d.Treatment, :, 1), d.Result) |
| 657 | + |
| 658 | + ft1 = ftest(mod) |
| 659 | + ft1base = ftest(nullmod, mod) |
| 660 | + @test ft1.nobs == ft1base.nobs |
| 661 | + @test ft1.dof ≈ dof(mod) - dof(nullmod) |
| 662 | + @test ft1.fstat ≈ ft1base.fstat[2] |
| 663 | + @test ft1.pval ≈ ft1base.pval[2] |
| 664 | + if VERSION >= v"1.6.0" |
| 665 | + @test sprint(show, ft1) == """ |
| 666 | + F-test against the null model: |
| 667 | + F-statistic: 241.62 on 12 observations and 1 degrees of freedom, p-value: <1e-07""" |
| 668 | + else |
| 669 | + @test sprint(show, ft1) == """ |
| 670 | + F-test against the null model: |
| 671 | + F-statistic: 241.62 on 12 observations and 1 degrees of freedom, p-value: <1e-7""" |
| 672 | + end |
| 673 | + |
| 674 | + ft2 = ftest(othermod) |
| 675 | + ft2base = ftest(nullmod, othermod) |
| 676 | + @test ft2.nobs == ft2base.nobs |
| 677 | + @test ft2.dof ≈ dof(othermod) - dof(nullmod) |
| 678 | + @test ft2.fstat ≈ ft2base.fstat[2] |
| 679 | + @test ft2.pval ≈ ft2base.pval[2] |
| 680 | + @test sprint(show, ft2) == """ |
| 681 | + F-test against the null model: |
| 682 | + F-statistic: 1.12 on 12 observations and 2 degrees of freedom, p-value: 0.3690""" |
| 683 | + |
| 684 | + ft3 = ftest(bothmod) |
| 685 | + ft3base = ftest(nullmod, bothmod) |
| 686 | + @test ft3.nobs == ft3base.nobs |
| 687 | + @test ft3.dof ≈ dof(bothmod) - dof(nullmod) |
| 688 | + @test ft3.fstat ≈ ft3base.fstat[2] |
| 689 | + @test ft3.pval ≈ ft3base.pval[2] |
| 690 | + if VERSION >= v"1.6.0" |
| 691 | + @test sprint(show, ft3) == """ |
| 692 | + F-test against the null model: |
| 693 | + F-statistic: 81.97 on 12 observations and 3 degrees of freedom, p-value: <1e-05""" |
| 694 | + else |
| 695 | + @test sprint(show, ft3) == """ |
| 696 | + F-test against the null model: |
| 697 | + F-statistic: 81.97 on 12 observations and 3 degrees of freedom, p-value: <1e-5""" |
| 698 | + end |
| 699 | + |
| 700 | + @test_throws ArgumentError ftest(nointerceptmod) |
| 701 | +end |
647 | 702 |
|
648 | 703 | @testset "F test for model comparison" begin |
649 | 704 | d = DataFrame(Treatment=[1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2.], |
|
895 | 950 | @test hash(NegativeBinomialLink(0.3)) == hash(NegativeBinomialLink(0.3)) |
896 | 951 | @test hash(NegativeBinomialLink(0.31)) != hash(NegativeBinomialLink(0.3)) |
897 | 952 | end |
| 953 | + |
| 954 | +@testset "hasintercept" begin |
| 955 | + d = DataFrame(Treatment=[1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2.], |
| 956 | + Result=[1.1, 1.2, 1, 2.2, 1.9, 2, .9, 1, 1, 2.2, 2, 2], |
| 957 | + Other=categorical([1, 1, 2, 1, 2, 1, 3, 1, 1, 2, 2, 1])) |
| 958 | + |
| 959 | + mod = lm(@formula(Result~Treatment), d).model |
| 960 | + @test hasintercept(mod) |
| 961 | + |
| 962 | + nullmod = lm(@formula(Result~1), d).model |
| 963 | + @test hasintercept(nullmod) |
| 964 | + |
| 965 | + nointerceptmod = lm(reshape(d.Treatment, :, 1), d.Result) |
| 966 | + @test !hasintercept(nointerceptmod) |
| 967 | + |
| 968 | + rng = StableRNG(1234321) |
| 969 | + secondcolinterceptmod = glm([randn(rng, 5) ones(5)], ones(5), Binomial(), LogitLink()) |
| 970 | + @test hasintercept(secondcolinterceptmod) |
| 971 | +end |
0 commit comments