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

optimise ExactPermutationTest. #225

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/permutation.jl
Expand Up @@ -21,8 +21,11 @@ that `f(x)` is equal to `f(y)`. All possible permutations are sampled.
function ExactPermutationTest(x::AbstractVector{R}, y::AbstractVector{S},
f::Function) where {R<:Real,S<:Real}
xy, rx, ry = ptstats(x,y)
P = permutations(xy)
samples = [f(view(p,rx)) - f(view(p,ry)) for p in P]
rxry = [rx;ry]
P = combinations(rxry,rx[end])
# check the length of the output before allocating memory (10^9 is time consuming, but feasible)
@assert binomial(big(length(rxry)),rx[end])<10^9 "Performing the exact test is computionally expensive, you may use the ApproximatePermutationTest function instead."
samples = [f(view(xy,p)) - f(view(xy,setdiff(rxry,p))) for p in P]
PermutationTest(f(x) - f(y), samples)
end

Expand Down