SimpleCOMPASS: Fit the discrete COMPASS Model

Description Usage Arguments Value Note Examples

View source: R/SimpleCOMPASS.R

Description

This function fits the COMPASS model from a user-provided set of stimulated / unstimulated matrices. See the NOTE for important details.

Usage

1
2
3
4
5
6
7
8
9
SimpleCOMPASS(
  n_s,
  n_u,
  meta,
  individual_id,
  iterations = 10000,
  replications = 8,
  verbose = TRUE
)

Arguments

n_s

The cell counts for stimulated cells.

n_u

The cell counts for unstimulated cells.

meta

A data.frame of metadata, describing the individuals in the experiment. Each row in meta should correspond to a row in data. There should be one row for each subject; i.e., one row for each element of n_s and n_u.

individual_id

The name of the vector in meta that denotes the individuals from which samples were drawn.

iterations

The number of iterations (per 'replication') to perform.

replications

The number of 'replications' to perform. In order to conserve memory, we only keep the model estimates from the last replication.

verbose

Boolean; if TRUE we output progress information.

Value

A list with class COMPASSResult with two components, the fit containing parameter estimates and parameter acceptance rates, and data containing the generated data used as input for the model.

Note

n_s and n_u counts matrices should contain ALL 2^M possible combinations of markers, even if they are 0 for some combinations. The code expects the marker combinations to be named in the following way: "M1&M2&!M3" means the combination represents cells expressing marker "M1" and "M2" and not "M3". For 3 markers, there should be 8 such combinations, such that n_s and n_u have 8 columns.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 set.seed(123)
n <- 10 ## number of subjects
k <- 3 ## number of markers

## generate some sample data
iid_vec <- paste0("iid_", 1:n) # Subject id
data <- replicate(2*n, {
nrow <- round(runif(1) * 1E4 + 1000)
ncol <- k
vals <- rexp( nrow * ncol, runif(1, 1E-5, 1E-3) )
vals[ vals < 2000 ] <- 0
output <- matrix(vals, nrow, ncol)
output <- output[ apply(output, 1, sum) > 0, ]
colnames(output) <- paste0("M", 1:k)
return(output)
})

meta <- cbind(iid=iid_vec, data.frame(trt=rep( c("Control", "Treatment"), each=n/2 )))

## generate counts for n_s, n_u
n_s <- CellCounts( data[1:n], Combinations(k) )
n_u <- CellCounts( data[(n+1):(2*n)], Combinations(k) )
rownames(n_s) = unique(meta$iid)
rownames(n_u) = rownames(n_s)
## A smaller number of iterations is used here for running speed;
## prefer using more iterations for a real fit
scr = SimpleCOMPASS(n_s, n_u, meta, "iid", iterations=1000)

COMPASS documentation built on Nov. 8, 2020, 8:05 p.m.