Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Add bayes glm model #9235

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

cearlefraym
Copy link

@cearlefraym cearlefraym commented Apr 27, 2024

  • tests added / passed.
  • code/documentation is well formatted.
  • properly formatted commit message. See
    NumPy's guide.

The Bayes Generalized Linear Model (BGLM) is available in R through the arm package and was released with the corresponding paper titled A Weakly Informative Default Prior Distribution for Logistic and other Regression Models. BGLM is a Generalized Linear Model (GLM) that accepts prior mean, prior standard deviation, and prior degrees of freedom for the coefficients, and fits a model with additional pseudo-data points.

I was unable to find a Python package that implements the same BGLM algorithm as is found in the arm package. statsmodels does, however, contain a GLM model which was built to provide the same glm functionality in Python as is available in R. Since the bayesglm is built off the glm I used this as a starting point to translate the bayesglm process to Python.

Detailed translation notes can be found in the example notebook bayesglm.ipynb

Notes:

  • It is essential that you add a test when making code changes. Tests are not
    needed for doc changes.
  • When adding a new function, test values should usually be verified in another package (e.g., R/SAS/Stata).
  • When fixing a bug, you must add a test that would produce the bug in main and
    then show that it is fixed with the new code.
  • New code additions must be well formatted. Changes should pass flake8. If on Linux or OSX, you can
    verify you changes are well formatted by running
    git diff upstream/main -u -- "*.py" | flake8 --diff --isolated
    
    assuming flake8 is installed. This command is also available on Windows
    using the Windows System for Linux once flake8 is installed in the
    local Linux environment. While passing this test is not required, it is good practice and it help
    improve code quality in statsmodels.
  • Docstring additions must render correctly, including escapes and LaTeX.

@pep8speaks
Copy link

pep8speaks commented Apr 27, 2024

Hello @cearlefraym! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 2750:1: W391 blank line at end of file
Line 2750:1: W293 blank line contains whitespace

Comment last updated at 2024-04-27 15:40:48 UTC

@cearlefraym cearlefraym changed the title Add bayes glm model ENH: Add bayes glm model Apr 27, 2024
@josef-pkt
Copy link
Member

Note, GPL is not license compatible with our BSD-3 license.
This means statsmodels cannot include code that is a translation of GPL code.
So we cannot accept this code as it is a translation.

Also, statsmodels is mainly focused on frequentist model, with some Bayesian approaches where it provides additional advantages.
AFAIK, for GLM there are Python packages that provide a better support of Baysian models than what we can add in statsmodels, although most packages in scientific python including datascience, machine learning and statistics have BSD/MIT compatible licenses and cannot take code based on GPL licenses code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants