terms.Term

terms.Term(*components)

Model term.

Terms are made of one or more components. Components are instances of Variable or Call. Terms with only one component are known as main effects and terms with more than one component are known as interaction effects. The order of the interaction is given by the number of components in the term.

Parameters

components : Variable or Call = ()

Atomic components of a term.

Attributes

data : np.ndarray

The values associated with the term as they go into the design matrix.

kind : str

Indicates the type of the term. Can be one of "numeric", "categoric", or "interaction".

name : str

The name of the term as it was originally written in the model formula.

Methods

Name Description
eval_new_data Evaluates the term with new data.
get_component Returns a component by name.
set_data Obtains and stores the final data object related to this term.
set_type Set type of the components in the term.

eval_new_data

terms.Term.eval_new_data(data)

Evaluates the term with new data.

Calls .eval_new_data() method on each component in the term and combines the results appropriately.

Parameters

data : pd.DataFrame

The data frame where variables are taken from

Returns

result : np.array

The values resulting from evaluating this term using the new data.

get_component

terms.Term.get_component(name)

Returns a component by name.

Parameters

name : str

The name of the component to return.

Returns

component : Variable or Call

The component with name name.

set_data

terms.Term.set_data(spans_intercept)

Obtains and stores the final data object related to this term.

Calls .set_data() method on each component in the term. Then, it uses the .data attribute on each of them to build self.data.

Parameters

spans_intercept : dict or bool

Indicates whether categorical components span the intercept. When it is a dictionary, keys are component names and values indicate whether each component spans the intercept. When it is a boolean, the same value is used for all components.

set_type

terms.Term.set_type(data, env)

Set type of the components in the term.

Calls .set_type() method on each component in the term. For those components of class Variable it only passes the data mask. For Call objects it also passes the evaluation environment.

Parameters

data : pd.DataFrame

The data frame where variables are taken from

env : Environment

The environment where values and functions are taken from.