Skip to content
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

Add Constructor to FisherExactTest #156

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/fisher.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ export FisherExactTest

"""
FisherExactTest(a::Integer, b::Integer, c::Integer, d::Integer)
FisherExactTest(x)

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.

See [`pvalue(::FisherExactTest)`](@ref) and [`confint(::FisherExactTest)`](@ref) for details
about the computation of the default p-value and confidence interval, respectively.

Expand All @@ -41,10 +45,11 @@ The contingency table is structured as:
|*Y1*| a | b |
|*Y2*| c | d |

!!! note
!!! Note:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is syntax, not text, so please keep it as-is.

The `show` function output contains the conditional maximum likelihood estimate of the
odds ratio rather than the sample odds ratio; it maximizes the likelihood given by
Fisher's non-central hypergeometric distribution.
The entries must be non-negative integers.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Say this in the sentence about contingency table rather than in this note, which is about something else.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made all the suggested changes.


Implements: [`pvalue(::FisherExactTest)`](@ref), [`confint(::FisherExactTest)`](@ref)

Expand Down Expand Up @@ -73,6 +78,10 @@ struct FisherExactTest <: HypothesisTest
end
end

function FisherExactTest(x::AbstractMatrix{T}) where T<:Integer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function FisherExactTest(x::AbstractMatrix{T}) where T<:Integer
function FisherExactTest(x::AbstractMatrix{<:Integer})

FisherExactTest(x[1,1], x[1,2], x[2,1], x[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
Expand Down