Description Usage Arguments Value Note Author(s) References See Also Examples
View source: R/counterfactual_plot_continuous.R
Function that creates a plot of the distribution of exposure
X
under counterfactual scenario when exposure is continuous.
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)
|
X |
Univariate |
cft |
Counterfactual function of the exposure **Optional** |
weights |
Normalized survey |
adjust |
Adjust bandwith parameter from density from
|
n |
Number of equally spaced points at which the density is to be
estimated (see |
ktype |
|
bw |
Smoothing bandwith parameter from density from
|
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 |
fill |
Boolean that indicates whether there is interior colouring. Default |
colors |
String vector with colors for plots. |
check_exposure |
Check that exposure |
cft_plot ggplot
object plotting the shift
from actual to counterfactual distribution.
This function reproduces the classic counterfactual plot from Figure 25.1 of Vander Hoorn as well as additional plots.
Rodrigo Zepeda-Tello rzepeda17@gmail.com
Dalia Camacho-Garc<c3><ad>a-Forment<c3><ad> daliaf172@gmail.com
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.
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
.
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.