def __init__(self): from scikits.statsmodels.datasets.sunspots import load self.data = load() self.rho, self.sigma = yule_walker(self.data.endog, order=4, method="mle") self.R_params = [1.2831003105694765, -0.45240924374091945, -0.20770298557575195, 0.047943648089542337]
if __name__ == '__main__': nobs = 50 ar = [1.0, -0.8, 0.1] ma = [1.0, 0.1, 0.2] #ma = [1] np.random.seed(9875789) y = arma_generate_sample(ar, ma, nobs, 2) y -= y.mean() #I haven't checked treatment of mean yet, so remove mod = MLEGLS(y) mod.nar, mod.nma = 2, 2 #needs to be added, no init method mod.nobs = len(y) res = mod.fit(start_params=[0.1, -0.8, 0.2, 0.1, 1.]) print 'DGP', ar, ma print res.params from scikits.statsmodels.regression import yule_walker print yule_walker(y, 2) #resi = mod.fit_invertible(start_params=[0.1,0,0.2,0, 0.5]) #print resi.params arpoly, mapoly = getpoly(mod, res.params[:-1]) data = sm.datasets.sunspots.load() #ys = data.endog[-100:] ## ys = data.endog[12:]-data.endog[:-12] ## ys -= ys.mean() ## mods = MLEGLS(ys) ## mods.nar, mods.nma = 13, 1 #needs to be added, no init method ## mods.nobs = len(ys) ## ress = mods.fit(start_params=np.r_[0.4, np.zeros(12), [0.2, 5.]],maxiter=200) ## print ress.params ## #from scikits.statsmodels.sandbox.tsa import arima as tsaa
if __name__ == '__main__': nobs = 50 ar = [1.0, -0.8, 0.1] ma = [1.0, 0.1, 0.2] #ma = [1] np.random.seed(9875789) y = arma_generate_sample(ar,ma,nobs,2) y -= y.mean() #I haven't checked treatment of mean yet, so remove mod = MLEGLS(y) mod.nar, mod.nma = 2, 2 #needs to be added, no init method mod.nobs = len(y) res = mod.fit(start_params=[0.1, -0.8, 0.2, 0.1, 1.]) print 'DGP', ar, ma print res.params from scikits.statsmodels.regression import yule_walker print yule_walker(y, 2) #resi = mod.fit_invertible(start_params=[0.1,0,0.2,0, 0.5]) #print resi.params arpoly, mapoly = getpoly(mod, res.params[:-1]) data = sm.datasets.sunspots.load() #ys = data.endog[-100:] ## ys = data.endog[12:]-data.endog[:-12] ## ys -= ys.mean() ## mods = MLEGLS(ys) ## mods.nar, mods.nma = 13, 1 #needs to be added, no init method ## mods.nobs = len(ys) ## ress = mods.fit(start_params=np.r_[0.4, np.zeros(12), [0.2, 5.]],maxiter=200) ## print ress.params ## #from scikits.statsmodels.sandbox.tsa import arima as tsaa
examples_all = range(10) + ["test_copy"] examples = examples_all # [5] if 0 in examples: print "\n Example 0" X = np.arange(1, 8) X = sm.add_constant(X) Y = np.array((1, 3, 4, 5, 8, 10, 9)) rho = 2 model = GLSAR(Y, X, 2) for i in range(6): results = model.fit() print "AR coefficients:", model.rho rho, sigma = yule_walker(results.resid, order=model.order) model = GLSAR(Y, X, rho) par0 = results.params print par0 model0if = GLSAR(Y, X, 2) res = model0if.iterative_fit(6) print "iterativefit beta", res.params results.t() # is this correct? it does equal params/bse # but isn't the same as the AR example (which was wrong in the first place..) print results.t_test([0, 1]) # are sd and t correct? vs print results.f_test(np.eye(2)) rhotrue = [0.5, 0.2] rhotrue = np.asarray(rhotrue)