Calculate, print and plot the Monte Carlo error of the samples from a JointAI model.

MC_error(
  x,
  subset = NULL,
  exclude_chains = NULL,
  start = NULL,
  end = NULL,
  thin = NULL,
  digits = 2,
  warn = TRUE,
  mess = TRUE,
  ...
)

# S3 method for MCElist
plot(x, data_scale = TRUE, plotpars = NULL, ablinepars = list(v = 0.05), ...)

Arguments

x

object inheriting from class 'JointAI'

subset

subset of parameters/variables/nodes (columns in the MCMC sample). Uses the same logic as the argument monitor_params in *_imp.

exclude_chains

optional vector of the index numbers of chains that should be excluded

start

the first iteration of interest (see window.mcmc)

end

the last iteration of interest (see window.mcmc)

thin

thinning interval (see window.mcmc)

digits

number of digits for output

warn

logical; should warnings be given? Default is TRUE. (Note: this applies only to warnings given directly by JointAI.)

mess

logical; should messages be given? Default is TRUE. (Note: this applies only to messages given directly by JointAI.)

...

Arguments passed on to mcmcse::mcse.mat

size

represents the batch size in ``bm'' and the truncation point in ``bartlett'' and ``tukey''. Default is NULL which implies that an optimal batch size is calculated using the batchSize() function. Can take character values of ``sqroot'' and ``cuberoot'' or any numeric value between 1 and n/2. ``sqroot'' means size is floor(n^(1/2)) and ``cuberoot'' means size is floor(n^(1/3)).

g

a function such that \(E(g(x))\) is the quantity of interest. The default is NULL, which causes the identity function to be used.

method

any of ``bm'', ``obm'', ``bartlett'', ``tukey''. ``bm'' represents batch means estimator, ``obm'' represents overlapping batch means estimator with, ``bartlett'' and ``tukey'' represents the modified-Bartlett window and the Tukey-Hanning windows for spectral variance estimators.

r

the lugsail parameter that converts a lag window into its lugsail equivalent. Larger values of ``r'' will typically imply less underestimation of ``cov'', but higher variability of the estimator. Default is ``r = 3'' and ``r = 1,2'' are good choices. ``r > 5'' is not recommended. Non-integer values are ok.

data_scale

show the Monte Carlo error of the sample transformed back to the scale of the data (TRUE) or on the sampling scale (this requires the argument keep_scaled_mcmc = TRUE in the JointAI model)

plotpars

optional; list of parameters passed to plot()

ablinepars

optional; list of parameters passed to abline()

Value

An object of class MCElist with elements unscaled, scaled and digits. The first two are matrices with columns est (posterior mean), MCSE (Monte Carlo error), SD (posterior standard deviation) and MCSE/SD (Monte Carlo error divided by post. standard deviation.)

Methods (by generic)

  • plot: plot Monte Carlo error

Note

Lesaffre & Lawson (2012) [p. 195] suggest the Monte Carlo error of a parameter should not be more than 5% of the posterior standard deviation of this parameter (i.e., \(MCSE/SD \le 0.05\)).

References

Lesaffre, E., & Lawson, A. B. (2012). Bayesian Biostatistics. John Wiley & Sons.

See also

The vignette Parameter Selection provides some examples how to specify the argument subset.

Examples

mod <- lm_imp(y ~ C1 + C2 + M2, data = wideDF, n.iter = 100) MC_error(mod)
#> est MCSE SD MCSE/SD #> (Intercept) 35.99 1.5053 26.07 0.058 #> C1 -27.15 1.0508 18.20 0.058 #> C2 0.90 0.0400 0.69 0.058 #> M22 -0.35 0.0697 0.59 0.119 #> M23 0.15 0.0836 0.63 0.133 #> M24 -1.09 0.0683 0.56 0.121 #> sigma_y 2.22 0.0091 0.16 0.058
plot(MC_error(mod), ablinepars = list(lty = 2))