def test_ziopmodel(self): self.assertAlmostEqual(zmiopc.iopmod('ziop', data, X, Y, Z, pstart=pstartziop, method='bfgs', weights=1, offsetx=0, offsetz=0).coefs.iloc[4, 0], -0.29, places=1) self.assertAlmostEqual(zmiopc.iopmod('ziop', data, X, Y, Z, pstart=pstartziop, method='bfgs', weights=1, offsetx=0, offsetz=0).coefs.iloc[5, 0], 0.04, places=1)
def test_miopmodel(self): self.assertAlmostEqual(zmiopc.iopmod('miop', DAT, X, Y, Z).coefs.iloc[2, 0], 0.43, places=1) self.assertAlmostEqual(zmiopc.iopmod('miop', DAT, X, Y, Z).coefs.iloc[14, 0], 0.90, places=1)
def test_vuongopziopc(self): self.assertAlmostEqual(zmiopc.vuong_opiop( zmiopc.opmod(data, X, Y, pstart=pstartop, method='bfgs', weights=1, offsetx=0), zmiopc.iopmod('ziop', data, X, Y, Z, pstart=pstartziop, method='bfgs', weights=1, offsetx=0, offsetz=0)), -4.909, places=1) self.assertAlmostEqual(zmiopc.vuong_opiopc( zmiopc.opmod(data, X, Y, pstart=pstartop, method='bfgs', weights=1, offsetx=0), zmiopc.iopcmod('ziopc', data, X, Y, Z, pstart=pstartziopc, method='bfgs', weights=1, offsetx=0, offsetz=0)), -5.424, places=1)
pstartziopc = [-1.31, .32, 2.5, -.21, .2, -0.2, -0.4, 0.2, .9, -.4, .1] start_time = time.time() ziopc_JCR = zmiopc.iopcmod('ziopc', data, X, Y, Z, pstart=pstartziopc, method='bfgs', weights=1, offsetx=0, offsetz=0) model_time = time.time() - start_time print("%s seconds" % model_time) start_time = time.time() ziop_JCR = zmiopc.iopmod('ziop', data, X, Y, Z, pstart=pstartziop, method='bfgs', weights=1, offsetx=0, offsetz=0) model_time = time.time() - start_time print("%s seconds" % model_time) # OP Model pstartop = [-1, 0.3, -0.2, -0.5, 0.2, .9, -.4] start_time = time.time() JCR_OP = zmiopc.opmod(data, X, Y, pstart=pstartop, method='bfgs', weights=1, offsetx=0) model_time = time.time() - start_time print("%s seconds" % model_time)
DAT = pd.read_stata( os.getcwd() + "/data/EUKnowledge.dta", convert_categoricals=False) Y = ["EU_support_ET"] X = ["polit_trust", "Xenophobia", "discuss_politics", "Professional", "Executive", "Manual", "Farmer", "Unemployed", "rural", "female", "age", "student", "income", "Educ_high", "Educ_high_mid", "Educ_low_mid"] Z = ["discuss_politics", "rural", "female", "age", "student", "EUbid_Know", "EU_Know_obj", "TV", "Educ_high", "Educ_high_mid", "Educ_low_mid"] start_time = time.time() miop_model_paper = zmiopc.iopmod('miop', DAT, X, Y, Z) model_time = time.time() - start_time print("%s seconds" % model_time) start_time = time.time() miopc_model_paper = zmiopc.iopcmod('miopc', DAT, X, Y, Z) model_time = time.time() - start_time print("%s seconds" % model_time) # This is the specification for the Documentation Example: X2 = ['Xenophobia', 'discuss_politics'] Z2 = ['discuss_politics', 'EU_Know_obj'] start_time = time.time() miop_model_short = zmiopc.iopmod('miop', DAT, X2, Y, Z2)
def test_miop_coefs(): miop_EU = zmiopc.iopmod('miop', dataeu, X2, Y2, Z2) assert len(miop_EU.coefs) == len(X2 + Z2) + len(yvar)
def test_iop_fitted(): ziop_JCR = zmiopc.iopmod('ziop', data, X, Y, Z, pstart=pstartziop) fitttedziop = zmiopc.iopfit(ziop_JCR) assert len(fitttedziop.responseordered) == len(fitttedziop.responsefull)
def test_ziop_coefs(): ziop_JCR = zmiopc.iopmod('ziop', data, X, Y, Z, pstart=pstartziop) assert len(ziop_JCR.coefs) == len(pstartziop)
pstartziopsmall = np.array([-1.31, .32, 2.5, -.21, .2, -0.2, -0.4, 0.2]) pstartziopc = np.array([-1.31, .32, 2.5, -.21, .2, -0.2, -0.4, 0.2, .9, -.4, .1]) # These are correct pstart ziopc_JCR = zmiopc.iopcmod('ziopc', data, X, Y, Z, pstart=pstartziopc, method='bfgs', weights=1, offsetx=0, offsetz=0) ziop_JCR = zmiopc.iopmod('ziop', data, X, Y, Z, pstart=pstartziop, method='bfgs', weights=1, offsetx=0, offsetz=0) ziopc_JCR_test = zmiopc.iopcmod('ziopc', data, X, Y, Z) ziop_JCR = zmiopc.iopmod('ziop', data, X, Y, Z) ziop_JCRsmall = zmiopc.iopmod('ziop', pstartziopsmall, data, Xsmall, Y, Z, method='bfgs', weights=1, offsetx=0, offsetz=0) # ziopc_JCR.coefs.to_csv("ZIOPC_0131.csv") # ziop_JCR.coefs.to_csv("ZIOP_0131.csv")