zepid.calc.utils.semibayes(prior_mean, prior_lcl, prior_ucl, mean, lcl, ucl, ln_transform=False, alpha=0.05, decimal=3, print_results=True)

A simple Bayesian Analysis. Note that this analysis assumes a normal distribution for the continuous measure. See chapter 18 of Modern Epidemiology 3rd Edition (specifically pages 334, 340 for this procedure)

The posterior estimate is calculated as

\[E_{posterior} = \frac{\left(E_{prior} \times \frac{1}{Var_{prior}}\right) + (E \times \frac{1}{Var})}{E_{prior} \times \frac{1}{Var_{prior}}}\]

and the posterior variance is

\[Var_{posterior} = \frac{1}{\frac{1}{Var_{prior}} + \frac{1}{Var}}\]
  • prior_mean (float) – Prior designated point estimate
  • prior_lcl (float) – Prior designated lower confidence limit
  • prior_ucl (float) – Prior designated upper confidence limit
  • mean (float) – Point estimate result obtained from analysis
  • lcl (float) – Lower confidence limit estimate obtained from analysis
  • ucl (float) – Upper confidence limit estimate obtained from analysis
  • ln_transform (bool, optional) – Whether to natural log transform results before conducting analysis. Should be used for RR, OR, or or other Ratio measure. Default is False (use for RD and other absolute measures)
  • alpha (float, optional) – Alpha level for confidence intervals. Default is 0.05
  • decimal (float, optional) – Number of decimal places to display. Default is three
  • print_results (bool, optional) – Whether to print the results of the semi-Bayesian calculations. Default is True

Tuple of posterior mean, posterior lower CL, posterior upper CL

Return type:



Make sure that the alpha used to generate the confidence intervals matches the alpha used in this calculation. Additionally, this calculation can only handle normally distributed priors and observed


Posterior Risk Difference

>>> from zepid.calc import semibayes
>>> semibayes(prior_mean=-0.15, prior_lcl=-0.5, prior_ucl=0.2, mean=-0.1, lcl=-0.3, ucl=0.1, print_results=False)

Posterior Risk Ratio

>>> semibayes(prior_mean=0.9, prior_lcl=0.75, prior_ucl=1.2, mean=0.85, lcl=0.77, ucl=0.91, ln_transform=True)


Rothman KJ, Greenland S, Lash TL. (2008). Modern epidemiology (Vol. 3). Philadelphia: Wolters Kluwer Health/Lippincott Williams & Wilkins.