Monte Carlo test (source code)

= Monte Carlo test
{c}
{title2=$p_B=[1+\sum_{b=1}^B\mathbf1_{\{T_b\ge T_{\rm obs}\}}]/(B+1)$}

Generate independent replicated datasets under a fully specified <null hypothesis> and calculate the same <predictive discrepancy statistic> for them and the observation. Their null exchangeability gives a finite-simulation rank test. The displayed add-one tail probability is valid with conservative treatment of ties, and avoids reporting zero solely because no replicate exceeds the observation.