Generic Maximum Likelihood Estimator


In [ ]:
import numpy as np
from scipy import stats
import statsmodels.api as sm
from statsmodels.base.model import GenericLikelihoodModel

In [ ]:
print sm.datasets.spector.NOTE

In [ ]:
data = sm.datasets.spector.load_pandas()
exog = sm.add_constant(data.exog, prepend=True)
endog = data.endog

In [ ]:
sm_probit = sm.Probit(endog, exog).fit()
* To create your own Likelihood Model, you just need to overwrite the loglike method.

In [ ]:
class MyProbit(GenericLikelihoodModel):
    def loglike(self, params):
        exog = self.exog
        endog = self.endog
        q = 2 * endog - 1
        return stats.norm.logcdf(q*np.dot(exog, params)).sum()

In [ ]:
my_probit = MyProbit(endog, exog).fit()

In [ ]:
print sm_probit.params

In [ ]:
print sm_probit.cov_params()

In [ ]:
print my_probit.params
You can get the variance-covariance of the parameters. Notice that we didn't have to provide Hessian or Score functions.

In [ ]:
print my_probit.cov_params()