Skip to content

Commit 010711e

Browse files
authored
Merge pull request #147 from Jacobluke-/vnbdev
∆∆ updates and Issue #144 fixes
2 parents f41f3d5 + 486005a commit 010711e

File tree

122 files changed

+1866
-560
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+1866
-560
lines changed

.github/workflows/test-image.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ jobs:
88
- uses: actions/checkout@v3
99
- uses: actions/setup-python@v4
1010
with:
11-
python-version: 3.9
11+
python-version: 3.8
1212
cache: "pip"
1313
cache-dependency-path: settings.ini
1414
- name: Run pytest
1515
run: |
1616
python -m pip install --upgrade pip
17-
pip install .[dev]
17+
pip install -e '.[dev]'
1818
pytest nbs/tests/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Python**. This new version provided the following new features:
1717
2. **Proportional data.** Generates proportional bar plots,
1818
proportional differences, and calculates Cohen’s h. Also enables
1919
plotting Sankey diagrams for paired binary data. This is the
20-
estimation equivalent to a bar chart with Fischer’s exact test.
20+
estimation equivalent to a bar chart with Fisher’s exact test.
2121

2222
3. **The $\Delta\Delta$ plot.** Calculates the delta-delta
2323
($\Delta\Delta$) for 2 × 2 experimental designs and plots the four

bumpver.toml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# bumpver.toml
2+
# This file is used for BumpVer, don't use nbdev_bump_version to bump version
3+
# since it's only available for increasing one digit.
4+
# After finishing all the setup for this package, run through all the notebooks for version updates in docs.
5+
6+
[bumpver]
7+
current_version = "2023.03.29"
8+
version_pattern = "YYYY.0M.0D"
9+
commit_message = "bump version {old_version} -> {new_version}"
10+
commit = true
11+
tag = true
12+
push = false
13+
14+
[bumpver.file_patterns]
15+
"bumpver.toml" = [
16+
'current_version = "{version}"',
17+
]
18+
"settings.ini" = [
19+
'version = {version}'
20+
]
21+
"dabest/__init__.py" = [
22+
'__version__ = "{version}"'
23+
]

dabest/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from ._api import load
1+
from ._api import load, prop_dataset
22
from ._stats_tools import effsize as effsize
33
from ._classes import TwoGroupsEffectSize, PermutationTest
44

5-
__version__ = "2023.2.14"
5+
__version__ = "2023.03.29"

dabest/_api.py

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/API/load.ipynb.
22

33
# %% auto 0
4-
__all__ = ['load']
4+
__all__ = ['load', 'prop_dataset']
55

66
# %% ../nbs/API/load.ipynb 4
77
def load(data, idx=None, x=None, y=None, paired=None, id_col=None,
@@ -77,3 +77,54 @@ def load(data, idx=None, x=None, y=None, paired=None, id_col=None,
7777
return Dabest(data, idx, x, y, paired, id_col, ci, resamples, random_seed, proportional, delta2, experiment, experiment_label, x1_level, mini_meta)
7878

7979

80+
81+
# %% ../nbs/API/load.ipynb 5
82+
import numpy as np
83+
from typing import Union, Optional
84+
85+
def prop_dataset(group:Union[list, tuple, np.ndarray, dict], #Accepts lists, tuples, or numpy ndarrays of numeric types.
86+
group_names: Optional[list] = None):
87+
'''
88+
Convenient function to generate a dataframe of binary data.
89+
'''
90+
import pandas as pd
91+
92+
if isinstance(group, dict):
93+
# If group_names is not provided, use the keys of the dict as group_names
94+
if group_names is None:
95+
group_names = list(group.keys())
96+
elif not set(group_names) == set(group.keys()):
97+
# Check if the group_names provided is the same as the keys of the dict
98+
raise ValueError('group_names must be the same as the keys of the dict.')
99+
# Check if the values in the dict are numeric
100+
if not all([isinstance(group[name], (list, tuple, np.ndarray)) for name in group_names]):
101+
raise ValueError('group must be a dict of lists, tuples, or numpy ndarrays of numeric types.')
102+
# Check if the values in the dict only have two elements under each parent key
103+
if not all([len(group[name]) == 2 for name in group_names]):
104+
raise ValueError('Each parent key should have only two elements.')
105+
group_val = group
106+
107+
else:
108+
if group_names is None:
109+
raise ValueError('group_names must be provided if group is not a dict.')
110+
# Check if the length of group is two times of the length of group_names
111+
if not len(group) == 2 * len(group_names):
112+
raise ValueError('The length of group must be two times of the length of group_names.')
113+
group_val = {group_names[i]: [group[i*2], group[i*2+1]] for i in range(len(group_names))}
114+
115+
# Check if the sum of values in group_val under each key are the same
116+
if not all([sum(group_val[name]) == sum(group_val[group_names[0]]) for name in group_val.keys()]):
117+
raise ValueError('The sum of values under each key must be the same.')
118+
119+
id_col = pd.Series(range(1, sum(group_val[group_names[0]])+1))
120+
121+
final_df = pd.DataFrame()
122+
123+
for name in group_val.keys():
124+
col = np.repeat(0, group_val[name][0]).tolist() + np.repeat(1, group_val[name][1]).tolist()
125+
df = pd.DataFrame({name:col})
126+
final_df = pd.concat([final_df, df], axis=1)
127+
128+
final_df['ID'] = id_col
129+
130+
return final_df

0 commit comments

Comments
 (0)