Using the posterior samples, estimate how much the variance of errors is reduced by group-level pooling.
shrinkage(errors, ..., use_sd = TRUE)
# S3 method for bbi_nmbayes_model
shrinkage(errors, ..., use_sd = TRUE)
# S3 method for draws
shrinkage(errors, errors_name, group_idx = NULL, ..., use_sd = TRUE)
# S3 method for rvar
shrinkage(errors, variance = NULL, group_idx = NULL, ..., use_sd = TRUE)
An object from which errors can be extracted.
For a bbi_nmbayes_model
object, the ETA
values are taken as the
errors, and variance for each ETA
is extracted from the diagonal of the
OMEGA
matrix. As a special case, if *.iph
files do not exist, the
shrinkage values are collected from the *.shk
files and summarized as
medians across chains.
For a posterior draws object, the errors are extracted for the
parameter name specified by errors_name
. When passing a draws object,
the variance is calculated from the errors, and there is not support for
also providing separate variance values; to do that, pass rvar objects
instead.
For a posterior rvar object, the errors and variance are supplied directly.
Additional arguments passed on to methods.
Whether to calculate shrinkage with standard deviation (default) instead of variance.
Name of a parameter to extract from the draws_rvars
object and use as the errors.
A vector of indices specifying which dimension(s) correspond to groups. Defaults to the last dimension when not specified.
A posterior rvar object specifying variance of the
errors. If not specified, it is set to the variance across groups in
errors
. Note that this should be variance, not standard deviation, even
when use_sd
is TRUE
.
Vector of shrinkage estimates, in the same order as the values
specified by errors
.
The dimensions of the input errors determines the dimensions of the return
value. For example, errors of the form X[i,j]
, where j
is the
group-level index, would lead to a vector of i
values. And errors
X[i,j,k]
, where k
is the group-level index, would lead to a matrix with
i
rows and j
columns.
The shrinkage calculation here follows Gelman and Pardoe's pooling factor definition, with a few adjustments:
Keeping with pharmacometrics conventions, the calculation uses standard
deviation rather than variance by default (controlled by use_sd
argument).
As with NONMEM's shrinkage values, the returned values are percentages rather than fractions.
If the variance of the errors is supplied, the denominator is calculated by taking the expectation of those values.
Andrew Gelman, Iain Pardoe (2006) Bayesian measures of explained variance and pooling in multilevel (hierarchical) models. Technometrics. 48(2), 241--251.