What's the most efficient way to resample from an array many times and take the mode of each sample?

Question:

So bootstrapping, but for modes.

The end goal is to create a probability distribution out of these modes. I need to create a test statistic that compares these distributions (and then perform a permutation test), so the initial bootstrapping needs to be as quick as possible so that creating the null distribution doesn’t take too much time.
Can I use numpy’s random.choice for this?

Asked By: Anthony Petruzzio

||

Answers:

Adapting from Using bootstrapping random.choice

import scipy.stats as ss

array = ...
num_samples = 1000

sample_size = 100

Replications = np.array([np.random.choice(array, sample_size, replace = True) for _ in range(num_samples)])
mode_result = ss.mode(Replications, axis=1)

mode = mode_result.mode
Answered By: Dash
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.