Exemplo n.º 1
0
    def test_nominal(self):

        family = Multinomial(3)

        endog, exog, groups = load_data("gee_nominal_1.csv", icept=False)

        # Test with independence correlation
        v = Independence()
        md = GEE(endog, exog, groups, None, family, v)
        md.setup_nominal()
        mdf1 = md.fit()

        # From statsmodels.GEE (not an independent test)
        cf1 = np.r_[0.44944752, 0.45569985, -0.92007064, -0.46766728]
        se1 = np.r_[0.09801821, 0.07718842, 0.13229421, 0.08544553]
        assert_almost_equal(mdf1.params, cf1, decimal=5)
        assert_almost_equal(mdf1.standard_errors(), se1, decimal=5)

        # Test with global odds ratio dependence
        v = GlobalOddsRatio("nominal")
        md = GEE(endog, exog, groups, None, family, v)
        md.setup_nominal()
        mdf2 = md.fit(start_params=mdf1.params)

        # From statsmodels.GEE (not an independent test)
        cf2 = np.r_[0.45397549, 0.42278345, -0.91997131, -0.50115943]
        se2 = np.r_[0.09646057, 0.07405713, 0.1324629, 0.09025019]
        assert_almost_equal(mdf2.params, cf2, decimal=5)
        assert_almost_equal(mdf2.standard_errors(), se2, decimal=5)
Exemplo n.º 2
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)
Exemplo n.º 3
0
    def test_nominal(self):

        family = Multinomial(3)

        endog, exog, groups = load_data("gee_nominal_1.csv", icept=False)

        # Test with independence correlation
        v = Independence()
        md = NominalGEE(endog, exog, groups, None, family, v)
        mdf1 = md.fit()

        # From statsmodels.GEE (not an independent test)
        cf1 = np.r_[0.44944752, 0.45569985, -0.92007064, -0.46766728]
        se1 = np.r_[0.09801821, 0.07718842, 0.13229421, 0.08544553]
        assert_almost_equal(mdf1.params, cf1, decimal=5)
        assert_almost_equal(mdf1.standard_errors(), se1, decimal=5)

        # Test with global odds ratio dependence
        v = GlobalOddsRatio("nominal")
        md = NominalGEE(endog, exog, groups, None, family, v)
        mdf2 = md.fit(start_params=mdf1.params)

        # From statsmodels.GEE (not an independent test)
        cf2 = np.r_[0.45448248, 0.41945568, -0.92008924, -0.50485758]
        se2 = np.r_[0.09632274, 0.07433944, 0.13264646, 0.0911768]
        assert_almost_equal(mdf2.params, cf2, decimal=5)
        assert_almost_equal(mdf2.standard_errors(), se2, decimal=5)
Exemplo n.º 4
0
def gendat_nominal():

    ns = nominal_simulator()

    # The last component of params must be identically zero
    ns.params = [np.r_[0., 1], np.r_[-1., 0], np.r_[0., 0]]
    ns.ngroups = 200
    ns.dparams = [
        1.,
    ]
    ns.simulate()

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

    ns.endog_ex, ns.exog_ex, ns.exog_ne, ns.nlevel = \
        gee_setup_nominal(data, 0, [3,])

    ns.group_ex = ns.exog_ne[:, 0]

    va = GlobalOddsRatio(3, "nominal")

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

    return ns, va, Multinomial(3), (lhs, rhs)
