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.
Usage
hypothesis_test(
x = NULL,
y = NULL,
method = "jarque_bera",
population_mean = 0,
lag_max = NULL,
index = NULL,
sse_restricted = NULL,
sse_full = NULL,
df_restricted = NULL,
df_full = NULL
)Arguments
- x
numeric vector: the sample (the two-sample methods' first sample, or the response series for
"linear_trend"). Ignored for"f_models".- y
numeric vector, the second sample. Required for the two-sample methods listed above, and rejected (must be
NULL) for every other method – earlier versions silently discarded aysupplied to a one-sample method instead of raising.- method
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".- population_mean
the hypothesized mean for
"one_sample_t". Default 0.- lag_max
the max lag for
"ljung_box". DefaultNULL(use the C# default rule).- index
the index (x-axis) vector for
"linear_trend". DefaultNULL, meaningseq_along(x).- sse_restricted, sse_full, df_restricted, df_full
the four
"f_models"inputs: the restricted and full models' sum of squared errors and degrees of freedom.
Value
a named numeric vector: p_value for every method but "f_models", which returns
c(f_statistic =, p_value =).
Details
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(defaultNULL, meaningfloor(min(10 * log10(length(x)), length(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(defaultseq_along(x), i.e.1:length(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.
Examples
hypothesis_test(c(4, 5, 5, 6, 9, 12, 13, 14, 14, 19, 22, 24, 25), method = "jarque_bera")
#> p_value
#> 0.592128