formulaic_contrasts.FormulaicContrasts#

class formulaic_contrasts.FormulaicContrasts(data, design)#

Build contrasts for a model design specified as formulaic formula.

Keeps track of factors and their metadata and provides the {func}`~FormulaicContrasts.cond` method for building contrasts.

Parameters:
  • data (DataFrame) – Metadata to be passed to formulaic

  • design (str) – Formulaic formula of the model definition

Attributes table#

variables

Get the names of the variables used in the model definition.

Methods table#

cond(**kwargs)

Get a contrast vector representing a specific condition.

contrast(column, baseline, group_to_compare)

Build a simple contrast for pairwise comparisons of a single variable.

Attributes#

FormulaicContrasts.variables#

Get the names of the variables used in the model definition.

Methods#

FormulaicContrasts.cond(**kwargs)#

Get a contrast vector representing a specific condition.

The kwargs are key/value pairs where the key refers to a variable used in the design and the value represents a category of that variable. Variables not specified will be filled with their default/baseline value.

The vectors generated by .cond can be combined using standard arithmetic operations to obtain the desired contrast, e.g.

>>> contrast = model.cond(treatment="drugA") - model.cond(treatment="placebo")

For more information on how to build contrasts, see Building contrasts.

Parameters:

**kwargs – column/value pairs.

Returns:

A vector with one element per column in the design matrix, where the kwargs arguments are coded as in the design matrix.

FormulaicContrasts.contrast(column, baseline, group_to_compare)#

Build a simple contrast for pairwise comparisons of a single variable.

For more complex contrasts, please use construct a contrast vector using cond().

Parameters:
  • column – column in adata.obs to test on.

  • baseline – baseline category (denominator).

  • group_to_compare – category to compare against baseline (nominator).

Returns:

Numeric contrast vector.