3.11.5.2.1. statsmodels.stats.contrast.Contrast

class statsmodels.stats.contrast.Contrast(term, design)[source]

This class is used to construct contrast matrices in regression models.

They are specified by a (term, design) pair. The term, T, is a linear combination of columns of the design matrix. The matrix attribute of Contrast is a contrast matrix C so that

colspan(dot(D, C)) = colspan(dot(D, dot(pinv(D), T)))

where pinv(D) is the generalized inverse of D. Further, the matrix

Tnew = dot(C, D)

is full rank. The rank attribute is the rank of

dot(D, dot(pinv(D), T))

In a regression model, the contrast tests that E(dot(Tnew, Y)) = 0 for each column of Tnew.

Parameters:

term : array-like

design : array-like

-7.77260726e-17 -8.41929574e-18 -7.36359622e-17 -1.39760860e-16

1.82976904e-16 -3.75277947e-18]

Get another contrast

>>> zero = np.zeros((40,))
>>> new_term3 = np.column_stack((zero,X[:,2]))
>>> c3 = sm.contrast.Contrast(new_term3, X)
>>> test2 = [0]*2 + [1] + [0]*7
>>> np.allclose(c3.contrast_matrix, test2)
True

Attributes

contrast_matrix Gets the contrast_matrix property
__init__(term, design)[source]

3.11.5.2.1.1. Methods

__init__(term, design)
compute_matrix() Construct a contrast matrix C so that

3.11.5.2.1.2. Attributes

contrast_matrix Gets the contrast_matrix property