pertpy.tools.DistanceTest#
- class DistanceTest(metric, n_perms=1000, layer_key=None, obsm_key=None, alpha=0.05, correction='holm-sidak', cell_wise_metric=None)[source]#
Run permutation tests using a distance of choice between groups of cells.
Performs Monte-Carlo permutation testing using a distance metric of choice as test statistic. Tests all groups of cells against a specified contrast group (which normally would be your “control” cells).
- Parameters:
metric (
Literal['edistance','euclidean','root_mean_squared_error','mse','mean_absolute_error','pearson_distance','spearman_distance','kendalltau_distance','cosine_distance','r2_distance','mean_pairwise','mmd','wasserstein','sym_kldiv','t_test','ks_test','nb_ll','classifier_proba','classifier_cp','mean_var_distribution','mahalanobis']) – Distance metric to use between groups of cells.n_perms (
int, default:1000) – Number of permutations to run.layer_key (
str, default:None) – Name of the counts layer containing raw counts to calculate distances for. Mutually exclusive with ‘obsm_key’. If equal to None the parameter is ignored.obsm_key (
str, default:None) – Name of embedding in adata.obsm to use. Mutually exclusive with ‘counts_layer_key’. Defaults to None, but is set to “X_pca” if not set explicitly internally.alpha (
float, default:0.05) – Significance level.correction (
str, default:'holm-sidak') – Multiple testing correction method.cell_wise_metric (default:
None) – Metric to use between single cells.
Examples
>>> import pertpy as pt >>> adata = pt.dt.distance_example() >>> distance_test = pt.tl.DistanceTest("edistance", n_perms=1000) >>> tab = distance_test(adata, groupby="perturbation", contrast="control")
Methods table#
|
Run permutation test for metrics that take precomputed distances. |
|
Run permutation test for metric not supporting precomputed distances. |
Methods#
- DistanceTest.test_precomputed(adata, groupby, contrast, verbose=True)[source]#
Run permutation test for metrics that take precomputed distances.
- Parameters:
- Returns:
- Results of the permutation test, with columns:
distance: distance between the contrast group and the group
pvalue: p-value of the permutation test
significant: whether the group is significantly different from the contrast group
pvalue_adj: p-value after multiple testing correction
significant_adj: whether the group is significantly different from the contrast group after multiple testing correction
- Return type:
Examples
>>> import pertpy as pt >>> adata = pt.dt.distance_example() >>> distance_test = pt.tl.DistanceTest("edistance", n_perms=1000) >>> test_results = distance_test.test_precomputed(adata, groupby="perturbation", contrast="control")
- DistanceTest.test_xy(adata, groupby, contrast, show_progressbar=True)[source]#
Run permutation test for metric not supporting precomputed distances.
Runs a permutation test for a metric that can not be computed using precomputed pairwise distances, but need the actual data points. This is generally slower than test_precomputed.
- Parameters:
- Returns:
- Results of the permutation test, with columns:
distance: distance between the contrast group and the group
pvalue: p-value of the permutation test
significant: whether the group is significantly different from the contrast group
pvalue_adj: p-value after multiple testing correction
significant_adj: whether the group is significantly different from the contrast group after multiple testing correction
- Return type:
Examples
>>> import pertpy as pt >>> adata = pt.dt.distance_example() >>> distance_test = pt.tl.DistanceTest("edistance", n_perms=1000) >>> test_results = distance_test.test_xy(adata, groupby="perturbation", contrast="control")