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 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.

Examples

see also subclasses in directory miscmodels

import statsmodels.api as sm data = sm.datasets.spector.load(as_pandas=False) 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)

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

hessian_factor(params[, scale, observed])

Weights for calculating Hessian

information(params)

Fisher information matrix of model.

initialize()

Initialize (possibly re-initialize) a Model instance.

loglike(params)

Log-likelihood of model at params

loglikeobs(params)

Log-likelihood of individual observations at params

nloglike(params)

Negative log-likelihood of model at params

predict(params[, exog])

After a model has been fit predict returns the fitted values.

reduceparams(params)

Reduce parameters

score(params)

Gradient of log-likelihood evaluated at params

score_obs(params, **kwds)

Jacobian/Gradient of log-likelihood evaluated at params for each observation.

Properties

endog_names

Names of endogenous variables.

exog_names

Names of exogenous variables.