Predict distributional parameters in long format
Source:R/predict-parameters.R
predict_parameters.Rdpredict_parameters() returns predicted distributional parameters from a
drmTMB fit in one long data frame. It is a compact data surface for
interpretation tables and future plotting or marginalisation helpers: the
same grid can hold location/mean, scale, shape, probability, and coscale
quantities.
Usage
predict_parameters(object, ...)
# S3 method for class 'drmTMB'
predict_parameters(
object,
newdata = NULL,
dpar = NULL,
type = c("response", "link"),
include_newdata = TRUE,
conf.int = FALSE,
conf.level = 0.95,
...
)Arguments
- object
A
drmTMBfit.- ...
Reserved for future options.
- newdata
Optional data frame for prediction. If omitted, fitted rows are used.
- dpar
Optional character vector of distributional parameters to predict, such as
"mu","sigma","nu","rho12","sigma1", or"sigma2", plus fitted random-effect scale model names such as"sd(id)".NULLpredicts all fitted distributional parameters.- type
Prediction scale:
"response"or"link".- include_newdata
Logical; when
TRUEandnewdatais supplied, append the supplied covariate columns to the returned table.- conf.int
Logical; include Wald fixed-effect confidence intervals when available for the supplied prediction grid.
- conf.level
Confidence level for Wald intervals when
conf.int = TRUE.
Value
A data frame with columns row, row_label, dpar, component,
type, estimate, conf.status, and interval_source. When
conf.int = TRUE, std.error, conf.low, conf.high, and conf.level
are also included. When include_newdata = TRUE, supplied newdata
columns are appended after those core columns.
Details
The helper calls predict.drmTMB() for each requested distributional
parameter. With newdata = NULL, predictions use the fitted rows. With
newdata supplied, predictions are fixed-effect, population-level
predictions for those rows, matching predict.drmTMB().
By default, the table includes interval provenance columns with
conf.status = "not_requested" and
interval_source = "not_available". When conf.int = TRUE and newdata is
supplied for ordinary fixed-effect distributional parameters, the helper
adds Wald fixed-effect intervals from the fitted coefficient covariance and
records the requested confidence level. These are population-level intervals
for the supplied grid; they do not include random-effect mode uncertainty,
profile-likelihood uncertainty, or uncertainty for direct random-effect scale
models.
Examples
dat <- data.frame(
y = c(0.2, 0.5, 1.1, 1.4, 1.8, 2.2),
x = c(-1, -0.5, 0, 0.5, 1, 1.5)
)
fit <- drmTMB(bf(y ~ x, sigma ~ x), data = dat)
grid <- data.frame(x = c(0, 1))
predict_parameters(
fit,
newdata = grid,
dpar = c("mu", "sigma"),
conf.int = TRUE
)
#> row row_label dpar component type estimate std.error
#> 1 1 1 mu location response 9.999961e-01 NA
#> 2 2 2 mu location response 1.799999e+00 NA
#> 3 1 1 sigma distributional-scale response 9.135855e-02 NA
#> 4 2 2 sigma distributional-scale response 3.318231e-06 NA
#> conf.low conf.high conf.level conf.status interval_source x
#> 1 NA NA 0.95 wald_unavailable not_available 0
#> 2 NA NA 0.95 wald_unavailable not_available 1
#> 3 NA NA 0.95 wald_unavailable not_available 0
#> 4 NA NA 0.95 wald_unavailable not_available 1