Generate realisations of a fitted curve over a predictor grid
Source:R/toxval-predict.R
toxval_predict.RdEvaluates a fitted concentration-response model over a grid of predictor
values, once per realisation of the fit. The result can be passed to ecx()
and nsec() in place of the fitted model.
Usage
toxval_predict(
object,
...,
x_var = NULL,
group_var = NULL,
resolution = 500,
x_range = NULL,
x_control = NULL
)
# Default S3 method
toxval_predict(
object,
...,
x_var = NULL,
group_var = NULL,
resolution = 500,
x_range = NULL,
x_control = NULL
)
# S3 method for class 'brmsfit'
toxval_predict(
object,
...,
x_var = NULL,
group_var = NULL,
resolution = 500,
x_range = NULL,
x_control = NULL,
asymptote = NULL
)
# S3 method for class 'drc'
toxval_predict(
object,
...,
x_var = NULL,
group_var = NULL,
resolution = 500,
x_range = NULL,
x_control = NULL,
n_boot = 1000,
seed = NULL
)
# S3 method for class 'bayesnecfit'
toxval_predict(
object,
...,
x_var = NULL,
group_var = NULL,
resolution = 500,
x_range = NULL,
x_control = NULL
)
# S3 method for class 'bayesmanecfit'
toxval_predict(
object,
...,
x_var = NULL,
group_var = NULL,
resolution = 500,
x_range = NULL,
x_control = NULL
)
# S3 method for class 'bnecfit'
toxval_predict(
object,
...,
x_var = NULL,
group_var = NULL,
resolution = 500,
x_range = NULL,
x_control = NULL
)Arguments
- object
A model fitted with brms, drc or bayesnec.
- ...
Additional arguments passed to methods, such as
n_bootandseedfor adrcfit, orasymptotefor abrmsfit.- x_var
A string naming the predictor variable in
object, orNULLwhere the class ofobjectrecords which of its variables is the predictor. Each method states whether it acceptsNULL.- group_var
A string naming the grouping variable in
object, orNULLfor a single curve.- resolution
A whole number giving the number of predictor values to evaluate the curve at. Larger values estimate a metric more precisely.
- x_range
A numeric vector of length 2 giving the range of predictor values to evaluate over, or
NULLto use the range in the model data. The first value must equal the control concentration.- x_control
A number, the control concentration, at which the control response is predicted and the grid starts, or
NULLfor the lowest predictor value in the data. A value outside the range of the data warns.- asymptote
The lower and upper asymptotes of a
brmsfit, fortype = "relative", as a vector nameddecreasing,increasingor both. Each is the name of a non-linear parameter, such asc(decreasing = "bot", increasing = "top"), or a number on the response scale.- n_boot
A whole number giving the number of parametric bootstrap replicates to draw.
- seed
A whole number used to seed the bootstrap draw, or
NULLto use the current random number state.
Value
A toxval_pred object.
Details
Realisations are posterior draws for a Bayesian fit and parametric bootstrap replicates for a frequentist one. A bootstrap replicate is drawn from a multivariate normal with the coefficients as its mean and their covariance.
Supply group_var to get one curve per level rather than a single curve.
The curves follow the order of the levels of a factor, and otherwise their
sorted order. Each method states what group_var must name.
The grid starts at the control concentration, where the control response is
predicted, and every reference, ECx and NSEC is measured from that response.
By default the control concentration is the lowest predictor value in the
data. Use x_control to name another, such as 0 for a predictor measured as
the reduction from an ambient level. A value outside the range of the data
warns. A grouped fit has one control concentration for every curve.
Methods (by class)
toxval_predict(default): Method for any class without one, which errors.toxval_predict(brmsfit): Method for a brms::brmsfit. Realisations are the posterior draws, with group-level effects excluded.x_varis required.group_varmust name a population-level effect; a variable that appears only in a group-level term, such assiteiny ~ x + (1 | site), is an error.A multivariate fit gives one curve per response, named as
brmsnames them, for examplespsurvivalfor a columnsp_survival.A binomial response, such as
y | trials(n) ~ x, is predicted at one trial, socontrolandreferenceare proportions. The NSEC and ECx do not depend on the number of trials.type = "relative"needsasymptote, and is not supported for a multivariate fit.toxval_predict(drc): Method for a fit fromdrc::drm(). Realisations are parametric bootstrap replicates, so results vary between calls unlessseedis supplied. A parameter that must be positive, such aseinLL.4(), is drawn on the log scale.x_varis read from the fit if not supplied.group_varmust name the column passed ascurveid. The asymptotes used bytype = "relative"are the lower and upper limits of the fitted function.toxval_predict(bayesnecfit): Method for a single fit frombayesnec::bnec(), of classbayesnecfit, which requiresbayesnecto be installed. Realisations are the posterior draws, with group-level effects excluded.x_varis read from thecrf()term if not supplied.group_varmust beNULL. A predictor transformed insidecrf(), such ascrf(log(x), ...), is reported in units ofx, soxform = expmust not be supplied. A binomial or beta-binomial response is predicted at one trial, so its curve is a proportion. The asymptotes used bytype = "relative"are thebotparameter, or 0 for an equation without one, and 1 for a proportion. An asymptote isNAwhere the family has no such bound or the link is not identity.toxval_predict(bayesmanecfit): Method for a model average frombayesnec::bnec(), of classbayesmanecfit, which requiresbayesnecto be installed. Each model is predicted as for abayesnecfit. Realisations are the drawsbayesneckeeps from each model in proportion to its weight, the same draws its own estimates use, and each takes its asymptotes from its own model. The random number state of the session is left unchanged.toxval_predict(bnecfit): Method for any otherbayesnecfit, which errors. Group fits, joint refits and hurdle pairs each hold more than one curve, over concentrations that can differ between curves, which a toxval_pred does not yet represent.
Examples
# \donttest{
fit <- drc::drm(rootl ~ conc, data = drc::ryegrass, fct = drc::LL.4())
toxval_predict(fit, seed = 42)
#> <toxval_pred> drc
#> realisations: 1000 (bootstrap)
#> grid: conc, 500 values from 0 to 30
#> curves: 1 (ungrouped)
#> threshold: none
#> control: none
if (requireNamespace("bayesnec", quietly = TRUE)) {
toxval_predict(bayesnec::manec_example)
}
#> <toxval_pred> bayesmanecfit
#> realisations: 100 (draws)
#> grid: x, 500 values from 0.03234801 to 3.22052
#> curves: 1 (ungrouped)
#> threshold: none
#> control: none
# }