Fix dynamic calculation of required test samples #136
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Richard Samworth pointed out in a comment by email, that an iterative algorithm which computes the number permutation samples dynamically makes the number of permutations used by the test a function of the resampled data set, but it has to be independent of that set if the Type I error probabilities should hold theoretically.
One possibility was to use the worst case value 0.5 and compute the number of required samples from that, but this is very pessimistic when the pvalue is very small (orders of magnitude). As a compromise, this patch uses only two iterations. In the first iteration, a burn sample of 10 permutations is used to get a crude estimate of the pvalue. The required number of samples is then computed from the pvalue obtained in the burn sample. The second sample is statistically independent of the first, so this should avoid the problem.