Extracts the predicted NEC value as desired from an object of class bayesnecfit or bayesmanecfit.

nec(
  object,
  posterior = FALSE,
  xform = NULL,
  x_scale = c("recorded", "fitted"),
  prob_vals = c(0.5, 0.025, 0.975),
  extrapolate = FALSE,
  ...,
  no_effect = FALSE,
  pool = NULL
)

Arguments

object

An object of class bayesnecfit or bayesmanecfit returned by bnec.

posterior

A logical value indicating if the full posterior sample of calculated NEC values should be returned instead of just the median and 95% credible intervals.

xform

NULL or identity leaves the estimate on x_scale. Any other function is applied to the estimate on the selected scale. With an inline predictor transformation, a function on the default recorded scale gives a warning; see Details.

x_scale

"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.

prob_vals

A vector indicating the probability values over which to return the estimated NEC value. Defaults to 0.5 (median) and 0.025 and 0.975 (95 percent credible intervals).

extrapolate

The bound beyond which the estimate is reported as censored. FALSE, the default, censors at the prediction range the fit was built on. TRUE removes the bound at both ends. A single number is an upper limit, and a pair of numbers is a lower and an upper limit, in that order. See the Extrapolation section of nec.

...

Additional arguments passed to methods. sig_val, resolution and x_range are forwarded to nsec where an observed group level is read off its curve, and sig_val and resolution where a finite extrapolate limit requires a curve to be re-evaluated. Otherwise nec returns the estimate stored when the model was fitted, and a message names those it did not use. Any other argument is refused.

no_effect

For a bayesnecjointfit only, a logical value. FALSE, the default, returns NA for a smooth equation with no nec parameter. A monotone threshold equation returns its sampled NEC, and a hormesis threshold equation returns the NSEC of its fitted curve. TRUE additionally returns the NSEC of each smooth equation. The ne_type column labels every estimate. The other classes reject this argument.

pool

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. "mean_curve" is unavailable for a sampled NEC parameter. A joint fit defaults to "none"; other fits with spanning group terms default to "mixture".

Value

A vector containing the estimated no-effect value, including upper and lower 95% credible interval bounds (or other interval as specified by prob_vals). Where any posterior draw lies beyond the range the model was predicted over, that draw keeps its rank in the summary and is given no finite value, so an entry falling among such draws is the end of the prediction range rather than a quantile. With posterior = TRUE, draws censored above the range are Inf and those censored below are -Inf; attribute "censored" records their bounds. Attribute "censored_summary" marks which entries those are and states how many draws lie beyond each end.

Under the default asymptote_observed = TRUE, the nec prior is bounded at the lowest and highest concentrations tested. Where the data do not place the threshold inside that range, much of the posterior can lie near a bound, and a credible limit there is set by the prior. Where more than 7.5% of the finite draws of a sampled NEC lie within the outer 5% of its prior range at either end, a message says so and attribute "prior_bound_summary" holds a data.frame with one row per bounded end. Its columns are the equation (model), its model weight (wi), parameter, side, the bound on the scale of the returned estimate (bound) and on the fitted scale (fitted_bound), and the number (n_near) and share (share) of n_draws finite draws within that 5%. The window is measured on the fitted scale, as 5% of the prior range, or of the prediction range where only one end is bounded. On a model set there is a row per sampled NEC equation, each from that equation's own draws, and attr(, "weighted_share") gives the model-weighted share at each end, which is the share the 7.5% applies to. On a bayesnecgroupfit each level's record is kept, with a level column, on the table, and attr(, "weighted_share") is a list of those shares named by level, for the levels fitted as a model set. The estimate and its quantiles are unchanged. There is no record where the estimate is not a sampled NEC, as for an NSEC, a two-block fit with a smooth block or the combined estimate of a bayesnechurdlefit; where it is read per observed level; or with posterior = TRUE or extrapolate. curve_params gives the same record for every sampled nec and ec50 parameter, whatever the share.

Details

The monotone threshold equations are nec3param, nec4param, neclin and necsigm. In each, the sampled nec parameter is the last concentration before the fitted response declines from its control level (Fox 2010), and nec returns it as the NEC.

