delnx.tl.build_designΒΆ
- delnx.tl.build_design(obs, formula=None, condition_key=None, reference=None, covariate_keys=None)[source]ΒΆ
Build a design matrix from a formula or condition_key.
- Parameters:
obs (
DataFrame) β Observation metadata (typicallyadata.obs).formula (
str|None(default:None)) β R-style formula (e.g.,"~ treatment + batch"). Mutually exclusive withcondition_key.condition_key (
str|None(default:None)) β Column inobsfor condition labels. Builds a formula internally. Mutually exclusive withformula.reference (
str|None(default:None)) β Reference level for the condition. Used to reorder categorical levels so the reference becomes the intercept. Only used withcondition_keyor whenformulacontains a simple term matching a categorical column.covariate_keys (
list[str] |None(default:None)) β Additional columns to include as covariates. Only used withcondition_key(ignored whenformulais provided, since covariates should be part of the formula).
- Return type:
- Returns:
tuple[np.ndarray, list[str]] Design matrix of shape
(n_obs, n_coef)and list of column names.- Raises:
ValueError β If both
formulaandcondition_keyare specified, or neither is.