Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dunnett alter arg and function test #69

Merged
merged 2 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions scikit_posthocs/_posthocs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import itertools as it
from typing import Tuple, Union
from typing import Tuple, Union, Literal
import numpy as np
import scipy.stats as ss
from statsmodels.sandbox.stats.multicomp import multipletests
Expand Down Expand Up @@ -1565,6 +1565,7 @@ def posthoc_dunnett(a: Union[list, np.ndarray, DataFrame],
val_col: str = None,
group_col: str = None,
control: str = None,
alternative: Literal['two-sided', 'less', 'greater'] = 'two-sided',
sort: bool = False,
to_matrix: bool = True) -> Union[Series, DataFrame]:
"""
Expand Down Expand Up @@ -1592,6 +1593,11 @@ def posthoc_dunnett(a: Union[list, np.ndarray, DataFrame],
have a nominal scale (categorical). Must be specified if `a` is a pandas
DataFrame.

alternative : ['two-sided', 'less', or 'greater'], optional
Whether to get the p-value for the one-sided hypothesis
('less' or 'greater') or for the two-sided hypothesis ('two-sided').
Defaults to 'two-sided'.

sort : bool, optional
Specifies whether to sort DataFrame by group_col or not. Recommended
unless you sort your data manually.
Expand Down Expand Up @@ -1619,7 +1625,7 @@ def posthoc_dunnett(a: Union[list, np.ndarray, DataFrame],
control_data = x_embedded.loc[control]
treatment_data = x_embedded.drop(control)

pvals = ss.dunnett(*treatment_data, control=control_data).pvalue
pvals = ss.dunnett(*treatment_data, control=control_data, alternative=alternative).pvalue

multi_index = MultiIndex.from_product([[control], treatment_data.index.tolist()])
dunnett_sr = Series(pvals, index=multi_index)
Expand Down
15 changes: 15 additions & 0 deletions tests/test_posthocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,21 @@ def test_posthoc_tukey(self):
self.assertTrue(np.allclose(results, r_results, atol=1.e-3))


def test_posthoc_dunnett(self):
r_results = [8.125844e-11, 2.427434e-01]
results = sp.posthoc_dunnett(self.df.sort_index(), val_col='pulse', group_col='kind',
control='rest', to_matrix=False)

# scipy use randomized Quasi-Monte Carlo integration of the multivariate-t distribution
# to compute the p-values. The result may vary slightly from run to run.
# we run the test 1000 times (maximum absolute tolerance = 1.e-4 for example data)
is_close = []
for i in range(1000):
is_close.append(np.allclose(results, r_results, atol=1.e-4))
is_close = all(is_close)
self.assertTrue(is_close)


if __name__ == '__main__':
unittest.main()

Loading