Extracts posterior predicted values from a list of class
bayesnecfit or bayesmanecfit model fits and
compares these across a vector of fitted values.
compare_fitted(
x,
resolution = 50,
x_range = NA,
make_newdata = TRUE,
seed = 10,
...
)A named list of
bayesnecfit or bayesmanecfit objects.
The number of grid points each curve is predicted over. Defaults to 50.
A range of x values over which to consider extracting ECx.
Should the
user allow the package to create newdata for predictions?
If so, arguments resolution and x_range will be used. Defaults
to TRUE. See details.
A numeric vector of length 1. Passed to
set.seed before the draws of the posteriors being
compared are paired, so that two calls on the same fits return the same
answer. The caller's saved RNG state is restored afterwards, and a
set.seed in the session therefore does not change the
result. A different value gives another realisation of the same Monte
Carlo approximation. NULL is refused, because
set.seed(NULL) re-initialises the stream from the clock.
Reproducibility assumes the same RNG kind; the sampling algorithm is fixed
to sample.kind = "Rejection". The saved RNG state is restored,
but the cached normal variate used by normal.kind = "Box-Muller"
is not part of that state. With Box-Muller, the next normal draw can change
after an odd number of preceding normal draws. Use R's default
normal.kind = "Inversion" to preserve subsequent normal draws.
Further arguments that control posterior predictions via
posterior_epred.
A named list containing paired differences
in posterior predictions of the bayesnecfit or
bayesmanecfit model fits contained in x. See Details.
The argument make_newdata is relevant to those who want the
package to create a data.frame from which to make predictions. This is done
via bnec_newdata and uses arguments resolution and
x_range. If make_newdata = FALSE and no additional
newdata argument is provided (via ...), then the predictions
are made for the raw data. Else, to generate predictions for a specific
user-specific data.frame, set make_newdata = FALSE and provide
an additional data.frame via the newdata argument. For guidance
on how to structure newdata, see for example
posterior_epred.
The draws of each posterior are put in a random order, a longer posterior
being randomly subsampled to the length of the shortest, and are then paired
by position. prob_diff and the difference intervals are therefore a
Monte Carlo approximation that uses n of the n^2 available
pairs. The permutation is drawn under
seed, so two calls on the same fits return the same comparison and a
set.seed in the session has no effect on it. A different
seed gives another realisation of the same approximation;
where the approximation matters, compare a few and report the spread. The
caller's random number state is restored afterwards.
Where the posteriors being compared are independent, the paired differences
approximate the posterior of the difference between the estimates. Fits to
separate data that share no parameter, such as the levels of a
bayesnecgroupfit, have independent posteriors. For such
posteriors, pairing the draws by their index would approximate the same
distribution, so the random permutation is one Monte Carlo pairing and is
not required.
Whether two estimates are independent depends on their joint posterior, not
on the number of calls that fitted them. Two quantities that are dependent in
one posterior, for example two levels of one fit that share a group-level
term or a dispersion parameter, are contrasted by subtracting aligned draws
(draw i of each), which keeps their covariance. Pairing their draws
at random removes that covariance. Depending on its sign, the difference
posterior can then be wider or narrower, and prob_diff can move
towards or away from 0.5. Conversely, the levels of a
bnec_joint refit that share no parameter, as under its
defaults, have independent posteriors although they are estimated in one fit.
Where the fits share data or fitted components, the comparison is of a
different kind. Two equations pulled from one bayesmanecfit
with pull_out, as in the examples, are fitted to the same
observations, and a model-averaged fit includes the draws of its own
equations. The comparison then contrasts two estimates of one quantity from
one dataset, pairing their draws as if they were independent, and
prob_diff describes how far the two posteriors overlap, i.e. how much
the estimate depends on the equation fitted. How far it can be read as a
posterior probability is uncertain, because no joint posterior of the two
estimates is defined.