linearmodels.iv.covariance.ClusteredCovariance¶
-
class linearmodels.iv.covariance.ClusteredCovariance(x: ndarray[tuple[int, ...], dtype[float64]], y: ndarray[tuple[int, ...], dtype[float64]], z: ndarray[tuple[int, ...], dtype[float64]], params: ndarray[tuple[int, ...], dtype[float64]], clusters: ndarray[tuple[int, ...], Any] | None =
None, debiased: bool =False, kappa: int | float =1, extra_df: int =0)[source]¶ Covariance estimation for clustered data.
- Parameters:¶
- x: ndarray[tuple[int, ...], dtype[float64]]¶
Model regressors (nobs by nvar).
- y: ndarray[tuple[int, ...], dtype[float64]]¶
Series modeled (nobs by 1).
- z: ndarray[tuple[int, ...], dtype[float64]]¶
Instruments used for endogenous regressors (nobs by ninstr).
- params: ndarray[tuple[int, ...], dtype[float64]]¶
Estimated model parameters (nvar by 1).
- clusters: ndarray[tuple[int, ...], Any] | None =
None¶ Cluster group assignment, with shape nobs by ncluster where ncluster is 1 or 2. If not provided, every observation is its own cluster. A
ValueErroris raised for more columns.- debiased: bool =
False¶ Flag indicating whether to use a small-sample adjustment. The default is False.
- kappa: int | float =
1¶ Value of kappa in the k-class estimator. The default is 1.
- extra_df: int =
0¶ Degrees of freedom that the model uses in addition to the nvar columns of x, for example the absorbed effects of AbsorbingLS. The default is 0. It is only used if
debiasedis True, when n / (n-k) becomes n / (n-k-extra_df).
- Raises:¶
ValueError – If the number of rows of x, y and z differ, if x and params have incompatible dimensions, if clusters does not have one row for each observation or has more than 2 columns, or if
debiasedis True and there are no more observations than the columns of x plusextra_df.
Notes
Covariance is estimated using
\[n^{-1} V^{-1} \hat{S} V^{-1}\]where
\[\begin{split}\hat{S} & = n^{-1} (G/(G-1)) \sum_{g=1}^G \xi_{g}^\prime \xi_{g} \\ \xi_{g} & = \sum_{i\in\mathcal{G}_g} \hat{\epsilon}_i \hat{x}_i \\\end{split}\]where \(\hat{\gamma}=(Z'Z)^{-1}(Z'X)\) and \(\hat{x}_i = z_i\hat{\gamma}\). \(\mathcal{G}_g\) contains the indices of elements in cluster g. If
debiasedis true, then \(S\) is scaled by g(n - 1) / ((g-1)(n-k-df)) where g is the number of groups, k is the number of columns of x and df isextra_df.\[V = n^{-1} X'Z(Z'Z)^{-1}Z'X\]where \(X\) is the matrix of variables included in the model and \(Z\) is the matrix of instruments, including exogenous regressors.
Methods
Properties
Return the options of the covariance estimator as a dict.
Return the covariance of the estimated parameters.
Return a flag indicating if the covariance is debiased.
Return the clustered estimator of the score covariance.
Return the variance of the residuals, adjusted if debiased.