class statsmodels.genmod.bayes_mixed_glm.BinomialBayesMixedGLM(endog, exog, exog_vc, ident, vcp_p=1, fe_p=2, fep_names=None, vcp_names=None, vc_names=None)
[source]
Fit a generalized linear mixed model using Bayesian methods.
The class implements the Laplace approximation to the posterior distribution (fit_map
) and a variational Bayes approximation to the posterior (fit_vb
). See the two fit method docstrings for more information about the fitting approaches.
Parameters: |
|
---|---|
Returns: | |
Return type: |
MixedGLMResults object |
There are three types of values in the posterior distribution: fixed effects parameters (fep), corresponding to the columns of exog
, random effects realizations (vc), corresponding to the columns of exog_vc
, and the standard deviations of the random effects realizations (vcp), corresponding to the unique labels in ident
.
All random effects are modeled as being independent Gaussian values (given the variance parameters). Every column of exog_vc
has a distinct realized random effect that is used to form the linear predictors. The elements of ident
determine the distinct random effect variance parameters. Two random effect realizations that have the same value in ident
are constrained to have the same variance. When fitting with a formula, ident
is constructed internally (each element of vc_formulas
yields a distinct label in ident
).
The random effect standard deviation parameters (vcp) have log-normal prior distributions with mean 0 and standard deviation vcp_p
.
Note that for some families, e.g. Binomial, the posterior mode may be difficult to find numerically if vcp_p
is set to too large of a value. Setting vcp_p
to 0.5 seems to work well.
The prior for the fixed effects parameters is Gaussian with mean 0 and standard deviation fe_p
.
A binomial (logistic) random effects model with random intercepts for villages and random slopes for each year within each village:
>>> data['year_cen'] = data['Year'] - data.Year.mean() >>> random = ['0 + C(Village)', '0 + C(Village)*year_cen'] >>> model = BinomialBayesMixedGLM.from_formula('y ~ year_cen', random, data) >>> result = model.fit()
Introduction to generalized linear mixed models: https://stats.idre.ucla.edu/other/mult-pkg/introduction-to-generalized-linear-mixed-models
SAS documentation: https://support.sas.com/documentation/cdl/en/statug/63033/HTML/default/viewer.htm#statug_intromix_a0000000215.htm
An assessment of estimation methods for generalized linear mixed models with binary outcomes https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3866838/
fit () | Fit a model to data. |
fit_map ([method, minim_opts]) | Construct the Laplace approximation to the posterior distribution. |
fit_vb ([mean, sd, fit_method, minim_opts, …]) | Fit a model using the variational Bayes mean field approximation. |
from_formula (formula, vc_formulas, data[, …]) | Fit a BayesMixedGLM using a formula. |
logposterior (params) | The overall log-density: log p(y, fe, vc, vcp). |
logposterior_grad (params) | The gradient of the log posterior. |
predict (params[, exog]) | After a model has been fit predict returns the fitted values. |
vb_elbo (vb_mean, vb_sd) | Returns the evidence lower bound (ELBO) for the model. |
vb_elbo_base (h, tm, fep_mean, vcp_mean, …) | Returns the evidence lower bound (ELBO) for the model. |
vb_elbo_grad (vb_mean, vb_sd) | Returns the gradient of the model’s evidence lower bound (ELBO). |
vb_elbo_grad_base (h, tm, tv, fep_mean, …) | Return the gradient of the ELBO function. |
endog_names | Names of endogenous variables |
exog_names | Names of exogenous variables |
rng | |
verbose |
© 2009–2012 Statsmodels Developers
© 2006–2008 Scipy Developers
© 2006 Jonathan E. Taylor
Licensed under the 3-clause BSD License.
http://www.statsmodels.org/stable/generated/statsmodels.genmod.bayes_mixed_glm.BinomialBayesMixedGLM.html