<s> """<STR_LIT>""" <EOL> from statsmodels . compat . python import long , lrange <EOL> import warnings <EOL> import pandas <EOL> import numpy as np <EOL> from numpy . testing import ( assert_almost_equal , assert_approx_equal , assert_ , <EOL> assert_raises , assert_equal , assert_allclose ) <EOL> from scipy . linalg import toeplitz <EOL> from statsmodels . tools . tools import add_constant , categorical <EOL> from statsmodels . compat . numpy import np_matrix_rank <EOL> from statsmodels . regression . linear_model import OLS , WLS , GLS , yule_walker <EOL> from statsmodels . datasets import longley <EOL> from scipy . stats import t as student_t <EOL> DECIMAL_4 = <NUM_LIT:4> <EOL> DECIMAL_3 = <NUM_LIT:3> <EOL> DECIMAL_2 = <NUM_LIT:2> <EOL> DECIMAL_1 = <NUM_LIT:1> <EOL> DECIMAL_7 = <NUM_LIT:7> <EOL> DECIMAL_0 = <NUM_LIT:0> <EOL> class CheckRegressionResults ( object ) : <EOL> """<STR_LIT>""" <EOL> decimal_params = DECIMAL_4 <EOL> def test_params ( self ) : <EOL> assert_almost_equal ( self . res1 . params , self . res2 . params , <EOL> self . decimal_params ) <EOL> decimal_standarderrors = DECIMAL_4 <EOL> def test_standarderrors ( self ) : <EOL> assert_almost_equal ( self . res1 . bse , self . res2 . bse , <EOL> self . decimal_standarderrors ) <EOL> decimal_confidenceintervals = DECIMAL_4 <EOL> def test_confidenceintervals ( self ) : <EOL> conf1 = self . res1 . conf_int ( ) <EOL> conf2 = self . res2 . conf_int ( ) <EOL> for i in range ( len ( conf1 ) ) : <EOL> assert_approx_equal ( conf1 [ i ] [ <NUM_LIT:0> ] , conf2 [ i ] [ <NUM_LIT:0> ] , <EOL> self . decimal_confidenceintervals ) <EOL> assert_approx_equal ( conf1 [ i ] [ <NUM_LIT:1> ] , conf2 [ i ] [ <NUM_LIT:1> ] , <EOL> self . decimal_confidenceintervals ) <EOL> decimal_conf_int_subset = DECIMAL_4 <EOL> def test_conf_int_subset ( self ) : <EOL> if len ( self . res1 . params ) > <NUM_LIT:1> : <EOL> ci1 = self . res1 . conf_int ( cols = ( <NUM_LIT:1> , <NUM_LIT:2> ) ) <EOL> ci2 = self . res1 . conf_int ( ) [ <NUM_LIT:1> : <NUM_LIT:3> ] <EOL> assert_almost_equal ( ci1 , ci2 , self . decimal_conf_int_subset ) <EOL> else : <EOL> pass <EOL> decimal_scale = DECIMAL_4 <EOL> def test_scale ( self ) : <EOL> assert_almost_equal ( self . res1 . scale , self . res2 . scale , <EOL> self . decimal_scale ) <EOL> decimal_rsquared = DECIMAL_4 <EOL> def test_rsquared ( self ) : <EOL> assert_almost_equal ( self . res1 . rsquared , self . res2 . rsquared , <EOL> self . decimal_rsquared ) <EOL> decimal_rsquared_adj = DECIMAL_4 <EOL> def test_rsquared_adj ( self ) : <EOL> assert_almost_equal ( self . res1 . rsquared_adj , self . res2 . rsquared_adj , <EOL> self . decimal_rsquared_adj ) <EOL> def test_degrees ( self ) : <EOL> assert_equal ( self . res1 . model . df_model , self . res2 . df_model ) <EOL> assert_equal ( self . res1 . model . df_resid , self . res2 . df_resid ) <EOL> decimal_ess = DECIMAL_4 <EOL> def test_ess ( self ) : <EOL> assert_almost_equal ( self . res1 . ess , self . res2 . ess , <EOL> self . decimal_ess ) <EOL> decimal_ssr = DECIMAL_4 <EOL> def test_sumof_squaredresids ( self ) : <EOL> assert_almost_equal ( self . res1 . ssr , self . res2 . ssr , self . decimal_ssr ) <EOL> decimal_mse_resid = DECIMAL_4 <EOL> def test_mse_resid ( self ) : <EOL> assert_almost_equal ( self . res1 . mse_model , self . res2 . mse_model , <EOL> self . decimal_mse_resid ) <EOL> decimal_mse_model = DECIMAL_4 <EOL> def test_mse_model ( self ) : <EOL> assert_almost_equal ( self . res1 . mse_resid , self . res2 . mse_resid , <EOL> self . decimal_mse_model ) <EOL> decimal_mse_total = DECIMAL_4 <EOL> def test_mse_total ( self ) : <EOL> assert_almost_equal ( self . res1 . mse_total , self . res2 . mse_total , <EOL> self . decimal_mse_total , err_msg = "<STR_LIT>" % self ) <EOL> decimal_fvalue = DECIMAL_4 <EOL> def test_fvalue ( self ) : <EOL> assert_almost_equal ( self . res1 . fvalue , self . res2 . fvalue , <EOL> self . decimal_fvalue ) <EOL> decimal_loglike = DECIMAL_4 <EOL> def test_loglike ( self ) : <EOL> assert_almost_equal ( self . res1 . llf , self . res2 . llf , self . decimal_loglike ) <EOL> decimal_aic = DECIMAL_4 <EOL> def test_aic ( self ) : <EOL> assert_almost_equal ( self . res1 . aic , self . res2 . aic , self . decimal_aic ) <EOL> decimal_bic = DECIMAL_4 <EOL> def test_bic ( self ) : <EOL> assert_almost_equal ( self . res1 . bic , self . res2 . bic , self . decimal_bic ) <EOL> decimal_pvalues = DECIMAL_4 <EOL> def test_pvalues ( self ) : <EOL> assert_almost_equal ( self . res1 . pvalues , self . res2 . pvalues , <EOL> self . decimal_pvalues ) <EOL> decimal_wresid = DECIMAL_4 <EOL> def test_wresid ( self ) : <EOL> assert_almost_equal ( self . res1 . wresid , self . res2 . wresid , <EOL> self . decimal_wresid ) <EOL> decimal_resids = DECIMAL_4 <EOL> def test_resids ( self ) : <EOL> assert_almost_equal ( self . res1 . resid , self . res2 . resid , <EOL> self . decimal_resids ) <EOL> decimal_norm_resids = DECIMAL_4 <EOL> def test_norm_resids ( self ) : <EOL> assert_almost_equal ( self . res1 . resid_pearson , self . res2 . resid_pearson , <EOL> self . decimal_norm_resids ) <EOL> class TestOLS ( CheckRegressionResults ) : <EOL> @ classmethod <EOL> def setupClass ( cls ) : <EOL> from . results . results_regression import Longley <EOL> data = longley . load ( ) <EOL> data . exog = add_constant ( data . exog , prepend = False ) <EOL> res1 = OLS ( data . endog , data . exog ) . fit ( ) <EOL> res2 = Longley ( ) <EOL> res2 . wresid = res1 . wresid <EOL> cls . res1 = res1 <EOL> cls . res2 = res2 <EOL> res_qr = OLS ( data . endog , data . exog ) . fit ( method = "<STR_LIT>" ) <EOL> model_qr = OLS ( data . endog , data . exog ) <EOL> Q , R = np . linalg . qr ( data . exog ) <EOL> model_qr . exog_Q , model_qr . exog_R = Q , R <EOL> model_qr . normalized_cov_params = np . linalg . inv ( np . dot ( R . T , R ) ) <EOL> model_qr . rank = np_matrix_rank ( R ) <EOL> res_qr2 = model_qr . fit ( method = "<STR_LIT>" ) <EOL> cls . res_qr = res_qr <EOL> cls . res_qr_manual = res_qr2 <EOL> def test_eigenvalues ( self ) : <EOL> eigenval_perc_diff = ( self . res_qr . eigenvals - self . res_qr_manual . eigenvals ) <EOL> eigenval_perc_diff /= self . res_qr . eigenvals <EOL> zeros = np . zeros_like ( eigenval_perc_diff ) <EOL> assert_almost_equal ( eigenval_perc_diff , zeros , DECIMAL_7 ) <EOL> def test_HC0_errors ( self ) : <EOL> assert_almost_equal ( self . res1 . HC0_se [ : - <NUM_LIT:1> ] , <EOL> self . res2 . HC0_se [ : - <NUM_LIT:1> ] , DECIMAL_4 ) <EOL> assert_approx_equal ( np . round ( self . res1 . HC0_se [ - <NUM_LIT:1> ] ) , self . res2 . HC0_se [ - <NUM_LIT:1> ] ) <EOL> def test_HC1_errors ( self ) : <EOL> assert_almost_equal ( self . res1 . HC1_se [ : - <NUM_LIT:1> ] , <EOL> self . res2 . HC1_se [ : - <NUM_LIT:1> ] , DECIMAL_4 ) <EOL> assert_approx_equal ( self . res1 . HC1_se [ - <NUM_LIT:1> ] , self . res2 . HC1_se [ - <NUM_LIT:1> ] ) <EOL> def test_HC2_errors ( self ) : <EOL> assert_almost_equal ( self . res1 . HC2_se [ : - <NUM_LIT:1> ] , <EOL> self . res2 . HC2_se [ : - <NUM_LIT:1> ] , DECIMAL_4 ) <EOL> assert_approx_equal ( self . res1 . HC2_se [ - <NUM_LIT:1> ] , self . res2 . HC2_se [ - <NUM_LIT:1> ] ) <EOL> def test_HC3_errors ( self ) : <EOL> assert_almost_equal ( self . res1 . HC3_se [ : - <NUM_LIT:1> ] , <EOL> self . res2 . HC3_se [ : - <NUM_LIT:1> ] , DECIMAL_4 ) <EOL> assert_approx_equal ( self . res1 . HC3_se [ - <NUM_LIT:1> ] , self . res2 . HC3_se [ - <NUM_LIT:1> ] ) <EOL> def test_qr_params ( self ) : <EOL> assert_almost_equal ( self . res1 . params , <EOL> self . res_qr . params , <NUM_LIT:6> ) <EOL> def test_qr_normalized_cov_params ( self ) : <EOL> assert_almost_equal ( np . ones_like ( self . res1 . normalized_cov_params ) , <EOL> self . res1 . normalized_cov_params / <EOL> self . res_qr . normalized_cov_params , <NUM_LIT:5> ) <EOL> def test_missing ( self ) : <EOL> data = longley . load ( ) <EOL> data . exog = add_constant ( data . exog , prepend = False ) <EOL> data . endog [ [ <NUM_LIT:3> , <NUM_LIT:7> , <NUM_LIT> ] ] = np . nan <EOL> mod = OLS ( data . endog , data . exog , missing = '<STR_LIT>' ) <EOL> assert_equal ( mod . endog . shape [ <NUM_LIT:0> ] , <NUM_LIT> ) <EOL> assert_equal ( mod . exog . shape [ <NUM_LIT:0> ] , <NUM_LIT> ) <EOL> def test_rsquared_adj_overfit ( self ) : <EOL> with warnings . catch_warnings ( record = True ) : <EOL> x = np . random . randn ( <NUM_LIT:5> ) <EOL> y = np . random . randn ( <NUM_LIT:5> , <NUM_LIT:6> ) <EOL> results = OLS ( x , y ) . fit ( ) <EOL> rsquared_adj = results . rsquared_adj <EOL> assert_equal ( rsquared_adj , np . nan ) <EOL> def test_qr_alternatives ( self ) : <EOL> assert_allclose ( self . res_qr . params , self . res_qr_manual . params , <EOL> rtol = <NUM_LIT> ) <EOL> def test_norm_resid ( self ) : <EOL> resid = self . res1 . wresid <EOL> norm_resid = resid / np . sqrt ( np . sum ( resid ** <NUM_LIT> ) / self . res1 . df_resid ) <EOL> model_norm_resid = self . res1 . resid_pearson <EOL> assert_almost_equal ( model_norm_resid , norm_resid , DECIMAL_7 ) <EOL> def test_norm_resid_zero_variance ( self ) : <EOL> with warnings . catch_warnings ( record = True ) : <EOL> y = self . res1 . model . endog <EOL> res = OLS ( y , y ) . fit ( ) <EOL> assert_allclose ( res . scale , <NUM_LIT:0> , atol = <NUM_LIT> ) <EOL> assert_allclose ( res . wresid , res . resid_pearson , atol = <NUM_LIT> ) <EOL> class TestRTO ( CheckRegressionResults ) : <EOL> @ classmethod <EOL> def setupClass ( cls ) : <EOL> from . results . results_regression import LongleyRTO <EOL> data = longley . load ( ) <EOL> res1 = OLS ( data . endog , data . exog ) . fit ( ) <EOL> res2 = LongleyRTO ( ) <EOL> res2 . wresid = res1 . wresid <EOL> cls . res1 = res1 <EOL> cls . res2 = res2 <EOL> res_qr = OLS ( data . endog , data . exog ) . fit ( method = "<STR_LIT>" ) <EOL> cls . res_qr = res_qr <EOL> class TestFtest ( object ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def setupClass ( cls ) : <EOL> data = longley . load ( ) <EOL> data . exog = add_constant ( data . exog , prepend = False ) <EOL> cls . res1 = OLS ( data . endog , data . exog ) . fit ( ) <EOL> R = np . identity ( <NUM_LIT:7> ) [ : - <NUM_LIT:1> , : ] <EOL> cls . Ftest = cls . res1 . f_test ( R ) <EOL> def test_F ( self ) : <EOL> assert_almost_equal ( self . Ftest . fvalue , self . res1 . fvalue , DECIMAL_4 ) <EOL> def test_p ( self ) : <EOL> assert_almost_equal ( self . Ftest . pvalue , self . res1 . f_pvalue , DECIMAL_4 ) <EOL> def test_Df_denom ( self ) : <EOL> assert_equal ( self . Ftest . df_denom , self . res1 . model . df_resid ) <EOL> def test_Df_num ( self ) : <EOL> assert_equal ( self . Ftest . df_num , <NUM_LIT:6> ) <EOL> class TestFTest2 ( object ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def setupClass ( cls ) : <EOL> data = longley . load ( ) <EOL> data . exog = add_constant ( data . exog , prepend = False ) <EOL> res1 = OLS ( data . endog , data . exog ) . fit ( ) <EOL> R2 = [ [ <NUM_LIT:0> , <NUM_LIT:1> , - <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] , [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , - <NUM_LIT:1> , <NUM_LIT:0> ] ] <EOL> cls . Ftest1 = res1 . f_test ( R2 ) <EOL> hyp = '<STR_LIT>' <EOL> cls . NewFtest1 = res1 . f_test ( hyp ) <EOL> def test_new_ftest ( self ) : <EOL> assert_equal ( self . NewFtest1 . fvalue , self . Ftest1 . fvalue ) <EOL> def test_fvalue ( self ) : <EOL> assert_almost_equal ( self . Ftest1 . fvalue , <NUM_LIT> , DECIMAL_4 ) <EOL> def test_pvalue ( self ) : <EOL> assert_almost_equal ( self . Ftest1 . pvalue , <NUM_LIT> , <EOL> DECIMAL_4 ) <EOL> def test_df_denom ( self ) : <EOL> assert_equal ( self . Ftest1 . df_denom , <NUM_LIT:9> ) <EOL> def test_df_num ( self ) : <EOL> assert_equal ( self . Ftest1 . df_num , <NUM_LIT:2> ) <EOL> class TestFtestQ ( object ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def setupClass ( cls ) : <EOL> data = longley . load ( ) <EOL> data . exog = add_constant ( data . exog , prepend = False ) <EOL> res1 = OLS ( data . endog , data . exog ) . fit ( ) <EOL> R = np . array ( [ [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ] ] ) <EOL> q = np . array ( [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ] ) <EOL> cls . Ftest1 = res1 . f_test ( ( R , q ) ) <EOL> def test_fvalue ( self ) : <EOL> assert_almost_equal ( self . Ftest1 . fvalue , <NUM_LIT> , <NUM_LIT:5> ) <EOL> def test_pvalue ( self ) : <EOL> assert_almost_equal ( self . Ftest1 . pvalue , <NUM_LIT> , <NUM_LIT:10> ) <EOL> def test_df_denom ( self ) : <EOL> assert_equal ( self . Ftest1 . df_denom , <NUM_LIT:9> ) <EOL> def test_df_num ( self ) : <EOL> assert_equal ( self . Ftest1 . df_num , <NUM_LIT:5> ) <EOL> class TestTtest ( object ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def setupClass ( cls ) : <EOL> data = longley . load ( ) <EOL> data . exog = add_constant ( data . exog , prepend = False ) <EOL> cls . res1 = OLS ( data . endog , data . exog ) . fit ( ) <EOL> R = np . identity ( <NUM_LIT:7> ) <EOL> cls . Ttest = cls . res1 . t_test ( R ) <EOL> hyp = '<STR_LIT>' <EOL> cls . NewTTest = cls . res1 . t_test ( hyp ) <EOL> def test_new_tvalue ( self ) : <EOL> assert_equal ( self . NewTTest . tvalue , self . Ttest . tvalue ) <EOL> def test_tvalue ( self ) : <EOL> assert_almost_equal ( self . Ttest . tvalue , self . res1 . tvalues , DECIMAL_4 ) <EOL> def test_sd ( self ) : <EOL> assert_almost_equal ( self . Ttest . sd , self . res1 . bse , DECIMAL_4 ) <EOL> def test_pvalue ( self ) : <EOL> assert_almost_equal ( self . Ttest . pvalue , student_t . sf ( <EOL> np . abs ( self . res1 . tvalues ) , self . res1 . model . df_resid ) * <NUM_LIT:2> , <EOL> DECIMAL_4 ) <EOL> def test_df_denom ( self ) : <EOL> assert_equal ( self . Ttest . df_denom , self . res1 . model . df_resid ) <EOL> def test_effect ( self ) : <EOL> assert_almost_equal ( self . Ttest . effect , self . res1 . params ) <EOL> class TestTtest2 ( object ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def setupClass ( cls ) : <EOL> R = np . zeros ( <NUM_LIT:7> ) <EOL> R [ <NUM_LIT:4> : <NUM_LIT:6> ] = [ <NUM_LIT:1> , - <NUM_LIT:1> ] <EOL> data = longley . load ( ) <EOL> data . exog = add_constant ( data . exog , prepend = False ) <EOL> res1 = OLS ( data . endog , data . exog ) . fit ( ) <EOL> cls . Ttest1 = res1 . t_test ( R ) <EOL> def test_tvalue ( self ) : <EOL> assert_almost_equal ( self . Ttest1 . tvalue , - <NUM_LIT> , <EOL> DECIMAL_4 ) <EOL> def test_sd ( self ) : <EOL> assert_almost_equal ( self . Ttest1 . sd , <NUM_LIT> , DECIMAL_4 ) <EOL> def test_pvalue ( self ) : <EOL> assert_almost_equal ( self . Ttest1 . pvalue , <NUM_LIT:2> * <NUM_LIT> , <EOL> DECIMAL_4 ) <EOL> def test_df_denom ( self ) : <EOL> assert_equal ( self . Ttest1 . df_denom , <NUM_LIT:9> ) <EOL> def test_effect ( self ) : <EOL> assert_almost_equal ( self . Ttest1 . effect , - <NUM_LIT> , DECIMAL_4 ) <EOL> class TestGLS ( object ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def setupClass ( cls ) : <EOL> from . results . results_regression import LongleyGls <EOL> data = longley . load ( ) <EOL> exog = add_constant ( np . column_stack ( ( data . exog [ : , <NUM_LIT:1> ] , <EOL> data . exog [ : , <NUM_LIT:4> ] ) ) , prepend = False ) <EOL> tmp_results = OLS ( data . endog , exog ) . fit ( ) <EOL> rho = np . corrcoef ( tmp_results . resid [ <NUM_LIT:1> : ] , <EOL> tmp_results . resid [ : - <NUM_LIT:1> ] ) [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] <EOL> order = toeplitz ( np . arange ( <NUM_LIT:16> ) ) <EOL> sigma = rho ** order <EOL> GLS_results = GLS ( data . endog , exog , sigma = sigma ) . fit ( ) <EOL> cls . res1 = GLS_results <EOL> cls . res2 = LongleyGls ( ) <EOL> cls . sigma = sigma <EOL> cls . exog = exog <EOL> cls . endog = data . endog <EOL> def test_aic ( self ) : <EOL> assert_approx_equal ( self . res1 . aic + <NUM_LIT:2> , self . res2 . aic , <NUM_LIT:3> ) <EOL> def test_bic ( self ) : <EOL> assert_approx_equal ( self . res1 . bic , self . res2 . bic , <NUM_LIT:2> ) <EOL> def test_loglike ( self ) : <EOL> assert_almost_equal ( self . res1 . llf , self . res2 . llf , DECIMAL_0 ) <EOL> def test_params ( self ) : <EOL> assert_almost_equal ( self . res1 . params , self . res2 . params , DECIMAL_1 ) <EOL> def test_resid ( self ) : <EOL> assert_almost_equal ( self . res1 . resid , self . res2 . resid , DECIMAL_4 ) <EOL> def test_scale ( self ) : <EOL> assert_almost_equal ( self . res1 . scale , self . res2 . scale , DECIMAL_4 ) <EOL> def test_tvalues ( self ) : <EOL> assert_almost_equal ( self . res1 . tvalues , self . res2 . tvalues , DECIMAL_4 ) <EOL> def test_standarderrors ( self ) : <EOL> assert_almost_equal ( self . res1 . bse , self . res2 . bse , DECIMAL_4 ) <EOL> def test_fittedvalues ( self ) : <EOL> assert_almost_equal ( self . res1 . fittedvalues , self . res2 . fittedvalues , <EOL> DECIMAL_4 ) <EOL> def test_pvalues ( self ) : <EOL> assert_almost_equal ( self . res1 . pvalues , self . res2 . pvalues , DECIMAL_4 ) <EOL> def test_missing ( self ) : <EOL> endog = self . endog . copy ( ) <EOL> endog [ [ <NUM_LIT:4> , <NUM_LIT:7> , <NUM_LIT> ] ] = np . nan <EOL> mod = GLS ( endog , self . exog , sigma = self . sigma , missing = '<STR_LIT>' ) <EOL> assert_equal ( mod . endog . shape [ <NUM_LIT:0> ] , <NUM_LIT> ) <EOL> assert_equal ( mod . exog . shape [ <NUM_LIT:0> ] , <NUM_LIT> ) <EOL> assert_equal ( mod . sigma . shape , ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> class TestGLS_alt_sigma ( CheckRegressionResults ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def setupClass ( cls ) : <EOL> data = longley . load ( ) <EOL> data . exog = add_constant ( data . exog , prepend = False ) <EOL> ols_res = OLS ( data . endog , data . exog ) . fit ( ) <EOL> gls_res = GLS ( data . endog , data . exog ) . fit ( ) <EOL> gls_res_scalar = GLS ( data . endog , data . exog , sigma = <NUM_LIT:1> ) <EOL> cls . endog = data . endog <EOL> cls . exog = data . exog <EOL> cls . res1 = gls_res <EOL> cls . res2 = ols_res <EOL> cls . res3 = gls_res_scalar <EOL> def test_wrong_size_sigma_1d ( self ) : <EOL> n = len ( self . endog ) <EOL> assert_raises ( ValueError , GLS , self . endog , self . exog , sigma = np . ones ( n - <NUM_LIT:1> ) ) <EOL> def test_wrong_size_sigma_2d ( self ) : <EOL> n = len ( self . endog ) <EOL> assert_raises ( ValueError , GLS , self . endog , self . exog , sigma = np . ones ( ( n - <NUM_LIT:1> , n - <NUM_LIT:1> ) ) ) <EOL> class TestLM ( object ) : <EOL> @ classmethod <EOL> def setupClass ( cls ) : <EOL> X = np . random . randn ( <NUM_LIT:100> , <NUM_LIT:3> ) <EOL> b = np . ones ( ( <NUM_LIT:3> , <NUM_LIT:1> ) ) <EOL> e = np . random . randn ( <NUM_LIT:100> , <NUM_LIT:1> ) <EOL> y = np . dot ( X , b ) + e <EOL> cls . res1_full = OLS ( y , X ) . fit ( ) <EOL> cls . res1_restricted = OLS ( y , X [ : , <NUM_LIT:0> ] ) . fit ( ) <EOL> cls . res2_full = cls . res1_full . get_robustcov_results ( '<STR_LIT>' ) <EOL> cls . res2_restricted = cls . res1_restricted . get_robustcov_results ( '<STR_LIT>' ) <EOL> cls . X = X <EOL> cls . Y = y <EOL> def test_LM_homoskedastic ( self ) : <EOL> resid = self . res1_restricted . wresid <EOL> n = resid . shape [ <NUM_LIT:0> ] <EOL> X = self . X <EOL> S = np . dot ( resid , resid ) / n * np . dot ( X . T , X ) / n <EOL> Sinv = np . linalg . inv ( S ) <EOL> s = np . mean ( X * resid [ : , None ] , <NUM_LIT:0> ) <EOL> LMstat = n * np . dot ( np . dot ( s , Sinv ) , s . T ) <EOL> LMstat_OLS = self . res1_full . compare_lm_test ( self . res1_restricted ) <EOL> LMstat2 = LMstat_OLS [ <NUM_LIT:0> ] <EOL> assert_almost_equal ( LMstat , LMstat2 , DECIMAL_7 ) <EOL> def test_LM_heteroskedastic_nodemean ( self ) : <EOL> resid = self . res1_restricted . wresid <EOL> n = resid . shape [ <NUM_LIT:0> ] <EOL> X = self . X <EOL> scores = X * resid [ : , None ] <EOL> S = np . dot ( scores . T , scores ) / n <EOL> Sinv = np . linalg . inv ( S ) <EOL> s = np . mean ( scores , <NUM_LIT:0> ) <EOL> LMstat = n * np . dot ( np . dot ( s , Sinv ) , s . T ) <EOL> LMstat_OLS = self . res2_full . compare_lm_test ( self . res2_restricted , demean = False ) <EOL> LMstat2 = LMstat_OLS [ <NUM_LIT:0> ] <EOL> assert_almost_equal ( LMstat , LMstat2 , DECIMAL_7 ) <EOL> def test_LM_heteroskedastic_demean ( self ) : <EOL> resid = self . res1_restricted . wresid <EOL> n = resid . shape [ <NUM_LIT:0> ] <EOL> X = self . X <EOL> scores = X * resid [ : , None ] <EOL> scores_demean = scores - scores . mean ( <NUM_LIT:0> ) <EOL> S = np . dot ( scores_demean . T , scores_demean ) / n <EOL> Sinv = np . linalg . inv ( S ) <EOL> s = np . mean ( scores , <NUM_LIT:0> ) <EOL> LMstat = n * np . dot ( np . dot ( s , Sinv ) , s . T ) <EOL> LMstat_OLS = self . res2_full . compare_lm_test ( self . res2_restricted ) <EOL> LMstat2 = LMstat_OLS [ <NUM_LIT:0> ] <EOL> assert_almost_equal ( LMstat , LMstat2 , DECIMAL_7 ) <EOL> def test_LM_heteroskedastic_LRversion ( self ) : <EOL> resid = self . res1_restricted . wresid <EOL> resid_full = self . res1_full . wresid <EOL> n = resid . shape [ <NUM_LIT:0> ] <EOL> X = self . X <EOL> scores = X * resid [ : , None ] <EOL> s = np . mean ( scores , <NUM_LIT:0> ) <EOL> scores = X * resid_full [ : , None ] <EOL> S = np . dot ( scores . T , scores ) / n <EOL> Sinv = np . linalg . inv ( S ) <EOL> LMstat = n * np . dot ( np . dot ( s , Sinv ) , s . T ) <EOL> LMstat_OLS = self . res2_full . compare_lm_test ( self . res2_restricted , use_lr = True ) <EOL> LMstat2 = LMstat_OLS [ <NUM_LIT:0> ] <EOL> assert_almost_equal ( LMstat , LMstat2 , DECIMAL_7 ) <EOL> def test_LM_nonnested ( self ) : <EOL> assert_raises ( ValueError , self . res2_restricted . compare_lm_test , self . res2_full ) <EOL> class TestOLS_GLS_WLS_equivalence ( object ) : <EOL> @ classmethod <EOL> def setupClass ( cls ) : <EOL> data = longley . load ( ) <EOL> data . exog = add_constant ( data . exog , prepend = False ) <EOL> y = data . endog <EOL> X = data . exog <EOL> n = y . shape [ <NUM_LIT:0> ] <EOL> w = np . ones ( n ) <EOL> cls . results = [ ] <EOL> cls . results . append ( OLS ( y , X ) . fit ( ) ) <EOL> cls . results . append ( WLS ( y , X , w ) . fit ( ) ) <EOL> cls . results . append ( GLS ( y , X , <NUM_LIT:100> * w ) . fit ( ) ) <EOL> cls . results . append ( GLS ( y , X , np . diag ( <NUM_LIT:0.1> * w ) ) . fit ( ) ) <EOL> def test_ll ( self ) : <EOL> llf = np . array ( [ r . llf for r in self . results ] ) <EOL> llf_1 = np . ones_like ( llf ) * self . results [ <NUM_LIT:0> ] . llf <EOL> assert_almost_equal ( llf , llf_1 , DECIMAL_7 ) <EOL> ic = np . array ( [ r . aic for r in self . results ] ) <EOL> ic_1 = np . ones_like ( ic ) * self . results [ <NUM_LIT:0> ] . aic <EOL> assert_almost_equal ( ic , ic_1 , DECIMAL_7 ) <EOL> ic = np . array ( [ r . bic for r in self . results ] ) <EOL> ic_1 = np . ones_like ( ic ) * self . results [ <NUM_LIT:0> ] . bic <EOL> assert_almost_equal ( ic , ic_1 , DECIMAL_7 ) <EOL> def test_params ( self ) : <EOL> params = np . array ( [ r . params for r in self . results ] ) <EOL> params_1 = np . array ( [ self . results [ <NUM_LIT:0> ] . params ] * len ( self . results ) ) <EOL> assert_allclose ( params , params_1 ) <EOL> def test_ss ( self ) : <EOL> bse = np . array ( [ r . bse for r in self . results ] ) <EOL> bse_1 = np . array ( [ self . results [ <NUM_LIT:0> ] . bse ] * len ( self . results ) ) <EOL> assert_allclose ( bse , bse_1 ) <EOL> def test_rsquared ( self ) : <EOL> rsquared = np . array ( [ r . rsquared for r in self . results ] ) <EOL> rsquared_1 = np . array ( [ self . results [ <NUM_LIT:0> ] . rsquared ] * len ( self . results ) ) <EOL> assert_almost_equal ( rsquared , rsquared_1 , DECIMAL_7 ) <EOL> class TestGLS_WLS_equivalence ( TestOLS_GLS_WLS_equivalence ) : <EOL> @ classmethod <EOL> def setupClass ( cls ) : <EOL> data = longley . load ( ) <EOL> data . exog = add_constant ( data . exog , prepend = False ) <EOL> y = data . endog <EOL> X = data . exog <EOL> n = y . shape [ <NUM_LIT:0> ] <EOL> np . random . seed ( <NUM_LIT:5> ) <EOL> w = np . random . uniform ( <NUM_LIT:0.5> , <NUM_LIT:1> , n ) <EOL> w_inv = <NUM_LIT:1.> / w <EOL> cls . results = [ ] <EOL> cls . results . append ( WLS ( y , X , w ) . fit ( ) ) <EOL> cls . results . append ( WLS ( y , X , <NUM_LIT> * w ) . fit ( ) ) <EOL> cls . results . append ( GLS ( y , X , <NUM_LIT:100> * w_inv ) . fit ( ) ) <EOL> cls . results . append ( GLS ( y , X , np . diag ( <NUM_LIT:0.1> * w_inv ) ) . fit ( ) ) <EOL> def test_rsquared ( self ) : <EOL> assert_almost_equal ( self . results [ <NUM_LIT:1> ] . rsquared , self . results [ <NUM_LIT:0> ] . rsquared , <EOL> DECIMAL_7 ) <EOL> assert_almost_equal ( self . results [ <NUM_LIT:3> ] . rsquared , self . results [ <NUM_LIT:2> ] . rsquared , <EOL> DECIMAL_7 ) <EOL> class TestNonFit ( object ) : <EOL> @ classmethod <EOL> def setupClass ( cls ) : <EOL> data = longley . load ( ) <EOL> data . exog = add_constant ( data . exog , prepend = False ) <EOL> cls . endog = data . endog <EOL> cls . exog = data . exog <EOL> cls . ols_model = OLS ( data . endog , data . exog ) <EOL> def test_df_resid ( self ) : <EOL> df_resid = self . endog . shape [ <NUM_LIT:0> ] - self . exog . shape [ <NUM_LIT:1> ] <EOL> assert_equal ( self . ols_model . df_resid , long ( <NUM_LIT:9> ) ) <EOL> class TestWLS_CornerCases ( object ) : <EOL> @ classmethod <EOL> def setupClass ( cls ) : <EOL> cls . exog = np . ones ( ( <NUM_LIT:1> , ) ) <EOL> cls . endog = np . ones ( ( <NUM_LIT:1> , ) ) <EOL> weights = <NUM_LIT:1> <EOL> cls . wls_res = WLS ( cls . endog , cls . exog , weights = weights ) . fit ( ) <EOL> def test_wrong_size_weights ( self ) : <EOL> weights = np . ones ( ( <NUM_LIT:10> , <NUM_LIT:10> ) ) <EOL> assert_raises ( ValueError , WLS , self . endog , self . exog , weights = weights ) <EOL> class TestWLSExogWeights ( CheckRegressionResults ) : <EOL> def __init__ ( self ) : <EOL> from . results . results_regression import CCardWLS <EOL> from statsmodels . datasets . ccard import load <EOL> dta = load ( ) <EOL> dta . exog = add_constant ( dta . exog , prepend = False ) <EOL> nobs = <NUM_LIT> <EOL> weights = <NUM_LIT:1> / dta . exog [ : , <NUM_LIT:2> ] <EOL> scaled_weights = ( ( weights * nobs ) / weights . sum ( ) ) <EOL> self . res1 = WLS ( dta . endog , dta . exog , weights = scaled_weights ) . fit ( ) <EOL> self . res2 = CCardWLS ( ) <EOL> self . res2 . wresid = scaled_weights ** <NUM_LIT> * self . res2 . resid <EOL> corr_ic = <NUM_LIT:2> * ( self . res1 . llf - self . res2 . llf ) <EOL> self . res2 . aic -= corr_ic <EOL> self . res2 . bic -= corr_ic <EOL> self . res2 . llf += <NUM_LIT:0.5> * np . sum ( np . log ( self . res1 . model . weights ) ) <EOL> def test_wls_example ( ) : <EOL> Y = [ <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] <EOL> X = lrange ( <NUM_LIT:1> , <NUM_LIT:8> ) <EOL> X = add_constant ( X , prepend = False ) <EOL> wls_model = WLS ( Y , X , weights = lrange ( <NUM_LIT:1> , <NUM_LIT:8> ) ) . fit ( ) <EOL> assert_almost_equal ( wls_model . fvalue , <NUM_LIT> , <NUM_LIT:6> ) <EOL> assert_almost_equal ( wls_model . scale , <NUM_LIT> ** <NUM_LIT:2> , <NUM_LIT:6> ) <EOL> def test_wls_tss ( ) : <EOL> y = np . array ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> X = [ [ <NUM_LIT:1> , <NUM_LIT:0> ] , [ <NUM_LIT:1> , <NUM_LIT:0> ] , [ <NUM_LIT:1> , <NUM_LIT:1> ] , [ <NUM_LIT:0> , <NUM_LIT:1> ] , [ <NUM_LIT:0> , <NUM_LIT:1> ] , [ <NUM_LIT:0> , <NUM_LIT:1> ] ] <EOL> ols_mod = OLS ( y , add_constant ( X , prepend = False ) ) . fit ( ) <EOL> yw = np . array ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> Xw = [ [ <NUM_LIT:1> , <NUM_LIT:0> ] , [ <NUM_LIT:1> , <NUM_LIT:1> ] , [ <NUM_LIT:0> , <NUM_LIT:1> ] ] <EOL> w = np . array ( [ <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT> ] ) <EOL> wls_mod = WLS ( yw , add_constant ( Xw , prepend = False ) , weights = w ) . fit ( ) <EOL> assert_equal ( ols_mod . centered_tss , wls_mod . centered_tss ) <EOL> class TestWLSScalarVsArray ( CheckRegressionResults ) : <EOL> @ classmethod <EOL> def setupClass ( cls ) : <EOL> from statsmodels . datasets . longley import load <EOL> dta = load ( ) <EOL> dta . exog = add_constant ( dta . exog , prepend = True ) <EOL> wls_scalar = WLS ( dta . endog , dta . exog , weights = <NUM_LIT:1.> / <NUM_LIT:3> ) . fit ( ) <EOL> weights = [ <NUM_LIT:1> / <NUM_LIT> ] * len ( dta . endog ) <EOL> wls_array = WLS ( dta . endog , dta . exog , weights = weights ) . fit ( ) <EOL> cls . res1 = wls_scalar <EOL> cls . res2 = wls_array <EOL> def test_wls_missing ( ) : <EOL> from statsmodels . datasets . ccard import load <EOL> data = load ( ) <EOL> endog = data . endog <EOL> endog [ [ <NUM_LIT:10> , <NUM_LIT> ] ] = np . nan <EOL> mod = WLS ( data . endog , data . exog , weights = <NUM_LIT:1> / data . exog [ : , <NUM_LIT:2> ] , missing = '<STR_LIT>' ) <EOL> assert_equal ( mod . endog . shape [ <NUM_LIT:0> ] , <NUM_LIT> ) <EOL> assert_equal ( mod . exog . shape [ <NUM_LIT:0> ] , <NUM_LIT> ) <EOL> assert_equal ( mod . weights . shape [ <NUM_LIT:0> ] , <NUM_LIT> ) <EOL> class TestWLS_OLS ( CheckRegressionResults ) : <EOL> @ classmethod <EOL> def setupClass ( cls ) : <EOL> data = longley . load ( ) <EOL> data . exog = add_constant ( data . exog , prepend = False ) <EOL> cls . res1 = OLS ( data . endog , data . exog ) . fit ( ) <EOL> cls . res2 = WLS ( data . endog , data . exog ) . fit ( ) <EOL> def check_confidenceintervals ( self , conf1 , conf2 ) : <EOL> assert_almost_equal ( conf1 , conf2 ( ) , DECIMAL_4 ) <EOL> class TestGLS_OLS ( CheckRegressionResults ) : <EOL> @ classmethod <EOL> def setupClass ( cls ) : <EOL> data = longley . load ( ) <EOL> data . exog = add_constant ( data . exog , prepend = False ) <EOL> cls . res1 = GLS ( data . endog , data . exog ) . fit ( ) <EOL> cls . res2 = OLS ( data . endog , data . exog ) . fit ( ) <EOL> def check_confidenceintervals ( self , conf1 , conf2 ) : <EOL> assert_almost_equal ( conf1 , conf2 ( ) , DECIMAL_4 ) <EOL> class TestYuleWalker ( object ) : <EOL> @ classmethod <EOL> def setupClass ( cls ) : <EOL> from statsmodels . datasets . sunspots import load <EOL> data = load ( ) <EOL> cls . rho , cls . sigma = yule_walker ( data . endog , order = <NUM_LIT:4> , <EOL> method = "<STR_LIT>" ) <EOL> cls . R_params = [ <NUM_LIT> , - <NUM_LIT> , <EOL> - <NUM_LIT> , <NUM_LIT> ] <EOL> def test_params ( self ) : <EOL> assert_almost_equal ( self . rho , self . R_params , DECIMAL_4 ) <EOL> class TestDataDimensions ( CheckRegressionResults ) : <EOL> @ classmethod <EOL> def setupClass ( cls ) : <EOL> np . random . seed ( <NUM_LIT> ) <EOL> cls . endog_n_ = np . random . uniform ( <NUM_LIT:0> , <NUM_LIT:20> , size = <NUM_LIT:30> ) <EOL> cls . endog_n_one = cls . endog_n_ [ : , None ] <EOL> cls . exog_n_ = np . random . uniform ( <NUM_LIT:0> , <NUM_LIT:20> , size = <NUM_LIT:30> ) <EOL> cls . exog_n_one = cls . exog_n_ [ : , None ] <EOL> cls . degen_exog = cls . exog_n_one [ : - <NUM_LIT:1> ] <EOL> cls . mod1 = OLS ( cls . endog_n_one , cls . exog_n_one ) <EOL> cls . mod1 . df_model += <NUM_LIT:1> <EOL> cls . res1 = cls . mod1 . fit ( ) <EOL> cls . mod2 = OLS ( cls . endog_n_one , cls . exog_n_one ) <EOL> cls . mod2 . df_model += <NUM_LIT:1> <EOL> cls . res2 = cls . mod2 . fit ( ) <EOL> def check_confidenceintervals ( self , conf1 , conf2 ) : <EOL> assert_almost_equal ( conf1 , conf2 ( ) , DECIMAL_4 ) <EOL> class TestGLS_large_data ( TestDataDimensions ) : <EOL> @ classmethod <EOL> def setupClass ( cls ) : <EOL> nobs = <NUM_LIT:1000> <EOL> y = np . random . randn ( nobs , <NUM_LIT:1> ) <EOL> X = np . random . randn ( nobs , <NUM_LIT:20> ) <EOL> sigma = np . ones_like ( y ) <EOL> cls . gls_res = GLS ( y , X , sigma = sigma ) . fit ( ) <EOL> cls . gls_res_scalar = GLS ( y , X , sigma = <NUM_LIT:1> ) . fit ( ) <EOL> cls . gls_res_none = GLS ( y , X ) . fit ( ) <EOL> cls . ols_res = OLS ( y , X ) . fit ( ) <EOL> def test_large_equal_params ( self ) : <EOL> assert_almost_equal ( self . ols_res . params , self . gls_res . params , DECIMAL_7 ) <EOL> def test_large_equal_loglike ( self ) : <EOL> assert_almost_equal ( self . ols_res . llf , self . gls_res . llf , DECIMAL_7 ) <EOL> def test_large_equal_params_none ( self ) : <EOL> assert_almost_equal ( self . gls_res . params , self . gls_res_none . params , <EOL> DECIMAL_7 ) <EOL> class TestNxNx ( TestDataDimensions ) : <EOL> @ classmethod <EOL> def setupClass ( cls ) : <EOL> super ( TestNxNx , cls ) . setupClass ( ) <EOL> cls . mod2 = OLS ( cls . endog_n_ , cls . exog_n_ ) <EOL> cls . mod2 . df_model += <NUM_LIT:1> <EOL> cls . res2 = cls . mod2 . fit ( ) <EOL> class TestNxOneNx ( TestDataDimensions ) : <EOL> @ classmethod <EOL> def setupClass ( cls ) : <EOL> super ( TestNxOneNx , cls ) . setupClass ( ) <EOL> cls . mod2 = OLS ( cls . endog_n_one , cls . exog_n_ ) <EOL> cls . mod2 . df_model += <NUM_LIT:1> <EOL> cls . res2 = cls . mod2 . fit ( ) <EOL> class TestNxNxOne ( TestDataDimensions ) : <EOL> @ classmethod <EOL> def setupClass ( cls ) : <EOL> super ( TestNxNxOne , cls ) . setupClass ( ) <EOL> cls . mod2 = OLS ( cls . endog_n_ , cls . exog_n_one ) <EOL> cls . mod2 . df_model += <NUM_LIT:1> <EOL> cls . res2 = cls . mod2 . fit ( ) <EOL> def test_bad_size ( ) : <EOL> np . random . seed ( <NUM_LIT> ) <EOL> data = np . random . uniform ( <NUM_LIT:0> , <NUM_LIT:20> , <NUM_LIT> ) <EOL> assert_raises ( ValueError , OLS , data , data [ <NUM_LIT:1> : ] ) <EOL> def test_const_indicator ( ) : <EOL> np . random . seed ( <NUM_LIT> ) <EOL> X = np . random . randint ( <NUM_LIT:0> , <NUM_LIT:3> , size = <NUM_LIT:30> ) <EOL> X = categorical ( X , drop = True ) <EOL> y = np . dot ( X , [ <NUM_LIT:1.> , <NUM_LIT> , <NUM_LIT> ] ) + np . random . normal ( size = <NUM_LIT:30> ) <EOL> modc = OLS ( y , add_constant ( X [ : , <NUM_LIT:1> : ] , prepend = True ) ) . fit ( ) <EOL> mod = OLS ( y , X , hasconst = True ) . fit ( ) <EOL> assert_almost_equal ( modc . rsquared , mod . rsquared , <NUM_LIT:12> ) <EOL> def test_706 ( ) : <EOL> y = pandas . Series ( np . random . randn ( <NUM_LIT:10> ) ) <EOL> x = pandas . Series ( np . ones ( <NUM_LIT:10> ) ) <EOL> res = OLS ( y , x ) . fit ( ) <EOL> conf_int = res . conf_int ( ) <EOL> np . testing . assert_equal ( conf_int . shape , ( <NUM_LIT:1> , <NUM_LIT:2> ) ) <EOL> np . testing . assert_ ( isinstance ( conf_int , pandas . DataFrame ) ) <EOL> def test_summary ( ) : <EOL> import re <EOL> dta = longley . load_pandas ( ) <EOL> X = dta . exog <EOL> X [ "<STR_LIT>" ] = <NUM_LIT:1> <EOL> y = dta . endog <EOL> with warnings . catch_warnings ( record = True ) : <EOL> res = OLS ( y , X ) . fit ( ) <EOL> table = res . summary ( ) . as_latex ( ) <EOL> table = re . sub ( "<STR_LIT>" , <EOL> "<STR_LIT>" , table ) <EOL> table = re . sub ( "<STR_LIT>" , <EOL> "<STR_LIT>" , table ) <EOL> expected = """<STR_LIT>""" <EOL> assert_equal ( table , expected ) <EOL> class TestRegularizedFit ( object ) : <EOL> def test_empty_model ( self ) : <EOL> np . random . seed ( <NUM_LIT> ) <EOL> n = <NUM_LIT:100> <EOL> endog = np . random . normal ( size = n ) <EOL> exog = np . random . normal ( size = ( n , <NUM_LIT:3> ) ) <EOL> model = OLS ( endog , exog ) <EOL> result = model . fit_regularized ( alpha = <NUM_LIT:1000> ) <EOL> assert_equal ( result . params , <NUM_LIT:0.> ) <EOL> assert_equal ( result . bse , <NUM_LIT:0.> ) <EOL> def test_regularized ( self ) : <EOL> import os <EOL> from . import glmnet_r_results <EOL> cur_dir = os . path . dirname ( os . path . abspath ( __file__ ) ) <EOL> data = np . loadtxt ( os . path . join ( cur_dir , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> delimiter = "<STR_LIT:U+002C>" ) <EOL> tests = [ x for x in dir ( glmnet_r_results ) if x . startswith ( "<STR_LIT>" ) ] <EOL> for test in tests : <EOL> vec = getattr ( glmnet_r_results , test ) <EOL> n = vec [ <NUM_LIT:0> ] <EOL> p = vec [ <NUM_LIT:1> ] <EOL> L1_wt = float ( vec [ <NUM_LIT:2> ] ) <EOL> lam = float ( vec [ <NUM_LIT:3> ] ) <EOL> params = vec [ <NUM_LIT:4> : ] . astype ( np . float64 ) <EOL> endog = data [ <NUM_LIT:0> : int ( n ) , <NUM_LIT:0> ] <EOL> exog = data [ <NUM_LIT:0> : int ( n ) , <NUM_LIT:1> : ( int ( p ) + <NUM_LIT:1> ) ] <EOL> endog = endog - endog . mean ( ) <EOL> endog /= endog . std ( ddof = <NUM_LIT:1> ) <EOL> exog = exog - exog . mean ( <NUM_LIT:0> ) <EOL> exog /= exog . std ( <NUM_LIT:0> , ddof = <NUM_LIT:1> ) <EOL> mod = OLS ( endog , exog ) <EOL> rslt = mod . fit_regularized ( L1_wt = L1_wt , alpha = lam ) <EOL> assert_almost_equal ( rslt . params , params , decimal = <NUM_LIT:3> ) <EOL> smry = rslt . summary ( ) <EOL> def test_formula_missing_cat ( ) : <EOL> import statsmodels . api as sm <EOL> from statsmodels . formula . api import ols <EOL> from patsy import PatsyError <EOL> dta = sm . datasets . grunfeld . load_pandas ( ) . data <EOL> dta . ix [ <NUM_LIT:0> , '<STR_LIT>' ] = np . nan <EOL> mod = ols ( formula = '<STR_LIT>' , <EOL> data = dta . dropna ( ) ) <EOL> res = mod . fit ( ) <EOL> mod2 = ols ( formula = '<STR_LIT>' , <EOL> data = dta ) <EOL> res2 = mod2 . fit ( ) <EOL> assert_almost_equal ( res . params . values , res2 . params . values ) <EOL> assert_raises ( PatsyError , ols , '<STR_LIT>' , <EOL> data = dta , missing = '<STR_LIT>' ) <EOL> def test_missing_formula_predict ( ) : <EOL> nsample = <NUM_LIT:30> <EOL> data = pandas . DataFrame ( { '<STR_LIT:x>' : np . linspace ( <NUM_LIT:0> , <NUM_LIT:10> , nsample ) } ) <EOL> null = pandas . DataFrame ( { '<STR_LIT:x>' : np . array ( [ np . nan ] ) } ) <EOL> data = pandas . concat ( [ data , null ] ) <EOL> beta = np . array ( [ <NUM_LIT:1> , <NUM_LIT:0.1> ] ) <EOL> e = np . random . normal ( size = nsample + <NUM_LIT:1> ) <EOL> data [ '<STR_LIT:y>' ] = beta [ <NUM_LIT:0> ] + beta [ <NUM_LIT:1> ] * data [ '<STR_LIT:x>' ] + e <EOL> model = OLS . from_formula ( '<STR_LIT>' , data = data ) <EOL> fit = model . fit ( ) <EOL> pred = fit . predict ( exog = data [ : - <NUM_LIT:1> ] ) <EOL> def test_fvalue_implicit_constant ( ) : <EOL> nobs = <NUM_LIT:100> <EOL> np . random . seed ( <NUM_LIT:2> ) <EOL> x = np . random . randn ( nobs , <NUM_LIT:1> ) <EOL> x = ( ( x > <NUM_LIT:0> ) == [ True , False ] ) . astype ( int ) <EOL> y = x . sum ( <NUM_LIT:1> ) + np . random . randn ( nobs ) <EOL> w = <NUM_LIT:1> + <NUM_LIT> * np . random . rand ( nobs ) <EOL> from statsmodels . regression . linear_model import OLS , WLS <EOL> res = OLS ( y , x ) . fit ( cov_type = '<STR_LIT>' ) <EOL> assert_ ( np . isnan ( res . fvalue ) ) <EOL> assert_ ( np . isnan ( res . f_pvalue ) ) <EOL> res . summary ( ) <EOL> res = WLS ( y , x ) . fit ( cov_type = '<STR_LIT>' ) <EOL> assert_ ( np . isnan ( res . fvalue ) ) <EOL> assert_ ( np . isnan ( res . f_pvalue ) ) <EOL> res . summary ( ) <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>
