<s> """<STR_LIT>""" <EOL> from __future__ import division , absolute_import , print_function <EOL> import numpy as np <EOL> import pandas as pd <EOL> import os <EOL> import re <EOL> import warnings <EOL> from statsmodels . tsa . statespace import dynamic_factor <EOL> from . results import results_varmax , results_dynamic_factor <EOL> from numpy . testing import assert_equal , assert_almost_equal , assert_raises , assert_allclose <EOL> from nose . exc import SkipTest <EOL> from statsmodels . iolib . summary import forg <EOL> try : <EOL> import matplotlib . pyplot as plt <EOL> have_matplotlib = True <EOL> except ImportError : <EOL> have_matplotlib = False <EOL> current_path = os . path . dirname ( os . path . abspath ( __file__ ) ) <EOL> output_path = '<STR_LIT>' + os . sep + '<STR_LIT>' <EOL> output_results = pd . read_csv ( current_path + os . sep + output_path ) <EOL> class CheckDynamicFactor ( object ) : <EOL> @ classmethod <EOL> def setup_class ( cls , true , k_factors , factor_order , cov_type = '<STR_LIT>' , <EOL> included_vars = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> demean = False , filter = True , ** kwargs ) : <EOL> cls . true = true <EOL> dta = pd . DataFrame ( <EOL> results_varmax . lutkepohl_data , columns = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> index = pd . date_range ( '<STR_LIT>' , '<STR_LIT>' , freq = '<STR_LIT>' ) ) <EOL> dta [ '<STR_LIT>' ] = np . log ( dta [ '<STR_LIT>' ] ) . diff ( ) <EOL> dta [ '<STR_LIT>' ] = np . log ( dta [ '<STR_LIT>' ] ) . diff ( ) <EOL> dta [ '<STR_LIT>' ] = np . log ( dta [ '<STR_LIT>' ] ) . diff ( ) <EOL> endog = dta . ix [ '<STR_LIT>' : '<STR_LIT>' , included_vars ] <EOL> if demean : <EOL> endog -= dta . ix [ <NUM_LIT:1> : , included_vars ] . mean ( ) <EOL> cls . model = dynamic_factor . DynamicFactor ( endog , k_factors = k_factors , <EOL> factor_order = factor_order , <EOL> ** kwargs ) <EOL> if filter : <EOL> cls . results = cls . model . smooth ( true [ '<STR_LIT>' ] , cov_type = cov_type ) <EOL> def test_params ( self ) : <EOL> self . model . filter ( self . model . start_params ) <EOL> assert_equal ( len ( self . model . start_params ) , len ( self . model . param_names ) ) <EOL> actual = self . model . transform_params ( self . model . untransform_params ( self . model . start_params ) ) <EOL> assert_allclose ( actual , self . model . start_params ) <EOL> self . model . enforce_stationarity = False <EOL> actual = self . model . transform_params ( self . model . untransform_params ( self . model . start_params ) ) <EOL> self . model . enforce_stationarity = True <EOL> assert_allclose ( actual , self . model . start_params ) <EOL> def test_results ( self ) : <EOL> self . results . summary ( ) <EOL> if self . model . factor_order > <NUM_LIT:0> : <EOL> coefficients = np . array ( self . results . params [ self . model . _params_factor_transition ] ) . reshape ( self . model . k_factors , self . model . k_factors * self . model . factor_order ) <EOL> coefficient_matrices = np . array ( [ <EOL> coefficients [ : self . model . k_factors , i * self . model . k_factors : ( i + <NUM_LIT:1> ) * self . model . k_factors ] <EOL> for i in range ( self . model . factor_order ) <EOL> ] ) <EOL> assert_equal ( self . results . coefficient_matrices_var , coefficient_matrices ) <EOL> else : <EOL> assert_equal ( self . results . coefficient_matrices_var , None ) <EOL> if have_matplotlib : <EOL> fig = self . results . plot_coefficients_of_determination ( ) ; <EOL> plt . close ( fig ) <EOL> def test_no_enforce ( self ) : <EOL> return <EOL> params = self . model . untransform_params ( self . true [ '<STR_LIT>' ] ) <EOL> params [ self . model . _params_transition ] = ( <EOL> self . true [ '<STR_LIT>' ] [ self . model . _params_transition ] ) <EOL> self . model . enforce_stationarity = False <EOL> results = self . model . filter ( params , transformed = False ) <EOL> self . model . enforce_stationarity = True <EOL> assert_allclose ( results . llf , self . results . llf , rtol = <NUM_LIT> ) <EOL> def test_mle ( self ) : <EOL> with warnings . catch_warnings ( record = True ) as w : <EOL> results = self . model . fit ( method = '<STR_LIT>' , maxiter = <NUM_LIT:100> , disp = False ) <EOL> results = self . model . fit ( results . params , maxiter = <NUM_LIT:1000> , disp = False ) <EOL> results = self . model . fit ( results . params , method = '<STR_LIT>' , maxiter = <NUM_LIT:1000> , <EOL> disp = False ) <EOL> if not results . llf > self . results . llf : <EOL> assert_allclose ( results . llf , self . results . llf , rtol = <NUM_LIT> ) <EOL> def test_loglike ( self ) : <EOL> assert_allclose ( self . results . llf , self . true [ '<STR_LIT>' ] , rtol = <NUM_LIT> ) <EOL> def test_aic ( self ) : <EOL> assert_allclose ( self . results . aic , self . true [ '<STR_LIT>' ] , atol = <NUM_LIT:3> ) <EOL> def test_bic ( self ) : <EOL> assert_allclose ( self . results . bic , self . true [ '<STR_LIT>' ] , atol = <NUM_LIT:3> ) <EOL> def test_predict ( self , ** kwargs ) : <EOL> assert_allclose ( <EOL> self . results . predict ( end = '<STR_LIT>' , ** kwargs ) , <EOL> self . true [ '<STR_LIT>' ] , <EOL> atol = <NUM_LIT> ) <EOL> def test_dynamic_predict ( self , ** kwargs ) : <EOL> assert_allclose ( <EOL> self . results . predict ( end = '<STR_LIT>' , dynamic = '<STR_LIT>' , ** kwargs ) , <EOL> self . true [ '<STR_LIT>' ] , <EOL> atol = <NUM_LIT> ) <EOL> class TestDynamicFactor ( CheckDynamicFactor ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def setup_class ( cls ) : <EOL> true = results_dynamic_factor . lutkepohl_dfm . copy ( ) <EOL> true [ '<STR_LIT>' ] = output_results . ix [ <NUM_LIT:1> : , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ] <EOL> true [ '<STR_LIT>' ] = output_results . ix [ <NUM_LIT:1> : , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ] <EOL> super ( TestDynamicFactor , cls ) . setup_class ( true , k_factors = <NUM_LIT:1> , factor_order = <NUM_LIT:2> ) <EOL> def test_bse_approx ( self ) : <EOL> bse = self . results . _cov_params_approx ( ) . diagonal ( ) ** <NUM_LIT:0.5> <EOL> assert_allclose ( bse , self . true [ '<STR_LIT>' ] , atol = <NUM_LIT> ) <EOL> class TestDynamicFactor2 ( CheckDynamicFactor ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def setup_class ( cls ) : <EOL> true = results_dynamic_factor . lutkepohl_dfm2 . copy ( ) <EOL> true [ '<STR_LIT>' ] = output_results . ix [ <NUM_LIT:1> : , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ] <EOL> true [ '<STR_LIT>' ] = output_results . ix [ <NUM_LIT:1> : , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ] <EOL> super ( TestDynamicFactor2 , cls ) . setup_class ( true , k_factors = <NUM_LIT:2> , factor_order = <NUM_LIT:1> ) <EOL> def test_mle ( self ) : <EOL> pass <EOL> def test_bse ( self ) : <EOL> pass <EOL> def test_aic ( self ) : <EOL> pass <EOL> def test_bic ( self ) : <EOL> pass <EOL> def test_summary ( self ) : <EOL> summary = self . results . summary ( ) <EOL> tables = [ str ( table ) for table in summary . tables ] <EOL> params = self . true [ '<STR_LIT>' ] <EOL> assert_equal ( len ( tables ) , <NUM_LIT:2> + self . model . k_endog + self . model . k_factors + <NUM_LIT:1> ) <EOL> assert_equal ( re . search ( r'<STR_LIT>' , tables [ <NUM_LIT:0> ] ) is None , False ) <EOL> for i in range ( self . model . k_endog ) : <EOL> offset_loading = self . model . k_factors * i <EOL> offset_var = self . model . k_factors * self . model . k_endog <EOL> table = tables [ i + <NUM_LIT:2> ] <EOL> name = self . model . endog_names [ i ] <EOL> assert_equal ( re . search ( '<STR_LIT>' % name , table ) is None , False ) <EOL> assert_equal ( len ( table . split ( '<STR_LIT:\n>' ) ) , <NUM_LIT:7> ) <EOL> assert_equal ( re . search ( '<STR_LIT>' + forg ( params [ offset_loading + <NUM_LIT:0> ] , prec = <NUM_LIT:4> ) , table ) is None , False ) <EOL> assert_equal ( re . search ( '<STR_LIT>' + forg ( params [ offset_loading + <NUM_LIT:1> ] , prec = <NUM_LIT:4> ) , table ) is None , False ) <EOL> for i in range ( self . model . k_factors ) : <EOL> offset = self . model . k_endog * ( self . model . k_factors + <NUM_LIT:1> ) + i * self . model . k_factors <EOL> table = tables [ self . model . k_endog + i + <NUM_LIT:2> ] <EOL> name = self . model . endog_names [ i ] <EOL> assert_equal ( re . search ( '<STR_LIT>' % ( i + <NUM_LIT:1> ) , table ) is None , False ) <EOL> assert_equal ( len ( table . split ( '<STR_LIT:\n>' ) ) , <NUM_LIT:7> ) <EOL> assert_equal ( re . search ( '<STR_LIT>' + forg ( params [ offset + <NUM_LIT:0> ] , prec = <NUM_LIT:4> ) , table ) is None , False ) <EOL> assert_equal ( re . search ( '<STR_LIT>' + forg ( params [ offset + <NUM_LIT:1> ] , prec = <NUM_LIT:4> ) , table ) is None , False ) <EOL> table = tables [ <NUM_LIT:2> + self . model . k_endog + self . model . k_factors ] <EOL> name = self . model . endog_names [ i ] <EOL> assert_equal ( re . search ( '<STR_LIT>' , table ) is None , False ) <EOL> assert_equal ( len ( table . split ( '<STR_LIT:\n>' ) ) , <NUM_LIT:8> ) <EOL> offset = self . model . k_endog * self . model . k_factors <EOL> for i in range ( self . model . k_endog ) : <EOL> assert_equal ( re . search ( '<STR_LIT>' % ( self . model . endog_names [ i ] , forg ( params [ offset + i ] , prec = <NUM_LIT:4> ) ) , table ) is None , False ) <EOL> class TestDynamicFactor_exog1 ( CheckDynamicFactor ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def setup_class ( cls ) : <EOL> true = results_dynamic_factor . lutkepohl_dfm_exog1 . copy ( ) <EOL> true [ '<STR_LIT>' ] = output_results . ix [ <NUM_LIT:1> : , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ] <EOL> true [ '<STR_LIT>' ] = output_results . ix [ <NUM_LIT:1> : , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ] <EOL> exog = np . ones ( ( <NUM_LIT> , <NUM_LIT:1> ) ) <EOL> super ( TestDynamicFactor_exog1 , cls ) . setup_class ( true , k_factors = <NUM_LIT:1> , factor_order = <NUM_LIT:1> , exog = exog ) <EOL> def test_predict ( self ) : <EOL> exog = np . ones ( ( <NUM_LIT:16> , <NUM_LIT:1> ) ) <EOL> super ( TestDynamicFactor_exog1 , self ) . test_predict ( exog = exog ) <EOL> def test_dynamic_predict ( self ) : <EOL> exog = np . ones ( ( <NUM_LIT:16> , <NUM_LIT:1> ) ) <EOL> super ( TestDynamicFactor_exog1 , self ) . test_dynamic_predict ( exog = exog ) <EOL> def test_bse_approx ( self ) : <EOL> bse = self . results . _cov_params_approx ( ) . diagonal ( ) ** <NUM_LIT:0.5> <EOL> assert_allclose ( bse ** <NUM_LIT:2> , self . true [ '<STR_LIT>' ] , atol = <NUM_LIT> ) <EOL> class TestDynamicFactor_exog2 ( CheckDynamicFactor ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def setup_class ( cls ) : <EOL> true = results_dynamic_factor . lutkepohl_dfm_exog2 . copy ( ) <EOL> true [ '<STR_LIT>' ] = output_results . ix [ <NUM_LIT:1> : , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ] <EOL> true [ '<STR_LIT>' ] = output_results . ix [ <NUM_LIT:1> : , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ] <EOL> exog = np . c_ [ np . ones ( ( <NUM_LIT> , <NUM_LIT:1> ) ) , ( np . arange ( <NUM_LIT> ) + <NUM_LIT:2> ) [ : , np . newaxis ] ] <EOL> super ( TestDynamicFactor_exog2 , cls ) . setup_class ( true , k_factors = <NUM_LIT:1> , factor_order = <NUM_LIT:1> , exog = exog ) <EOL> def test_bse_approx ( self ) : <EOL> bse = self . results . _cov_params_approx ( ) . diagonal ( ) ** <NUM_LIT:0.5> <EOL> assert_allclose ( bse ** <NUM_LIT:2> , self . true [ '<STR_LIT>' ] , atol = <NUM_LIT> ) <EOL> def test_predict ( self ) : <EOL> exog = np . c_ [ np . ones ( ( <NUM_LIT:16> , <NUM_LIT:1> ) ) , ( np . arange ( <NUM_LIT> , <NUM_LIT> + <NUM_LIT:16> ) + <NUM_LIT:2> ) [ : , np . newaxis ] ] <EOL> super ( TestDynamicFactor_exog2 , self ) . test_predict ( exog = exog ) <EOL> def test_dynamic_predict ( self ) : <EOL> exog = np . c_ [ np . ones ( ( <NUM_LIT:16> , <NUM_LIT:1> ) ) , ( np . arange ( <NUM_LIT> , <NUM_LIT> + <NUM_LIT:16> ) + <NUM_LIT:2> ) [ : , np . newaxis ] ] <EOL> super ( TestDynamicFactor_exog2 , self ) . test_dynamic_predict ( exog = exog ) <EOL> def test_summary ( self ) : <EOL> summary = self . results . summary ( ) <EOL> tables = [ str ( table ) for table in summary . tables ] <EOL> params = self . true [ '<STR_LIT>' ] <EOL> assert_equal ( len ( tables ) , <NUM_LIT:2> + self . model . k_endog + self . model . k_factors + <NUM_LIT:1> ) <EOL> assert_equal ( re . search ( r'<STR_LIT>' , tables [ <NUM_LIT:0> ] ) is None , False ) <EOL> assert_equal ( re . search ( r'<STR_LIT>' , tables [ <NUM_LIT:0> ] ) is None , False ) <EOL> for i in range ( self . model . k_endog ) : <EOL> offset_loading = self . model . k_factors * i <EOL> offset_exog = self . model . k_factors * self . model . k_endog <EOL> table = tables [ i + <NUM_LIT:2> ] <EOL> name = self . model . endog_names [ i ] <EOL> assert_equal ( re . search ( '<STR_LIT>' % name , table ) is None , False ) <EOL> assert_equal ( len ( table . split ( '<STR_LIT:\n>' ) ) , <NUM_LIT:8> ) <EOL> assert_equal ( re . search ( '<STR_LIT>' + forg ( params [ offset_loading + <NUM_LIT:0> ] , prec = <NUM_LIT:4> ) , table ) is None , False ) <EOL> assert_equal ( re . search ( '<STR_LIT>' + forg ( params [ offset_exog + i * <NUM_LIT:2> + <NUM_LIT:0> ] , prec = <NUM_LIT:4> ) , table ) is None , False ) <EOL> assert_equal ( re . search ( '<STR_LIT>' + forg ( params [ offset_exog + i * <NUM_LIT:2> + <NUM_LIT:1> ] , prec = <NUM_LIT:4> ) , table ) is None , False ) <EOL> for i in range ( self . model . k_factors ) : <EOL> offset = self . model . k_endog * ( self . model . k_factors + <NUM_LIT:3> ) + i * self . model . k_factors <EOL> table = tables [ self . model . k_endog + i + <NUM_LIT:2> ] <EOL> name = self . model . endog_names [ i ] <EOL> assert_equal ( re . search ( '<STR_LIT>' % ( i + <NUM_LIT:1> ) , table ) is None , False ) <EOL> assert_equal ( len ( table . split ( '<STR_LIT:\n>' ) ) , <NUM_LIT:6> ) <EOL> assert_equal ( re . search ( '<STR_LIT>' + forg ( params [ offset + <NUM_LIT:0> ] , prec = <NUM_LIT:4> ) , table ) is None , False ) <EOL> table = tables [ <NUM_LIT:2> + self . model . k_endog + self . model . k_factors ] <EOL> name = self . model . endog_names [ i ] <EOL> assert_equal ( re . search ( '<STR_LIT>' , table ) is None , False ) <EOL> assert_equal ( len ( table . split ( '<STR_LIT:\n>' ) ) , <NUM_LIT:8> ) <EOL> offset = self . model . k_endog * ( self . model . k_factors + <NUM_LIT:2> ) <EOL> for i in range ( self . model . k_endog ) : <EOL> assert_equal ( re . search ( '<STR_LIT>' % ( self . model . endog_names [ i ] , forg ( params [ offset + i ] , prec = <NUM_LIT:4> ) ) , table ) is None , False ) <EOL> class TestDynamicFactor_general_errors ( CheckDynamicFactor ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def setup_class ( cls ) : <EOL> true = results_dynamic_factor . lutkepohl_dfm_gen . copy ( ) <EOL> true [ '<STR_LIT>' ] = output_results . ix [ <NUM_LIT:1> : , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ] <EOL> true [ '<STR_LIT>' ] = output_results . ix [ <NUM_LIT:1> : , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ] <EOL> super ( TestDynamicFactor_general_errors , cls ) . setup_class ( true , k_factors = <NUM_LIT:1> , factor_order = <NUM_LIT:1> , error_var = True , error_order = <NUM_LIT:1> , error_cov_type = '<STR_LIT>' ) <EOL> def test_bse_approx ( self ) : <EOL> bse = self . results . _cov_params_approx ( ) . diagonal ( ) <EOL> assert_allclose ( bse [ : <NUM_LIT:3> ] , self . true [ '<STR_LIT>' ] [ : <NUM_LIT:3> ] , atol = <NUM_LIT> ) <EOL> assert_allclose ( bse [ - <NUM_LIT:10> : ] , self . true [ '<STR_LIT>' ] [ - <NUM_LIT:10> : ] , atol = <NUM_LIT> ) <EOL> def test_mle ( self ) : <EOL> raise SkipTest ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> def test_summary ( self ) : <EOL> summary = self . results . summary ( ) <EOL> tables = [ str ( table ) for table in summary . tables ] <EOL> params = self . true [ '<STR_LIT>' ] <EOL> assert_equal ( len ( tables ) , <NUM_LIT:2> + self . model . k_endog + self . model . k_factors + self . model . k_endog + <NUM_LIT:1> ) <EOL> assert_equal ( re . search ( r'<STR_LIT>' , tables [ <NUM_LIT:0> ] ) is None , False ) <EOL> assert_equal ( re . search ( r'<STR_LIT>' , tables [ <NUM_LIT:0> ] ) is None , False ) <EOL> for i in range ( self . model . k_endog ) : <EOL> offset_loading = self . model . k_factors * i <EOL> table = tables [ i + <NUM_LIT:2> ] <EOL> name = self . model . endog_names [ i ] <EOL> assert_equal ( re . search ( '<STR_LIT>' % name , table ) is None , False ) <EOL> assert_equal ( len ( table . split ( '<STR_LIT:\n>' ) ) , <NUM_LIT:6> ) <EOL> assert_equal ( re . search ( '<STR_LIT>' + forg ( params [ offset_loading + <NUM_LIT:0> ] , prec = <NUM_LIT:4> ) , table ) is None , False ) <EOL> for i in range ( self . model . k_factors ) : <EOL> offset = self . model . k_endog * self . model . k_factors + <NUM_LIT:6> + i * self . model . k_factors <EOL> table = tables [ <NUM_LIT:2> + self . model . k_endog + i ] <EOL> name = self . model . endog_names [ i ] <EOL> assert_equal ( re . search ( '<STR_LIT>' % ( i + <NUM_LIT:1> ) , table ) is None , False ) <EOL> assert_equal ( len ( table . split ( '<STR_LIT:\n>' ) ) , <NUM_LIT:6> ) <EOL> assert_equal ( re . search ( '<STR_LIT>' + forg ( params [ offset + <NUM_LIT:0> ] , prec = <NUM_LIT:4> ) , table ) is None , False ) <EOL> for i in range ( self . model . k_endog ) : <EOL> offset = self . model . k_endog * ( self . model . k_factors + i ) + <NUM_LIT:6> + self . model . k_factors <EOL> table = tables [ <NUM_LIT:2> + self . model . k_endog + self . model . k_factors + i ] <EOL> name = self . model . endog_names [ i ] <EOL> assert_equal ( re . search ( '<STR_LIT>' % name , table ) is None , False ) <EOL> assert_equal ( len ( table . split ( '<STR_LIT:\n>' ) ) , <NUM_LIT:8> ) <EOL> for j in range ( self . model . k_endog ) : <EOL> name = self . model . endog_names [ j ] <EOL> assert_equal ( re . search ( '<STR_LIT>' % ( name , forg ( params [ offset + j ] , prec = <NUM_LIT:4> ) ) , table ) is None , False ) <EOL> table = tables [ <NUM_LIT:2> + self . model . k_endog + self . model . k_factors + self . model . k_endog ] <EOL> name = self . model . endog_names [ i ] <EOL> assert_equal ( re . search ( '<STR_LIT>' , table ) is None , False ) <EOL> assert_equal ( len ( table . split ( '<STR_LIT:\n>' ) ) , <NUM_LIT:11> ) <EOL> offset = self . model . k_endog * self . model . k_factors <EOL> assert_equal ( re . search ( '<STR_LIT>' + forg ( params [ offset + <NUM_LIT:0> ] , prec = <NUM_LIT:4> ) , table ) is None , False ) <EOL> assert_equal ( re . search ( '<STR_LIT>' + forg ( params [ offset + <NUM_LIT:1> ] , prec = <NUM_LIT:4> ) , table ) is None , False ) <EOL> assert_equal ( re . search ( '<STR_LIT>' + forg ( params [ offset + <NUM_LIT:2> ] , prec = <NUM_LIT:4> ) , table ) is None , False ) <EOL> assert_equal ( re . search ( '<STR_LIT>' + forg ( params [ offset + <NUM_LIT:3> ] , prec = <NUM_LIT:4> ) , table ) is None , False ) <EOL> assert_equal ( re . search ( '<STR_LIT>' + forg ( params [ offset + <NUM_LIT:4> ] , prec = <NUM_LIT:4> ) , table ) is None , False ) <EOL> assert_equal ( re . search ( '<STR_LIT>' + forg ( params [ offset + <NUM_LIT:5> ] , prec = <NUM_LIT:4> ) , table ) is None , False ) <EOL> class TestDynamicFactor_ar2_errors ( CheckDynamicFactor ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def setup_class ( cls ) : <EOL> true = results_dynamic_factor . lutkepohl_dfm_ar2 . copy ( ) <EOL> true [ '<STR_LIT>' ] = output_results . ix [ <NUM_LIT:1> : , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ] <EOL> true [ '<STR_LIT>' ] = output_results . ix [ <NUM_LIT:1> : , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ] <EOL> super ( TestDynamicFactor_ar2_errors , cls ) . setup_class ( true , k_factors = <NUM_LIT:1> , factor_order = <NUM_LIT:1> , error_order = <NUM_LIT:2> ) <EOL> def test_bse_approx ( self ) : <EOL> bse = self . results . _cov_params_approx ( ) . diagonal ( ) <EOL> assert_allclose ( bse , self . true [ '<STR_LIT>' ] , atol = <NUM_LIT> ) <EOL> def test_mle ( self ) : <EOL> with warnings . catch_warnings ( record = True ) as w : <EOL> mod = self . model <EOL> res1 = mod . fit ( maxiter = <NUM_LIT:100> , optim_score = '<STR_LIT>' , disp = False ) <EOL> res = mod . fit ( res1 . params , method = '<STR_LIT>' , maxiter = <NUM_LIT> , optim_score = '<STR_LIT>' , disp = False ) <EOL> assert_allclose ( res . llf , self . results . llf , atol = <NUM_LIT> ) <EOL> class TestDynamicFactor_scalar_error ( CheckDynamicFactor ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def setup_class ( cls ) : <EOL> true = results_dynamic_factor . lutkepohl_dfm_scalar . copy ( ) <EOL> true [ '<STR_LIT>' ] = output_results . ix [ <NUM_LIT:1> : , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ] <EOL> true [ '<STR_LIT>' ] = output_results . ix [ <NUM_LIT:1> : , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ] <EOL> exog = np . ones ( ( <NUM_LIT> , <NUM_LIT:1> ) ) <EOL> super ( TestDynamicFactor_scalar_error , cls ) . setup_class ( true , k_factors = <NUM_LIT:1> , factor_order = <NUM_LIT:1> , exog = exog , error_cov_type = '<STR_LIT>' ) <EOL> def test_bse_approx ( self ) : <EOL> bse = self . results . _cov_params_approx ( ) . diagonal ( ) <EOL> assert_allclose ( bse , self . true [ '<STR_LIT>' ] , atol = <NUM_LIT> ) <EOL> def test_predict ( self ) : <EOL> exog = np . ones ( ( <NUM_LIT:16> , <NUM_LIT:1> ) ) <EOL> super ( TestDynamicFactor_scalar_error , self ) . test_predict ( exog = exog ) <EOL> def test_dynamic_predict ( self ) : <EOL> exog = np . ones ( ( <NUM_LIT:16> , <NUM_LIT:1> ) ) <EOL> super ( TestDynamicFactor_scalar_error , self ) . test_dynamic_predict ( exog = exog ) <EOL> class TestStaticFactor ( CheckDynamicFactor ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def setup_class ( cls ) : <EOL> true = results_dynamic_factor . lutkepohl_sfm . copy ( ) <EOL> true [ '<STR_LIT>' ] = output_results . ix [ <NUM_LIT:1> : , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ] <EOL> true [ '<STR_LIT>' ] = output_results . ix [ <NUM_LIT:1> : , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ] <EOL> super ( TestStaticFactor , cls ) . setup_class ( true , k_factors = <NUM_LIT:1> , factor_order = <NUM_LIT:0> ) <EOL> def test_bse_approx ( self ) : <EOL> bse = self . results . _cov_params_approx ( ) . diagonal ( ) <EOL> assert_allclose ( bse , self . true [ '<STR_LIT>' ] , atol = <NUM_LIT> ) <EOL> def test_bic ( self ) : <EOL> pass <EOL> class TestSUR ( CheckDynamicFactor ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def setup_class ( cls ) : <EOL> true = results_dynamic_factor . lutkepohl_sur . copy ( ) <EOL> true [ '<STR_LIT>' ] = output_results . ix [ <NUM_LIT:1> : , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ] <EOL> true [ '<STR_LIT>' ] = output_results . ix [ <NUM_LIT:1> : , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ] <EOL> exog = np . c_ [ np . ones ( ( <NUM_LIT> , <NUM_LIT:1> ) ) , ( np . arange ( <NUM_LIT> ) + <NUM_LIT:2> ) [ : , np . newaxis ] ] <EOL> super ( TestSUR , cls ) . setup_class ( true , k_factors = <NUM_LIT:0> , factor_order = <NUM_LIT:0> , exog = exog , error_cov_type = '<STR_LIT>' ) <EOL> def test_bse_approx ( self ) : <EOL> bse = self . results . _cov_params_approx ( ) . diagonal ( ) <EOL> assert_allclose ( bse [ : <NUM_LIT:6> ] , self . true [ '<STR_LIT>' ] [ : <NUM_LIT:6> ] , atol = <NUM_LIT> ) <EOL> def test_predict ( self ) : <EOL> exog = np . c_ [ np . ones ( ( <NUM_LIT:16> , <NUM_LIT:1> ) ) , ( np . arange ( <NUM_LIT> , <NUM_LIT> + <NUM_LIT:16> ) + <NUM_LIT:2> ) [ : , np . newaxis ] ] <EOL> super ( TestSUR , self ) . test_predict ( exog = exog ) <EOL> def test_dynamic_predict ( self ) : <EOL> exog = np . c_ [ np . ones ( ( <NUM_LIT:16> , <NUM_LIT:1> ) ) , ( np . arange ( <NUM_LIT> , <NUM_LIT> + <NUM_LIT:16> ) + <NUM_LIT:2> ) [ : , np . newaxis ] ] <EOL> super ( TestSUR , self ) . test_dynamic_predict ( exog = exog ) <EOL> class TestSUR_autocorrelated_errors ( CheckDynamicFactor ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def setup_class ( cls ) : <EOL> true = results_dynamic_factor . lutkepohl_sur_auto . copy ( ) <EOL> true [ '<STR_LIT>' ] = output_results . ix [ <NUM_LIT:1> : , [ '<STR_LIT>' , '<STR_LIT>' ] ] <EOL> true [ '<STR_LIT>' ] = output_results . ix [ <NUM_LIT:1> : , [ '<STR_LIT>' , '<STR_LIT>' ] ] <EOL> exog = np . c_ [ np . ones ( ( <NUM_LIT> , <NUM_LIT:1> ) ) , ( np . arange ( <NUM_LIT> ) + <NUM_LIT:2> ) [ : , np . newaxis ] ] <EOL> super ( TestSUR_autocorrelated_errors , cls ) . setup_class ( true , k_factors = <NUM_LIT:0> , factor_order = <NUM_LIT:0> , exog = exog , error_order = <NUM_LIT:1> , error_var = True , error_cov_type = '<STR_LIT>' , included_vars = [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_bse_approx ( self ) : <EOL> bse = self . results . _cov_params_approx ( ) . diagonal ( ) <EOL> assert_allclose ( bse , self . true [ '<STR_LIT>' ] , atol = <NUM_LIT> ) <EOL> def test_predict ( self ) : <EOL> exog = np . c_ [ np . ones ( ( <NUM_LIT:16> , <NUM_LIT:1> ) ) , ( np . arange ( <NUM_LIT> , <NUM_LIT> + <NUM_LIT:16> ) + <NUM_LIT:2> ) [ : , np . newaxis ] ] <EOL> super ( TestSUR_autocorrelated_errors , self ) . test_predict ( exog = exog ) <EOL> def test_dynamic_predict ( self ) : <EOL> exog = np . c_ [ np . ones ( ( <NUM_LIT:16> , <NUM_LIT:1> ) ) , ( np . arange ( <NUM_LIT> , <NUM_LIT> + <NUM_LIT:16> ) + <NUM_LIT:2> ) [ : , np . newaxis ] ] <EOL> super ( TestSUR_autocorrelated_errors , self ) . test_dynamic_predict ( exog = exog ) <EOL> def test_misspecification ( ) : <EOL> endog = np . arange ( <NUM_LIT:20> ) . reshape ( <NUM_LIT:10> , <NUM_LIT:2> ) <EOL> assert_raises ( ValueError , dynamic_factor . DynamicFactor , endog [ : , <NUM_LIT:0> ] , k_factors = <NUM_LIT:0> , factor_order = <NUM_LIT:0> ) <EOL> assert_raises ( ValueError , dynamic_factor . DynamicFactor , endog , k_factors = <NUM_LIT:2> , factor_order = <NUM_LIT:1> ) <EOL> assert_raises ( ValueError , dynamic_factor . DynamicFactor , endog , k_factors = <NUM_LIT:1> , factor_order = <NUM_LIT:1> , order = ( <NUM_LIT:1> , <NUM_LIT:0> ) , error_cov_type = '<STR_LIT>' ) <EOL> def test_miscellaneous ( ) : <EOL> exog = np . arange ( <NUM_LIT> ) <EOL> mod = CheckDynamicFactor ( ) <EOL> mod . setup_class ( true = None , k_factors = <NUM_LIT:1> , factor_order = <NUM_LIT:1> , exog = exog , filter = False ) <EOL> exog = pd . Series ( np . arange ( <NUM_LIT> ) , index = pd . date_range ( start = '<STR_LIT>' , end = '<STR_LIT>' , freq = '<STR_LIT>' ) ) <EOL> mod = CheckDynamicFactor ( ) <EOL> mod . setup_class ( true = None , k_factors = <NUM_LIT:1> , factor_order = <NUM_LIT:1> , exog = exog , filter = False ) </s>
