Example #1
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)
Example #2
0
    def test_nominal(self):

        family = Multinomial(3)

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

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

        # Recode as indicators
        endog, exog, exog_ne, nlevel = gee_setup_nominal(data, 0, [3])

        groups = exog_ne[:, 0]

        # Test with independence correlation
        v = Independence()
        md = GEE(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(nlevel, "nominal")
        md = GEE(endog, exog, groups, None, family, v)
        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)
Example #3
0
    def test_nominal(self):

        family = Multinomial(3)

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

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

        # Recode as indicators
        endog, exog, exog_ne, nlevel = gee_setup_nominal(data, 0, [
            3,
        ])

        groups = exog_ne[:, 0]

        # Test with independence correlation
        v = Independence()
        md = GEE(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(nlevel, "nominal")
        md = GEE(endog, exog, groups, None, family, v)
        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)
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)