View source: R/plot_calibration.R
calibration.plot | R Documentation |
This function makes the calibration plot of matched pairs, i.e. the agreement between observed and predicted pairwise treatment effect. Please note, this function is only applicable for binary outcomes.
calibration.plot(
matched.patients = NULL,
g = 5,
plot.CI = FALSE,
show = TRUE,
...
)
matched.patients |
dataframe; dataframe of matched patients, which contains predicted treatment effect of matched patients (matched.tau.hat) and observed treatment effect (matched.tau.obs) of matched patients |
g |
integer; indicating the number of groups in calibration plot |
plot.CI |
boolean; TRUE if you want to plot the confidence interval of the calibration plot of predicted versus observed treatment effect of matched patients |
show |
boolean; TRUE if you want to show the plot; FALSE if not |
... |
additional arguments for loess function from loess package |
The output of the E.for.benefit function is a "list" with the following components.
matched.patients
a dataframe containing the matched patients.
build.plot
ggplot2 object of the plot.
quantiles
of treatment effect.
se.quantiles
standard error of quantiles of treatment effect.
library(HTEPredictionMetrics)
set.seed(1)
n <- 100
Y <- sample(0:1, n, replace=TRUE)
W <- sample(0:1, n, replace=TRUE)
X <- matrix(rnorm(n*4), n, 4)
p.0 <- runif(n)
p.1 <- runif(n)
tau.hat <- runif(n)
g <- 5 # number of groups in calibration plot
# OPTION 1
matched.patients <- match.patients(Y=Y, W=W, X=X,
p.0=p.0, p.1=p.1, tau.hat=tau.hat,
CI=FALSE, message=TRUE,
measure="nearest", distance="mahalanobis",
estimand=NULL)
CP <- calibration.plot(matched.patients=matched.patients$df.matched.patients, g=g,
plot.CI=TRUE, show=TRUE)
# OPTION 2
EB.out <- E.for.Benefit(Y=Y, W=W, X=X, p.0=p.0, p.1=p.1, tau.hat=tau.hat,
CI=TRUE, nr.bootstraps=100, message=TRUE,
matched.patients=NULL,
measure="nearest", distance="mahalanobis",
estimand=NULL)
CP <- calibration.plot(matched.patients=EB.out$matched.patients, g=g,
plot.CI=TRUE, show=TRUE)
# EDIT THE CALIBRATION PLOT USING GGPLOT
CP$build.plot <- CP$build.plot+ggplot2::scale_x_continuous(limits=c(-1, 1))
show(CP)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.