<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> from statsmodels . compat . python import ( iteritems , StringIO , lrange , BytesIO , <EOL> range ) <EOL> from nose . tools import assert_raises <EOL> import nose <EOL> import os <EOL> import sys <EOL> import numpy as np <EOL> import statsmodels . api as sm <EOL> import statsmodels . tsa . vector_ar . util as util <EOL> import statsmodels . tools . data as data_util <EOL> from statsmodels . tsa . vector_ar . var_model import VAR <EOL> from numpy . testing import ( assert_almost_equal , assert_equal , assert_ , <EOL> assert_allclose ) <EOL> DECIMAL_12 = <NUM_LIT:12> <EOL> DECIMAL_6 = <NUM_LIT:6> <EOL> DECIMAL_5 = <NUM_LIT:5> <EOL> DECIMAL_4 = <NUM_LIT:4> <EOL> DECIMAL_3 = <NUM_LIT:3> <EOL> DECIMAL_2 = <NUM_LIT:2> <EOL> class CheckVAR ( object ) : <EOL> res1 = None <EOL> res2 = None <EOL> def test_params ( self ) : <EOL> assert_almost_equal ( self . res1 . params , self . res2 . params , DECIMAL_3 ) <EOL> def test_neqs ( self ) : <EOL> assert_equal ( self . res1 . neqs , self . res2 . neqs ) <EOL> def test_nobs ( self ) : <EOL> assert_equal ( self . res1 . avobs , self . res2 . nobs ) <EOL> def test_df_eq ( self ) : <EOL> assert_equal ( self . res1 . df_eq , self . res2 . df_eq ) <EOL> def test_rmse ( self ) : <EOL> results = self . res1 . results <EOL> for i in range ( len ( results ) ) : <EOL> assert_almost_equal ( results [ i ] . mse_resid ** <NUM_LIT> , <EOL> eval ( '<STR_LIT>' + str ( i + <NUM_LIT:1> ) ) , DECIMAL_6 ) <EOL> def test_rsquared ( self ) : <EOL> results = self . res1 . results <EOL> for i in range ( len ( results ) ) : <EOL> assert_almost_equal ( results [ i ] . rsquared , <EOL> eval ( '<STR_LIT>' + str ( i + <NUM_LIT:1> ) ) , DECIMAL_3 ) <EOL> def test_llf ( self ) : <EOL> results = self . res1 . results <EOL> assert_almost_equal ( self . res1 . llf , self . res2 . llf , DECIMAL_2 ) <EOL> for i in range ( len ( results ) ) : <EOL> assert_almost_equal ( results [ i ] . llf , <EOL> eval ( '<STR_LIT>' + str ( i + <NUM_LIT:1> ) ) , DECIMAL_2 ) <EOL> def test_aic ( self ) : <EOL> assert_almost_equal ( self . res1 . aic , self . res2 . aic ) <EOL> def test_bic ( self ) : <EOL> assert_almost_equal ( self . res1 . bic , self . res2 . bic ) <EOL> def test_hqic ( self ) : <EOL> assert_almost_equal ( self . res1 . hqic , self . res2 . hqic ) <EOL> def test_fpe ( self ) : <EOL> assert_almost_equal ( self . res1 . fpe , self . res2 . fpe ) <EOL> def test_detsig ( self ) : <EOL> assert_almost_equal ( self . res1 . detomega , self . res2 . detsig ) <EOL> def test_bse ( self ) : <EOL> assert_almost_equal ( self . res1 . bse , self . res2 . bse , DECIMAL_4 ) <EOL> def get_macrodata ( ) : <EOL> data = sm . datasets . macrodata . load ( ) . data [ [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ] <EOL> names = data . dtype . names <EOL> nd = data . view ( ( float , <NUM_LIT:3> ) , type = np . ndarray ) <EOL> nd = np . diff ( np . log ( nd ) , axis = <NUM_LIT:0> ) <EOL> return nd . ravel ( ) . view ( data . dtype , type = np . ndarray ) <EOL> def generate_var ( ) : <EOL> from rpy2 . robjects import r <EOL> import pandas . rpy . common as prp <EOL> r . source ( '<STR_LIT>' ) <EOL> return prp . convert_robj ( r [ '<STR_LIT:result>' ] , use_pandas = False ) <EOL> def write_generate_var ( ) : <EOL> result = generate_var ( ) <EOL> np . savez ( '<STR_LIT>' , ** result ) <EOL> class RResults ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> from . results . results_var_data import var_results <EOL> data = var_results . __dict__ <EOL> self . names = data [ '<STR_LIT>' ] . dtype . names <EOL> self . params = data [ '<STR_LIT>' ] . view ( ( float , len ( self . names ) ) , type = np . ndarray ) <EOL> self . stderr = data [ '<STR_LIT>' ] . view ( ( float , len ( self . names ) ) , type = np . ndarray ) <EOL> self . irf = data [ '<STR_LIT>' ] . item ( ) <EOL> self . orth_irf = data [ '<STR_LIT>' ] . item ( ) <EOL> self . nirfs = int ( data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> self . nobs = int ( data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> self . totobs = int ( data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> crit = data [ '<STR_LIT>' ] . item ( ) <EOL> self . aic = crit [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> self . sic = self . bic = crit [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> self . hqic = crit [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> self . fpe = crit [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> self . detomega = data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> self . loglike = data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> self . nahead = int ( data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> self . ma_rep = data [ '<STR_LIT>' ] <EOL> self . causality = data [ '<STR_LIT>' ] <EOL> def close_plots ( ) : <EOL> try : <EOL> import matplotlib . pyplot as plt <EOL> plt . close ( '<STR_LIT:all>' ) <EOL> except ImportError : <EOL> pass <EOL> _orig_stdout = None <EOL> def setup_module ( ) : <EOL> global _orig_stdout <EOL> _orig_stdout = sys . stdout <EOL> sys . stdout = StringIO ( ) <EOL> def teardown_module ( ) : <EOL> sys . stdout = _orig_stdout <EOL> close_plots ( ) <EOL> def have_matplotlib ( ) : <EOL> try : <EOL> import matplotlib <EOL> return True <EOL> except ImportError : <EOL> return False <EOL> class CheckIRF ( object ) : <EOL> ref = None ; res = None ; irf = None <EOL> k = None <EOL> def test_irf_coefs ( self ) : <EOL> self . _check_irfs ( self . irf . irfs , self . ref . irf ) <EOL> self . _check_irfs ( self . irf . orth_irfs , self . ref . orth_irf ) <EOL> def _check_irfs ( self , py_irfs , r_irfs ) : <EOL> for i , name in enumerate ( self . res . names ) : <EOL> ref_irfs = r_irfs [ name ] . view ( ( float , self . k ) , type = np . ndarray ) <EOL> res_irfs = py_irfs [ : , : , i ] <EOL> assert_almost_equal ( ref_irfs , res_irfs ) <EOL> def test_plot_irf ( self ) : <EOL> if not have_matplotlib ( ) : <EOL> raise nose . SkipTest <EOL> self . irf . plot ( ) <EOL> self . irf . plot ( plot_stderr = False ) <EOL> self . irf . plot ( impulse = <NUM_LIT:0> , response = <NUM_LIT:1> ) <EOL> self . irf . plot ( impulse = <NUM_LIT:0> ) <EOL> self . irf . plot ( response = <NUM_LIT:0> ) <EOL> self . irf . plot ( orth = True ) <EOL> self . irf . plot ( impulse = <NUM_LIT:0> , response = <NUM_LIT:1> , orth = True ) <EOL> close_plots ( ) <EOL> def test_plot_cum_effects ( self ) : <EOL> if not have_matplotlib ( ) : <EOL> raise nose . SkipTest <EOL> self . irf . plot_cum_effects ( ) <EOL> self . irf . plot_cum_effects ( plot_stderr = False ) <EOL> self . irf . plot_cum_effects ( impulse = <NUM_LIT:0> , response = <NUM_LIT:1> ) <EOL> self . irf . plot_cum_effects ( orth = True ) <EOL> self . irf . plot_cum_effects ( impulse = <NUM_LIT:0> , response = <NUM_LIT:1> , orth = True ) <EOL> close_plots ( ) <EOL> class CheckFEVD ( object ) : <EOL> fevd = None <EOL> def test_fevd_plot ( self ) : <EOL> if not have_matplotlib ( ) : <EOL> raise nose . SkipTest <EOL> self . fevd . plot ( ) <EOL> close_plots ( ) <EOL> def test_fevd_repr ( self ) : <EOL> self . fevd <EOL> def test_fevd_summary ( self ) : <EOL> self . fevd . summary ( ) <EOL> def test_fevd_cov ( self ) : <EOL> pass <EOL> class TestVARResults ( CheckIRF , CheckFEVD ) : <EOL> @ classmethod <EOL> def setupClass ( cls ) : <EOL> cls . p = <NUM_LIT:2> <EOL> cls . data = get_macrodata ( ) <EOL> cls . model = VAR ( cls . data ) <EOL> cls . names = cls . model . endog_names <EOL> cls . ref = RResults ( ) <EOL> cls . k = len ( cls . ref . names ) <EOL> cls . res = cls . model . fit ( maxlags = cls . p ) <EOL> cls . irf = cls . res . irf ( cls . ref . nirfs ) <EOL> cls . nahead = cls . ref . nahead <EOL> cls . fevd = cls . res . fevd ( ) <EOL> def test_constructor ( self ) : <EOL> ndarr = self . data . view ( ( float , <NUM_LIT:3> ) , type = np . ndarray ) <EOL> model = VAR ( ndarr ) <EOL> res = model . fit ( self . p ) <EOL> def test_names ( self ) : <EOL> assert_equal ( self . model . endog_names , self . ref . names ) <EOL> model2 = VAR ( self . data ) <EOL> assert_equal ( model2 . endog_names , self . ref . names ) <EOL> def test_get_eq_index ( self ) : <EOL> assert ( type ( self . res . names ) is list ) <EOL> for i , name in enumerate ( self . names ) : <EOL> idx = self . res . get_eq_index ( i ) <EOL> idx2 = self . res . get_eq_index ( name ) <EOL> assert_equal ( idx , i ) <EOL> assert_equal ( idx , idx2 ) <EOL> assert_raises ( Exception , self . res . get_eq_index , '<STR_LIT:foo>' ) <EOL> def test_repr ( self ) : <EOL> foo = str ( self . res ) <EOL> bar = repr ( self . res ) <EOL> def test_params ( self ) : <EOL> assert_almost_equal ( self . res . params , self . ref . params , DECIMAL_3 ) <EOL> def test_cov_params ( self ) : <EOL> self . res . cov_params <EOL> def test_cov_ybar ( self ) : <EOL> self . res . cov_ybar ( ) <EOL> def test_tstat ( self ) : <EOL> self . res . tvalues <EOL> def test_pvalues ( self ) : <EOL> self . res . pvalues <EOL> def test_summary ( self ) : <EOL> summ = self . res . summary ( ) <EOL> def test_detsig ( self ) : <EOL> assert_almost_equal ( self . res . detomega , self . ref . detomega ) <EOL> def test_aic ( self ) : <EOL> assert_almost_equal ( self . res . aic , self . ref . aic ) <EOL> def test_bic ( self ) : <EOL> assert_almost_equal ( self . res . bic , self . ref . bic ) <EOL> def test_hqic ( self ) : <EOL> assert_almost_equal ( self . res . hqic , self . ref . hqic ) <EOL> def test_fpe ( self ) : <EOL> assert_almost_equal ( self . res . fpe , self . ref . fpe ) <EOL> def test_lagorder_select ( self ) : <EOL> ics = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> for ic in ics : <EOL> res = self . model . fit ( maxlags = <NUM_LIT:10> , ic = ic , verbose = True ) <EOL> assert_raises ( Exception , self . model . fit , ic = '<STR_LIT:foo>' ) <EOL> def test_nobs ( self ) : <EOL> assert_equal ( self . res . nobs , self . ref . nobs ) <EOL> def test_stderr ( self ) : <EOL> assert_almost_equal ( self . res . stderr , self . ref . stderr , DECIMAL_4 ) <EOL> def test_loglike ( self ) : <EOL> assert_almost_equal ( self . res . llf , self . ref . loglike ) <EOL> def test_ma_rep ( self ) : <EOL> ma_rep = self . res . ma_rep ( self . nahead ) <EOL> assert_almost_equal ( ma_rep , self . ref . ma_rep ) <EOL> def test_causality ( self ) : <EOL> causedby = self . ref . causality [ '<STR_LIT>' ] <EOL> for i , name in enumerate ( self . names ) : <EOL> variables = self . names [ : i ] + self . names [ i + <NUM_LIT:1> : ] <EOL> result = self . res . test_causality ( name , variables , kind = '<STR_LIT:f>' ) <EOL> assert_almost_equal ( result [ '<STR_LIT>' ] , causedby [ i ] , DECIMAL_4 ) <EOL> rng = lrange ( self . k ) <EOL> rng . remove ( i ) <EOL> result2 = self . res . test_causality ( i , rng , kind = '<STR_LIT:f>' ) <EOL> assert_almost_equal ( result [ '<STR_LIT>' ] , result2 [ '<STR_LIT>' ] , DECIMAL_12 ) <EOL> result = self . res . test_causality ( name , variables , kind = '<STR_LIT>' ) <EOL> _ = self . res . test_causality ( self . names [ <NUM_LIT:0> ] , self . names [ <NUM_LIT:1> ] ) <EOL> _ = self . res . test_causality ( <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> assert_raises ( Exception , self . res . test_causality , <NUM_LIT:0> , <NUM_LIT:1> , kind = '<STR_LIT:foo>' ) <EOL> def test_select_order ( self ) : <EOL> result = self . model . fit ( <NUM_LIT:10> , ic = '<STR_LIT>' , verbose = True ) <EOL> result = self . model . fit ( <NUM_LIT:10> , ic = '<STR_LIT>' , verbose = True ) <EOL> model = VAR ( self . model . endog ) <EOL> model . select_order ( ) <EOL> def test_is_stable ( self ) : <EOL> assert ( self . res . is_stable ( verbose = True ) ) <EOL> def test_acf ( self ) : <EOL> acfs = self . res . acf ( <NUM_LIT:10> ) <EOL> acfs = self . res . acf ( ) <EOL> assert ( len ( acfs ) == self . p + <NUM_LIT:1> ) <EOL> def test_acorr ( self ) : <EOL> acorrs = self . res . acorr ( <NUM_LIT:10> ) <EOL> def test_forecast ( self ) : <EOL> point = self . res . forecast ( self . res . y [ - <NUM_LIT:5> : ] , <NUM_LIT:5> ) <EOL> def test_forecast_interval ( self ) : <EOL> y = self . res . y [ : - self . p : ] <EOL> point , lower , upper = self . res . forecast_interval ( y , <NUM_LIT:5> ) <EOL> def test_plot_sim ( self ) : <EOL> if not have_matplotlib ( ) : <EOL> raise nose . SkipTest <EOL> self . res . plotsim ( steps = <NUM_LIT:100> ) <EOL> close_plots ( ) <EOL> def test_plot ( self ) : <EOL> if not have_matplotlib ( ) : <EOL> raise nose . SkipTest <EOL> self . res . plot ( ) <EOL> close_plots ( ) <EOL> def test_plot_acorr ( self ) : <EOL> if not have_matplotlib ( ) : <EOL> raise nose . SkipTest <EOL> self . res . plot_acorr ( ) <EOL> close_plots ( ) <EOL> def test_plot_forecast ( self ) : <EOL> if not have_matplotlib ( ) : <EOL> raise nose . SkipTest <EOL> self . res . plot_forecast ( <NUM_LIT:5> ) <EOL> close_plots ( ) <EOL> def test_reorder ( self ) : <EOL> data = self . data . view ( ( float , <NUM_LIT:3> ) , type = np . ndarray ) <EOL> names = self . names <EOL> data2 = np . append ( np . append ( data [ : , <NUM_LIT:2> , None ] , data [ : , <NUM_LIT:0> , None ] , axis = <NUM_LIT:1> ) , data [ : , <NUM_LIT:1> , None ] , axis = <NUM_LIT:1> ) <EOL> names2 = [ ] <EOL> names2 . append ( names [ <NUM_LIT:2> ] ) <EOL> names2 . append ( names [ <NUM_LIT:0> ] ) <EOL> names2 . append ( names [ <NUM_LIT:1> ] ) <EOL> res2 = VAR ( data2 ) . fit ( maxlags = self . p ) <EOL> res3 = self . res . reorder ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> assert_almost_equal ( res2 . params , res3 . params ) <EOL> assert_almost_equal ( res2 . sigma_u , res3 . sigma_u ) <EOL> assert_almost_equal ( res2 . bic , res3 . bic ) <EOL> assert_almost_equal ( res2 . stderr , res3 . stderr ) <EOL> def test_pickle ( self ) : <EOL> fh = BytesIO ( ) <EOL> self . res . save ( fh ) <EOL> fh . seek ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> res_unpickled = self . res . __class__ . load ( fh ) <EOL> assert_ ( type ( res_unpickled ) is type ( self . res ) ) <EOL> class E1_Results ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . irf_stderr = np . array ( [ [ [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] , <EOL> [ [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] , <EOL> [ [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] ] ) <EOL> self . cum_irf_stderr = np . array ( [ [ [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] , <EOL> [ [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] , <EOL> [ [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] ] ) <EOL> self . lr_stderr = np . array ( [ [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] ) <EOL> basepath = os . path . split ( sm . __file__ ) [ <NUM_LIT:0> ] <EOL> resultspath = basepath + '<STR_LIT>' <EOL> def get_lutkepohl_data ( name = '<STR_LIT>' ) : <EOL> lut_data = basepath + '<STR_LIT>' <EOL> path = lut_data + '<STR_LIT>' % name <EOL> return util . parse_lutkepohl_data ( path ) <EOL> def test_lutkepohl_parse ( ) : <EOL> files = [ '<STR_LIT>' % i for i in range ( <NUM_LIT:1> , <NUM_LIT:7> ) ] <EOL> for f in files : <EOL> get_lutkepohl_data ( f ) <EOL> class TestVARResultsLutkepohl ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . p = <NUM_LIT:2> <EOL> sdata , dates = get_lutkepohl_data ( '<STR_LIT>' ) <EOL> data = data_util . struct_to_ndarray ( sdata ) <EOL> adj_data = np . diff ( np . log ( data ) , axis = <NUM_LIT:0> ) <EOL> self . model = VAR ( adj_data [ : - <NUM_LIT:16> ] , dates = dates [ <NUM_LIT:1> : - <NUM_LIT:16> ] , freq = '<STR_LIT>' ) <EOL> self . res = self . model . fit ( maxlags = self . p ) <EOL> self . irf = self . res . irf ( <NUM_LIT:10> ) <EOL> self . lut = E1_Results ( ) <EOL> def test_approx_mse ( self ) : <EOL> mse2 = np . array ( [ [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] ) * <NUM_LIT> <EOL> assert_almost_equal ( mse2 , self . res . forecast_cov ( <NUM_LIT:3> ) [ <NUM_LIT:1> ] , <EOL> DECIMAL_3 ) <EOL> def test_irf_stderr ( self ) : <EOL> irf_stderr = self . irf . stderr ( orth = False ) <EOL> for i in range ( <NUM_LIT:1> , <NUM_LIT:1> + len ( self . lut . irf_stderr ) ) : <EOL> assert_almost_equal ( np . round ( irf_stderr [ i ] , <NUM_LIT:3> ) , <EOL> self . lut . irf_stderr [ i - <NUM_LIT:1> ] ) <EOL> def test_cum_irf_stderr ( self ) : <EOL> stderr = self . irf . cum_effect_stderr ( orth = False ) <EOL> for i in range ( <NUM_LIT:1> , <NUM_LIT:1> + len ( self . lut . cum_irf_stderr ) ) : <EOL> assert_almost_equal ( np . round ( stderr [ i ] , <NUM_LIT:3> ) , <EOL> self . lut . cum_irf_stderr [ i - <NUM_LIT:1> ] ) <EOL> def test_lr_effect_stderr ( self ) : <EOL> stderr = self . irf . lr_effect_stderr ( orth = False ) <EOL> orth_stderr = self . irf . lr_effect_stderr ( orth = True ) <EOL> assert_almost_equal ( np . round ( stderr , <NUM_LIT:3> ) , self . lut . lr_stderr ) <EOL> def test_get_trendorder ( ) : <EOL> results = { <EOL> '<STR_LIT:c>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:2> , <EOL> '<STR_LIT>' : <NUM_LIT:3> <EOL> } <EOL> for t , trendorder in iteritems ( results ) : <EOL> assert ( util . get_trendorder ( t ) == trendorder ) <EOL> def test_var_constant ( ) : <EOL> import datetime <EOL> from pandas import DataFrame , DatetimeIndex <EOL> series = np . array ( [ [ <NUM_LIT> , <NUM_LIT> ] , [ <NUM_LIT:1> , <NUM_LIT> ] , [ <NUM_LIT:1> , <NUM_LIT> ] , [ <NUM_LIT:1> , <NUM_LIT> ] , [ <NUM_LIT:1.> , <NUM_LIT> ] ] ) <EOL> data = DataFrame ( series ) <EOL> d = datetime . datetime . now ( ) <EOL> delta = datetime . timedelta ( days = <NUM_LIT:1> ) <EOL> index = [ ] <EOL> for i in range ( data . shape [ <NUM_LIT:0> ] ) : <EOL> index . append ( d ) <EOL> d += delta <EOL> data . index = DatetimeIndex ( index ) <EOL> model = VAR ( data ) <EOL> assert_raises ( ValueError , model . fit , <NUM_LIT:1> ) <EOL> def test_var_trend ( ) : <EOL> data = get_macrodata ( ) . view ( ( float , <NUM_LIT:3> ) , type = np . ndarray ) <EOL> model = sm . tsa . VAR ( data ) <EOL> results = model . fit ( <NUM_LIT:4> ) <EOL> irf = results . irf ( <NUM_LIT:10> ) <EOL> data_nc = data - data . mean ( <NUM_LIT:0> ) <EOL> model_nc = sm . tsa . VAR ( data_nc ) <EOL> results_nc = model_nc . fit ( <NUM_LIT:4> , trend = '<STR_LIT>' ) <EOL> assert_raises ( ValueError , model . fit , <NUM_LIT:4> , trend = '<STR_LIT:t>' ) <EOL> def test_irf_trend ( ) : <EOL> data = get_macrodata ( ) . view ( ( float , <NUM_LIT:3> ) , type = np . ndarray ) <EOL> model = sm . tsa . VAR ( data ) <EOL> results = model . fit ( <NUM_LIT:4> ) <EOL> irf = results . irf ( <NUM_LIT:10> ) <EOL> data_nc = data - data . mean ( <NUM_LIT:0> ) <EOL> model_nc = sm . tsa . VAR ( data_nc ) <EOL> results_nc = model_nc . fit ( <NUM_LIT:4> , trend = '<STR_LIT>' ) <EOL> irf_nc = results_nc . irf ( <NUM_LIT:10> ) <EOL> assert_allclose ( irf_nc . stderr ( ) [ <NUM_LIT:1> : <NUM_LIT:4> ] , irf . stderr ( ) [ <NUM_LIT:1> : <NUM_LIT:4> ] , rtol = <NUM_LIT> ) <EOL> trend = <NUM_LIT> * np . arange ( len ( data ) ) / ( len ( data ) - <NUM_LIT:1> ) <EOL> data_t = data + trend [ : , None ] <EOL> model_t = sm . tsa . VAR ( data_t ) <EOL> results_t = model_t . fit ( <NUM_LIT:4> , trend = '<STR_LIT>' ) <EOL> irf_t = results_t . irf ( <NUM_LIT:10> ) <EOL> assert_allclose ( irf_t . stderr ( ) [ <NUM_LIT:1> : <NUM_LIT:4> ] , irf . stderr ( ) [ <NUM_LIT:1> : <NUM_LIT:4> ] , rtol = <NUM_LIT> ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> import nose <EOL> nose . runmodule ( argv = [ __file__ , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> exit = False ) </s>
