Nonparametric Tests for Two-Sample Problems

twosample.brunner_munzel_test(x: list, y: list, alternative='two.sided', quantile='t') → list[source]

Function to calculate the Brunner-Munzel test. It is recommended to use the t-approximation for small samples.

Args:

x (list(float)): data from first group

y (list(float)): data from second group

alternative (str): either ‘two.sided’, ‘less’ or ‘greater’

quantile (str): either ‘t’ for the small sample approximation with a t-distribution or ‘normal’ for the large sample procedure.

Returns:

namedtuple(‘BrunnerMunzelResult’, (‘alternative’, ‘statistic’, ‘df’, ‘pvalue’)):

chosen alternative (str)

test statistic (float)

estimated degrees of freedom for the t-approximation, only when quantile = ‘t’ (float)

p-value (float)

twosample.hodges_lehmann(x: list, y: list, alpha=0.05)[source]

Function to calculate the Hodges-Lehmann estimator.

Let us assume a location shift effect, i.e., F_1(x) = F(x - mu_1), i = 1,2 and theta = mu_2 - mu_1.

The Hodges-Lehmann estimator theta_hat is an asymptotically unbiased estimator for theta.

Note that the calculated confidence interval is only valid if there are no ties in the data.

Args:

x (list(float)): data from first group

y (list(float)): data from second group

Returns:

namedtuple(‘HodgesLehmannEstimator’, (‘estimate’, ‘lowerCI’, ‘upperCI’)):

Hodges-Lehmann estimator theta_hat (float)

lower bound for the asymptotic 1-alpha/2 confidence interval for theta (float)

upper bound for the 1-alpha/2 confidence interval for theta (float)

twosample.wilcoxon_mann_whitney_ssp(x: list, y: list, power=0.8, alpha=0.05, t=0.5)[source]

Function to do sample size planning for the WMW test.

Args:

x (list(float)): prior information from first group

y (list(float)): prior information from second group

power (float): probablity to detect an effect based on prior information

alpha (float): type-I error probability

t (float): ratio of subjects assigned to first group.

Returns:

namedtuple(‘WilcoxonMannWhitneyResult’, (‘alpha’, ‘power’, ‘relEffect’, ‘N’, ‘t’, ‘n1’, ‘n2’, ‘Nrounded’, ‘n1rouned’, ‘n2rouned’)):

alpha (float)

power(float)

relEffect (float): calculated relative Effect

N (float): minimal sample size required

n1 (float): sample size for group 1 required; N = t*n1

n2 (float): sample size for group 2 required; N = (1-t)*n1

twosample.wilcoxon_mann_whitney_test(x: list, y: list, alternative='two.sided', alpha=0.05, method='asymptotic')[source]

Function to calculate the Wilcoxon-Mann-Whitney test.

Args:

x (list(float)): data from first group

y (list(float)): data from second group

alternative (str): either ‘two.sided’, ‘less’ (x less y) or ‘greater’ (x greater y)

alpha (float): 1-alpha confidence interval (only valid if there are no ties)

method (str): use ‘asymptotic’ for the asymptotic test (normal distribution) or the exact test with ‘exact’.

Returns:

namedtuple(‘WilcoxonMannWhitneyResult’, (‘alternative’, ‘statistic’, ‘HodgesLehmann’, ‘lowerCI’, ‘upperCI’, ‘pvalue’)):

chosen alternative (str)

test statistic (float)

hodges lehmann estimate for a location shift effect y - x (float)

lower bound for 1-alpha CI for location shift effect (float)

upper bound for 1-alpha CI for location shift effect (float)

p-value