def setupClass(cls): data = longley.load() data.exog = add_constant(data.exog) ols_res = OLS(data.endog, data.exog).fit() gls_res = GLS(data.endog, data.exog).fit() cls.res1 = gls_res cls.res2 = ols_res
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]
def setupClass(cls): data = longley.load() data.exog = add_constant(data.exog) ols_res = OLS(data.endog, data.exog).fit() gls_res = GLS(data.endog, data.exog).fit() cls.res1 = gls_res cls.res2 = ols_res
def __init__(self): from scikits.statsmodels.datasets.longley import load data = load() data.exog = add_constant(data.exog) self.res1 = OLS(data.endog, data.exog).fit() R = np.identity(7)[:-1,:] self.Ftest = self.res1.f_test(R)
def __init__(self): from scikits.statsmodels.datasets.longley import load data = load() data.exog = add_constant(data.exog) ols_res = OLS(data.endog, data.exog).fit() gls_res = GLS(data.endog, data.exog).fit() self.res1 = gls_res self.res2 = ols_res
def setupClass(cls): data = longley.load() data.exog = add_constant(data.exog) res1 = OLS(data.endog, data.exog).fit() R = np.array([[0, 1, 1, 0, 0, 0, 0], [0, 1, 0, 1, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 1, 0]]) q = np.array([0, 0, 0, 1, 0]) cls.Ftest1 = res1.f_test(R, q)
def __init__(self): from scikits.statsmodels.datasets.longley import load from results.results_regression import Longley data = load() data.exog = add_constant(data.exog) res1 = OLS(data.endog, data.exog).fit() res2 = Longley() res2.wresid = res1.wresid # workaround hack self.res1 = res1 self.res2 = res2
def setupClass(cls): data = longley.load() data.exog = add_constant(data.exog) res1 = OLS(data.endog, data.exog).fit() R = np.array([[0,1,1,0,0,0,0], [0,1,0,1,0,0,0], [0,1,0,0,0,0,0], [0,0,0,0,1,0,0], [0,0,0,0,0,1,0]]) q = np.array([0,0,0,1,0]) cls.Ftest1 = res1.f_test(R,q)
def setupClass(cls): from results.results_glm import Cpunish from scikits.statsmodels.datasets.cpunish import load data = load() data.exog[:,3] = np.log(data.exog[:,3]) data.exog = add_constant(data.exog) exposure = [100] * len(data.endog) cls.res1 = GLM(data.endog, data.exog, family=sm.families.Poisson(), exposure=exposure).fit() cls.res1.params[-1] += np.log(100) # add exposure back in to param # to make the results the same cls.res2 = Cpunish()
def setupClass(cls): from results.results_glm import Cpunish from scikits.statsmodels.datasets.cpunish import load data = load() data.exog[:, 3] = np.log(data.exog[:, 3]) data.exog = add_constant(data.exog) exposure = [100] * len(data.endog) cls.res1 = GLM(data.endog, data.exog, family=sm.families.Poisson(), exposure=exposure).fit() cls.res1.params[-1] += np.log(100) # add exposure back in to param # to make the results the same cls.res2 = Cpunish()
def setupClass(cls): from results.results_regression import Longley data = longley.load() data.exog = add_constant(data.exog) res1 = OLS(data.endog, data.exog).fit() res2 = Longley() res2.wresid = res1.wresid # workaround hack cls.res1 = res1 cls.res2 = res2 res_qr = OLS(data.endog, data.exog).fit(method="qr") cls.res_qr = res_qr
def setupClass(cls): from results.results_regression import Longley data = longley.load() data.exog = add_constant(data.exog) res1 = OLS(data.endog, data.exog).fit() res2 = Longley() res2.wresid = res1.wresid # workaround hack cls.res1 = res1 cls.res2 = res2 res_qr = OLS(data.endog, data.exog).fit(method="qr") cls.res_qr = res_qr
def setupClass(cls): from results.results_regression import LongleyGls data = longley.load() exog = add_constant(np.column_stack((data.exog[:, 1], data.exog[:, 4]))) tmp_results = OLS(data.endog, exog).fit() rho = np.corrcoef(tmp_results.resid[1:], tmp_results.resid[:-1])[0][1] # by assumption order = toeplitz(np.arange(16)) sigma = rho ** order GLS_results = GLS(data.endog, exog, sigma=sigma).fit() cls.res1 = GLS_results cls.res2 = LongleyGls()
def __init__(self): from scikits.statsmodels.datasets.longley import load data = load() self.data = data data.exog = add_constant(data.exog) self.res1 = OLS(data.endog, data.exog).fit() # def setup(self): # if skipR: # raise SkipTest, "Rpy not installed" # else: R = np.identity(7) self.Ttest = self.res1.t_test(R)
def setupClass(cls): from results.results_regression import LongleyGls data = longley.load() exog = add_constant(np.column_stack(\ (data.exog[:,1],data.exog[:,4]))) tmp_results = OLS(data.endog, exog).fit() rho = np.corrcoef(tmp_results.resid[1:], tmp_results.resid[:-1])[0][1] # by assumption order = toeplitz(np.arange(16)) sigma = rho**order GLS_results = GLS(data.endog, exog, sigma=sigma).fit() cls.res1 = GLS_results cls.res2 = LongleyGls()
def __init__(self): ''' Tests Poisson family with canonical log link. Test results were obtained by R. ''' from results.results_glm import Cpunish from scikits.statsmodels.datasets.cpunish import load self.data = load() self.data.exog[:,3] = np.log(self.data.exog[:,3]) self.data.exog = add_constant(self.data.exog) self.res1 = GLM(self.data.endog, self.data.exog, family=sm.families.Poisson()).fit() self.res2 = Cpunish()
def setupClass(cls): # if skipR: # raise SkipTest, "Rpy not installed" # try: # r.library('car') # except RPyRException: # raise SkipTest, "car library not installed for R" R = np.zeros(7) R[4:6] = [1, -1] # self.R = R data = longley.load() data.exog = add_constant(data.exog) res1 = OLS(data.endog, data.exog).fit() cls.Ttest1 = res1.t_test(R)
def __init__(self): ''' Tests Poisson family with canonical log link. Test results were obtained by R. ''' from results.results_glm import Cpunish from scikits.statsmodels.datasets.cpunish import load self.data = load() self.data.exog[:,3] = np.log(self.data.exog[:,3]) self.data.exog = add_constant(self.data.exog) self.res1 = GLM(self.data.endog, self.data.exog, family=sm.families.Poisson()).fit() self.res2 = Cpunish()
def setupClass(cls): # if skipR: # raise SkipTest, "Rpy not installed" # try: # r.library('car') # except RPyRException: # raise SkipTest, "car library not installed for R" R = np.zeros(7) R[4:6] = [1,-1] # self.R = R data = longley.load() data.exog = add_constant(data.exog) res1 = OLS(data.endog, data.exog).fit() cls.Ttest1 = res1.t_test(R)
def __init__(self): from scikits.statsmodels.datasets.longley import load from results.results_regression import LongleyGls data = load() exog = add_constant(np.column_stack(\ (data.exog[:,1],data.exog[:,4]))) tmp_results = OLS(data.endog, exog).fit() rho = np.corrcoef(tmp_results.resid[1:], tmp_results.resid[:-1])[0][1] # by assumption order = toeplitz(np.arange(16)) sigma = rho**order GLS_results = GLS(data.endog, exog, sigma=sigma).fit() self.res1 = GLS_results self.res2 = LongleyGls()
def __init__(self): ''' Test Gaussian family with canonical identity link ''' # Test Precisions self.decimal_resids = DECIMAL_3 self.decimal_params = DECIMAL_2 self.decimal_bic = DECIMAL_0 self.decimal_bse = DECIMAL_3 from scikits.statsmodels.datasets.longley import load self.data = load() self.data.exog = add_constant(self.data.exog) self.res1 = GLM(self.data.endog, self.data.exog, family=sm.families.Gaussian()).fit() from results.results_glm import Longley self.res2 = Longley()
def __init__(self): ''' Test Gaussian family with canonical identity link ''' # Test Precisions self.decimal_resids = DECIMAL_3 self.decimal_params = DECIMAL_2 self.decimal_bic = DECIMAL_0 self.decimal_bse = DECIMAL_3 from scikits.statsmodels.datasets.longley import load self.data = load() self.data.exog = add_constant(self.data.exog) self.res1 = GLM(self.data.endog, self.data.exog, family=sm.families.Gaussian()).fit() from results.results_glm import Longley self.res2 = Longley()
def __init__(self): ''' Test Binomial family with canonical logit link using star98 dataset. ''' self.decimal_resids = DECIMAL_1 self.decimal_bic = DECIMAL_2 from scikits.statsmodels.datasets.star98 import load from results.results_glm import Star98 data = load() data.exog = add_constant(data.exog) self.res1 = GLM(data.endog, data.exog, \ family=sm.families.Binomial()).fit() #NOTE: if you want to replicate with RModel #res2 = RModel(data.endog[:,0]/trials, data.exog, r.glm, # family=r.binomial, weights=trials) self.res2 = Star98()
def __init__(self): ''' Test Binomial family with canonical logit link using star98 dataset. ''' self.decimal_resids = DECIMAL_1 self.decimal_bic = DECIMAL_2 from scikits.statsmodels.datasets.star98 import load from results.results_glm import Star98 data = load() data.exog = add_constant(data.exog) self.res1 = GLM(data.endog, data.exog, \ family=sm.families.Binomial()).fit() #NOTE: if you want to replicate with RModel #res2 = RModel(data.endog[:,0]/trials, data.exog, r.glm, # family=r.binomial, weights=trials) self.res2 = Star98()
def __init__(self): ''' Tests Gamma family with canonical inverse link (power -1) ''' # Test Precisions self.decimal_aic_R = -1 #TODO: off by about 1, we are right with Stata self.decimal_resids = DECIMAL_2 from scikits.statsmodels.datasets.scotland import load from results.results_glm import Scotvote data = load() data.exog = add_constant(data.exog) res1 = GLM(data.endog, data.exog, \ family=sm.families.Gamma()).fit() self.res1 = res1 # res2 = RModel(data.endog, data.exog, r.glm, family=r.Gamma) res2 = Scotvote() res2.aic_R += 2 # R doesn't count degree of freedom for scale with gamma self.res2 = res2
def __init__(self): ''' Tests Gamma family with canonical inverse link (power -1) ''' # Test Precisions self.decimal_aic_R = -1 #TODO: off by about 1, we are right with Stata self.decimal_resids = DECIMAL_2 from scikits.statsmodels.datasets.scotland import load from results.results_glm import Scotvote data = load() data.exog = add_constant(data.exog) res1 = GLM(data.endog, data.exog, \ family=sm.families.Gamma()).fit() self.res1 = res1 # res2 = RModel(data.endog, data.exog, r.glm, family=r.Gamma) res2 = Scotvote() res2.aic_R += 2 # R doesn't count degree of freedom for scale with gamma self.res2 = res2
def __init__(self): ''' Test Negative Binomial family with canonical log link ''' # Test Precision self.decimal_resid = DECIMAL_1 self.decimal_params = DECIMAL_3 self.decimal_resids = -1 # 1 % mismatch at 0 self.decimal_fittedvalues = DECIMAL_1 from scikits.statsmodels.datasets.committee import load self.data = load() self.data.exog[:,2] = np.log(self.data.exog[:,2]) interaction = self.data.exog[:,2]*self.data.exog[:,1] self.data.exog = np.column_stack((self.data.exog,interaction)) self.data.exog = add_constant(self.data.exog) self.res1 = GLM(self.data.endog, self.data.exog, family=sm.families.NegativeBinomial()).fit() from results.results_glm import Committee res2 = Committee() res2.aic_R += 2 # They don't count a degree of freedom for the scale self.res2 = res2
def __init__(self): ''' Test Negative Binomial family with canonical log link ''' # Test Precision self.decimal_resid = DECIMAL_1 self.decimal_params = DECIMAL_3 self.decimal_resids = -1 # 1 % mismatch at 0 self.decimal_fittedvalues = DECIMAL_1 from scikits.statsmodels.datasets.committee import load self.data = load() self.data.exog[:,2] = np.log(self.data.exog[:,2]) interaction = self.data.exog[:,2]*self.data.exog[:,1] self.data.exog = np.column_stack((self.data.exog,interaction)) self.data.exog = add_constant(self.data.exog) self.res1 = GLM(self.data.endog, self.data.exog, family=sm.families.NegativeBinomial()).fit() from results.results_glm import Committee res2 = Committee() res2.aic_R += 2 # They don't count a degree of freedom for the scale self.res2 = res2
"""Example: scikits.statsmodels.OLS """ from scikits.statsmodels.datasets.longley import load import scikits.statsmodels.api as sm from scikits.statsmodels.iolib.table import (SimpleTable, default_txt_fmt, default_latex_fmt, default_html_fmt) import numpy as np data = load() data_orig = (data.endog.copy(), data.exog.copy()) #Note: In this example using zscored/standardized variables has no effect on # regression estimates. Are there no numerical problems? rescale = 0 #0: no rescaling, 1:demean, 2:standardize, 3:standardize and transform back rescale_ratio = data.endog.std() / data.exog.std(0) if rescale > 0: # rescaling data.endog -= data.endog.mean() data.exog -= data.exog.mean(0) if rescale > 1: data.endog *= 1. / data.endog.std() #data.exog *= 1000./data.exog.var(0) data.exog /= data.exog.std(0) #rescale_ratio = data.exog.var(0)/data.endog.var() #skip because mean has been removed, but dimension is hardcoded in table
"""Example: scikits.statsmodels.OLS """ from scikits.statsmodels.datasets.longley import load import scikits.statsmodels as sm from scikits.statsmodels.iolib.table import (SimpleTable, default_txt_fmt, default_latex_fmt, default_html_fmt) import numpy as np data = load() data_orig = (data.endog.copy(), data.exog.copy()) #Note: In this example using zscored/standardized variables has no effect on # regression estimates. Are there no numerical problems? rescale = 0 #0: no rescaling, 1:demean, 2:standardize, 3:standardize and transform back rescale_ratio = data.endog.std()/data.exog.std(0) if rescale > 0: # rescaling data.endog -= data.endog.mean() data.exog -= data.exog.mean(0) if rescale > 1: data.endog *= 1./data.endog.std() #data.exog *= 1000./data.exog.var(0) data.exog /= data.exog.std(0) #rescale_ratio = data.exog.var(0)/data.endog.var() #skip because mean has been removed, but dimension is hardcoded in table data.exog = sm.tools.add_constant(data.exog)
def setupClass(cls): data = longley.load() data.exog = add_constant(data.exog) cls.res1 = OLS(data.endog, data.exog).fit() cls.res2 = WLS(data.endog, data.exog).fit()
def __init__(self): from scikits.statsmodels.datasets.ccard import load data = load() self.res1 = WLS(data.endog, data.exog, weights = 1/data.exog[:,2]).fit() self.res2 = GLS(data.endog, data.exog, sigma = data.exog[:,2]).fit()
def setupClass(cls): data = longley.load() data.exog = add_constant(data.exog) cls.res1 = OLS(data.endog, data.exog).fit() R = np.identity(7) cls.Ttest = cls.res1.t_test(R)
def setupClass(cls): data = longley.load() data.exog = add_constant(data.exog) res1 = OLS(data.endog, data.exog).fit() R2 = [[0,1,-1,0,0,0,0],[0, 0, 0, 0, 1, -1, 0]] cls.Ftest1 = res1.f_test(R2)
def setupClass(cls): data = longley.load() data.exog = add_constant(data.exog) res1 = OLS(data.endog, data.exog).fit() R2 = [[0, 1, -1, 0, 0, 0, 0], [0, 0, 0, 0, 1, -1, 0]] cls.Ftest1 = res1.f_test(R2)
def setupClass(cls): data = longley.load() data.exog = add_constant(data.exog) cls.res1 = OLS(data.endog, data.exog).fit() R = np.identity(7) cls.Ttest = cls.res1.t_test(R)
def setupClass(cls): data = longley.load() data.exog = add_constant(data.exog) cls.res1 = OLS(data.endog, data.exog).fit() cls.res2 = WLS(data.endog, data.exog).fit()