The hormesis threshold equations are nechorme, nechorme4, neclinhorme, nechormepwr, nechorme4pwr and nechormepwr01. In each, the nec parameter is the concentration at which the decline term starts. The fitted response there can be above the control, and where the slope of the stimulation term exceeds the initial rate of decline the curve continues to rise beyond it, so the parameter is not a no-effect concentration. nec returns the NSEC of these equations instead: the concentration at which the fitted curve, after any rise, falls below the lower sig_val quantile of the fitted control. This extends the NSEC of Fisher and Fox (2023), which was defined for monotone curves, to a hormetic curve. The nec parameter remains available through curve_params.

Under a fitted group term whose levels span concentrations, the NEC is read for each observed level, including its deviation on the parameter. 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 mixes the remaining observed levels by their observation counts; pool = "none" returns them separately.

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.

What is actually returned depends on the model set. Despite the function name, nec returns a no-effect estimate of whichever type the fitted model(s) support, following the convention set out in Fisher et al. (2023):

  • For a bayesnecfit holding a monotone threshold equation, the NEC: the nec parameter itself.

  • For a bayesnecfit holding a hormesis threshold equation, the NSEC read off the fitted curve, as nsec reads it. It is computed when the model is fitted, with the sig_val passed to bnec, on the grid of resolution points stored with the fit, 1000 by default. nsec reads it again on a grid of its own resolution, 500 by default, so the two can differ in the last figures.

  • For a bayesnecfit holding a smooth (ecx-type) equation, which has no nec parameter, nec stops with an error. Use nsec for its no-effect estimate, the NSEC (Fisher and Fox 2023): the concentration at which the fitted curve falls below a reference taken from the sig_val quantile of the control posterior.

  • For a bayesmanecfit whose model set contains both kinds, the weighted posterior mixes sampled NEC draws from monotone threshold equations with NSEC draws from smooth and hormesis threshold equations, in proportion to the model weights. The result is the model-averaged N(S)EC, and a message is emitted to say so. It is not a pure NEC and should not be reported as one.

  • For a bayesnecjointfit, a data.frame with one row per level of the grouping factor, the equation fitted at that level in a model column and the type of the estimate in an ne_type column. A composed joint refit fits one equation per level, so each level's estimate is a NEC or an NSEC and never a mixture of the two. no_effect = FALSE, the default, reports a sampled NEC for a monotone threshold equation, a curve-read NSEC for a hormesis threshold equation and NA for a smooth equation. no_effect = TRUE also reports the NSEC of a smooth equation. Where every level has a smooth equation and no_effect = FALSE, nec stops, as it does for a single smooth equation. The ne_type column is what a model-averaged N(S)EC cannot report.

  • For a bayesnecgroupfit, a data.frame with one row per level, each read as for the fit held at that level. A level fitted with a single smooth equation has no nec parameter, and its row is NA. One message names those levels and points to nsec. Where every level is of that kind, or with pool other than "none" where any is, nec stops. A level holding a model set always has an estimate, of the kind described above.

The result carries attribute "toxicity_estimate", "nec", "nsec" or "n(s)ec", which names the type of the estimate and is printed with it. summary labels the estimate NEC, NSEC or N(S)EC in the same way. Use nsec where an NSEC is wanted from every model regardless of type.

Where crf() transforms the predictor inline, as in crf(log(concentration)), a sampled nec parameter is on the transformed scale. Without xform it is returned on the recorded scale, a concentration, by the inverse of the transformation. The inverse is exact for log, log10, log2, log1p, sqrt and exp of the predictor, alone or shifted by a constant, as in log(concentration + 1). For any other transformation it is read off the prediction grid by linear interpolation, and a draw beyond that grid that is not censored is an error naming the remedy. xform = identity leaves the estimate on the recorded scale. Another function is applied to the concentration after the inverse, with a warning naming the transformation. Pass x_scale = "fitted" to apply a function to the fitted-scale estimate.

Capping and dropping

Two operations are both called censoring and they are not the same. A threshold equation's nec is a sampled parameter: a draw above the top of the prediction range has a value, and that value is known to exceed the bound, which is right-censoring in the ordinary sense. An NSEC or an ECx is read off a fitted curve: a draw whose curve never reaches the target has no such concentration in the range and may have none at any concentration, so the draw is not capped at the bound, it is recorded as lying beyond it. Both are reported the same way in the summary. With posterior = TRUE, both return Inf or -Inf for a censored draw, which keeps its position in sort() and quantile().

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.

