cluster_permute_test {CellaRepertorium} | R Documentation

## Tests for independence between labels and covariates using permutation of cells

### 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

    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

    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)

[Package CellaRepertorium version 1.2.0 Index]