matrices.CommonEffectsMatrix

matrices.CommonEffectsMatrix(terms)

Common-effects matrix.

Parameters

terms : list

A list of Term objects.

Attributes

design_matrix : np.array

A 2-dimensional numpy array containing the values of the design matrix.

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 terms passed at instantiation. The keys are given by the term names.

Methods

Name Description
as_dataframe Returns self.design_matrix as a pandas.DataFrame.
evaluate Obtain design matrix for common effects.
evaluate_new_data Evaluates common terms with new data and return a new instance of

as_dataframe

matrices.CommonEffectsMatrix.as_dataframe()

Returns self.design_matrix as a pandas.DataFrame.

evaluate

matrices.CommonEffectsMatrix.evaluate(data, env)

Obtain design matrix for common effects.

Uses self.terms inside the data mask provided by data and updates self.design_matrix. This method also sets the values of self.data and self.env.

It also populates the dictionary self.slices

Parameters

data : pandas.DataFrame

The data frame where variables are taken from

env : Environment

The environment where values and functions are taken from.

evaluate_new_data

matrices.CommonEffectsMatrix.evaluate_new_data(data)

Evaluates common terms with new data and return a new instance of CommonEffectsMatrix.

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 terms, which means parameters involved in the transformation are not overwritten with the new data.

Parameters

data : pandas.DataFrame

The data frame where variables are taken from

Returns

new_instance : CommonEffectsMatrix

A new instance of CommonEffectsMatrix whose design matrix is obtained with the values in the new data set.