Skip to content

Instantly share code, notes, and snippets.

View johnlees's full-sized avatar

John Lees johnlees

View GitHub Profile
@johnlees
johnlees / firth_regression.py
Last active May 9, 2023 19:11
Firth regression in python
#!/usr/bin/env python
'''Python implementation of Firth regression by John Lees
See https://www.ncbi.nlm.nih.gov/pubmed/12758140'''
def firth_likelihood(beta, logit):
return -(logit.loglike(beta) + 0.5*np.log(np.linalg.det(-logit.hessian(beta))))
# Do firth regression
# Note information = -hessian, for some reason available but not implemented in statsmodels
def fit_firth(y, X, start_vec=None, step_limit=1000, convergence_limit=0.0001):