diff --git a/.travis.yml b/.travis.yml index c62046e0..a0920e0b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ os: julia: - 1.0 - - 1.3 + - 1 - nightly matrix: diff --git a/Project.toml b/Project.toml index 977e3b7d..0c87d520 100644 --- a/Project.toml +++ b/Project.toml @@ -22,7 +22,8 @@ julia = "1" [extras] DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab" +StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["DelimitedFiles", "Test"] +test = ["DelimitedFiles", "StableRNGs", "Test"] diff --git a/src/HypothesisTests.jl b/src/HypothesisTests.jl index 565bfb33..8939ca00 100644 --- a/src/HypothesisTests.jl +++ b/src/HypothesisTests.jl @@ -98,7 +98,8 @@ function check_level(level::Float64) end # Pretty-print -function Base.show(io::IO, test::T) where T<:HypothesisTest +function Base.show(_io::IO, test::T) where T<:HypothesisTest + io = IOContext(_io, :compact=>get(_io, :compact, true)) println(io, testname(test)) println(io, repeat("-", length(testname(test)))) diff --git a/test/f.jl b/test/f.jl index a0ab58f4..772d869f 100644 --- a/test/f.jl +++ b/test/f.jl @@ -1,11 +1,12 @@ using HypothesisTests, Test using HypothesisTests: default_tail +using StableRNGs @testset "F-tests" begin @testset "Basic variance F-test" begin - Random.seed!(12) - y1_h0 = 4 .+ randn(500) - y2_h0 = 4 .+ randn(400) + rng = StableRNG(12) + y1_h0 = 4 .+ randn(rng, 500) + y2_h0 = 4 .+ randn(rng, 400) t = VarianceFTest(y1_h0, y2_h0) @@ -13,10 +14,10 @@ using HypothesisTests: default_tail @test t.n_y == 400 @test t.df_x == 499 @test t.df_y == 399 - @test t.F ≈ 0.974693 rtol=1e-5 - @test pvalue(t) ≈ 0.784563 rtol=1e-5 - @test pvalue(t, tail=:left) ≈ 0.392281 rtol=1e-5 - @test pvalue(t, tail=:right) ≈ 0.607718 rtol=1e-5 + @test t.F ≈ 0.859582 rtol=1e-5 + @test pvalue(t) ≈ 0.109714 rtol=1e-5 + @test pvalue(t, tail=:left) ≈ 0.0548572 rtol=1e-5 + @test pvalue(t, tail=:right) ≈ 0.945143 rtol=1e-5 @test default_tail(t) == :both t = VarianceFTest(y2_h0, y1_h0) @@ -25,14 +26,14 @@ using HypothesisTests: default_tail @test t.n_y == 500 @test t.df_x == 399 @test t.df_y == 499 - @test t.F ≈ 1.025963 rtol=1e-5 - @test pvalue(t) ≈ 0.784563 rtol=1e-5 - @test pvalue(t, tail=:right) ≈ 0.392281 rtol=1e-5 - @test pvalue(t, tail=:left) ≈ 0.607718 rtol=1e-5 + @test t.F ≈ 1.163355 rtol=1e-5 + @test pvalue(t) ≈ 0.109714 rtol=1e-5 + @test pvalue(t, tail=:right) ≈ 0.0548572 rtol=1e-5 + @test pvalue(t, tail=:left) ≈ 0.945143 rtol=1e-5 @test default_tail(t) == :both - y1_h1 = 0.7*randn(200) - y2_h1 = 1.3*randn(120) + y1_h1 = 0.7*randn(rng, 200) + y2_h1 = 1.3*randn(rng, 120) t = VarianceFTest(y1_h1, y2_h1) @@ -40,7 +41,7 @@ using HypothesisTests: default_tail @test t.n_y == 120 @test t.df_x == 199 @test t.df_y == 119 - @test t.F ≈ 0.367547 rtol=1e-5 + @test t.F ≈ 0.264161 rtol=1e-5 @test pvalue(t) < 1e-8 @test default_tail(t) == :both @test pvalue(t, tail=:left) < 1e-8 diff --git a/test/show.jl b/test/show.jl index d07c35d9..34919f5f 100644 --- a/test/show.jl +++ b/test/show.jl @@ -5,6 +5,7 @@ using HypothesisTests, Test d = [[762,484] [327,239] [468,477]] m = PowerDivergenceTest(d) +if VERSION < v"1.4" @test sprint(show, m, context=:compact => true) == """ Pearson's Chi-square Test @@ -51,6 +52,54 @@ m = PowerDivergenceTest(d) residuals: [0.0, -1.11803, 1.11803] std. residuals: [0.0, -1.36931, 1.36931] """ +else +@test sprint(show, m, context=:compact => true) == + """ + Pearson's Chi-square Test + ------------------------- + Population details: + parameter of interest: Multinomial Probabilities + value under h_0: [0.255231, 0.19671, 0.11594, 0.0893561, 0.193574, 0.14919] + point estimate: [0.276387, 0.175553, 0.118607, 0.0866884, 0.16975, 0.173014] + 95% confidence interval: [(0.2545, 0.2994), (0.1573, 0.1955), (0.1033, 0.1358), (0.0736, 0.1019), (0.1517, 0.1894), (0.1548, 0.1928)] + + Test summary: + outcome with 95% confidence: reject h_0 + one-sided p-value: <1e-6 + + Details: + Sample size: 2757 + statistic: 30.070149095754687 + degrees of freedom: 2 + residuals: [2.19886, -2.50467, 0.41137, -0.468583, -2.84324, 3.23867] + std. residuals: [4.50205, -4.50205, 0.699452, -0.699452, -5.31595, 5.31595] + """ + +d = [ 20, 15, 25 ] +m = PowerDivergenceTest(d) + +@test sprint(show, m, context=:compact => true) == + """ + Pearson's Chi-square Test + ------------------------- + Population details: + parameter of interest: Multinomial Probabilities + value under h_0: [0.333333, 0.333333, 0.333333] + point estimate: [0.333333, 0.25, 0.416667] + 95% confidence interval: [(0.2167, 0.481), (0.1333, 0.3976), (0.3, 0.5643)] + + Test summary: + outcome with 95% confidence: fail to reject h_0 + one-sided p-value: 0.2865 + + Details: + Sample size: 60 + statistic: 2.5 + degrees of freedom: 2 + residuals: [0.0, -1.11803, 1.11803] + std. residuals: [0.0, -1.36931, 1.36931] + """ +end # based on t.jl tests tst = OneSampleTTest(-5:10) diff --git a/test/white.jl b/test/white.jl index df118655..e01be522 100644 --- a/test/white.jl +++ b/test/white.jl @@ -221,15 +221,15 @@ e = [ 5.19346; Population details: parameter of interest: T*R2 value under h_0: 0 - point estimate: $(w_test.lm) + point estimate: $(sprint(show, w_test.lm; context=:compact => true)) Test summary: outcome with 95% confidence: fail to reject h_0 one-sided p-value: $(round(w_pval,digits=4)) Details: - T*R^2 statistic: $(w_test.lm) - degrees of freedom: $(w_test.dof) + T*R^2 statistic: $(sprint(show, w_test.lm ; context=:compact => true)) + degrees of freedom: $(sprint(show, w_test.dof ; context=:compact => true)) type: $(w_test.type) """