A toxval_pred holds realisations of one or more fitted curves (posterior
draws for a Bayesian fit, parametric bootstrap replicates for a frequentist
one) evaluated over a common predictor grid. It is returned by
toxval_predict() and can be passed to ecx() and nsec() in place of
the fitted model.
Usage
new_toxval_pred(
curves,
keys,
x_vec,
meta,
threshold = NULL,
control = NULL,
asymptote = NULL
)Arguments
- curves
An unnamed list of numeric matrices, one element per row of
keys. Each matrix has one row per realisation and one column per value ofx_vec.- keys
A data frame identifying the curves, one row per element of
curves. See Identifying curves.- x_vec
A numeric vector of at least two finite, strictly increasing predictor values.
- meta
A named list of metadata. See Metadata.
- threshold
An unnamed list of numeric vectors of per-realisation values of a threshold parameter such as an NEC, one element per row of
keys, orNULLwhere the model has none.- control
An unnamed list of numeric vectors of per-realisation control responses from a separate control-only fit, one element per row of
keys, orNULL.- asymptote
An unnamed list, one element per row of
keys, of lists of two numeric vectors of per-realisation asymptotes nameddecreasing(the lower asymptote) andincreasing(the upper one), orNULLwhere the model supplies none. Used bytype = "relative".
Value
An object of class toxval_pred, a list with elements curves,
keys, x_vec, threshold, control, asymptote and meta.
Details
new_toxval_pred() builds one, and is for developers writing a
toxval_predict() method for a new model class.
Identifying curves
Row i of keys identifies element i of curves, and of threshold,
control and asymptote when they are supplied. The columns of keys are
drawn from group and response, and become the descriptor columns of the
result:
- Ungrouped
One row and no columns, such as
data.frame(row.names = 1L).- Grouped
A
groupcolumn, a factor with one row per level.- Multivariate
A
responsecolumn, a factor with one row per response.- Grouped multivariate
Both columns, with one row per combination of group and response.
Rows of keys are unique and contain no missing values.
Realisation alignment
Realisation i is the same posterior draw or bootstrap replicate in every
slot: row i of every matrix in curves, and element i of every element
of threshold, control and asymptote. new_toxval_pred() checks that
the dimensions agree with meta$n_realisation and length(x_vec), but
cannot check that the realisations themselves are aligned.
Metadata
meta must contain the following elements. Additional elements are
permitted and ignored.
source_classString, the class of the fitted object the realisations came from.
x_varString, the name of the predictor variable.
group_varString naming the grouping variable. Required when
keyshas agroupcolumn, andNULLotherwise.multi_varCharacter vector of the response names of a multivariate fit, including every level of
keys$response. Required whenkeyshas aresponsecolumn, andNULLotherwise.resolutionWhole number, the number of values in
x_vec.x_rangeNumeric of length 2, the range of
x_vec.x_controlNumber, the control concentration, at which the control response is predicted: the lowest predictor value in the data, unless the caller names another. It must be the first value of
x_vec.familyString naming the response distribution, such as the
brmsfamily or thetypeof adrcfit, orNULL. A multivariate fit whose responses differ in family gives a character vector named by response. A binomial family is taken to be on the proportion scale.realisationEither
"draws"or"bootstrap".n_realisationWhole number, the number of realisations.
seedWhole number, the seed used to generate bootstrap realisations or to choose the realisations of a model average, or
NULL.
The following elements are optional, and are checked when they are present. A model average records them.
model_weightsNamed numeric, the weight of each model in a model average, each between 0 and 1 and summing to 1. A model whose weight gives it no realisation is still listed.
draw_modelCharacter, one value per realisation, naming the model the realisation came from. Each value is a name in
model_weightswhen that is present.model_controlAn unnamed list, one element per row of
keys, of named lists of numeric vectors. Each vector holds the control response of one model in every draw of its own fit, including draws left out of the average, so its length can differ fromn_realisation. It requiresdraw_model, and every model named there has a vector. Underanchor = "component",nsec()takes each model's reference from it.
Examples
new_toxval_pred(
curves = list(matrix(c(10, 9, 8, 7, 11, 9, 7, 5), nrow = 2, byrow = TRUE)),
keys = data.frame(row.names = 1L),
x_vec = c(0, 1, 2, 3),
meta = list(
source_class = "brmsfit",
x_var = "x",
group_var = NULL,
multi_var = NULL,
resolution = 4,
x_range = c(0, 3),
x_control = 0,
family = "gaussian",
realisation = "draws",
n_realisation = 2,
seed = NULL
)
)
#> <toxval_pred> brmsfit
#> realisations: 2 (draws)
#> grid: x, 4 values from 0 to 3
#> curves: 1 (ungrouped)
#> threshold: none
#> control: none