BasisBuilder.ri()

BasisBuilder.ri()#

BasisBuilder.ri(cluster, basis_name='B', penalty=None)[source]#

Random intercept basis.

Parameters:
  • cluster (str) – Name of the cluster variable.

  • basis_name (str, default: 'B') – Name of the basis variable.

  • penalty (Array | ndarray | bool | number | bool | int | float | complex | None, default: None) – Custom penalty matrix to use. Default is an iid penalty.

Return type:

Basis

Notes

If the penalty is iid, then each column of the basis consists only of binary (0/1) entries, and each row has only one non-zero entry. In this case it is not necessary to store the full matrix in memory and evaluate the term as a dot product basis @ coef.

Instead, we can simply store a 1d array of indices, identifying the nonzero column for each row of the basis matrix, and use this index to access the corresponding coefficient. This scenario is common for independent random intercepts.

This method returns such a sparse representation of the random intercept basis if penalty=None.

Examples

>>> import liesel_gam as gam
>>> df = gam.demo_data(n=100)
>>> registry = gam.PandasRegistry(df)
>>> bb = gam.BasisBuilder(registry)
>>> bb.ri("x_cat")
Basis(name="B(x_cat)")