A collection of statistical tests

The tests module gathers a selection of statistical tests that are not routinely available in other packages.

[1]:
# imports
import pandas as pd
import numpy as np
from stats_misc import tests

Wald based interaction test

The following test can be used to determine whether there is a statistical difference between two subgroup specific estimates.

[2]:
res = tests.wald_interaction_test([0.1, 0.05], [0.01, 0.03])
print(f"The difference: {res.point_estimate:.2f} and its p-value {res.p_value:.3f}.")
The difference: 0.05 and its p-value 0.114.

Comparing observed data against an arbitrary theoretical distribution

TThe ks_test function compares observed data against a null distribution across known groups.

[3]:
data = pd.DataFrame({
    'group': ['A', 'A', 'B', 'B', 'C'],
    'values': [0.1, 0.2, 0.3, 0.4, 0.5]
})
res = tests.ks_test(data, 'group', 'values', nulldistribution='uniform')
res["B"].pvalue
[3]:
0.32000000000000006

Aggregate data one-way ANOVA

An one-way ANOVA based on aggregate data - the results will be identical to a one-way ANOVA using the individual participants data which gave rise to the aggregate data.

[4]:
means = [2.0, 3.0, 8.0]
variances = [0.2, 0.2, 0.8]
sizes = [10, 11, 9]
res = tests.anova_one_way(means, variances, sizes)
print(f'The F-statistic is {res.test_statistic:.2f} with a p-value of {res.p_value:.4f}.')
The F-statistic is 256.99 with a p-value of 0.0000.