bayesnecjointfit of one model fitted across the levels of a factorR/bayesnecjointfit-class.R
bayesnecjointfit-class.RdReturned by bnec_joint applied to a
bayesnecgroupfit. Each level is fitted the equation its own
weights favour, with every curve parameter taking a separate value per level
of the grouping factor within a single posterior.
The object holds the fit and the level structure and nothing
derived from a prediction grid. A level term is a population-level term, so
re_formula = NA does not drop it and the prediction grid has to name
a level: bnec_newdata on a joint refit returns
resolution rows for each level rather than resolution rows,
with the level varying slowest.
ecx, nsec, nec and
ecnsec therefore return a
data.frame with one row per level, named in a
level column, rather than the named vector of three they return for a
bayesnecfit. For ecx, nsec and
ecnsec that is the same table a bayesnecgroupfit
returns, so the two routes can be read against each other.
ecnsec returns, at each level, the percent effect at the
nsec supplied, which is one value for every level, read off that
level's own curve as ecnsec reads it off a single fit.
Its columns are named as those of the ecx table —
Q50, Q2.5 and Q97.5 under the default
prob_vals — where ecnsec on a single fit keeps the
names quantile gives. Its bound_ columns are
empty, because ecnsec records no censoring.
exceedance returns one row per level, preceded by a
level column, as it does for a bayesnecgroupfit.
autoplot() draws one panel per level and
ggbnec_data names the level in a panel column, again
matching the grouped fit.
nec adds two columns, because a composed refit fits one
equation per level and only some equations estimate a nec parameter:
model names the equation fitted at that level and ne_type the
type of the estimate reported there. By default the estimate is the sampled
nec parameter for a monotone threshold equation, the curve-read NSEC
for a hormesis threshold equation and NA for a smooth equation;
nec(x, no_effect = TRUE) also returns the NSEC of a smooth equation.
One equation per level
is what makes that label possible: the model-averaged estimate of a
bayesmanecfit mixes NEC and NSEC draws in proportion to the
model weights and so has no single type to report.
Each level is estimated on its own grid, one level at a time, rather than from one prediction spanning them all. A control posterior, an ECx crossing and an NSEC search each read a single monotone curve, and a grid holding every level concatenated is not one: the crossing search would find the first level's crossing and report it for the fit.
The coefficient one level holds on one parameter is named
b_<parameter>_<group_var><level> in the draws — b_top_sitea
for level "a" of a grouping variable named site — where
every level was fitted the same equation. The level part is the label as
brms renames it, which drops a space and spells out some punctuation,
so level "Site A" is b_top_siteSiteA. Where the levels were
fitted different equations, each level's parameters are brms
non-linear parameters in their own right and the
name is b_<parameter><level tag>_Intercept, the tag being the level
name reduced to letters and digits followed by Lv and its rank in the
sorted level set. print() reports the tags.
fitThe brmsfit.
modelThe equation fitted at every level, or NA where the
levels favoured different equations.
modelsA named character vector, the equation
fitted at each level.
level_specThe level structure the fit was built from: the level tags, indicator columns and mask values where the equations differ, and the grouping variable and levels either way.
level_weightsThe weight the equation fitted at each level holds at that level, from the grouped fit. A level's own weights sum to one, so this is the share of that level's evidence behind the equation used there.
bayesnecformulaThe bayesnecformula the fit was built
from, carrying the equation of the first level.
initThe initial values the fit was given.
group_varThe name of the grouping column.
levelsThe factor levels, in the order their coefficients are in.
disp_by_levelWhether the family's dispersion parameter was also given a value per level.
dataThe data.frame fitted, all levels.
familyThe family, carried over from the grouped fit.
model_weightsThe summed model weight of every equation across the levels of the grouped fit, in decreasing order.
model_weight_shareThe share of the summed weight the forced equation
holds, between 0 and 1, where model named one. NA where each
level was fitted its own equation, because no equation was imposed on the
set for such a share to describe, and NA where model named an
equation no level fitted.
A joint refit has the methods of a bayesnecfit. A method
that returns one result per fit returns one per level here, and a method
that describes the sampler or the data describes the one
brmsfit fitted to every level.
summary() gives the equations, the brms summary and
the divergent transitions of the fit. It then gives one row per level for
the no-effect estimate, labelled NEC or NSEC as
nec(x, no_effect = TRUE) labels it, for each ECx asked for with
ecx = TRUE, and for the Bayesian R-squared of that level's rows.
The estimate rows are the tables nec and ecx
return. print() on the summary warns where a level fails
rhat_cutoff, or where the divergent transitions of the fit are a
larger proportion of its retained draws than divergence_cutoff,
0.00125 (0.125%) by default as in check_sampling.
plot() draws one base-graphics panel per level, as it draws
a bayesnecfit.
fitted(), predict(), posterior_epred() and
posterior_predict() predict the fitted rows of every level, as
they do for a bayesnecfit. A newdata must name the
level of each row in the grouping column, as the grid
bnec_newdata returns does. Where the levels were fitted
different equations, the indicator columns the model reads are added
from that column.
pp_check() returns a named list of one check per level,
each made against that level's own rows.
rhat returns one element per level, with the Rhat
of that level's coefficients and of the parameters the levels share,
such as lp__, with the verdict against rhat_cutoff.
check_chains and check_priors draw one
page per level, and a last page for any population-level parameter the
levels share. check_priors also returns the plots
invisibly, as a named list.
check_sampling returns one row per level, and
screen_models returns the refit unchanged where every level
passes and stops where any fails, since no level can be dropped.
dispersion returns one statistic per level, and
group_level_sd the group-level standard deviations of the
fit.
check_fit returns the checkfit_group object a
bayesnecgroupfit returns, with one table per level, all
read from one simulation. An explicit group has one value per
fitted row.
curve_params returns one table with a leading
level column, as for a bayesnecgroupfit, or with
summary = FALSE a named list of draws per level. wi is 1,
because each level is fitted a single equation.
formula() returns a named list of one
bayesnecformula per level, naming the equation fitted
there, and model.frame() a named list of each level's fitted rows.
The brms formula and data of the whole fit are those of the
brmsfit that pull_brmsfit returns.
get_priors returns the priors the fit used.
pull_best returns the fit unchanged, since each
level already has one equation. failed_models returns an
empty record, since a joint refit that fails stops with an error.
update() refits the same model with other brms
arguments, such as iter or control, or to
newdata, which must hold rows at every level. The family, the
formula and the arguments that build the default priors are kept; to
change them, refit with bnec_joint.
ecx, nsec, nec,
ecnsec, exceedance,
compare_posterior, bnec_newdata,
ggbnec_data and autoplot() are described under
Details.
amend, pull_out, c() and +
stop with a message. Each level of a joint refit has one equation, and the
refit is not a model set, so it has no equation to add or drop, no level
can be taken out of it without refitting, and it cannot join a set of fits
to the same data. To change the equations, amend the
bnec_group fit and refit it, or fit one equation at every
level with the model argument of bnec_joint.