Repository navigation
Add composition_test(sample_col=) and say what the default p-values assume - #150
Merged
Merged
Conversation
…ssume (#144) The Fisher test per group counts every cell as an independent observation, so with thousands of cells nearly every difference is significant, including one that is only donor-to-donor variation. In the issue's null simulation (12 donors, 6 against 6, each with its own cell-type proportions, no condition effect) the default reported a significant cell type in 35 of 40 runs. The unit that replicates is the donor. sample_col names the sample each cell came from. Each group's proportion in each sample is compared between the two levels with a two-sided Mann-Whitney test, BH adjusted across groups as before. In the same simulation that is 1 significant run in 40, and a cell type three times as common in one condition is still found in 10 of 10. prop_<level> becomes the mean of the per-sample proportions; odds_ratio and chisq_p are cell-level and are not reported. A sample in both levels is an error, and a design too small to reach p < 0.05, such as three against three, warns using the exact bound 2 / C(n1 + n2, n1). scipy returns NaN when every value is identical, which would have turned every adjusted p-value into NaN, so that is p = 1. The default path is unchanged apart from the docstring and attrs['method']. The shared tail (BH, labels, direction, order) is one helper both paths use. Seven mutants of the new mode each fail their own test. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… when a level has none (#144) A missing sample id went through astype(str), which makes it a sample called "nan" on pandas 2 and drops it on pandas 3, and either way its cell was still counted in n_<level>. Such cells are now dropped before anything is computed, so the result does not depend on the pandas version, and the group set and the cell counts follow the cells actually used. A level none of whose cells has a sample made scipy raise "x and y must be of nonzero size". That is now a ValueError naming the level. Both are mutation-tested. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
# Conflicts: # CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #144.
The Fisher test per group counts every cell as an independent observation, so with thousands of cells nearly every difference is significant, including one that is only donor-to-donor variation. In the issue's null simulation (12 donors, 6 against 6, each with its own cell-type proportions, no condition effect) the default reports a significant cell type in 35 of 40 runs, which I reproduced exactly. The unit that replicates is the donor.
What changed
sample_col=, as the issue's second suggestion. It names the sample each cell came from. Each group's proportion in each sample is compared between the two levels with a two-sided Mann-Whitney test, BH-adjusted across groups as before. It is opt-in, and the default path is unchanged.sample_col. The spatial skill's example uses it and says why, and the api-map signature has it.2 / C(n1 + n2, n1), which is 0.1 for three samples against three, and 0.057 for three against four. Past 0.05 nothing can come out significant, however large the difference. I checked the formula against scipy for five designs.Judgement calls, in case you want any of them different
prop_<level>is the mean of the per-sample proportions,odds_ratioandchisq_pare not reported (they are cell-level quantities), anddf.attrscarriesmethod,sample_colandn_samples.df.attrs['method']is also set on the default path ("fisher_exact"); nothing else there changes.astype(str)would make it a sample called"nan"on pandas 2 and drop it on pandas 3), and a level none of whose cells has a sample is a clearValueErrorrather than scipy's.One bug the tests found on the way
scipy returns
NaN, not an error, when every value is identical (a group with the same proportion in every sample)._bhthen turned every adjusted p-value intoNaN. That case is now p = 1, and there is a test for it.Verification
sample_col="donor"1 (the nominal 5% is 2), no spurious warnings. It is not just conservative: a cell type made three times as common in one condition is found in 10 of 10 runs.tests/test_composition_samples.py: the null simulation (with a precondition that it can show the problem), the table checked againstscipy.stats.mannwhitneyucomputed independently, the errors, the warning at 6, 7, 8 and 12 donors, the NaN case, and cells with no sample.composition.py(2), mypy at its 4 baseline errors.No release is needed for this change on its own. The CHANGELOG entry is under
[Unreleased]→ Added.🤖 Generated with Claude Code