Skip to content

Commit

Permalink
Expand p-value tail handling, test paired Hotelling
Browse files Browse the repository at this point in the history
  • Loading branch information
ararslan committed Mar 15, 2018
2 parents bed1760 + 0a0632c commit 920f087
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/covariance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ StatsBase.dof(B::BartlettsTest) = div(B.p * (B.p + 1), 2)

HypothesisTests.testname(::BartlettsTest) =
"Bartlett's Test for Equality of Covariance Matrices"
HypothesisTests.pvalue(B::BartlettsTest) = pvalue(Chisq(dof(B)), B.L′)
HypothesisTests.default_tail(::BartlettsTest) = :right
HypothesisTests.pvalue(B::BartlettsTest; tail=:right) = pvalue(Chisq(dof(B)), B.L′, tail=tail)

function HypothesisTests.show_params(io::IO, B::BartlettsTest, indent="")
println(io, indent, "number of observations: ", nobs(B))
Expand Down
4 changes: 3 additions & 1 deletion src/hotelling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

abstract type HotellingT2Test <: HypothesisTest end

HypothesisTests.pvalue(T::HotellingT2Test) = pvalue(FDist(dof(T)...), T.F)
HypothesisTests.default_tail(::HotellingT2Test) = :right
HypothesisTests.pvalue(T::HotellingT2Test; tail=:right) =
pvalue(FDist(dof(T)...), T.F, tail=tail)

function HypothesisTests.show_params(io::IO, T::HotellingT2Test, indent="")
println(io, indent, "number of observations: ", nobs(T))
Expand Down
4 changes: 3 additions & 1 deletion src/partialcor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ function StatsBase.confint(test::PartialCorTest, alpha::Float64=0.05)
return (elo, ehi)
end

HypothesisTests.pvalue(test::PartialCorTest) = pvalue(TDist(dof(test)), test.t)
HypothesisTests.default_tail(::PartialCorTest) = :both
HypothesisTests.pvalue(test::PartialCorTest; tail=:both) =
pvalue(TDist(dof(test)), test.t, tail=tail)

function HypothesisTests.show_params(io::IO, test::PartialCorTest, indent="")
println(io, indent, "number of observations: ", nobs(test))
Expand Down
30 changes: 30 additions & 0 deletions test/data/spouse.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
2 3 5 5 4 4 5 5
5 5 4 4 4 5 5 5
4 5 5 5 4 4 5 5
4 3 4 4 4 5 5 5
3 3 5 5 4 4 5 5
3 3 4 5 3 3 4 4
3 4 4 4 4 3 5 4
4 4 5 5 3 4 5 5
4 5 5 5 4 4 5 4
4 4 3 3 3 4 4 4
4 4 5 5 4 5 5 5
5 5 4 4 5 5 5 5
4 4 4 4 4 4 5 5
4 3 5 5 4 4 4 4
4 4 5 5 4 4 5 5
3 3 4 5 3 4 4 4
4 5 4 4 5 5 5 5
5 5 5 5 4 5 4 4
5 5 4 4 3 4 4 4
4 4 4 4 5 3 4 4
4 4 4 4 5 3 4 4
4 4 4 4 4 5 4 4
3 4 5 5 2 5 5 5
5 3 5 5 3 4 5 5
5 5 3 3 4 3 5 5
3 3 4 4 4 4 4 4
4 4 4 4 4 4 5 5
3 3 5 5 3 4 4 4
4 4 3 3 4 4 5 4
4 4 5 5 4 4 5 5
14 changes: 14 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ swiss = readdlm(joinpath(@__DIR__, "data", "swiss3.txt"))
genuine = convert(Matrix{Float64}, swiss[view(swiss, :, 1) .== "real", 2:end])
counterfeit = convert(Matrix{Float64}, swiss[view(swiss, :, 1) .== "fake", 2:end])

# Columns are survey answers: husbands' to questions 1-4, wives' to questions 1-4
spouse = readdlm(joinpath(@__DIR__, "data", "spouse.txt"))

@testset "Utility functions" begin
MT = MultivariateTests

Expand Down Expand Up @@ -106,6 +109,17 @@ end
let out = sprint(show, t)
@test contains(out, "reject h_0") && !contains(out, "fail to")
end

# Paired
p = OneSampleHotellingT2(spouse[:,1:4], spouse[:,5:end])
@test nobs(p) == 30
@test dof(p) == (4, 26)
@test pvalue(p) 0.039369144 atol=1e-6
@test p. 13.127840261 atol=1e-6
@test p.F 2.942446955 atol=1e-6
let out = sprint(show, p)
@test contains(out, "reject h_0") && !contains(out, "fail to")
end
end

@testset "Two sample Hotelling's T²" begin
Expand Down

0 comments on commit 920f087

Please sign in to comment.