Skip to content

Commit 37786a3

Browse files
authored
Merge pull request #159 from ACCLAB/∆∆_bootstrap_rewrite
Delta2 Bootstrap Function Rewrite, nbdev Configuration and Templates for Bug Report, Feature Request added
2 parents 75fe1df + c8c8a4c commit 37786a3

19 files changed

Lines changed: 347 additions & 179 deletions
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: bug
6+
assignees: ''
7+
8+
---
9+
10+
**Describe the bug**
11+
A clear and concise description of what the bug is.
12+
13+
**To Reproduce**
14+
Steps to reproduce the behavior:
15+
1.
16+
2.
17+
18+
**Expected behavior**
19+
A clear and concise description of what you expected to happen.
20+
21+
**Screenshots**
22+
If applicable, add screenshots to help explain your problem.
23+
24+
**Your package version (please complete the following information):**
25+
- dabest: [e.g. 2023.3.29]
26+
- pandas:
27+
- numpy:
28+
- matplotlib:
29+
- seaborn:
30+
- scipy:
31+
32+
33+
**Additional context**
34+
Add any other context about the problem here.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ''
5+
labels: enhancement
6+
assignees: ''
7+
8+
---
9+
10+
**Is your feature request related to a problem? Please describe.**
11+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12+
13+
**Describe the solution you'd like**
14+
A clear and concise description of what you want to happen.
15+
16+
**Describe alternatives you've considered**
17+
A clear and concise description of any alternative solutions or features you've considered.
18+
19+
**Is a dataset available for testing out the functionality**
20+
If yes, please leave a Google Drive link
21+
22+
**Additional context**
23+
Add any other context or screenshots about the feature request here.

CODE_OF_CONDUCT.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to making participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, sex characteristics, gender identity and expression,
9+
level of experience, education, socio-economic status, nationality, personal
10+
appearance, race, religion, or sexual identity and orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
* Using welcoming and inclusive language
18+
* Being respectful of differing viewpoints and experiences
19+
* Gracefully accepting constructive criticism
20+
* Focusing on what is best for the community
21+
* Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
* The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
* Trolling, insulting/derogatory comments, and personal or political attacks
28+
* Public or private harassment
29+
* Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
* Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Our Responsibilities
35+
36+
Project maintainers are responsible for clarifying the standards of acceptable
37+
behavior and are expected to take appropriate and fair corrective action in
38+
response to any instances of unacceptable behavior.
39+
40+
Project maintainers have the right and responsibility to remove, edit, or
41+
reject comments, commits, code, wiki edits, issues, and other contributions
42+
that are not aligned to this Code of Conduct, or to ban temporarily or
43+
permanently any contributor for other behaviors that they deem inappropriate,
44+
threatening, offensive, or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies both within project spaces and in public spaces
49+
when an individual is representing the project or its community. Examples of
50+
representing a project or community include using an official project e-mail
51+
address, posting via an official social media account, or acting as an appointed
52+
representative at an online or offline event. Representation of a project may be
53+
further defined and clarified by project maintainers.
54+
55+
## Enforcement
56+
57+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58+
reported by contacting the project team at joseshowh@gmail.com. All
59+
complaints will be reviewed and investigated and will result in a response that
60+
is deemed necessary and appropriate to the circumstances. The project team is
61+
obligated to maintain confidentiality with regard to the reporter of an incident.
62+
Further details of specific enforcement policies may be posted separately.
63+
64+
Project maintainers who do not follow or enforce the Code of Conduct in good
65+
faith may face temporary or permanent repercussions as determined by other
66+
members of the project's leadership.
67+
68+
## Attribution
69+
70+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72+
73+
[homepage]: https://www.contributor-covenant.org
74+
75+
For answers to common questions about this code of conduct, see
76+
https://www.contributor-covenant.org/faq