Exemplo n.º 5
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)
Exemplo n.º 6
0
    def test_nominal(self):

        family = Multinomial(3)

        endog, exog, groups = load_data("gee_nominal_1.csv", icept=False)

        # Test with independence correlation
        va = Independence()
        mod1 = NominalGEE(endog, exog, groups, None, family, va)
        rslt1 = mod1.fit()

        # Regression test
        cf1 = np.r_[0.44944752, 0.45569985, -0.92007064, -0.46766728]
        se1 = np.r_[0.09801821, 0.07718842, 0.13229421, 0.08544553]
        assert_almost_equal(rslt1.params, cf1, decimal=5)
        assert_almost_equal(rslt1.standard_errors(), se1, decimal=5)

        # Test with global odds ratio dependence
        va = GlobalOddsRatio("nominal")
        mod2 = NominalGEE(endog, exog, groups, None, family, va)
        rslt2 = mod2.fit(start_params=rslt1.params)

        # Regression test
        cf2 = np.r_[0.45448248, 0.41945568, -0.92008924, -0.50485758]
        se2 = np.r_[0.09632274, 0.07433944, 0.13264646, 0.0911768]
        assert_almost_equal(rslt2.params, cf2, decimal=5)
        assert_almost_equal(rslt2.standard_errors(), se2, decimal=5)

        # Make sure we get the correct results type
        assert_equal(type(rslt1), NominalGEEResultsWrapper)
        assert_equal(type(rslt1._results), NominalGEEResults)
Exemplo n.º 7
0
    def setup_class(cls):

        family = Binomial()

        endog, exog, groups = load_data("gee_ordinal_1.csv", icept=False)

        va = GlobalOddsRatio("ordinal")

        cls.mod = OrdinalGEE(endog, exog, groups, None, family, va)
        cls.start_params = np.array([
            1.09250002, 0.0217443, -0.39851092, -0.01812116, 0.03023969,
            1.18258516, 0.01803453, -1.10203381
        ])
Exemplo n.º 8
0
    def test_wrapper(self):

        endog, exog, groups = load_data("gee_ordinal_1.csv", icept=False)

        endog = pd.Series(endog, name='yendog')
        exog = pd.DataFrame(exog)
        groups = pd.Series(groups, name='the_group')

        family = Binomial()
        va = GlobalOddsRatio("ordinal")
        mod = OrdinalGEE(endog, exog, groups, None, family, va)
        rslt2 = mod.fit()

        check_wrapper(rslt2)
Exemplo n.º 9
0
    def test_ordinal(self):

        family = Binomial()

        endog, exog, groups = load_data("gee_ordinal_1.csv", icept=False)

        v = GlobalOddsRatio("ordinal")

        md = GEE(endog, exog, groups, None, family, v)
        md.setup_ordinal()
        mdf = md.fit()

        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)
Exemplo n.º 10
0
    def test_ordinal(self):

        family = Binomial()

        endog, exog, groups = load_data("gee_ordinal_1.csv", icept=False)

        v = GlobalOddsRatio("ordinal")

        md = OrdinalGEE(endog, exog, groups, None, family, v)
        mdf = md.fit()

        cf = np.r_[1.09250002, 0.0217443, -0.39851092, -0.01812116, 0.03023969,
                   1.18258516, 0.01803453, -1.10203381]

        se = np.r_[0.10883461, 0.10330197, 0.11177088, 0.05486569, 0.05997153,
                   0.09168148, 0.05953324, 0.0853862]

        assert_almost_equal(mdf.params, cf, decimal=5)
        assert_almost_equal(mdf.bse, se, decimal=5)
Exemplo n.º 11
0
    def test_ordinal(self):

        family = Binomial()

        endog, exog, groups = load_data("gee_ordinal_1.csv", icept=False)

        va = GlobalOddsRatio("ordinal")

        mod = OrdinalGEE(endog, exog, groups, None, family, va)
        rslt = mod.fit()

        # Regression test
        cf = np.r_[1.09250002, 0.0217443, -0.39851092, -0.01812116, 0.03023969,
                   1.18258516, 0.01803453, -1.10203381]
        assert_almost_equal(rslt.params, cf, decimal=5)

        # Regression test
        se = np.r_[0.10883461, 0.10330197, 0.11177088, 0.05486569, 0.05997153,
                   0.09168148, 0.05953324, 0.0853862]
        assert_almost_equal(rslt.bse, se, decimal=5)

        # Check that we get the correct results type
        assert_equal(type(rslt), OrdinalGEEResultsWrapper)
        assert_equal(type(rslt._results), OrdinalGEEResults)