Beispiel #1
0
    def get_re_stats(self, method="QP", alpha=0.05):
        """Get random-effect statistics."""
        if method == "QP":
            n_iters = np.atleast_2d(self.tau2).shape[1]
            if n_iters > 10:
                warn("Method 'QP' is not parallelized; it may take a while to "
                     "compute CIs for {} parallel tau^2 values.".format(
                         n_iters))

            # Make sure we have an estimate of v if it wasn't observed
            v = self.estimator.get_v(self.dataset)

            cis = []
            for i in range(n_iters):
                args = {
                    "y": self.dataset.y[:, i],
                    "v": v[:, i],
                    "X": self.dataset.X,
                    "alpha": alpha,
                }

                try:
                    q_cis = q_profile(**args)
                except Exception:
                    q_cis = {"ci_l": np.nan, "ci_u": np.nan}

                cis.append(q_cis)

        else:
            raise ValueError(
                "Invalid CI method '{}'; currently only 'QP' is available.".
                format(method))

        return {
            "tau^2": self.tau2,
            "ci_l": np.array([ci["ci_l"] for ci in cis]),
            "ci_u": np.array([ci["ci_u"] for ci in cis]),
        }
Beispiel #2
0
def test_q_profile(vars_with_intercept):
    bounds = q_profile(*vars_with_intercept, 0.05)
    assert set(bounds.keys()) == {"ci_l", "ci_u"}
    assert round(bounds["ci_l"], 4) == 3.8076
    assert round(bounds["ci_u"], 2) == 59.61
Beispiel #3
0
def test_q_profile(vars_with_intercept):
    bounds = q_profile(*vars_with_intercept, 0.05)
    assert set(bounds.keys()) == {'ci_l', 'ci_u'}
    assert round(bounds['ci_l'], 4) == 3.8076
    assert round(bounds['ci_u'], 4) == 59.6144