Runs check_sampling, drops every candidate that failed, and reports what went and why. The message is the point of the function, not decoration: it is what a methods section has to cite, and an exclusion step that leaves no record is not reproducible.

screen_models(
  x,
  rhat_cutoff = 1.01,
  ess_cutoff = 400,
  divergence_cutoff = 0.00125,
  quiet = FALSE,
  group_action = c("per_level", "common")
)

Arguments

x

An object of class bayesnecfit, bayesmanecfit, bayesnechurdlefit, bayesnecgroupfit or bayesnecjointfit.

rhat_cutoff

A numeric vector of length 1.

ess_cutoff

A numeric vector of length 1.

divergence_cutoff

A numeric vector of length 1. The proportion of retained draws, from 0 to less than 1, above which the divergent transitions fail a model. Defaults to 0.00125, which is 10 of 8,000 draws. Inf turns the divergence criterion off.

quiet

A logical. Suppress the message reporting what was dropped. Defaults to FALSE; there is rarely a good reason to set it.

group_action

For a bayesnecgroupfit, either "per_level" to screen each independently fitted level separately, or "common" to remove from every level each equation which fails at any level. Ignored for other classes.

Value

The object with failing candidates removed. A bayesmanecfit reduced to one model becomes a bayesnecfit, as amend already does. A bayesnechurdlefit comes back as one, with each component screened. A bayesnecgroupfit comes back as one, with each element of fits replaced by its screened fit. A bayesnecjointfit that passes comes back unchanged.

What it screens on, and what it does not

Sampler diagnostics only. A poor check_fit is a modelling result — the model reproduces the data badly, which is information — and dropping on it silently would hide exactly what the user needs to see. A sampler failure is different in kind: the fit is unusable, whatever it says. So report the two side by side and screen on this one.

Three cases

Nothing failed — returns the object unchanged, and says so. amend is not called at all.

Some failed — the failed models the object holds are dropped with amend.

Everything failed — an error, raised before amend is called, that gives the reason each model failed. A fit where no candidate sampled properly is an outcome the analysis has to state, with what failed. An error raised by amend in the other cases is passed on unchanged.

Hurdle fits

A bayesnechurdlefit is screened one component at a time and rewrapped, as amend already does for that class. The two components may legitimately end up with different model sets — a model valid for the 0-1 bounded survival component need not be valid for growth.

Grouped fits

A bayesnecgroupfit is screened with group_action = "per_level" by default. An equation which fails at one level is then removed only from that level, because bnec_group fitted the levels independently. The returned levels may consequently have different candidate sets.

Set group_action = "common" to remove an equation from every level where it is present when it fails at any level. This keeps an initially common candidate set aligned, but discards fits which passed their own sampler diagnostics. Existing differences caused by equations that failed to fit cannot be restored by screening.

Joint refits

A bayesnecjointfit is screened one level at a time, on the table check_sampling returns. Each level has one equation in one posterior, so no level can be dropped. The refit is returned unchanged where every level passes, and the call stops, naming each level that failed, where any does, as it stops for a bayesnecfit that fails.

Examples

if (FALSE) { # \dontrun{
library(bayesnec)
screen_models(manec_example)
} # }