mcframework.utils.autocrit#

mcframework.utils.autocrit(confidence: float, n: int, method: str = 'auto') tuple[float, str][source]#

Select a critical value (z or t) for two-sided CIs.

Chooses between z_crit() and t_crit() based on the requested method and the sample size n:

  • method="z" – always use normal criticals.

  • method="t" – always use Student t with \mathrm{df} = \max(1, n-1).

  • method="auto" – use z if n \ge 30, else t.

Parameters:
confidencefloat

Confidence level in (0, 1).

nint

Sample size used to choose the rule-of-thumb cutoff for "auto".

method{“auto”, “z”, “t”}, default “auto”

Selection policy.

Returns:
(float, str)

Pair (crit, kind) where crit is the critical value and kind is the string "z" or "t" indicating the choice.

Raises:
ValueError

If confidence is invalid or method is not one of {"auto","z","t"}.

See also

mcframework.stats_engine.ci_mean

Uses this selector to build mean CIs.

Notes

The returned critical is intended for two-sided intervals of the form

\[\bar X \pm c \,\frac{s}{\sqrt{n}},\]

where \(c\) is either \(z_{\alpha/2}\) or \(t_{\alpha/2,\;\mathrm{df}}\) with \(\mathrm{df}=\max(1, n-1)\).

Examples

>>> c, kind = autocrit(0.95, n=20, method="auto")
>>> kind
't'
>>> round(c, 2)
2.09
>>> c, kind = autocrit(0.95, n=50, method="auto")
>>> kind
'z'
>>> round(c, 2)
1.96