statsmodels.base.model.GenericLikelihoodModel¶
-
class
statsmodels.base.model.
GenericLikelihoodModel
(endog, exog=None, loglike=None, score=None, hessian=None, missing='none', extra_params_names=None, **kwds)[source]¶ 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.)
Notes
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 caclulated 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.
Examples
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)
Attributes
endog_names
Names of endogenous variables exog_names
Names of exogenous variables Methods
expandparams
(params)expand to full parameter array when some parameters are fixed fit
([start_params, method, maxiter, ...])Fit the model using maximum likelihood. from_formula
(formula, data[, subset, drop_cols])Create a Model from a formula and dataframe. hessian
(params)Hessian of log-likelihood evaluated at params information
(params)Fisher information matrix of model initialize
()jac
(*args, **kwds)jac is deprecated, use score_obs instead! loglike
(params)loglikeobs
(params)nloglike
(params)predict
(params[, exog])After a model has been fit predict returns the fitted values. reduceparams
(params)score
(params)Gradient of log-likelihood evaluated at params score_obs
(params, **kwds)Jacobian/Gradient of log-likelihood evaluated at params for each observation. Methods
expandparams
(params)expand to full parameter array when some parameters are fixed fit
([start_params, method, maxiter, ...])Fit the model using maximum likelihood. from_formula
(formula, data[, subset, drop_cols])Create a Model from a formula and dataframe. hessian
(params)Hessian of log-likelihood evaluated at params information
(params)Fisher information matrix of model initialize
()jac
(*args, **kwds)jac is deprecated, use score_obs instead! loglike
(params)loglikeobs
(params)nloglike
(params)predict
(params[, exog])After a model has been fit predict returns the fitted values. reduceparams
(params)score
(params)Gradient of log-likelihood evaluated at params score_obs
(params, **kwds)Jacobian/Gradient of log-likelihood evaluated at params for each observation. Attributes
endog_names
Names of endogenous variables exog_names
Names of exogenous variables