'Fit method for likelihood based models
Parameters
start_params : array-like, optional
An optional
method : str
Method can be \'newton\', \'bfgs\', \'powell\', \'cg\', or \'ncg\'.
The default is newton.  See scipy.optimze for more information.'

def fit(self, start_params=None, method='newton', maxiter=35, tol=1e-08):

    methods = ['newton', 'bfgs', 'powell', 'cg', 'ncg', 'fmin']
    if (start_params is None):
        start_params = ([0] * self.exog.shape[1])
    if (not (method in methods)):
        raise ValueError(('Unknown    fit    method    %s' % method))
    f = (lambda params: (- self.loglike(params)))
    score = (lambda params: (- self.score(params)))
    hess = None
    if (method.lower() == 'newton'):
        iteration = 0
        start = np.array(start_params)
        history = [np.inf, start]
        while ((iteration < maxiter) and np.all((np.abs((history[(-1)] - history[(-2)])) > tol))):
            H = self.hessian(history[(-1)])
            newparams = (history[(-1)] - np.dot(np.linalg.inv(H), self.score(history[(-1)])))
            history.append(newparams)
            iteration += 1
        mlefit = LikelihoodModelResults(self, newparams)
        mlefit.iteration = iteration
    elif (method == 'bfgs'):
        score = None
        (xopt, fopt, gopt, Hopt, func_calls, grad_calls, warnflag) = optimize.fmin_bfgs(f, start_params, score, full_output=1, maxiter=maxiter, gtol=tol)
        converge = (not warnflag)
        mlefit = LikelihoodModelResults(self, xopt)
        optres = 'xopt,    fopt,    gopt,    Hopt,    func_calls,    grad_calls,    warnflag'
        self.optimresults = dict(zip(optres.split(',    '), [xopt, fopt, gopt, Hopt, func_calls, grad_calls, warnflag]))
    elif (method == 'ncg'):
        (xopt, fopt, fcalls, gcalls, hcalls, warnflag) = optimize.fmin_ncg(f, start_params, score, fhess=hess, full_output=1, maxiter=maxiter, avextol=tol)
        mlefit = LikelihoodModelResults(self, xopt)
        converge = (not warnflag)
    elif (method == 'fmin'):
        (xopt, fopt, niter, funcalls, warnflag) = optimize.fmin(f, start_params, full_output=1, maxiter=maxiter, xtol=tol)
        mlefit = LikelihoodModelResults(self, xopt)
        converge = (not warnflag)
    self._results = mlefit
    return mlefit
