1
-
2
1
from __future__ import print_function
3
2
import numpy as np
4
3
from scipy import stats
@@ -24,9 +23,10 @@ def __init__(self, model, params, **kwd):
24
23
def initialize (self , model , params , ** kwd ):
25
24
self .params = params
26
25
self .model = model
27
- if hasattr (model , ' k_constant' ):
26
+ if hasattr (model , " k_constant" ):
28
27
self .k_constant = model .k_constant
29
28
29
+
30
30
# TODO: public method?
31
31
32
32
@@ -176,61 +176,69 @@ class LikelihoodModelResults(Results):
176
176
True: converged. False: did not converge.
177
177
allvecs : list
178
178
Results at each iteration.
179
- """
179
+ """
180
180
181
181
# by default we use normal distribution
182
182
# can be overwritten by instances or subclasses
183
183
use_t = False
184
184
185
- def __init__ (self , model , params , normalized_cov_params = None , scale = 1. ,
186
- ** kwargs ):
185
+ def __init__ (self , model , params , normalized_cov_params = None , scale = 1.0 , ** kwargs ):
187
186
super (LikelihoodModelResults , self ).__init__ (model , params )
188
187
self .normalized_cov_params = normalized_cov_params
189
188
self .scale = scale
190
189
191
190
# robust covariance
192
191
# We put cov_type in kwargs so subclasses can decide in fit whether to
193
192
# use this generic implementation
194
- if ' use_t' in kwargs :
195
- use_t = kwargs [' use_t' ]
193
+ if " use_t" in kwargs :
194
+ use_t = kwargs [" use_t" ]
196
195
if use_t is not None :
197
196
self .use_t = use_t
198
- if 'cov_type' in kwargs :
199
- cov_type = kwargs .get ('cov_type' , 'nonrobust' )
200
- cov_kwds = kwargs .get ('cov_kwds' , {})
201
-
202
- if cov_type == 'nonrobust' :
203
- self .cov_type = 'nonrobust'
204
- self .cov_kwds = {'description' : 'Standard Errors assume that the ' +
205
- 'covariance matrix of the errors is correctly ' +
206
- 'specified.' }
197
+ if "cov_type" in kwargs :
198
+ cov_type = kwargs .get ("cov_type" , "nonrobust" )
199
+ cov_kwds = kwargs .get ("cov_kwds" , {})
200
+
201
+ if cov_type == "nonrobust" :
202
+ self .cov_type = "nonrobust"
203
+ self .cov_kwds = {
204
+ "description" : "Standard Errors assume that the "
205
+ + "covariance matrix of the errors is correctly "
206
+ + "specified."
207
+ }
207
208
else :
208
209
from statsmodels .base .covtype import get_robustcov_results
210
+
209
211
if cov_kwds is None :
210
212
cov_kwds = {}
211
213
use_t = self .use_t
212
214
# TODO: we shouldn't need use_t in get_robustcov_results
213
- get_robustcov_results (self , cov_type = cov_type , use_self = True ,
214
- use_t = use_t , ** cov_kwds )
215
+ get_robustcov_results (
216
+ self , cov_type = cov_type , use_self = True , use_t = use_t , ** cov_kwds
217
+ )
215
218
216
219
def normalized_cov_params (self ):
217
220
raise NotImplementedError
218
221
219
- def _get_robustcov_results (self , cov_type = 'nonrobust' , use_self = True ,
220
- use_t = None , ** cov_kwds ):
222
+ def _get_robustcov_results (
223
+ self , cov_type = "nonrobust" , use_self = True , use_t = None , ** cov_kwds
224
+ ):
221
225
from statsmodels .base .covtype import get_robustcov_results
226
+
222
227
if cov_kwds is None :
223
228
cov_kwds = {}
224
229
225
- if cov_type == 'nonrobust' :
226
- self .cov_type = 'nonrobust'
227
- self .cov_kwds = {'description' : 'Standard Errors assume that the ' +
228
- 'covariance matrix of the errors is correctly ' +
229
- 'specified.' }
230
+ if cov_type == "nonrobust" :
231
+ self .cov_type = "nonrobust"
232
+ self .cov_kwds = {
233
+ "description" : "Standard Errors assume that the "
234
+ + "covariance matrix of the errors is correctly "
235
+ + "specified."
236
+ }
230
237
else :
231
238
# TODO: we shouldn't need use_t in get_robustcov_results
232
- get_robustcov_results (self , cov_type = cov_type , use_self = True ,
233
- use_t = use_t , ** cov_kwds )
239
+ get_robustcov_results (
240
+ self , cov_type = cov_type , use_self = True , use_t = use_t , ** cov_kwds
241
+ )
234
242
235
243
@cache_readonly
236
244
def llf (self ):
@@ -250,13 +258,14 @@ def tvalues(self):
250
258
@cache_readonly
251
259
def pvalues (self ):
252
260
if self .use_t :
253
- df_resid = getattr (self , ' df_resid_inference' , self .df_resid )
261
+ df_resid = getattr (self , " df_resid_inference" , self .df_resid )
254
262
return stats .t .sf (np .abs (self .tvalues ), df_resid ) * 2
255
263
else :
256
264
return stats .norm .sf (np .abs (self .tvalues )) * 2
257
265
258
- def cov_params (self , r_matrix = None , column = None , scale = None , cov_p = None ,
259
- other = None ):
266
+ def cov_params (
267
+ self , r_matrix = None , column = None , scale = None , cov_p = None , other = None
268
+ ):
260
269
"""
261
270
Returns the variance/covariance matrix.
262
271
The variance/covariance matrix can be of a linear contrast
@@ -293,24 +302,30 @@ def cov_params(self, r_matrix=None, column=None, scale=None, cov_p=None,
293
302
OR
294
303
``(scale) * (X.T X)^(-1)[column][:,column]`` if column is 1d
295
304
"""
296
- if (hasattr (self , 'mle_settings' ) and
297
- self .mle_settings ['optimizer' ] in ['l1' , 'l1_cvxopt_cp' ]):
305
+ if hasattr (self , "mle_settings" ) and self .mle_settings ["optimizer" ] in [
306
+ "l1" ,
307
+ "l1_cvxopt_cp" ,
308
+ ]:
298
309
dot_fun = nan_dot
299
310
else :
300
311
dot_fun = np .dot
301
312
302
- if (cov_p is None and self .normalized_cov_params is None and
303
- not hasattr (self , 'cov_params_default' )):
304
- raise ValueError ('need covariance of parameters for computing '
305
- '(unnormalized) covariances' )
313
+ if (
314
+ cov_p is None
315
+ and self .normalized_cov_params is None
316
+ and not hasattr (self , "cov_params_default" )
317
+ ):
318
+ raise ValueError (
319
+ "need covariance of parameters for computing "
320
+ "(unnormalized) covariances"
321
+ )
306
322
if column is not None and (r_matrix is not None or other is not None ):
307
- raise ValueError ('Column should be specified without other '
308
- 'arguments.' )
323
+ raise ValueError ("Column should be specified without other " "arguments." )
309
324
if other is not None and r_matrix is None :
310
- raise ValueError (' other can only be specified with r_matrix' )
325
+ raise ValueError (" other can only be specified with r_matrix" )
311
326
312
327
if cov_p is None :
313
- if hasattr (self , ' cov_params_default' ):
328
+ if hasattr (self , " cov_params_default" ):
314
329
cov_p = self .cov_params_default
315
330
else :
316
331
if scale is None :
@@ -337,7 +352,7 @@ def cov_params(self, r_matrix=None, column=None, scale=None, cov_p=None,
337
352
else : # if r_matrix is None and column is None:
338
353
return cov_p
339
354
340
- def conf_int (self , alpha = .05 , cols = None , method = ' default' ):
355
+ def conf_int (self , alpha = 0 .05 , cols = None , method = " default" ):
341
356
"""
342
357
Returns the confidence interval of the fitted parameters.
343
358
@@ -396,7 +411,7 @@ def conf_int(self, alpha=.05, cols=None, method='default'):
396
411
397
412
if self .use_t :
398
413
dist = stats .t
399
- df_resid = getattr (self , ' df_resid_inference' , self .df_resid )
414
+ df_resid = getattr (self , " df_resid_inference" , self .df_resid )
400
415
q = dist .ppf (1 - alpha / 2 , df_resid )
401
416
else :
402
417
dist = stats .norm
0 commit comments