Ejemplo n.º 1
0
 def test_center(self, data):
     wm = OneWayClusteredWeightMatrix(data.clusters, True)
     weight = wm.weight_matrix(data.x, data.z, data.e)
     ze = data.z * data.e
     ze -= ze.mean(0)
     uc = np.unique(data.clusters)
     s = np.zeros((ze.shape[1], ze.shape[1]))
     for val in uc:
         obs = ze[data.clusters == val]
         sum = obs.sum(0)[:, None]
         s += sum @ sum.T
     assert_allclose(weight, s / data.nobs)
Ejemplo n.º 2
0
 def test_debiased(self, data):
     wm = OneWayClusteredWeightMatrix(data.clusters, debiased=True)
     weight = wm.weight_matrix(data.x, data.z, data.e)
     ze = data.z * data.e
     uc = np.unique(data.clusters)
     s = np.zeros((ze.shape[1], ze.shape[1]))
     for val in uc:
         obs = ze[data.clusters == val]
         sum = obs.sum(0)[:, None]
         s += sum @ sum.T
     nobs, nvar = data.nobs, data.nvar
     groups = len(uc)
     scale = (nobs - 1) / (nobs - nvar) * groups / (groups - 1)
     assert_allclose(weight, scale * s / data.nobs)
Ejemplo n.º 3
0
 def test_errors(self, data):
     wm = OneWayClusteredWeightMatrix(data.clusters[:10])
     with pytest.raises(ValueError):
         wm.weight_matrix(data.x, data.z, data.e)