statsmodels.genmod.cov_struct.Equivalence#

class statsmodels.genmod.cov_struct.Equivalence(pairs=None, labels=None, return_cov=False)[source]#

A covariance structure defined in terms of equivalence classes.

An ‘equivalence class’ is a set of pairs of observations such that the covariance of every pair within the equivalence class has a common value.

Parameters:
pairsdict-like

A dictionary of dictionaries, where pairs[group][label] provides the indices of all pairs of observations in the group that have the same covariance value. Specifically, pairs[group][label] is a tuple (j1, j2), where j1 and j2 are integer arrays of the same length. j1[i], j2[i] is one index pair that belongs to the label equivalence class. Only one triangle of each covariance matrix should be included. Positions where j1 and j2 have the same value are variance parameters.

labelsarray_like

An array of labels such that every distinct pair of labels defines an equivalence class. Either labels or pairs must be provided. When the two labels in a pair are equal two equivalence classes are defined: one for the diagonal elements (corresponding to variances) and one for the off-diagonal elements (corresponding to covariances).

return_covbool

If True, covariance_matrix returns an estimate of the covariance matrix, otherwise returns an estimate of the correlation matrix.

Methods

covariance_matrix(expval, index)

Returns the working covariance or correlation matrix for a given cluster of data.

covariance_matrix_solve(expval, index, ...)

Solves matrix equations of the form covmat * soln = rhs and returns the values of soln, where covmat is the covariance matrix represented by this class.

initialize(model[, rng])

Called by GEE, used by implementations that need additional setup prior to running fit.

summary()

Returns a text summary of the current estimate of the dependence structure.

update(params)

Update the association parameter values based on the current regression coefficients.

Notes

Using labels to define the class is much easier than using pairs, but is less general.

Any pair of values not contained in pairs will be assigned zero covariance.

The index values in pairs are row indices into the exog matrix. They are not updated if missing data are present. When using this covariance structure, missing data should be removed before constructing the model.

If using labels, after a model is defined using the covariance structure it is possible to remove a label pair from the second level of the pairs dictionary to force the corresponding covariance to be zero.

Examples

The following sets up the pairs dictionary for a model with two groups, equal variance for all observations, and constant covariance for all pairs of observations within each group.

>> pairs = {0: {}, 1: {}} >> pairs[0][0] = (np.r_[0, 1, 2], np.r_[0, 1, 2]) >> pairs[0][1] = np.tril_indices(3, -1) >> pairs[1][0] = (np.r_[3, 4, 5], np.r_[3, 4, 5]) >> pairs[1][2] = 3 + np.tril_indices(3, -1)

Methods

covariance_matrix(expval, index)

Returns the working covariance or correlation matrix for a given cluster of data.

covariance_matrix_solve(expval, index, ...)

Solves matrix equations of the form covmat * soln = rhs and returns the values of soln, where covmat is the covariance matrix represented by this class.

initialize(model[, rng])

Called by GEE, used by implementations that need additional setup prior to running fit.

summary()

Returns a text summary of the current estimate of the dependence structure.

update(params)

Update the association parameter values based on the current regression coefficients.