zepid.base.interaction_contrast_ratio

zepid.base.interaction_contrast_ratio(df, exposure, outcome, modifier, adjust=None, regression='logit', ci='delta', b_sample=200, alpha=0.05, decimal=5, print_results=True)

Calculate the Interaction Contrast Ratio (ICR) using a pandas dataframe, and conducts either log binomial or logistic regression through statsmodels. Can ONLY be used for a 0,1 coded exposure and modifier (exposure = {0,1}, modifier = {0,1}, outcome = {0,1}). Can handle missing data and adjustment for other confounders in the regression model. Prints the fit of the binomial regression, the ICR, and the corresponding ICR confidence interval

Interaction contrast ratio is defined as

\[ICR = RR_{11} - RR_{10} - RR_{01} + 1\]

Confidence intervals can be generated either through a bootstrap procedure or using the delta method

Parameters:
  • df (DataFrame) – Pandas dataframe containing variables of interest
  • exposure (string) – Column name of exposure variable. Must be coded as (0,1) where 1 is exposure
  • outcome (string) – Column name of outcome variable. Must be coded as (0,1) where 1 is outcome of interest
  • modifier (string) – Column name of modifier variable. Must be coded as (0,1) where 1 is modifier
  • adjust (string, optional) – String of other variables to adjust for, in correct statsmodels format. Default is None. Variables can NOT be named {E1M0,E0M1,E1M1} since this function creates variables with those names. Answers will be incorrect Example of accepted input is ‘C1 + C2 + C3 + Z’
  • regression (string, optional) – Type of regression model to fit. Default is ‘log’ which fits the log-binomial model. Options include: * ‘log’ Log-binomial model. Estimates the Risk Ratio * ‘logit’ Logistic model. Estimates Odds Ratio. Only valid when odds ratio approximates the risk ratio
  • ci (string, optional) – Type of confidence interval to return. Default is the delta method. Options include: * ‘delta’: Delta method as described by Hosmer and Lemeshow (1992) * ‘bootstrap’: bootstrap method (Assmann et al. 1996). The delta method is more time efficient than bootstrap
  • b_sample (integer, optional) – Number of times to resample to generate bootstrap confidence intervals. Only used if bootstrap confidence intervals are requested. Default is 1000
  • alpha (float, optional) – Alpha level for confidence interval. Default is 0.05, which returns 95% confidence intervals
  • decimal (integer, optional) – Decimal places to display in result. Default is 3
  • print_results (bool, optional) – Whether to print results from interaction contrast assessment

Note

statsmodels may produce a domain error for log binomial models in some versions

Examples

Setting up environment

>>> from zepid import interaction_contrast_ratio, load_sample_data
>>> df = load_sample_data(False)

Calculating interaction contrast ratio for ART and gender

>>> interaction_contrast_ratio(df, exposure='art', outcome='dead', modifier='male')

Calculating interaction contrast ratio for ART and gender, confidence intervals from bootstrap

>>> interaction_contrast_ratio(df, exposure='art', outcome='dead', modifier='male', ci='bootstrap')