Sensitivity analyses¶
Details for sensitivity analysis tools implemented within zEpid.
Distributions¶
trapezoidal (mini, mode1, mode2, maxi[, size]) 
Generates random data following a trapezoidal distribution. 
Sensitivity analyzers¶
MonteCarloRR (observed_RR[, sd, sample]) 
Monte Carlo simulation to assess the impact of an unmeasured binary confounder on the results of a study. 

zepid.sensitivity_analysis.distributions.
trapezoidal
(mini, mode1, mode2, maxi, size=None)¶ Generates random data following a trapezoidal distribution. This function can be used to generate distributions of probabilities and effect measures for sensitivity analyses. It is particularly useful when used in conjunction with rr_corr to determine a distribution of potential results due to a single unadjusted confounder
Parameters:  mini (float) – Minimum value of trapezoidal distribution
 mode1 (float) – Start of uniform distribution
 mode2 (float) – End of uniform distribution
 maxi (float) – Maximum value of trapezoidal distribution
 size (int, optional) – Number of observations to generate. Default is None, which returns a single draw
Returns: Returns either a single float from the distribution or an array of floats
Return type: float or array
Examples
Single draw from a trapezoidal distribution
>>>from zepid.sensitivity_analysis import trapezoidal >>>trapezoidal(mini=0.2, mode1=0.3, mode2=0.5, maxi=0.6)
100 draws from a trapezoidal distribution
>>>trapezoidal(mini=0.2, mode1=0.3, mode2=0.5, maxi=0.6, size=100)
References
Fox MP, Lash TL, Hamer DH. (2005). A sensitivity analysis of a randomized controlled trial of zinc in treatment of falciparum malaria in children. Contemporary clinical trials, 26(3), 281289.
Fox MP, Lash TL Greenland S. (2005). A method to automate probabilistic sensitivity analyses of misclassified binary variables. International journal of epidemiology, 34(6), 13701376.

class
zepid.sensitivity_analysis.Simple.
MonteCarloRR
(observed_RR, sd=None, sample=10000)¶ Monte Carlo simulation to assess the impact of an unmeasured binary confounder on the results of a study. Observed RR comes from the data analysis, while the RR between the unmeasured confounder and the outcome should be obtained from prior literature or constitute an reasonable guess. Probability of exposure between the groups should also be reasonable numbers.
The Monte Carlo corrected Risk Ratio is calculated in each iteration by
\[RR_{MC} = \frac{RR_{obs}}{\frac{p_1(RR_{c}  1) + 1}{p_0(RR_{c}  1) + 1}}\]Parameters:  observed_RR (float) – Observed RR from the data, not accounting for some binary unmeasured confounder
 sd (float, optional) – Standard deviation of the observed log(risk ratio). This parameter is optional. If specified, then random error is incorporated into the bias analysis estimates
 sample (integer, optional) – Number of MC simulations to run. It is important that the specified size of later distributions matches this number of samples
Examples
Monte Carlo bias analysis with trapezoidal distributions
>>> from zepid.sensitivity_analysis import MonteCarloRR, trapezoidal >>> mcrr = MonteCarloRR(observed_RR=0.73322, sample=10000) >>> mcrr.confounder_RR_distribution(trapezoidal(mini=0.9, mode1=1.1, mode2=1.7, maxi=1.8, size=10000)) >>> mcrr.prop_confounder_exposed(trapezoidal(mini=0.25, mode1=0.28, mode2=0.32, maxi=0.35, size=10000)) >>> mcrr.prop_confounder_unexposed(trapezoidal(mini=0.55, mode1=0.58, mode2=0.62, maxi=0.65, size=10000)) >>> mcrr.fit()
Printing a summarization of the bias analysis to the console
>>> mcrr.summary()
Creating a density plot of the bias analysis results
>>> import matplotlib.pyplot as plt >>> mcrr.plot() >>> plt.show()

confounder_RR_distribution
(dist, seed=None)¶ Distribution of the risk ratio between the unmeasured confounder and the outcome. This value should come from prior literature or a reasonable guess. Any numpy random distribution can be based to this function. Alternatively, the trapezoid distribution within this library can also be used
Parameters:  dist – Distribution from which the confounderoutcome Risk Ratio is pulled from. Input should be something like numpy.random.triangular(left=0.9,mode=1.2,right=1.6) or zepid.sensitivity_analysis.trapezoidal
 seed (int, optional) – NumPy seed for the generated distribution. Default is None

fit
()¶ After the observed Risk Ratio, distribution of the confounderoutcome Risk Ratio, proportion of the unmeasured confounder in exposed, proportion of the unmeasured confounder in the unexposed.
\[RR* = RR / d d = (p1 * (RRc1) + 1) / (p0 * (RRc  1) + 1)\]Where RR* is the corrected risk ratio, RR is the observed risk ratio in the data set, RRc is the risk ratio between unmeasured confounder and outcome, p1 is the probability/proportion of unmeasured confounder in exposed, and p0 is the probability/proportion of unmeasured confounder in unexposed

plot
(bw_method='scott', fill=True, color='b')¶ Generate a Gaussian kernel density plot of the corrected risk ratio distribution. The kernel density used is SciPy’s Gaussian kernel. Either Scott’s Rule or Silverman’s Rule can be implemented
Parameters:  bw_method (str, optional) – Method used to estimate the bandwidth. Following SciPy, either ‘scott’ or ‘silverman’ are valid options
 fill (bool, optional) – Whether to color the area under the density curves. Default is true
 color (str, optional) – Color of the line/area for the treated group. Default is Blue
Returns: Return type: matplotlib axes

prop_confounder_exposed
(dist, seed=None)¶ Distribution of the proportion of the unmeasured confounder in the exposed group. This value should come from prior literature or a reasonable guess. Any numpy random distribution can be based to this function. Alternatively, the trapezoid distribution within this library can also be used
Parameters:  dist – Distribution from which the confounderexposure probability is pulled from. Input should be something like numpy.random.triangular(left=0.9,mode=1.2,right=1.6) or zepid.sensitivity_analysis.trapezoidal
 seed (int, optional) – NumPy seed for the generated distribution. Default is None

prop_confounder_unexposed
(dist, seed=None)¶ Distribution of the proportion of the unmeasured confounder in the unexposed group. This value should come from prior literature or a reasonable guess. Any numpy random distribution can be based to this function. Alternatively, the trapezoid distribution within this library can also be used
Parameters:  dist – Distribution from which the confounderno exposure probability is pulled from. Input should be something like numpy.random.triangular(left=0.9,mode=1.2,right=1.6) or zepid.sensitivity_analysis.trapezoidal
 seed (int, optional) – NumPy seed for the generated distribution. Default is None

summary
(decimal=3)¶ Generate the summary information after the corrected risk ratio distribution is generated. fit() must be run before this
Parameters: decimal (int, optional) – Decimal places to display in output. Default is 3