CONTRIBUTING.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Contributing to DABEST-Python
2+
3+
4+
## Did you find a bug?
5+
- Ensure the bug was not already reported by searching in [Issues](https://github.com/ACCLAB/DABEST-python/issues). Check that the bug hasn't been addressed in a closed issue.
6+
7+
- If the bug isn't being addressed, open a new issue using the Bug report template. Be sure to fill in the necessary information, and a [minimally reproducible code sample](https://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports) demonstrating the expected behavior that is not occurring.
8+
9+
10+
## Did you write a patch that fixes a bug?
11+
- Open a new GitHub [pull request](https://help.github.com/en/articles/about-pull-requests) (PR for short) with the patch.
12+
13+
- Create the PR into the development branch, which is indicated by `v{latest version number}-dev`.
14+
15+
- Clearly state the problem and solution in the PR description. Include the relevant [issue number](https://guides.github.com/features/issues/) if applicable.
16+
17+
18+
## Do you intend to add a new feature or change an existing one?
19+
- Suggest your change by opening an issue using the Feature request template.
20+
- If the maintainers and the community are in favour, create a fork and start writing code.
21+
22+
23+
DABEST is a community tool for estimation statistics and analysis. We look forward to more robust and more elegant data visualizations from you all!

README.md

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,17 @@ obtain the dependencies easily.
8484

8585
You can install this package via `pip`.
8686

87-
To install, at the command line run <!-- ```shell
87+
To install, at the command line run
88+
89+
``` shell
8890
conda config --add channels conda-forge
8991
conda install dabest
9092
```
91-
or -->
93+
94+
or –\>
9295

9396
``` shell
94-
pip install --upgrade dabest
97+
pip install dabest
9598
```
9699

97100
You can also
@@ -150,18 +153,19 @@ tracker](https://github.com/ACCLAB/DABEST-python/issues/new).
150153
## Contributing
151154

152155
All contributions are welcome; please read the [Guidelines for
153-
contributing](https://github.com/ACCLAB/DABEST-python/blob/master/CONTRIBUTING.md)
154-
first.
156+
contributing](CONTRIBUTING.md) first.
155157

156-
We also have a [Code of
157-
Conduct](https://github.com/ACCLAB/DABEST-python/blob/master/CODE_OF_CONDUCT.md)
158-
to foster an inclusive and productive space.
158+
We also have a [Code of Conduct](CODE_OF_CONDUCT.md) to foster an
159+
inclusive and productive space.
159160

160161
### A wish list for new features
161162

162163
If you have any specific comments and ideas for new features that you
163-
would like to share with us, please fill this form. **Add the link to a
164-
google doc form**
164+
would like to share with us, please read the [Guidelines for
165+
contributing](CONTRIBUTING.md), create a new issue using Feature request
166+
template or create a new post in [our Google
167+
Group](https://groups.google.com/g/estimationstats).
168+
165169

166170
## Acknowledgements
167171

@@ -175,12 +179,20 @@ Stanislav Ott.
175179
## Testing
176180

177181
To test DABEST, you need to install
178-
[pytest](https://docs.pytest.org/en/latest).
179182

180-
Run `pytest` in the root directory of the source distribution. This runs
181-
the test suite in the folder `dabest/tests`. The test suite ensures that
182-
the bootstrapping functions and the plotting functions perform as
183-
expected.
183+
[pytest](https://docs.pytest.org/en/latest) and
184+
[nbdev](https://nbdev.fast.ai/).
185+
186+
- Run `pytest` in the root directory of the source distribution. This
187+
runs the test suite in the folder `dabest/tests/mpl_image_tests`.
188+
- Run `nbdev_test` in the root directory of the source distribution.
189+
This runs the value assertion tests in parent folder `dabest/tests`
190+
191+
The test suite ensures that the bootstrapping functions and the plotting
192+
functions perform as expected.
193+
194+
For detailed information, please refer to the [test
195+
folder](nbs/tests/README.md)
184196

185197
## DABEST in other languages
186198

dabest/_modidx.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
d = { 'settings': { 'branch': 'master',
44
'doc_baseurl': '/DABEST-python',
5-
'doc_host': 'https://ZHANGROU-99.github.io',
6-
'git_url': 'https://github.com/ZHANGROU-99/DABEST-python',
5+
'doc_host': 'https://acclab.github.io',
6+
'git_url': 'https://github.com/acclab/DABEST-python',
77
'lib_path': 'dabest'},
88
'syms': { 'dabest._stats_tools.confint_1group': { 'dabest._stats_tools.confint_1group.compute_1group_acceleration': ( 'API/confint_1group.html#compute_1group_acceleration',
99
'dabest/_stats_tools/confint_1group.py'),

dabest/_stats_tools/confint_2group_diff.py

Lines changed: 41 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -155,74 +155,57 @@ def compute_delta2_bootstrapped_diff(
155155
"""
156156

157157
rng = RandomState(PCG64(random_seed))
158-
x1_len = len(x1)
159-
x2_len = len(x2)
160-
x3_len = len(x3)
161-
x4_len = len(x4)
162-
out_delta_g = np.repeat(np.nan, resamples)
163-
deltadelta = np.repeat(np.nan, resamples)
164-
165-
n_a1_b1, n_a2_b1, n_a1_b2, n_a2_b2 = x1_len, x2_len, x3_len, x4_len
166-
s_a1_b1, s_a2_b1, s_a1_b2, s_a2_b2 = np.std(x1), np.std(x2), np.std(x3), np.std(x4)
167-
168-
sd_numerator = (
169-
(n_a2_b1 - 1) * s_a2_b1**2
170-
+ (n_a1_b1 - 1) * s_a1_b1**2
171-
+ (n_a2_b2 - 1) * s_a2_b2**2
172-
+ (n_a1_b2 - 1) * s_a1_b2**2
173-
)
174-
sd_denominator = (n_a2_b1 - 1) + (n_a1_b1 - 1) + (n_a2_b2 - 1) + (n_a1_b2 - 1)
158+
159+
x1, x2, x3, x4 = map(np.asarray, [x1, x2, x3, x4])
160+
161+
# Calculating pooled sample standard deviation
162+
stds = [np.std(x) for x in [x1, x2, x3, x4]]
163+
ns = [len(x) for x in [x1, x2, x3, x4]]
164+
165+
sd_numerator = sum((n - 1) * s**2 for n, s in zip(ns, stds))
166+
sd_denominator = sum(n - 1 for n in ns)
167+
168+
# Avoid division by zero
169+
if sd_denominator == 0:
170+
raise ValueError("Insufficient data to compute pooled standard deviation.")
171+
175172
pooled_sample_sd = np.sqrt(sd_numerator / sd_denominator)
176173

177-
for i in range(int(resamples)):
174+
# Ensure pooled_sample_sd is not NaN or zero (to avoid division by zero later)
175+
if np.isnan(pooled_sample_sd) or pooled_sample_sd == 0:
176+
raise ValueError("Pooled sample standard deviation is NaN or zero.")
177+
178+
out_delta_g = np.empty(resamples)
179+
deltadelta = np.empty(resamples)
180+
181+
# Bootstrapping
182+
for i in range(resamples):
183+
# Paired or unpaired resampling
178184
if is_paired:
179-
if (x1_len != x2_len) or (x3_len != x4_len):
180-
raise ValueError("The two arrays do not have the same length.")
181-
df_paired_1 = pd.DataFrame(
182-
{
183-
"value": np.concatenate([x1, x3]),
184-
"array_id": np.repeat(["x1", "x3"], [x1_len, x3_len]),
185-
}
186-
)
187-
df_paired_2 = pd.DataFrame(
188-
{
189-
"value": np.concatenate([x2, x4]),
190-
"array_id": np.repeat(["x2", "x4"], [x1_len, x3_len]),
191-
}
192-
)
193-
x_sample_index = rng.choice(
194-
len(df_paired_1), len(df_paired_1), replace=True
195-
)
196-
x_sample_1 = df_paired_1.loc[x_sample_index]
197-
x_sample_2 = df_paired_2.loc[x_sample_index]
198-
x1_sample = x_sample_1[x_sample_1["array_id"] == "x1"]["value"]
199-
x2_sample = x_sample_2[x_sample_2["array_id"] == "x2"]["value"]
200-
x3_sample = x_sample_1[x_sample_1["array_id"] == "x3"]["value"]
201-
x4_sample = x_sample_2[x_sample_2["array_id"] == "x4"]["value"]
185+
if len(x1) != len(x2) or len(x3) != len(x4):
186+
raise ValueError("Each control group must have the same length as its corresponding test group in paired analysis.")
187+
indices_1 = rng.choice(len(x1), len(x1), replace=True)
188+
indices_2 = rng.choice(len(x3), len(x3), replace=True)
189+
190+
x1_sample, x2_sample = x1[indices_1], x2[indices_1]
191+
x3_sample, x4_sample = x3[indices_2], x4[indices_2]
202192
else:
203-
df = pd.DataFrame(
204-
{
205-
"value": np.concatenate([x1, x2, x3, x4]),
206-
"array_id": np.repeat(
207-
["x1", "x2", "x3", "x4"], [x1_len, x2_len, x3_len, x4_len]
208-
),
209-
}
210-
)
211-
x_sample_index = rng.choice(len(df), len(df), replace=True)
212-
x_sample = df.loc[x_sample_index]
213-
x1_sample = x_sample[x_sample["array_id"] == "x1"]["value"]
214-
x2_sample = x_sample[x_sample["array_id"] == "x2"]["value"]
215-
x3_sample = x_sample[x_sample["array_id"] == "x3"]["value"]
216-
x4_sample = x_sample[x_sample["array_id"] == "x4"]["value"]
193+
x1_sample = rng.choice(x1, len(x1), replace=True)
194+
x2_sample = rng.choice(x2, len(x2), replace=True)
195+
x3_sample = rng.choice(x3, len(x3), replace=True)
196+
x4_sample = rng.choice(x4, len(x4), replace=True)
217197

198+
# Calculating deltas
218199
delta_1 = np.mean(x2_sample) - np.mean(x1_sample)
219200
delta_2 = np.mean(x4_sample) - np.mean(x3_sample)
220201
delta_delta = delta_2 - delta_1
202+
221203
deltadelta[i] = delta_delta
222204
out_delta_g[i] = delta_delta / pooled_sample_sd
223-
delta_g = (
224-
(np.mean(x4) - np.mean(x3)) - (np.mean(x2) - np.mean(x1))
225-
) / pooled_sample_sd
205+
206+
# Empirical delta_g calculation
207+
delta_g = ((np.mean(x4) - np.mean(x3)) - (np.mean(x2) - np.mean(x1))) / pooled_sample_sd
208+
226209
return out_delta_g, delta_g, deltadelta
227210

228211

nbs/01-getting_started.ipynb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
"Clone the [DABEST-python repo](https://github.com/ACCLAB/DABEST-python) locally (see instructions [here](https://help.github.com/articles/cloning-a-repository/)).\n",
7676
"\n",
7777
"Then, navigate to the cloned repo in the command line and run\n",
78-
"```\n",
78+
"``` shell\n",
7979
"$ pip install .\n",
8080
"```"
8181
]
@@ -93,9 +93,13 @@
9393
"id": "a9f8cb3e",
9494
"metadata": {},
9595
"source": [
96-
"To test DABEST, you will need to install [pytest](https://docs.pytest.org/en/latest/). \n",
96+
"To test DABEST, you will need to install [pytest](https://docs.pytest.org/en/latest/) and [nbdev](https://nbdev.fast.ai/). \n",
97+
"\n",
98+
"Run ``nbdev_export && nbdev_test`` in the root directory of the source distribution. This runs the value assertion tests in ``dabest/tests`` folder\n",
99+
"\n",
100+
"Run ``pytest`` in the root directory of the source distribution. This runs the image-based tests in ``dabest/tests/mpl_image_tests`` sub folder.\n",
97101
"\n",
98-
"Run ``pytest`` in the root directory of the source distribution. This runs the test suite in ``dabest/tests`` folder including also the image-based tests of the ``mpl_image_tests`` sub folder. The test suite will ensure that the bootstrapping functions and the plotting functions perform as expected.\n",
102+
"The test suite will ensure that the bootstrapping functions and the plotting functions perform as expected.\n",
99103
"\n"
100104
]
101105
},

0 commit comments

Comments
 (0)