Skip to content

Commit

Permalink
Merge c075476 into da3b70d
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasnoack committed Oct 7, 2020
2 parents da3b70d + c075476 commit c28e7ac
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ os:

julia:
- 1.0
- 1.3
- 1
- nightly

matrix:
Expand Down
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
3 changes: 2 additions & 1 deletion src/HypothesisTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))))

Expand Down
29 changes: 15 additions & 14 deletions test/f.jl
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
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)

@test t.n_x == 500
@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)
Expand All @@ -25,22 +26,22 @@ 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)

@test t.n_x == 200
@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
Expand Down
49 changes: 49 additions & 0 deletions test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions test/white.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
"""

Expand Down

0 comments on commit c28e7ac

Please sign in to comment.