#NEWLINE# def summary( self , yname = None , xname = None , title = 0 , alpha = 0.05 , returns = 'text' , model_info = None ) : #NEWLINE# #INDENT# "\n    Parameters\n    -----------\n    yname : string\n            optional, Default is `Y`\n    xname : list of strings\n            optional, Default is `X.#` for # in p the number of regressors\n    Confidance interval : (0,1) not implimented\n    title : string\n            optional, Defualt is 'Generalized linear model'\n    returns : string\n              'text', 'table', 'csv', 'latex', 'html'\n\n    Returns\n    -------\n    Default :\n    returns='print'\n            Prints the summarirized results\n\n    Option :\n    returns='text'\n            Prints the summarirized results\n\n    Option :\n    returns='table'\n             SimpleTable instance : summarizing the fit of a linear model.\n\n    Option :\n    returns='csv'\n            returns a string of csv of the results, to import into a spreadsheet\n\n    Option :\n    returns='latex'\n    Not implimented yet\n\n    Option :\n    returns='HTML'\n    Not implimented yet\n\n\n    Examples (needs updating)\n    --------\n    >>> import statsmodels as sm\n    >>> data = sm.datasets.longley.load()\n    >>> data.exog = sm.add_constant(data.exog)\n    >>> ols_results = sm.OLS(data.endog, data.exog).results\n    >>> print ols_results.summary()\n    ...\n\n    Notes\n    -----\n    conf_int calculated from normal dist.\n    " #NEWLINE# import time as time #NEWLINE# model_types = { #NEWLINE# #INDENT# 'OLS' : 'Ordinary least squares' , #NEWLINE# 'GLS' : 'Generalized least squares' , #NEWLINE# 'GLSAR' : 'Generalized least squares with AR(p)' , #NEWLINE# 'WLS' : 'Weigthed least squares' , #NEWLINE# 'RLM' : 'Robust linear model' , #NEWLINE# 'GLM' : 'Generalized linear model' , #NEWLINE# #UNINDENT# } #NEWLINE# model_methods = { #NEWLINE# #INDENT# 'OLS' : 'Least Squares' , #NEWLINE# 'GLS' : 'Least Squares' , #NEWLINE# 'GLSAR' : 'Least Squares' , #NEWLINE# 'WLS' : 'Least Squares' , #NEWLINE# 'RLM' : '?' , #NEWLINE# 'GLM' : '?' , #NEWLINE# #UNINDENT# } #NEWLINE# if ( title == 0 ) : #NEWLINE# #INDENT# title = model_types [ self . model . __class__ . __name__ ] #NEWLINE# #UNINDENT# if ( yname is None ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# yname = self . model . endog_names #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# yname = 'y' #NEWLINE# #UNINDENT# #UNINDENT# if ( xname is None ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# xname = self . model . exog_names #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# xname = [ ( 'var_%d' % i ) for i in range ( len ( self . params ) ) ] #NEWLINE# #UNINDENT# #UNINDENT# time_now = time . localtime ( ) #NEWLINE# time_of_day = [ time . strftime ( '%H:%M:%S' , time_now ) ] #NEWLINE# date = time . strftime ( '%a, %d %b %Y' , time_now ) #NEWLINE# modeltype = self . model . __class__ . __name__ #NEWLINE# nobs = self . nobs #NEWLINE# df_model = self . df_model #NEWLINE# df_resid = self . df_resid #NEWLINE# gen_left = [ ( 'Model type:' , [ modeltype ] ) , ( 'Date:' , [ date ] ) , ( 'Dependent Variable:' , yname ) , ( 'df model' , [ df_model ] ) ] #NEWLINE# ( gen_stubs_left , gen_data_left ) = zip_longest ( * gen_left ) #NEWLINE# gen_title = title #NEWLINE# gen_header = None #NEWLINE# gen_table_left = SimpleTable ( gen_data_left , gen_header , gen_stubs_left , title = gen_title , txt_fmt = gen_fmt ) #NEWLINE# gen_stubs_right = ( 'Method:' , 'Time:' , 'Number of Obs:' , 'df resid' ) #NEWLINE# gen_data_right = ( [ modeltype ] , time_of_day , [ nobs ] , [ df_resid ] ) #NEWLINE# gen_table_right = SimpleTable ( gen_data_right , gen_header , gen_stubs_right , title = gen_title , txt_fmt = gen_fmt ) #NEWLINE# gen_table_left . extend_right ( gen_table_right ) #NEWLINE# general_table = gen_table_left #NEWLINE# tstats = { #NEWLINE# #INDENT# 'OLS' : self . t ( ) , #NEWLINE# 'GLS' : self . t ( ) , #NEWLINE# 'GLSAR' : self . t ( ) , #NEWLINE# 'WLS' : self . t ( ) , #NEWLINE# 'RLM' : self . t ( ) , #NEWLINE# 'GLM' : self . t ( ) , #NEWLINE# #UNINDENT# } #NEWLINE# prob_stats = { #NEWLINE# #INDENT# 'OLS' : self . pvalues , #NEWLINE# 'GLS' : self . pvalues , #NEWLINE# 'GLSAR' : self . pvalues , #NEWLINE# 'WLS' : self . pvalues , #NEWLINE# 'RLM' : self . pvalues , #NEWLINE# 'GLM' : self . pvalues , #NEWLINE# #UNINDENT# } #NEWLINE# alp = ( str ( ( ( 1 - alpha ) * 100 ) ) + '%' ) #NEWLINE# param_header = { #NEWLINE# #INDENT# 'OLS' : [ 'coef' , 'std err' , 't' , 'P>|t|' , ( alp + ' Conf. Interval' ) ] , #NEWLINE# 'GLS' : [ 'coef' , 'std err' , 't' , 'P>|t|' , ( alp + ' Conf. Interval' ) ] , #NEWLINE# 'GLSAR' : [ 'coef' , 'std err' , 't' , 'P>|t|' , ( alp + ' Conf. Interval' ) ] , #NEWLINE# 'WLS' : [ 'coef' , 'std err' , 't' , 'P>|t|' , ( alp + ' Conf. Interval' ) ] , #NEWLINE# 'GLM' : [ 'coef' , 'std err' , 't' , 'P>|t|' , ( alp + ' Conf. Interval' ) ] , #NEWLINE# 'RLM' : [ 'coef' , 'std err' , 'z' , 'P>|z|' , ( alp + ' Conf. Interval' ) ] , #NEWLINE# #UNINDENT# } #NEWLINE# params_stubs = xname #NEWLINE# params = self . params #NEWLINE# conf_int = self . conf_int ( alpha ) #NEWLINE# std_err = self . bse #NEWLINE# exog_len = lrange ( len ( xname ) ) #NEWLINE# tstat = tstats [ modeltype ] #NEWLINE# prob_stat = prob_stats [ modeltype ] #NEWLINE# params_data = lzip ( [ ( '%#6.4g' % params [ i ] ) for i in exog_len ] , [ ( '%#6.4f' % std_err [ i ] ) for i in exog_len ] , [ ( '%#6.4f' % tstat [ i ] ) for i in exog_len ] , [ ( '%#6.4f' % prob_stat [ i ] ) for i in exog_len ] , [ ( '(%#5g, %#5g)' % tuple ( conf_int [ i ] ) ) for i in exog_len ] ) #NEWLINE# parameter_table = SimpleTable ( params_data , param_header [ modeltype ] , params_stubs , title = None , txt_fmt = fmt_2 ) #NEWLINE# def ols_printer( ) : #NEWLINE# #INDENT# '\n        print summary table for ols models\n        ' #NEWLINE# table = ( ( str ( general_table ) + '\n' ) + str ( parameter_table ) ) #NEWLINE# return table #NEWLINE# #UNINDENT# def ols_to_csv( ) : #NEWLINE# #INDENT# '\n        exports ols summary data to csv\n        ' #NEWLINE# pass #NEWLINE# #UNINDENT# def glm_printer( ) : #NEWLINE# #INDENT# table = ( ( str ( general_table ) + '\n' ) + str ( parameter_table ) ) #NEWLINE# return table #NEWLINE# pass #NEWLINE# #UNINDENT# printers = { #NEWLINE# #INDENT# 'OLS' : ols_printer , #NEWLINE# 'GLM' : glm_printer , #NEWLINE# #UNINDENT# } #NEWLINE# if ( returns == 'print' ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# return printers [ modeltype ] ( ) #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# return printers [ 'OLS' ] ( )