View source: R/calibrate_dag_S3.r
| plot.calibrated_DAG | R Documentation |
calibrated_DAG object
This function may be used to visually inspect how well a calibrate_dag function call was able to approximate the desired targets. If fitted with n_reps_eval > 1, it plots the distribution of the targets estimated on the n_reps_eval evaluation datasets using the determined parameters. Alternatively plots the bias directly.
## S3 method for class 'calibrated_DAG'
plot(x, type="errors", xlab=NULL,
ylab="auto", line_at_0=TRUE, ...)
x |
A |
type |
A single character string, specifying what should be plotted. Should be either |
xlab |
A single character string specifying the name of the x-axis or |
ylab |
A single character string specifying the name of the y-axis or |
line_at_0 |
Either |
... |
Further arguments passed to the |
The function internally relies on the ggplot2 package, so any further ggplot2 syntax may be used to customize the plot. Its main use is to visually assess whether the observed discrepancy between the estimated and desired targets is due to sampling error or a genuine difference.
Returns a standard ggplot2 object.
Robin Denz
# Jointly calibrate treatment and outcome prevalence.
# The DAG contains two free parameters and two targets.
# Parameter ranges are optional.
ldag <- lazy_dag(
empty_dag() +
node("X", type="rnorm") +
node("A", type="binomial",
formula= ~ param(intercept_A) + X * 0.5) +
node("Y", type="binomial",
formula= ~ param(intercept_Y) + A * 0.7 + X * 0.4)
)
targets <- list(
prevalence_A = list(
target = 0.4,
eval_fun = function(data) mean(data$A)
),
prevalence_Y = list(
target = 0.3,
eval_fun = function(data) mean(data$Y)
)
)
params <- list(
intercept_A = list(start = 0),
intercept_Y = list(start = 0)
)
fit <- calibrate_dag(
lazy_dag = ldag,
targets = targets,
params = params,
n_sim_run = 2000,
n_sim_eval = 1000,
n_reps_eval = 10,
seed = 123,
optim_control = list(
maxit = 200,
trace = 0,
ndeps = c(0.05, 0.05),
factr = 100
)
)
summary(fit)
# plot the targets directly
plot(fit, type="targets")
# plot the errors instead
plot(fit, type="errors")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.