spacr.baseline

Define the reference used to report regression effect sizes.

For a model of the form

y ~ fraction:grna + gene_fraction:gene + rowID + columnID

Patsy assigns coefficients to every guide and gene because both occur only in interactions with a continuous fraction. The first plate row and column define the intercept reference, but changing those categorical references shifts the intercept without changing guide or gene coefficients.

Guide coefficients are slopes with respect to guide fraction and therefore use zero guide fraction (no dose-response) as their fitted reference. This module records that reference explicitly and can re-express effects relative to non-targeting controls, a named gene or guide, or a supplied numeric value. Control-based baselines use the median coefficient to limit sensitivity to a control guide with a genuine phenotype.

Classes

Baseline

Store a selected baseline and its reporting sentence.

Functions

apply(frame, baseline, *[, column])

frame with every effect re-expressed against baseline.

describe_intercept(→ str)

Return a one-sentence description of the fitted intercept.

resolve(→ Baseline)

Resolve the baseline used to report effects.

Module Contents

class spacr.baseline.Baseline[source]

Store a selected baseline and its reporting sentence.

Parameters:
  • kind – baseline strategy actually applied; fallback results use ZERO even when another strategy was requested.

  • shift – effect offset subtracted from the selected coefficient column by apply(); zero leaves values unchanged.

  • n – number of coefficients supporting the resolved decision; zero for a zero or hand-supplied baseline.

  • sentence – nonempty caption text explaining the reference that must accompany reported effects.

  • reason – explanation for falling back from the requested strategy, or None when it was applied as requested.

property moves: bool[source]

Return whether applying the baseline changes effect values.

spacr.baseline.apply(frame, baseline: Baseline, *, column: str = 'coefficient')[source]

frame with every effect re-expressed against baseline.

Parameters:
  • frame – coefficient table to copy and re-express.

  • baseline – resolved baseline whose shift is applied.

The function returns a copy because the input may also supply coefficient tables, exports and other panels that must retain their original values.

Standard errors and p-values are unchanged: a location shift of every coefficient by one constant changes what each effect is measured from, not how precisely it was estimated. The p-values still test the coefficient against zero, which is why the sentence goes in the caption – a reader who sees shifted effects and unshifted stars must be told the two answer different questions.

spacr.baseline.describe_intercept(frame=None) → str[source]

Return a one-sentence description of the fitted intercept.

The intercept is the response at zero guide fraction in the categorical plate row and column selected by Patsy as references.

spacr.baseline.resolve(frame, kind: str = ZERO, *, column: str = 'coefficient', name: str | None = None, value=None, key_column: str = 'feature') → Baseline[source]

Resolve the baseline used to report effects.

Parameters:
  • frame – the coefficient table.

  • kind – ZERO, CONTROLS, NAMED or VALUE.

  • column – the effect column.

  • name – for NAMED, the gene or guide to normalise to.

  • value – for VALUE, the number to measure from.

Returns:

a Baseline. An unavailable requested baseline returns the zero baseline with an explanatory reason.

Raises:

ValueError – never. See above.