Exemple #1
0
    def gradient_momcond(self, params, epsilon=1e-4, method='centered'):

        momcond = self.momcond_mean
        if method == 'centered':
            gradmoms = (approx_fprime1(params, momcond, epsilon=epsilon) +
                    approx_fprime1(params, momcond, epsilon=-epsilon))/2
        else:
            gradmoms = approx_fprime1(params, momcond, epsilon=epsilon)

        return gradmoms
Exemple #2
0
 def grad(self, params=None, **kwds):
     if params is None:
         params = self.params
     kwds.setdefault('epsilon', 1e-4)
     from statsmodels.sandbox.regression.numdiff import approx_fprime1
     return approx_fprime1(params, self.fun, **kwds)
Exemple #3
0
 def grad(self, params=None, **kwds):
     if params is None:
         params = self.params
     kwds.setdefault('epsilon', 1e-4)
     from statsmodels.sandbox.regression.numdiff import approx_fprime1
     return approx_fprime1(params, self.fun, **kwds)
Exemple #4
0
'''

res_bfgs = mod_norm2.fit(start_params=start_params,
                         method="bfgs",
                         fprime=None,
                         maxiter=500,
                         retall=0)

from statsmodels.sandbox.regression.numdiff import approx_fprime1, approx_hess
hb = -approx_hess(res_norm3.params, mod_norm2.loglike, epsilon=-1e-4)[0]
hf = -approx_hess(res_norm3.params, mod_norm2.loglike, epsilon=1e-4)[0]
hh = (hf + hb) / 2.
print np.linalg.eigh(hh)

grad = -approx_fprime1(res_norm3.params, mod_norm2.loglike, epsilon=-1e-4)
print grad
gradb = -approx_fprime1(res_norm3.params, mod_norm2.loglike, epsilon=-1e-4)
gradf = -approx_fprime1(res_norm3.params, mod_norm2.loglike, epsilon=1e-4)
print(gradb + gradf) / 2.

print res_norm3.model.score(res_norm3.params)
print res_norm3.model.score(start_params)
mod_norm2.loglike(start_params / 2.)
print np.linalg.inv(-1 * mod_norm2.hessian(res_norm3.params))
print np.sqrt(np.diag(res_bfgs.cov_params()))
print res_norm3.bse

print "MLE - OLS parameter estimates"
print res_norm3.params[:-1] - res2.params
print "bse diff in percent"
tatsmodels\sandbox\regression\numdiff.py", line 81, in approx_fprime1
    nobs = np.size(f0) #len(f0)
TypeError: object of type 'numpy.float64' has no len()

'''

res_bfgs = mod_norm2.fit(start_params=start_params, method="bfgs", fprime=None,
maxiter = 500, retall=0)

from statsmodels.sandbox.regression.numdiff import approx_fprime1, approx_hess
hb=-approx_hess(res_norm3.params, mod_norm2.loglike, epsilon=-1e-4)[0]
hf=-approx_hess(res_norm3.params, mod_norm2.loglike, epsilon=1e-4)[0]
hh = (hf+hb)/2.
print np.linalg.eigh(hh)

grad = -approx_fprime1(res_norm3.params, mod_norm2.loglike, epsilon=-1e-4)
print grad
gradb = -approx_fprime1(res_norm3.params, mod_norm2.loglike, epsilon=-1e-4)
gradf = -approx_fprime1(res_norm3.params, mod_norm2.loglike, epsilon=1e-4)
print (gradb+gradf)/2.

print res_norm3.model.score(res_norm3.params)
print res_norm3.model.score(start_params)
mod_norm2.loglike(start_params/2.)
print np.linalg.inv(-1*mod_norm2.hessian(res_norm3.params))
print np.sqrt(np.diag(res_bfgs.cov_params()))
print res_norm3.bse

print "MLE - OLS parameter estimates"
print res_norm3.params[:-1] - res2.params
print "bse diff in percent"