cluster_permute_test: Tests for independence between labels and covariates using...

Description Usage Arguments Value See Also Examples

View source: R/permutation-testing.R

Description

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

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
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,
  ...
)

Arguments

ccdb

ContigCellDB

cell_covariate_keys

character naming fields in ccdb$cell_tbl

cell_label_key

character naming a single field in ccdb$cell_tbl

cell_stratify_keys

optional character naming fields in ccdb$cell_tbl under which permutations of cell_label_key will occur. This means that the test will occur conditional on these covariates. Must be disjoint from cell_covariate_keys.

statistic

function of label (vector) and covariate (data.frame). Must return a scalar

n_perm

number of permutations to run

alternative

character naming the direction statistic should be fall under the alternative hypothesis

sanity_check_strata

logical, should cell_stratify_keys be checked for sanity?

...

passed to statistic

Value

a list containing the observed value of the statistic, its expectation (under independence), a p-value, and the Monte Carlo standard error (of the expected value).

See Also

purity()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
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

cluster_permute_test(ccdb_test, 'subject', 'cluster_idx',
statistic = purity, n_perm  = 50)

CellaRepertorium documentation built on Nov. 8, 2020, 7:48 p.m.