cardioception.PAT.scoring.monte_carlo_threshold#

cardioception.PAT.scoring.monte_carlo_threshold(periods_ms, n_trials, n_sim=100000, q=0.95, fixed=False, seed=0, weights=None)[source]#

Chance threshold for the mean resultant length, by Monte Carlo.

Each simulated participant makes n_trials choices with delays drawn uniformly on [0, p), turned into angles with the same period p, and the MRL is computed. The threshold is the q quantile of n_sim such MRLs.

Since 2 pi U p / p = 2 pi U for U uniform on [0, 1), the angles are uniform on the circle whatever the periods, and the threshold depends only on n_trials, weights, n_sim, q and seed. The angles are drawn directly. periods_ms and fixed are checked and accepted, so callers can say which participant and mapping a threshold is for, but they do not change it.

Parameters
periods_msarray-like

The participant’s heart periods in ms (NaN ignored). They must hold at least one finite positive value; they do not change the threshold.

n_trialsint

Number of trials in each simulated participant.

n_simint

Number of simulated participants. 100,000 in the paper; fewer is fine for tests.

qfloat

Quantile of the simulated MRLs, 0.95 in the paper.

fixedbool

Fixed mapping (one period for all trials) rather than variable mapping. It does not change the threshold either.

seedint, np.random.Generator or None

Seed of the random generator. The default is fixed, so thresholds are reproducible; None draws fresh entropy.

weightsarray-like or None

Confidence weights, one per trial. When given, the null distribution is that of the weighted MRL with these weights and random angles.

Returns
thresholdfloat