- class statsmodels.base.model.GenericLikelihoodModel(endog, exog=None, loglike=None, score=None, hessian=None, missing='none', extra_params_names=None, **kwds)¶
Allows the fitting of any likelihood function via maximum likelihood.
A subclass needs to specify at least the log-likelihood If the log-likelihood is specified for each observation, then results that require the Jacobian will be available. (The other case is not tested yet.)
Optimization methods that require only a likelihood function are ‘nm’ and ‘powell’
Optimization methods that require a likelihood function and a score/gradient are ‘bfgs’, ‘cg’, and ‘ncg’. A function to compute the Hessian is optional for ‘ncg’.
Optimization method that require a likelihood function, a score/gradient, and a Hessian is ‘newton’
If they are not overwritten by a subclass, then numerical gradient, Jacobian and Hessian of the log-likelihood are calculated by numerical forward differentiation. This might results in some cases in precision problems, and the Hessian might not be positive definite. Even if the Hessian is not positive definite the covariance matrix of the parameter estimates based on the outer product of the Jacobian might still be valid.
see also subclasses in directory miscmodels
import statsmodels.api as sm data = sm.datasets.spector.load() data.exog = sm.add_constant(data.exog) # in this dir from model import GenericLikelihoodModel probit_mod = sm.Probit(data.endog, data.exog) probit_res = probit_mod.fit() loglike = probit_mod.loglike score = probit_mod.score mod = GenericLikelihoodModel(data.endog, data.exog, loglike, score) res = mod.fit(method=”nm”, maxiter = 500) import numpy as np np.allclose(res.params, probit_res.params)
expand to full parameter array when some parameters are fixed
fit([start_params, method, maxiter, ...])
Fit method for likelihood based models
from_formula(formula, data[, subset, drop_cols])
Create a Model from a formula and dataframe.
Hessian of log-likelihood evaluated at params
hessian_factor(params[, scale, observed])
Weights for calculating Hessian
Fisher information matrix of model.
Initialize (possibly re-initialize) a Model instance.
Log-likelihood of model at params
Log-likelihood of the model for all observations at params.
Negative log-likelihood of model at params
After a model has been fit predict returns the fitted values.
Gradient of log-likelihood evaluated at params
Jacobian/Gradient of log-likelihood evaluated at params for each observation.
Names of endogenous variables.
Names of exogenous variables.