Extract estimates and confidence bands of an effect curve
Source:R/as.data.frame.effect_curve.R
as.data.frame.effect_curve.Rdas.data.frame() returns the estimates of an effect curve at its grid points and the limits of their confidence bands as a data frame. These are the values plot() displays, so the data frame can be used to build a custom plot of the effect curve.
Usage
# S3 method for class 'effect_curve'
as.data.frame(
x,
row.names = NULL,
optional = FALSE,
conf_level = 0.95,
simultaneous = TRUE,
subset = NULL,
outcome = NULL,
proj = NULL,
transform = TRUE,
ci.type = "perc",
df = NULL,
...
)Arguments
- x
an
effect_curveobject; the output of a call toadrf()or functions that modify it.- row.names
NULLor a character vector of row names for the returned data frame. Default isNULLto use the row numbers.- optional
ignored.
- conf_level
the desired confidence level. Default is .95 for 95% confidence bands.
- simultaneous
logical; whether the computed confidence bands should be simultaneous (TRUE) or pointwise (FALSE). Simultaneous (also known as uniform) bands cover the full line at the desired confidence level, whereas pointwise confidence bands only cover each point at the desired level. Default isTRUE. See Details.- subset
an optional logical expression indicating the subset of the subgroups to plot. Can only be used when
bywas supplied to the original call toadrf(), and only to refer to variables defining subgroups.- outcome
an optional character vector naming the categories of the outcome to plot. Can only be used when the model gives a separate prediction for each category of the outcome (e.g., multinomial and ordinal models); see the section Categorical outcomes in Details of
adrf().- proj
an optional
curve_projectionobject, the output of a call tocurve_projection(). Supplying this adds the projection curve to the effect curve plot.- transform
whether to compute intervals on the transformed estimates. Allowable options include
TRUE,FALSE, a family object (e.g.,binomial()), a link object (e.g., the output ofmake.link()), or one of the functionslog,sqrt,exp,qlogis, orqnorm. Ignored unlessxis an ADRF and Wald inference is used (i.e., ignored with percentile intervals, the default with bootstrapping and Bayesian models). See Details.- ci.type
string; when bootstrapping or Bayesian inference is used in the original effect curve, which type of confidence interval is to be computed. For bootstrapping, allowable options include
"perc"for percentile intervals,"wald"for Wald intervals, and other options allowed byfwb::summary.fwb(). Whensimultaneous = TRUE, only"perc"and"wald"are allowed. For Bayesian models, allowable options include"perc"for equi-tailed intervals and"wald"for Wald intervals. Default is"perc". Ignored when bootstrapping is not used and the model is not Bayesian.- df
the "denominator" degrees of freedom to use for the critical test statistics for confidence bands. Default is to use the residual degrees of freedom from the original model if it is a linear model and
Infotherwise, or, for models fit to multiply imputed data, degrees of freedom that account for the number of imputations (seeadrf()).- ...
ignored.
Value
A data frame with one row for each grid point of the effect curve within each subgroup or contrast, ordered by subgroup or contrast and then by treatment value. It has the following columns:
the variables supplied to
byin the call toadrf()(when supplied), with one value for each subgroup, orcontrast, the label of each contrast, whenxis the output of a call tocurve_contrast(). For models that give a separate prediction for each category of the outcome, a column (usually namedoutcome) contains the category.a column named for the treatment (or
shiftfor a shift curve) containing the grid points.estimate: the estimate of the effect curve at each grid point.conf.lowandconf.high: the lower and upper limits of the confidence band at each grid point. These are omitted whenvcov = "none"in the call toadrf().proj_estimate: the estimate of the projection at each grid point, whenprojis supplied.
Details
The confidence bands are computed exactly as they are by plot.effect_curve(), with the same arguments, so a call to as.data.frame() and a call to plot() with the same arguments give the same band (with Wald inference and simultaneous = TRUE, the critical value is computed using a randomized algorithm, so set.seed() should be called before each for the bands to be identical). To compute estimates and confidence intervals at specific treatment values rather than at the grid points, call the effect curve with those values and use summary.curve_est() on the result.
See also
plot.effect_curve()for plotting an effect curvesummary.curve_est()for confidence intervals at specific treatment values
Examples
data("nhanes3lead")
fit <- lm(Math ~ poly(logBLL, 3) * Male + Age + Race +
PIR + NICU + Smoke_Pregnant,
data = nhanes3lead)
# ADRFs of logBLL on Math within subgroups
adrf1 <- adrf(fit, treat = "logBLL", by = ~Male,
n = 21)
# Estimates and simultaneous 95% confidence bands
# at the grid points
set.seed(123)
bands <- as.data.frame(adrf1)
head(bands)
#> Male logBLL estimate conf.low conf.high
#> 1 0 -0.35667494 8.825445 8.018613 9.632278
#> 2 0 -0.21760106 8.793493 8.167224 9.419762
#> 3 0 -0.07852718 8.754384 8.246975 9.261794
#> 4 0 0.06054671 8.708593 8.269553 9.147633
#> 5 0 0.19962059 8.656594 8.253283 9.059906
#> 6 0 0.33869447 8.598863 8.216720 8.981006
# Pointwise bands for one subgroup, with the linear
# projection of the ADRF
as.data.frame(adrf1, simultaneous = FALSE,
subset = Male == 1,
proj = curve_projection(adrf1, "linear")) |>
head()
#> Male logBLL estimate conf.low conf.high proj_estimate
#> 1 1 -0.35667494 8.321380 7.767064 8.875696 8.682132
#> 2 1 -0.21760106 8.344383 7.909623 8.779144 8.571710
#> 3 1 -0.07852718 8.343474 7.979274 8.707675 8.461289
#> 4 1 0.06054671 8.320511 7.990647 8.650374 8.350867
#> 5 1 0.19962059 8.277350 7.962885 8.591815 8.240446
#> 6 1 0.33869447 8.215852 7.911953 8.519751 8.130024