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)
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)
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)
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)
def setup_class(cls): family = Multinomial(3) endog, exog, groups = load_data("gee_nominal_1.csv", icept=False) # Test with independence correlation va = Independence() cls.mod = NominalGEE(endog, exog, groups, None, family, va) cls.start_params = np.array( [0.44944752, 0.45569985, -0.92007064, -0.46766728])
def test_wrapper(self): endog, exog, groups = load_data("gee_nominal_1.csv", icept=False) endog = pd.Series(endog, name='yendog') exog = pd.DataFrame(exog) groups = pd.Series(groups, name='the_group') family = Multinomial(3) va = Independence() mod = NominalGEE(endog, exog, groups, None, family, va) rslt2 = mod.fit() check_wrapper(rslt2)