For each given combination of phenotype and expression parameter, report the mean expression of the given marker in the specified cells.

compute_mean_expression_many(
  csd,
  phenotypes,
  params,
  tissue_categories = NULL,
  percentile = NULL,
  count = NULL,
  .by = "Slide ID"
)

Arguments

csd

Cell seg data to use. This should already have been filtered for the slides or fields of interest. It may already be nested by !!.by and Tissue Category.

phenotypes

A named list of phenotype selectors (see phenoptr::parse_phenotypes).

params

A named list matching phenotype names to expression column names.

tissue_categories

Optional vector of tissue category names to include.

percentile

The percentile cutoff for top-expressing cells. For example, to measure the top quartile, the percentile is 0.75. Negative numbers will use low-expressing cells; to measure the bottom decile, use a percentile of -0.1.

count

The number of top expressing cells to use. Only one of percentile and count can be provided. If both are omitted, all cells matching the phenotype are used and the result is the overall mean expression.

.by

Column to aggregate by

Value

A data frame with a column for mean for each param_pair.

Details

This is a very flexible function. If percentile and count are both omitted, it will compute the mean expression for all cells in the given phenotype. If either percentile or count is given, the mean expression of the highest expressing cells is computed. If a negative percentile is given, the lowest percentile is used; for example percentile=-.1 would give the expression of the lowest-expressing decile.

By default, this function aggregates by Slide ID and Tissue Category. To compute mean expression by a different aggregate, pass a column name in the .by parameter.

To aggregate over all cells, include "Total Cells"=NA as one of the phenotypes.