Skip to content

Commit

Permalink
Merge pull request #159 from ACCLAB/∆∆_bootstrap_rewrite
Browse files Browse the repository at this point in the history
Delta2 Bootstrap Function Rewrite, nbdev Configuration and Templates for Bug Report, Feature Request added
  • Loading branch information
Jacobluke- authored Feb 28, 2024
2 parents 75fe1df + c8c8a4c commit 37786a3
Show file tree
Hide file tree
Showing 19 changed files with 347 additions and 179 deletions.
34 changes: 34 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: bug
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1.
2.

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Your package version (please complete the following information):**
- dabest: [e.g. 2023.3.29]
- pandas:
- numpy:
- matplotlib:
- seaborn:
- scipy:


**Additional context**
Add any other context about the problem here.
23 changes: 23 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: enhancement
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Is a dataset available for testing out the functionality**
If yes, please leave a Google Drive link

**Additional context**
Add any other context or screenshots about the feature request here.
76 changes: 76 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at [email protected]. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html

[homepage]: https://www.contributor-covenant.org

For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq
23 changes: 23 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Contributing to DABEST-Python


## Did you find a bug?
- 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.

- 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.


## Did you write a patch that fixes a bug?
- Open a new GitHub [pull request](https://help.github.com/en/articles/about-pull-requests) (PR for short) with the patch.

- Create the PR into the development branch, which is indicated by `v{latest version number}-dev`.

- Clearly state the problem and solution in the PR description. Include the relevant [issue number](https://guides.github.com/features/issues/) if applicable.


## Do you intend to add a new feature or change an existing one?
- Suggest your change by opening an issue using the Feature request template.
- If the maintainers and the community are in favour, create a fork and start writing code.


DABEST is a community tool for estimation statistics and analysis. We look forward to more robust and more elegant data visualizations from you all!
42 changes: 27 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,17 @@ obtain the dependencies easily.

You can install this package via `pip`.

To install, at the command line run <!-- ```shell
To install, at the command line run

``` shell
conda config --add channels conda-forge
conda install dabest
```
or -->

or –\>

``` shell
pip install --upgrade dabest
pip install dabest
```

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

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

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

### A wish list for new features

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


## Acknowledgements

Expand All @@ -175,12 +179,20 @@ Stanislav Ott.
## Testing

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

Run `pytest` in the root directory of the source distribution. This runs
the test suite in the folder `dabest/tests`. The test suite ensures that
the bootstrapping functions and the plotting functions perform as
expected.
[pytest](https://docs.pytest.org/en/latest) and
[nbdev](https://nbdev.fast.ai/).

- Run `pytest` in the root directory of the source distribution. This
runs the test suite in the folder `dabest/tests/mpl_image_tests`.
- Run `nbdev_test` in the root directory of the source distribution.
This runs the value assertion tests in parent folder `dabest/tests`

The test suite ensures that the bootstrapping functions and the plotting
functions perform as expected.

For detailed information, please refer to the [test
folder](nbs/tests/README.md)

## DABEST in other languages

Expand Down
4 changes: 2 additions & 2 deletions dabest/_modidx.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

d = { 'settings': { 'branch': 'master',
'doc_baseurl': '/DABEST-python',
'doc_host': 'https://ZHANGROU-99.github.io',
'git_url': 'https://github.com/ZHANGROU-99/DABEST-python',
'doc_host': 'https://acclab.github.io',
'git_url': 'https://github.com/acclab/DABEST-python',
'lib_path': 'dabest'},
'syms': { 'dabest._stats_tools.confint_1group': { 'dabest._stats_tools.confint_1group.compute_1group_acceleration': ( 'API/confint_1group.html#compute_1group_acceleration',
'dabest/_stats_tools/confint_1group.py'),
Expand Down
99 changes: 41 additions & 58 deletions dabest/_stats_tools/confint_2group_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,74 +155,57 @@ def compute_delta2_bootstrapped_diff(
"""

rng = RandomState(PCG64(random_seed))
x1_len = len(x1)
x2_len = len(x2)
x3_len = len(x3)
x4_len = len(x4)
out_delta_g = np.repeat(np.nan, resamples)
deltadelta = np.repeat(np.nan, resamples)

n_a1_b1, n_a2_b1, n_a1_b2, n_a2_b2 = x1_len, x2_len, x3_len, x4_len
s_a1_b1, s_a2_b1, s_a1_b2, s_a2_b2 = np.std(x1), np.std(x2), np.std(x3), np.std(x4)

sd_numerator = (
(n_a2_b1 - 1) * s_a2_b1**2
+ (n_a1_b1 - 1) * s_a1_b1**2
+ (n_a2_b2 - 1) * s_a2_b2**2
+ (n_a1_b2 - 1) * s_a1_b2**2
)
sd_denominator = (n_a2_b1 - 1) + (n_a1_b1 - 1) + (n_a2_b2 - 1) + (n_a1_b2 - 1)

x1, x2, x3, x4 = map(np.asarray, [x1, x2, x3, x4])

# Calculating pooled sample standard deviation
stds = [np.std(x) for x in [x1, x2, x3, x4]]
ns = [len(x) for x in [x1, x2, x3, x4]]

sd_numerator = sum((n - 1) * s**2 for n, s in zip(ns, stds))
sd_denominator = sum(n - 1 for n in ns)

# Avoid division by zero
if sd_denominator == 0:
raise ValueError("Insufficient data to compute pooled standard deviation.")

pooled_sample_sd = np.sqrt(sd_numerator / sd_denominator)

for i in range(int(resamples)):
# Ensure pooled_sample_sd is not NaN or zero (to avoid division by zero later)
if np.isnan(pooled_sample_sd) or pooled_sample_sd == 0:
raise ValueError("Pooled sample standard deviation is NaN or zero.")

out_delta_g = np.empty(resamples)
deltadelta = np.empty(resamples)

# Bootstrapping
for i in range(resamples):
# Paired or unpaired resampling
if is_paired:
if (x1_len != x2_len) or (x3_len != x4_len):
raise ValueError("The two arrays do not have the same length.")
df_paired_1 = pd.DataFrame(
{
"value": np.concatenate([x1, x3]),
"array_id": np.repeat(["x1", "x3"], [x1_len, x3_len]),
}
)
df_paired_2 = pd.DataFrame(
{
"value": np.concatenate([x2, x4]),
"array_id": np.repeat(["x2", "x4"], [x1_len, x3_len]),
}
)
x_sample_index = rng.choice(
len(df_paired_1), len(df_paired_1), replace=True
)
x_sample_1 = df_paired_1.loc[x_sample_index]
x_sample_2 = df_paired_2.loc[x_sample_index]
x1_sample = x_sample_1[x_sample_1["array_id"] == "x1"]["value"]
x2_sample = x_sample_2[x_sample_2["array_id"] == "x2"]["value"]
x3_sample = x_sample_1[x_sample_1["array_id"] == "x3"]["value"]
x4_sample = x_sample_2[x_sample_2["array_id"] == "x4"]["value"]
if len(x1) != len(x2) or len(x3) != len(x4):
raise ValueError("Each control group must have the same length as its corresponding test group in paired analysis.")
indices_1 = rng.choice(len(x1), len(x1), replace=True)
indices_2 = rng.choice(len(x3), len(x3), replace=True)

x1_sample, x2_sample = x1[indices_1], x2[indices_1]
x3_sample, x4_sample = x3[indices_2], x4[indices_2]
else:
df = pd.DataFrame(
{
"value": np.concatenate([x1, x2, x3, x4]),
"array_id": np.repeat(
["x1", "x2", "x3", "x4"], [x1_len, x2_len, x3_len, x4_len]
),
}
)
x_sample_index = rng.choice(len(df), len(df), replace=True)
x_sample = df.loc[x_sample_index]
x1_sample = x_sample[x_sample["array_id"] == "x1"]["value"]
x2_sample = x_sample[x_sample["array_id"] == "x2"]["value"]
x3_sample = x_sample[x_sample["array_id"] == "x3"]["value"]
x4_sample = x_sample[x_sample["array_id"] == "x4"]["value"]
x1_sample = rng.choice(x1, len(x1), replace=True)
x2_sample = rng.choice(x2, len(x2), replace=True)
x3_sample = rng.choice(x3, len(x3), replace=True)
x4_sample = rng.choice(x4, len(x4), replace=True)

# Calculating deltas
delta_1 = np.mean(x2_sample) - np.mean(x1_sample)
delta_2 = np.mean(x4_sample) - np.mean(x3_sample)
delta_delta = delta_2 - delta_1

deltadelta[i] = delta_delta
out_delta_g[i] = delta_delta / pooled_sample_sd
delta_g = (
(np.mean(x4) - np.mean(x3)) - (np.mean(x2) - np.mean(x1))
) / pooled_sample_sd

# Empirical delta_g calculation
delta_g = ((np.mean(x4) - np.mean(x3)) - (np.mean(x2) - np.mean(x1))) / pooled_sample_sd

return out_delta_g, delta_g, deltadelta


Expand Down
10 changes: 7 additions & 3 deletions nbs/01-getting_started.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"Clone the [DABEST-python repo](https://github.com/ACCLAB/DABEST-python) locally (see instructions [here](https://help.github.com/articles/cloning-a-repository/)).\n",
"\n",
"Then, navigate to the cloned repo in the command line and run\n",
"```\n",
"``` shell\n",
"$ pip install .\n",
"```"
]
Expand All @@ -93,9 +93,13 @@
"id": "a9f8cb3e",
"metadata": {},
"source": [
"To test DABEST, you will need to install [pytest](https://docs.pytest.org/en/latest/). \n",
"To test DABEST, you will need to install [pytest](https://docs.pytest.org/en/latest/) and [nbdev](https://nbdev.fast.ai/). \n",
"\n",
"Run ``nbdev_export && nbdev_test`` in the root directory of the source distribution. This runs the value assertion tests in ``dabest/tests`` folder\n",
"\n",
"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",
"\n",
"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",
"The test suite will ensure that the bootstrapping functions and the plotting functions perform as expected.\n",
"\n"
]
},
Expand Down
Loading

0 comments on commit 37786a3

Please sign in to comment.