API Reference#

This reference provides detailed documentation for all modules, classes, and methods in the current release of formulae.

formulae#

formulae.design_matrices(formula, data, na_action='drop', env=0, extra_namespace=None)[source]#

Parse model formula and obtain a DesignMatrices object containing objects representing the response and the design matrices for both the common and group specific effects.

Parameters
  • formula (string) – A model formula.

  • data (pandas.DataFrame) – The data frame where variables in the formula are taken from.

  • na_action (string) – Describes what to do with missing values in data. "drop" means to drop all rows with a missing value, "error" means to raise an error, "pass" means to to keep all. Defaults to "drop".

  • env (integer) – The number of environments we walk up in the stack starting from the function’s caller to capture the environment where formula is evaluated. Defaults to 0 which means the evaluation environment is the environment where design_matrices is called.

  • extra_namespace (dict) – Additional user supplied transformations to include in the environment where the formula is evaluated. Defaults to None.

Returns

design – An instance of DesignMatrices that contains the design matrice(s) described by formula.

Return type

DesignMatrices

formulae.model_description(formula)[source]#

Interpret model formula and obtain a model description.

This function receives a string with a formula describing a statistical model and returns an object of class ModelTerms that describes the model interpreted from the formula.

Parameters

formula (string) – A string with a model description in formula language.

Return type

An object of class ModelTerms with an internal description of the model.

formulae.matrices#

class formulae.matrices.DesignMatrices(model, data, env)[source]#

A wrapper of the response, the common, and group specific effects.

Parameters
  • model (Model) – The model description, the result of calling model_description.

  • data (pandas.DataFrame) – The data frame where variables are taken from.

  • env (Environment) – The environment where values and functions are taken from.

response#

The response in the model. Access its values with self.response.design_matrix. It is None if there is no response term in the model.

Type

ResponseMatrix

common#

The common effects (a.k.a. fixed effects) in the model. The design matrix can be accessed with self.common.design_matrix. The submatrix for a term is accessed via self.common[term_name]. It is None if there are no common terms in the model.

Type

CommonEffectsMatrix

group#

The group specific effects (a.k.a. random effects) in the model. The design matrix can be accessed with self.group.design_matrix. The submatrix for a term is accessed via self.group[term_name]. It is None if there are no group specific terms in the model.

Type

GroupEffectsMatrix