counterfactual.plot.continuous: Create a plot of the distribution of exposure under...

Description Usage Arguments Value Note Author(s) References See Also Examples

View source: R/counterfactual_plot_continuous.R

Description

Function that creates a plot of the distribution of exposure X under counterfactual scenario when exposure is continuous.

Usage

1
2
3
4
5
6
7
8
9
counterfactual.plot.continuous(X, cft, weights = rep(1/nrow(as.matrix(X)),
  nrow(as.matrix(X))), adjust = 1, n = 512, ktype = c("gaussian",
  "epanechnikov", "rectangular", "triangular", "biweight", "cosine",
  "optcosine"), bw = c("SJ", "nrd0", "nrd", "ucv", "bcv"),
  title = "Exposure distribution under current and counterfactual scenarios",
  dnames = c("Current distribution", "Counterfactual distribution"),
  legendtitle = "Scenario", xlab = "Exposure", ylab = "Density",
  fill_limits = c(-Inf, Inf), fill = TRUE, colors = c("deepskyblue",
  "tomato3"), check_exposure = TRUE)

Arguments

X

Univariate vector continuous exposure levels.

cft

Counterfactual function of the exposure cft(X).

**Optional**

weights

Normalized survey weights for the sample X.

adjust

Adjust bandwith parameter from density from density.

n

Number of equally spaced points at which the density is to be estimated (see density).

ktype

kernel type: "gaussian", "epanechnikov", "rectangular", "triangular", "biweight", "cosine", "optcosine" (for kernel method). Additional information on kernels in density.

bw

Smoothing bandwith parameter from density from density. Default "SJ".

title

String with plot title.

dnames

String vector indicating the names of the distributions for the legend.

legendtitle

String title for the legend of plot.

xlab

String label for the X-axis of the plot (corresponding to "a").

ylab

String label for the Y-axis of the plot (corresponding to "b").

fill_limits

Vector. Limits of subset of the exposure X such that only fill_limits[1] < X < fill_limits[2] are filled with color.

fill

Boolean that indicates whether there is interior colouring. Default TRUE.

colors

String vector with colors for plots.

check_exposure

Check that exposure X is positive and numeric.

Value

cft_plot ggplot object plotting the shift from actual to counterfactual distribution.

Note

This function reproduces the classic counterfactual plot from Figure 25.1 of Vander Hoorn as well as additional plots.

Author(s)

Rodrigo Zepeda-Tello rzepeda17@gmail.com

Dalia Camacho-Garc<c3><ad>a-Forment<c3><ad> daliaf172@gmail.com

References

Vander Hoorn, S., Ezzati, M., Rodgers, A., Lopez, A. D., & Murray, C. J. (2004). Estimating attributable burden of disease from exposure and hazard data. Comparative quantification of health risks: global and regional burden of disease attributable to selected major risk factors. Geneva: World Health Organization, 2129-40.

See Also

counterfactual.plot.discrete for plotting discrete counterfactuals, pif for Potential Impact Fraction estimation, pif.heatmap for sensitivity analysis of the counterfactual, pif.plot for a plot of potential impact fraction as a function of the relative risk's parameter theta.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#Example 1: Normal distribution and linear counterfactual
#--------------------------------------------------------
set.seed(2783569)
X   <- data.frame(rnorm(1000, 150, 15))
cft <- function(X){0.35*X + 75}  
counterfactual.plot.continuous(X, cft, xlab = "Usual SBP (mmHg)", 
ylab = "Relative risk of ischaemic heart disease",
dnames = c("Current distribution", "Theoretical Minimum Risk Distribution"),
title = paste0("Effect of a non-linear hazard function and choice", 
               "\nof baseline on total population risk", 
               "\n(Fig 25 from Vander Hoorn et al)"))
  
#Example 2: Counterfactual of BMI reduction only for those with excess-weight (BMI > 25)
#--------------------------------------------------------
set.seed(2783569)
X <- data.frame(Exposure = rlnorm(1000, 3, 0.2))
cft <- function(X){

     #Find individuals with excess weight
     excess_weight <- which(X[,"Exposure"] > 25)
     
     #Set those with excess weight to BMI of 25
     X[excess_weight, "Exposure"] <- 22.5
     
     return(X)
}     

counterfactual.plot.continuous(X, cft, ktype = "epanechnikov")   

#Change bandwidth method to reduce noice
counterfactual.plot.continuous(X, cft, ktype = "epanechnikov", bw = "nrd0")   

#Focus on what happens to the exposure > 23 
counterfactual.plot.continuous(X, cft, ktype = "epanechnikov", bw = "nrd0",
fill_limits = c(23, Inf)) 

#Delete fill
counterfactual.plot.continuous(X, cft, ktype = "epanechnikov", bw = "nrd0", fill = FALSE)   
  

pifpaf documentation built on May 1, 2019, 9:11 p.m.