Extrapolation

extrapolate chooses the bound the estimate is censored at. It is read on the recorded predictor scale, the scale the data were supplied on, the scale bnec and nsec take x_range on, and the scale the estimate is returned on without xform. Under crf(log(concentration)) the limit is therefore a concentration and not a log concentration, whatever xform is given.

TRUE removes the bound at both ends. It is accepted only where every component of the reported estimate samples a NEC. An NSEC is read off a fitted curve and a curve cannot be evaluated on an infinite grid, so where any component is an NSEC — which includes the default bnec model set, because that set fits equations of both classes — TRUE is an error naming the finite form. A hormesis threshold equation contributes an NSEC, so TRUE is refused for a fit or a set that contains one. For a single fit the class is the one recorded in ne_type, which takes both blocks of a joint two-block fit into account. For a model-averaged set it is the type recorded for each equation when the set was built, from which summary also takes the label it prints, so the two cannot disagree about what the set is.

A finite limit applies to both classes, by a different route for each. The threshold components are compared against it, which requires no further computation because every draw of a sampled nec already has a value. The curve-read components are re-evaluated by nsec, with its extrapolate argument, on the stored prediction range with points appended out to the limit. That recomputes from the stored fit and needs no refit, but it does evaluate the curve once for each such equation, at a run time proportional to the number of grid points. The re-evaluation reuses the sig_val the fit was built with unless sig_val is given, and the number of grid points the fit stored unless resolution is given. The appended points keep that grid's spacing, so a wider range adds points rather than coarsening the grid, and its numbers can differ in the last digits from the stored summary.

Two requests re-evaluate nothing and return what extrapolate = FALSE returns: a limit equal to the current bounds, and any limit on a fit with no draw beyond either end, where every draw was identified inside the range the fit used and a wider grid has none left to identify. An object fitted by a version before 3.0.0 records nothing about which of its draws lie beyond the range, so it takes the second of those whatever its draws are, and extrapolate does nothing to it. Refit it, or rebuild the set with amend, to extrapolate from it.

A limit inside the prediction range is an error rather than a silent tightening, because it would report an estimate as censored at a value the fit had no trouble identifying. Narrow the range with x_range where the fit or the estimate is built instead.

Two constraints on the reach of an extrapolation are reported rather than corrected. Where the nec prior stored on the fit is itself bounded at the prediction range, the posterior holds no draw beyond that bound and a wider limit returns the same truncated posterior; where the call re-evaluates anything, a message states the bound. The default prior bounds nec to the tested range, so this applies to every fit made under the default asymptote_observed = TRUE of bnec: extrapolate reaches above that range only for a fit made under asymptote_observed = FALSE, which lifts the upper bound, or with a user prior that sets a wider one. The lower bound at the lowest value tested applies under both settings and is reported by the other arm of the same message. And a curve-read component is measured from the control, so a lower limit below the control concentration does not extend its search, and a message states that the search begins at the control.

References

Fisher R, Fox DR (2023). Introducing the no significant effect concentration (NSEC). Environmental Toxicology and Chemistry, 42(9), 2019–2028. doi: 10.1002/etc.5610.

Fisher R, Fox DR, Negri AP, van Dam J, Flores F, Koppel D (2023). Methods for estimating no-effect toxicity concentrations in ecotoxicology. Integrated Environmental Assessment and Management. doi: 10.1002/ieam.4809.

Fox DR (2010). A Bayesian Approach for Determining the No Effect Concentration and Hazardous Concentration in Ecotoxicology. Ecotoxicology and Environmental Safety, 73(2), 123–131. doi: 10.1016/j.ecoenv.2009.09.012.

See also

Examples

library(bayesnec)
data(manec_example)
nec(manec_example)
#> This bayesmanecfit combines sampled NEC and curve-read NSEC draws, so the returned estimate is the model-averaged N(S)EC. See ?nec and summary(), which labels it.
#>       Q50      Q2.5     Q97.5 
#> 1.4499461 0.7405499 1.5243864 
#> attr(,"toxicity_estimate")
#> [1] "n(s)ec"