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_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)