zepid.base.interaction_contrast

zepid.base.interaction_contrast(df, exposure, outcome, modifier, adjust=None, decimal=3, print_results=True)

Calculate the Interaction Contrast (IC) using a pandas dataframe and statsmodels to fit a linear binomial regression. Can ONLY be used for a 0,1 coded exposure and modifier (exposure = {0,1}, modifier = {0,1}, outcome = {0,1}). Can handle adjustment for other confounders in the regression model. Prints the fit of the linear binomial regression, the IC, and the corresponding IC 95% confidence interval.

Interaction Contrast is defined as the following

\[IC = RD_{11} - RD_{10} - RD_{01}\]

Note

statsmodels may produce a domain error in some versions.

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’
  • decimal (integer, optional) – Decimal places to display in result. Default is 3
  • print_results (bool, optional) – Whether to print results from interaction contrast assessment

Examples

Setting up environment

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

Calculating interaction contrast for ART and gender

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