| cluster_permute_test {CellaRepertorium} | R Documentation |
This tests a statistic for association between labels (for instance, cluster/clonal ID) and covariates (for instance, subject or treatment) by permuting the link between the two.
Each observation represents a cell.
statistic is any function of labels
cluster_permute_test(
ccdb,
cell_covariate_keys,
cell_label_key = ccdb$cluster_pk,
cell_stratify_keys,
statistic,
n_perm,
alternative = c("two.sided", "less", "greater"),
sanity_check_strata = TRUE,
...
)
plot_permute_test(perm_test)
ccdb |
|
cell_covariate_keys |
|
cell_label_key |
|
cell_stratify_keys |
optional |
statistic |
function of label (vector) and covariate (data.frame). Must return a scalar |
n_perm |
number of permutations to run |
alternative |
|
sanity_check_strata |
|
... |
passed to |
perm_test |
|
a list containing the observed value of the statistic, the permuted values of the statistic, its expectation (under independence), a p-value, and the Monte Carlo standard error (of the expected value).
A ggplot2 plot
plot_permute_test: Plot a histogram of permuted vs observed test statistic
library(dplyr)
# covariate should name one or more columns in `cell_tbl`
cluster_idx = c(1, 1, 1, 2, 2, 3, 3)
subject = c('A', 'A', 'B', 'B', 'B', 'C', 'C')
contig_tbl = tibble(contig_pk = seq_along(cluster_idx), cluster_idx, subject)
ccdb_test = ContigCellDB(contig_tbl = contig_tbl, contig_pk = 'contig_pk',
cell_pk = c('contig_pk', 'subject', 'cluster_idx'), cluster_pk = 'cluster_idx')
ccdb_test$cell_tbl
clust_test = cluster_permute_test(ccdb_test, 'subject', 'cluster_idx',
statistic = purity, n_perm = 50)
library(ggplot2)
plot_permute_test(perm_test = clust_test)