Extracts the predicted ECx value as desired from an object of class
bayesnecfit, bayesmanecfit,
bayesnechurdlefit, bayesnecgroupfit or
bayesnecjointfit.
An object of class bayesnecfit or
bayesmanecfit returned by bnec.
The desired percentage effect value, defaults to 10. Any
value above 0 is accepted for every type except "direct", where it
is a response value rather than a percentage. Values above 100 are
meaningful under "absolute" for a response that can go negative — see
Details.
The number of unique x values over which to find ECx. The crossing is located by linear interpolation between the two grid values that bracket it, so precision saturates well below the grid spacing. The default is 500 grid values, matching toxval. A finer grid can change an interpolated crossing and increases prediction time. With an inline predictor transformation the grid is even on the fitted scale.
A logical value indicating if the full
posterior sample of calculated ECx values should be returned instead of
just the median and 95 credible intervals.
A character vector, taking values of
"absolute" (the default), "relative", "range" or "direct". See Details.
A range of x values over which to consider extracting ECx.
NULL or identity leaves the estimate on
x_scale. Any other function is applied on the fitted scale and
requires x_scale = "recorded" when the predictor is
transformed inline; see Details.
"recorded" (the default) returns the predictor on
its recorded scale. "fitted" returns it on the scale fitted by
crf(). The scales differ only where crf() transforms the
predictor inline.
A vector indicating the probability values over which to return the estimated ECx value. Defaults to 0.5 (median) and 0.025 and 0.975 (95 percent credible intervals).
Additional arguments passed to methods. A method refuses any argument it does not use.
For a joint two-block fit only (family = "hurdle_gamma",
"zero_inflated_beta", "hurdle_poisson" or
"hurdle_negbinomial"), the parameter block to report:
"mu" for the response block, or "hu" ("zi" for the
zero-inflated families) for survival. Defaults to NULL, which gives
the expected positive response multiplied by 1 - hu. For continuous
hurdles the positive response is mu; for count hurdles it is
E[Y | Y > 0]. The zero-probability block is
inverted to survival before computing, so ECx keeps its usual meaning of a
percentage decline from the fitted control value. See Details.
For the count hurdles, "mu" is converted to the positive-count mean
E[Y | Y > 0] so it matches the growth component returned by
bnec_hurdle. With type = "relative", "mu" is
measured towards the response block's asymptote and "hu" or
"zi" towards the zero block's own bot, or 0 where its
equation has none. The combined curve, dpar = NULL, is refused under
type = "relative", because its asymptote is the product of the two
blocks' asymptotes rather than a fitted parameter.
How observed group levels are combined. "none" returns
per-level estimates. "mixture" gives each posterior draw to one level, in
proportion to the levels' observation counts, and keeps it at its position,
so that draw i of the mixture comes from posterior iteration
i. Separate fits with different numbers of draws are instead each
sampled over their full posterior. "mean_estimate" averages the levels'
estimates at each draw, and "mean_curve" estimates from their weighted
mean curve. A joint fit defaults to "none"; other fits with spanning group
terms default to "mixture".
"own" reads each level's control recorded at fitting, or
its lowest observed concentration for an older fit or one fitted without
x_control. "shared" reads the lowest control across levels;
a single finite number specifies
the concentration directly. A control below a level's observations
extrapolates its curve, and gives a warning unless it is the control
recorded at fitting. Level controls are recorded in the result's
x_control attribute.
FALSE, the default, uses the prediction range.
A finite upper limit or a pair of finite lower and upper limits extends the
search grid and marks any unresolved draw as censored at that limit.
Limits are on the recorded predictor scale. TRUE and limits that
narrow the current range are refused. The original grid points and their
spacing are retained when extension points are appended. The search begins
at the control, so a lower limit extends it only where the prediction range
begins above the control. For type = "range" the lowest response is
taken over the prediction range before it is extended, so a limit beyond
the data does not change the estimate.
The ECx estimate and credible bounds, or with
posterior = TRUE one value per draw. A draw censored above the
search range is Inf; one censored below it is -Inf. The
"censored" attribute records the bounds and affected draws.
Every ECx is measured from the control. The control is the
predicted mean at the control concentration, taken per posterior draw: the
x_control stated in bnec, or else the lowest
concentration in the supplied predictor. type names what the
percentage is measured towards:
"absolute" (the default) — control to 0.
"relative" — control to the equation's theoretical
asymptote, the bot parameter where the equation has one and 0
otherwise. Refused where the equation has no bot and the family
is unbounded below, because there is then no finite denominator. On the
positive counts of a negative binomial count hurdle the asymptote is
their zero-truncated mean at mu = bot, which needs the shape
there, and the estimate is refused where the shape is modelled by
disp(~x); see bnec.
"range" — control to the lowest response the curve
predicts over the predictor range.
"direct" — ecx_val is a response value rather than
a percentage, and the x value at which the curve reaches it is returned.
Measuring from the control rather than from the maximum of the predicted curve is what makes an ECx well defined for a hormesis equation: the target response lies below the control, the rising limb lies above it, so the curve crosses the target exactly once.
"absolute" measures towards 0 even for a family whose support is
unbounded below. This follows OECD TG 201, whose percent inhibition
rearranges to the same reference and which permits a value above 100 per
cent rather than truncating it, so ecx_val is not capped at 100.
Where the curve does not reach the target anywhere in the predictor range
the ECx is not identified. With posterior = TRUE the draw is
Inf, and a warning reports how many draws were affected.
Where crf() transforms the predictor inline, as in
crf(log(concentration)), the curve is searched on a grid even on
the fitted scale. The crossing is interpolated there and returned on the
recorded scale through the inverse. x_scale = "fitted" returns the
fitted-scale crossing. A supplied xform is applied on that scale;
xform = exp on crf(log(concentration)) returns the recorded
concentration. If a transformed range endpoint is infinite, as at
log(0), the search keeps the recorded grid because no finite grid
spans the fitted interval.
With a fitted group term whose levels span concentrations, the control and
curve are predicted for each observed level with its group deviations.
Terms whose levels each occur at one concentration are set to zero. The
level of a spanning term observed at only one concentration is excluded from
the estimate, with a message naming it. The default estimate mixes the
remaining observed levels by their observation counts;
pool = "none" returns them separately. A grouped or joint fit already
separates levels and defaults to pool = "none".
On a bayesnecjointfit, each level of the refit is mixed over
its own observed group levels. A group term whose values occur in the data
of more than one level, such as a batch in which two levels were both
tested, is read at the same value for every level at each posterior draw,
as often as their observation counts on that term allow. Terms they do not
share are chosen for each level independently. The levels can therefore be
contrasted draw by draw, as compare_posterior does.
Calls to functions ecx and nsec and
compare_fitted do not require the same level of flexibility
in the context of allowing argument newdata
(from a posterior_predict perspective) to
be supplied manually, as this is and should be handled within the function
itself. The argument resolution controls how precisely the
ecx or nsec value is estimated, with
argument x_range allowing estimation beyond the existing range of
the observed data (otherwise the default range) which can be useful in a
small number of cases. There is also no reasonable case where estimating
these from the raw data would be of value, because both functions would
simply return one of the treatment concentrations, making NOEC a better
metric in that case.
Selecting a component of a hurdle model
The two implementations of a hurdle model name the component differently,
and the two arguments are not interchangeable. A
bayesnechurdlefit from bnec_hurdle holds two
separate fits, so it takes which = "growth", "survival" or
"combined". A joint fit from bnec(family = "hurdle_gamma")
holds two parameter blocks inside one model, so it takes dpar naming
the brms distributional parameter. Supplying one where the other is
expected is an error rather than silently ignored.
A draw whose curve does not reach the target anywhere in the prediction
range has no such concentration in that range, and may have none at any
concentration. It is not capped at the top of the range, which would assert
that its estimate equals that value; it is recorded as lying beyond it. The
summary is then censored: the draw keeps its rank and is given no value, so
a reported quantile that falls among such draws is the end of the prediction
range rather than a quantile of the draws that did reach the target.
With posterior = TRUE, censored draws are returned as Inf
or -Inf, so sort() and quantile() retain their
positions. Attribute "censored" records their bounds and ends.
Attribute "censored_summary" marks which entries those are, and
states how many draws lie beyond each end and where the ends are. A draw
whose curve had already passed the target where the range begins is recorded
at the other end and reported the same way.
Which quantile estimator is used depends on whether anything is censored.
A posterior with no beyond-range draw is summarised with
quantile's default type 7, which interpolates between
two adjacent order statistics. Once any draw is censored every reported
entry becomes an order statistic instead, because a value interpolated
across a draw that has no value would be one the posterior does not
support. Every entry therefore changes a little when the first draw is
censored, including entries at the other end of the interval. See
nec for the same treatment of a threshold parameter, where
the draw does have a value and the operation is right-censoring in the
ordinary sense.
A draw whose curve declines away from the target everywhere — type =
"direct" with a response value the curve never attains, and an absolute
target above a control that is itself negative — has no such concentration
at any value of the predictor, not merely none within the range. It is
reported as at or beyond the top of the range, as is every draw the search
did not identify. The censored fraction beside the estimate distinguishes
the two: where it is the whole posterior, no draw reached the target.
bnec, bnec_hurdle, nsec, epx
# \donttest{
library(brms)
library(bayesnec)
data(manec_example)
ecx(manec_example, ecx_val = 50)
#> Q50 Q2.5 Q97.5
#> 1.672726 1.610535 1.726708
#> attr(,"resolution")
#> [1] 500
#> attr(,"ecx_val")
#> [1] 50
#> attr(,"toxicity_estimate")
#> [1] "ecx"
ecx(manec_example)
#> Q50 Q2.5 Q97.5
#> 1.4916201 0.9173307 1.5615410
#> attr(,"resolution")
#> [1] 500
#> attr(,"ecx_val")
#> [1] 10
#> attr(,"toxicity_estimate")
#> [1] "ecx"
# }