Exemple #1
0
 def test_center(self, data, kernel, bandwidth):
     wm = KernelWeightMatrix(kernel.kernel,
                             bandwidth,
                             center=True,
                             optimal_bw=True)
     weight = wm.weight_matrix(data.x, data.z, data.e)
     z, e, nobs = data.z, data.e, data.nobs
     bw = bandwidth or wm.bandwidth
     w = kernel.weight(bw, nobs - 1)
     ze = z * e
     ze = ze - ze.mean(0)
     s = ze.T @ ze
     for i in range(1, len(w)):
         op = ze[i:].T @ ze[:-i]
         s += w[i] * (op + op.T)
     assert_allclose(weight, s / nobs)
     assert wm.config['bandwidth'] == bw
     assert wm.config['kernel'] == kernel.kernel
     for name in kernel.alt_names:
         wm = KernelWeightMatrix(name,
                                 bandwidth,
                                 center=True,
                                 optimal_bw=True)
         weight2 = wm.weight_matrix(data.x, data.z, data.e)
         assert_equal(weight, weight2)
Exemple #2
0
    def test_config(self, data, kernel, bandwidth):
        wm = KernelWeightMatrix(kernel=kernel.kernel, bandwidth=bandwidth)
        weight = wm.weight_matrix(data.x, data.z, data.e)
        z, e, nobs = data.z, data.e, data.nobs
        bw = bandwidth or wm.bandwidth
        w = kernel.weight(bw, nobs - 1)
        ze = z * e
        s = ze.T @ ze
        for i in range(1, len(w)):
            op = ze[i:].T @ ze[:-i]
            s += w[i] * (op + op.T)
        assert_allclose(weight, s / nobs)
        assert wm.config['center'] is False
        assert wm.config['debiased'] is False
        assert wm.config['bandwidth'] == bw
        assert wm.config['kernel'] == kernel.kernel

        for name in kernel.alt_names:
            wm = KernelWeightMatrix(kernel=name, bandwidth=bandwidth)
            weight2 = wm.weight_matrix(data.x, data.z, data.e)
            assert_equal(weight, weight2)
Exemple #3
0
 def test_debiased(self, kernel, data, bandwidth):
     wm = KernelWeightMatrix(debiased=True, kernel=kernel.kernel, bandwidth=bandwidth)
     weight = wm.weight_matrix(data.x, data.z, data.e)
     z, e, nobs, nvar = data.z, data.e, data.nobs, data.nvar
     bw = bandwidth or nobs - 2
     w = kernel.weight(bw, nobs - 1)
     ze = z * e
     s = ze.T @ ze
     for i in range(1, len(w)):
         op = ze[i:].T @ ze[:-i]
         s += w[i] * (op + op.T)
     assert_allclose(weight, s / (nobs - nvar))
     assert wm.config['bandwidth'] == bw
     assert wm.config['kernel'] == kernel.kernel