-
Notifications
You must be signed in to change notification settings - Fork 88
Add Constructor to FisherExactTest #156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
3492754
037a393
87905cb
ce7d35a
150cda6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -26,11 +26,17 @@ export FisherExactTest | |||||
|
||||||
""" | ||||||
FisherExactTest(a::Integer, b::Integer, c::Integer, d::Integer) | ||||||
FisherExactTest(x[, y]) | ||||||
|
||||||
Perform Fisher's exact test of the null hypothesis that the success probabilities ``a/c`` | ||||||
and ``b/d`` are equal, that is the odds ratio ``(a/c) / (b/d)`` is one, against the | ||||||
alternative hypothesis that they are not equal. | ||||||
|
||||||
If `x` is a matrix with at least two rows and columns, it is taken as a two-dimensional | ||||||
contingency table. Otherwise, `x` and `y` must be vectors of the same length. The contingency | ||||||
table is calculated using `counts` function from the `StatsBase` package. | ||||||
Note that the entries of `x` (and `y` if provided) must be non-negative integers. | ||||||
|
||||||
See [`pvalue(::FisherExactTest)`](@ref) and [`confint(::FisherExactTest)`](@ref) for details | ||||||
about the computation of the default p-value and confidence interval, respectively. | ||||||
|
||||||
|
@@ -73,6 +79,15 @@ struct FisherExactTest <: HypothesisTest | |||||
end | ||||||
end | ||||||
|
||||||
function FisherExactTest(x::AbstractMatrix{T}) where T<:Integer | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
FisherExactTest(x[1,1], x[1,2], x[2,1], x[2,2]) | ||||||
end | ||||||
|
||||||
function FisherExactTest(x::AbstractVector{T}, y::AbstractVector{T}) where T<:Integer | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
d = counts(x, y) | ||||||
FisherExactTest(d[1,1], d[1,2], d[2,1], d[2,2]) | ||||||
end | ||||||
|
||||||
testname(::FisherExactTest) = "Fisher's exact test" | ||||||
population_param_of_interest(x::FisherExactTest) = ("Odds ratio", 1.0, x.ω) # parameter of interest: name, value under h0, point estimate | ||||||
default_tail(test::FisherExactTest) = :both | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
using HypothesisTests, Test | ||
using StatsBase | ||
using HypothesisTests: default_tail | ||
|
||
@testset "Fisher" begin | ||
|
@@ -107,4 +108,14 @@ show(IOBuffer(), t) | |
t = HypothesisTests.FisherExactTest(1, 1, 1, 1) | ||
@test HypothesisTests.pvalue(t, tail=:both) <= 1 | ||
show(IOBuffer(), t) | ||
|
||
# constructor test for matrix and vectors | ||
x=[1,1,1,0,0,0,0,0,1,1] | ||
y=[1,1,0,0,1,0,1,1,1,1] | ||
|
||
d = counts(x,y) | ||
|
||
FisherExactTest(d) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please check that results are the same for both calls, and that they are equal to what you get when passing |
||
FisherExactTest(x,y) | ||
|
||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.