1
"""Base Classes for Likelihood Models in time series analysis
3
Warning: imports numdifftools
7
Created on Sun Oct 10 15:00:47 2010
16
import numdifftools as ndt
18
from scikits.statsmodels.model import LikelihoodModel
20
#copied from sandbox/regression/mle.py
21
#TODO: I take it this is only a stub and should be included in another
23
class TSMLEModel(LikelihoodModel):
25
univariate time series model for estimation with maximum likelihood
27
Note: This is not working yet
30
def __init__(self, endog, exog=None):
31
#need to override p,q (nar,nma) correctly
32
super(TSMLEModel, self).__init__(endog, exog)
33
#set default arma(1,1)
38
def geterrors(self, params):
39
raise NotImplementedError
41
def loglike(self, params):
43
Loglikelihood for timeseries model
47
needs to be overwritten by subclass
49
raise NotImplementedError
52
def score(self, params):
54
Score vector for Arma model
58
jac = ndt.Jacobian(self.loglike, stepMax=1e-4)
59
return jac(params)[-1]
61
def hessian(self, params):
63
Hessian of arma model. Currently uses numdifftools
66
Hfun = ndt.Jacobian(self.score, stepMax=1e-4)
67
return Hfun(params)[-1]
70
def fit(self, start_params=None, maxiter=5000, method='fmin', tol=1e-08):
71
'''estimate model by minimizing negative loglikelihood
73
does this need to be overwritten ?
75
if start_params is None and hasattr(self, '_start_params'):
76
start_params = self._start_params
77
#start_params = np.concatenate((0.05*np.ones(self.nar + self.nma), [1]))
78
mlefit = super(TSMLEModel, self).fit(start_params=start_params,
79
maxiter=maxiter, method=method, tol=tol)
b'\\ No newline at end of file'