Statistical tests
SCP tests each variable (e.g. gene) for differences between groups of observations, and returns a table with one row per variable, most significant first.
| Test | Use for | Data |
|---|---|---|
SCP.mannwhitney | Two groups (Wilcoxon rank-sum test) | Sparse: SCP.logtransformed counts |
SCP.ftest | Several groups (one-way ANOVA), or comparing models | Transformed, not normalized: SCP.logtransformed or SCP.sctransformed counts |
SCP.ttest | Two groups, or a numerical covariate | Transformed, not normalized: SCP.logtransformed or SCP.sctransformed counts |
Workflow
- Decide which groups of cells to compare.
- Create an annotation table with two columns: the cell ID and the group. Give the group column an informative name.
- Load counts that include all cells to compare, and apply the usual quality filtering.
- Add the annotation with
SCP.annotate_obs. SCP.logtransformthe counts.- Do a
SCP.mannwhitneytest to get a table with one row per variable.
groups = DataFrame("cell_id" => cell_ids, "stage" => stages) # e.g. "early"/"late"
data = SCP.annotate_obs(filtered, groups)
transformed = SCP.logtransform(data)
result = fetch!(SCP.mannwhitney(transformed, "stage", "early", "late"))Change to an F-test if there are multiple groups, or to a t-test for a numerical covariate. They take the same log-transformed data, or sctransformed data.
Mann-Whitney U-test
SCP.mannwhitney(data, column, [group_a, group_b]) compares two groups of observations, as given by the obs column column:
- No groups given -
columnmust have exactly two values. - Only
group_a-group_aagainst all other observations. - Both -
group_aagainstgroup_b.
Observations with missing in column are skipped. data must contain a sparse matrix, so use SCP.logtransform rather than SCP.sctransform.
The result has the variable IDs, the U statistic and pValue, sorted by significance. Add z_col="z" to get the signed standardized statistic, which shows the direction of the effect.
F-test and t-test
transformed = SCP.logtransform(data) # or SCP.sctransform(data)
SCP.ftest(transformed, "celltype") # one-way ANOVA
SCP.ttest(transformed, "stage" => twogroup_covariate("early", "late")) # two groups
SCP.ttest(transformed, "age") # numerical covariateh1is the tested covariate, either an obs column name orcolumn => covariate description.- F-test: the type (categorical or numerical) is detected from the column, or given by
categorical_covariate()ornumerical_covariate(). - t-test: a column name is always treated as numerical. To compare two groups, give
column => twogroup_covariate(group_a, [group_b]); categorical covariates are rejected.
- F-test: the type (categorical or numerical) is detected from the column, or given by
h0gives covariates to control for, e.g.h0="fraction_mt", with the type detected as for the F-test. The null model also includes an intercept (center=true).- The t-test result includes a
differencecolumn, the estimated effect.
Don't SCP.normalize_matrix the data first; give covariates in h0 instead. Regressing covariates out beforehand removes them without the test knowing, so the degrees of freedom are wrong and the p-values too small.
Options for all tests
var_cols="name"- include morevarcolumns (e.g. gene names) in the result.statistic_col/pvalue_col- rename the output columns (nothingomits them).do_sort=false- keep the variables in their original order.
The p-values are not adjusted for multiple testing.