matrices.GroupEffectsMatrix
matrices.GroupEffectsMatrix(terms)Group-specific-effects matrix.
The sub-matrix that corresponds to a specific group effect can be accessed by self[term_name], for example self["1|g"].
Parameters
terms : list-
A list of GroupSpecificTerm objects.
Attributes
design_matrix : scipy.sparse.csr_matrix-
The design matrix in CSR format.
evaluated : bool-
Indicates if the terms have been evaluated at least once. The terms must have been evaluated before calling
self.evaluate_new_data()because we must know the kind of each term to correctly handle the new data passed and the terms here. terms : dict-
A dictionary that holds all the group specific terms. The keys are given by the term names.
Methods
| Name | Description |
|---|---|
| as_dataframe | Returns self.design_matrix as a pandas.DataFrame. |
| evaluate | Evaluate group specific terms. |
| evaluate_new_data | Evaluates group specific terms with new data and return a new instance of |
as_dataframe
matrices.GroupEffectsMatrix.as_dataframe()Returns self.design_matrix as a pandas.DataFrame.
evaluate
matrices.GroupEffectsMatrix.evaluate(data, env)Evaluate group specific terms.
This evaluates self.terms inside the data mask provided by data and the environment env. It updates self.design_matrix with the result from the evaluation of each term.
This method also sets the values of self.data and self.env. It also populates the dictionary self.slices with the columns each term occupies in the design matrix.
Parameters
evaluate_new_data
matrices.GroupEffectsMatrix.evaluate_new_data(data)Evaluates group specific terms with new data and return a new instance of GroupEffectsMatrix.
This method is intended to be used to obtain design matrices for new data and obtain out of sample predictions. Stateful transformations are properly handled if present in any of the group specific terms, which means parameters involved in the transformation are not overwritten with the new data.
Parameters
Returns
new_instance : GroupEffectsMatrix-
A new instance of
GroupEffectsMatrixwhose design matrix is obtained with the values in the new data set.