variance_function: Create Working Variance Functions

View source: R/variance.R

variance_functionR Documentation

Create Working Variance Functions

Description

Construct a working variance function for variance-aware Michaelis-Menten fitting.

Usage

variance_function(model = c("constant", "log", "sqrt", "cuberoot", "power"),
  power = NULL, label = NULL)

Arguments

model

A built-in model name or a vectorized function of concentration returning one finite, strictly positive numeric variance-shape value per input.

power

Optional exponent used when model = "power".

label

Optional non-empty descriptive label for a user-defined function.

Details

A custom function represents a fixed shape h(S) in \operatorname{Var}(Y\mid S)=\gamma h(S). It must be deterministic, pointwise, and vectorized: a value at a concentration must not depend on other elements of the input vector. It must return a numeric vector of the same length as its input, not a scalar recycled across observations. Values must be strictly positive and finite at all fitting and prediction concentrations, including zero if it is used. Invalid custom outputs cause an error; they are not clipped. For example, use function(S) rep(1, length(S)) for a constant shape.

All constants captured by a custom function must be fixed, not parameters to be estimated by fit_mm(). Keep its enclosing environment unchanged between fitting and prediction/refitting; use a local closure to capture external constants when needed. label describes the function but does not change its values. Custom functions are supported by fit_mm(), screen_mm(), and group_mm(), not currently by cluster_mm().

Value

A function of substrate concentration x.

Examples

h_log <- variance_function("log")
h_sqrt <- variance_function("sqrt")
h_log(c(0, 5, 10))
h_sqrt(c(0, 5, 10))
h_custom <- variance_function(function(S) 1 + S / 20,
                              label = "Var = gamma (1 + S/20)")
h_custom(c(0, 5, 10))

inferMM documentation built on Oct. 30, 2026, 9:06 a.m.