def test_debiased(self, data): wm = HomoskedasticWeightMatrix(debiased=True) weight = wm.weight_matrix(data.x, data.z, data.e) z, e, nobs, nvar = data.z, data.e, data.nobs, data.nvar s2 = (e - e.mean()).T @ (e - e.mean()) / nobs scale = nobs / (nobs - nvar) assert_allclose(weight, scale * s2 * z.T @ z / nobs)
def test_config(self, data): wm = HomoskedasticWeightMatrix() z, e, nobs = data.z, data.e, data.nobs weight = wm.weight_matrix(data.x, z, e) s2 = (e - e.mean()).T @ (e - e.mean()) / nobs assert_allclose(weight, s2 * z.T @ z / nobs) assert wm.config['center'] is False assert wm.config['debiased'] is False
def test_homoskedastic(self, data): c = IVGMMCovariance(data.x, data.y, data.z, data.params, data.i, 'unadjusted') s = HomoskedasticWeightMatrix().weight_matrix(data.x, data.z, data.e) x, z = data.x, data.z xzwswzx = x.T @ z @ s @ z.T @ x / data.nobs cov = data.xzizx_inv @ xzwswzx @ data.xzizx_inv cov = (cov + cov.T) / 2 assert_allclose(c.cov, cov) assert c.config['debiased'] is False
def test_defaults(self, data): wm = HomoskedasticWeightMatrix() z, e, nobs = data.z, data.e, data.nobs weight = wm.weight_matrix(data.x, z, e) s2 = (e - e.mean()).T @ (e - e.mean()) / nobs assert_allclose(weight, s2 * z.T @ z / nobs)
def test_center(self, data): wm = HomoskedasticWeightMatrix(True) weight = wm.weight_matrix(data.x, data.z, data.e) z, e, nobs = data.z, data.e, data.nobs s2 = (e - e.mean()).T @ (e - e.mean()) / nobs assert_allclose(weight, s2 * z.T @ z / nobs)