hypothesis_test
hypothesis_test(
x=None,
y=None,
method='jarque_bera',
population_mean=0.0,
lag_max=None,
index=None,
sse_restricted=None,
sse_full=None,
df_restricted=None,
df_full=None,
)Hypothesis tests.
Mirrors the C# HypothesisTests static class: thirteen one- and two-sample parametric and nonparametric hypothesis tests, reached through the shared hypothesis toolbox group. Every method but "f_models" returns the 2-sided p-value of its test statistic; "f_models" (the F-test comparing two nested regression models) additionally returns the F statistic itself.
Argument use by method, and the C# guard each one inherits:
"one_sample_t":x,population_mean(default 0). Needs at least 2 observations."equal_variance_t"/"unequal_variance_t":x,y.equal_variance_tneeds a combined length of at least 3;unequal_variance_thas no length guard (upstream has none either)."paired_t":x,y, which must be the same length."f":x,y, each needing at least 2 observations."f_models":sse_restricted,sse_full,df_restricted,df_full(all required;xandyare ignored).df_restrictedmust differ fromdf_full, anddf_fullmust be positive."jarque_bera"/"wald_wolfowitz":x. No length guard."ljung_box":x,lag_max(defaultNone, meaningfloor(min(10 * log10(len(x)), len(x) - 1)), the C# default rule)."mann_whitney":x,y.xmust be no longer thany, each must have more than 3 observations, and the combined length must exceed 20."mann_kendall":x. Needs at least 10 observations."linear_trend":x(the sample),index(default1..len(x)– a VALUE the regression is fit against, not an index intox).indexandxmust be the same length."unimodality":x. Needs at least 10 observations. Fits a 1-component and a 2-component Gaussian mixture model (both at the hard-coded seed 12345, so the result is deterministic) and returns the p-value of the likelihood-ratio statistic against a chi-square with 3 degrees of freedom, so a SMALL p-value is evidence against unimodality. If either mixture fit fails numerically the result isnanrather than an error, matching upstream.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| x | array_like | The sample (the two-sample methods’ first sample, or the response series for "linear_trend"). Ignored for "f_models". |
None |
| y | array_like | The second sample. Required for the two-sample methods listed above, and rejected (must be None) for every other method – earlier versions silently discarded a y supplied to a one-sample method instead of raising. |
None |
| method | str | One of "one_sample_t", "equal_variance_t", "unequal_variance_t", "paired_t", "f", "f_models", "jarque_bera", "wald_wolfowitz", "ljung_box", "mann_whitney", "mann_kendall", "linear_trend", "unimodality". |
'jarque_bera' |
| population_mean | float | The hypothesized mean for "one_sample_t". Default 0. |
0.0 |
| lag_max | int | The max lag for "ljung_box". Default None (use the C# default rule). |
None |
| index | array_like | The index (x-axis) vector for "linear_trend". Default None, meaning 1..len(x). |
None |
| sse_restricted | float | The four "f_models" inputs: the restricted and full models’ sum of squared errors and degrees of freedom. |
None |
| sse_full | float | The four "f_models" inputs: the restricted and full models’ sum of squared errors and degrees of freedom. |
None |
| df_restricted | float | The four "f_models" inputs: the restricted and full models’ sum of squared errors and degrees of freedom. |
None |
| df_full | float | The four "f_models" inputs: the restricted and full models’ sum of squared errors and degrees of freedom. |
None |
Returns
| Name | Type | Description |
|---|---|---|
| dict | {"p_value": ...} for every method but "f_models", which returns {"f_statistic": ..., "p_value": ...}. |
Examples
>>> from corehydropy import hypothesis_test
>>> round(
... hypothesis_test(
... [4, 5, 5, 6, 9, 12, 13, 14, 14, 19, 22, 24, 25], method="jarque_bera"
... )["p_value"],
... 6,
... )
0.592128