def gendat_ordinal():

    os = ordinal_simulator()
    os.params = np.r_[0., 1]
    os.ngroups = 200
    os.thresholds = [1, 0, -1]
    os.dparams = [1.,]
    os.simulate()

    data = np.concatenate((os.endog[:,None], os.exog,
                           os.group[:,None]), axis=1)

    os.endog_ex, os.exog_ex, os.intercepts, os.nthresh = \
        gee_setup_ordinal(data, 0)

    os.group_ex = os.exog_ex[:,-1]
    os.exog_ex = os.exog_ex[:,0:-1]

    os.exog_ex = np.concatenate((os.intercepts, os.exog_ex),
                                axis=1)

    va = GlobalOddsRatio(4, "ordinal")

    lhs = np.array([[0., 0., 0, 1., 0.], [0., 0, 0, 0, 1]])
    rhs = np.r_[0., 1]

    return os, va, Binomial(), (lhs, rhs)
Beispiel #2
0
def gendat_ordinal():

    os = ordinal_simulator()
    os.params = np.r_[0., 1]
    os.ngroups = 200
    os.thresholds = [1, 0, -1]
    os.dparams = [
        1.,
    ]
    os.simulate()

    data = np.concatenate((os.endog[:, None], os.exog, os.group[:, None]),
                          axis=1)

    os.endog_ex, os.exog_ex, os.intercepts, os.nthresh = \
        gee_setup_ordinal(data, 0)

    os.group_ex = os.exog_ex[:, -1]
    os.exog_ex = os.exog_ex[:, 0:-1]

    os.exog_ex = np.concatenate((os.intercepts, os.exog_ex), axis=1)

    va = GlobalOddsRatio(4, "ordinal")

    lhs = np.array([[0., 0., 0, 1., 0.], [0., 0, 0, 0, 1]])
    rhs = np.r_[0., 1]

    return os, va, Binomial(), (lhs, rhs)
Beispiel #3
0
    def test_ordinal_pandas(self):

        family = Binomial()

        endog_orig, exog_orig, groups = load_data("gee_ordinal_1.csv",
                                                  icept=False)

        data = np.concatenate(
            (endog_orig[:, None], exog_orig, groups[:, None]), axis=1)
        data = pd.DataFrame(data)
        data.columns = ["endog", "x1", "x2", "x3", "x4", "x5", "group"]

        # Recode as cumulative indicators
        endog, exog, intercepts, nlevel = \
            gee_setup_ordinal(data, "endog")

        exog1 = np.concatenate((intercepts, exog), axis=1)
        groups = exog1[:, -1]
        exog1 = exog1[:, 0:-1]

        v = GlobalOddsRatio(nlevel, "ordinal")

        beta = gee_ordinal_starting_values(endog_orig, exog_orig.shape[1])

        md = GEE(endog, exog1, groups, None, family, v)
        mdf = md.fit(start_params=beta)

        cf = np.r_[1.09238131, 0.02148193, -0.39879146, -0.01855666,
                   0.02983409, 1.18123172, 0.01845318, -1.10233886]
        se = np.r_[0.10878752, 0.10326078, 0.11171241, 0.05488705, 0.05995019,
                   0.0916574, 0.05951445, 0.08539281]

        assert_almost_equal(mdf.params, cf, decimal=2)
        assert_almost_equal(mdf.bse, se, decimal=2)
Beispiel #4
0
    def test_ordinal(self):

        family = Binomial()

        endog_orig, exog_orig, groups = load_data("gee_ordinal_1.csv",
                                                  icept=False)

        data = np.concatenate((endog_orig[:,None], exog_orig,
                               groups[:,None]), axis=1)

        # Recode as cumulative indicators
        endog, exog, intercepts, nlevel = gee_setup_ordinal(data, 0)

        exog1 = np.concatenate((intercepts, exog), axis=1)
        groups = exog1[:,-1]
        exog1 = exog1[:,0:-1]

        v = GlobalOddsRatio(nlevel, "ordinal")

        beta = gee_ordinal_starting_values(endog_orig,
                                           exog_orig.shape[1])

        md = GEE(endog, exog1, groups, None, family, v)
        mdf = md.fit(start_params = beta)

        cf = np.r_[1.09238131, 0.02148193, -0.39879146, -0.01855666,
                   0.02983409, 1.18123172,  0.01845318, -1.10233886]
        se = np.r_[0.10878752,  0.10326078,  0.11171241, 0.05488705,
                   0.05995019, 0.0916574,  0.05951445,  0.08539281]

        assert_almost_equal(mdf.params, cf, decimal=5)
        assert_almost_equal(mdf.bse, se, decimal=5)