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

MC_error(x, subset = 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 lm_imp, glm_imp, clm_imp, lme_imp, glme_imp, survreg_imp and coxph_imp.

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

the batch size. The default value is “sqroot”, which uses the square root of the sample size. “cuberoot” will cause the function to use the cube root of the sample size. A numeric value may be provided if neither “sqroot” nor “cuberoot” is satisfactory.

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

the method used to compute the standard error. This is one of “bm” (batch means, the default), “obm” (overlapping batch means), “tukey” (spectral variance method with a Tukey-Hanning window), or “bartlett” (spectral variance method with a Bartlett window).

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 contains some examples how to specify the argument subset.

Examples

mod <- lm_imp(y~C1 + C2 + M2, data = wideDF, n.iter = 100)
#> This is new software. Please report any bugs to the package maintainer.
MC_error(mod)
#> est MCSE SD MCSE/SD #> (Intercept) 34.70 0.943 23.74 0.040 #> C1 -26.22 0.654 16.57 0.039 #> C2 0.99 0.036 0.65 0.056 #> M22 -0.38 0.029 0.65 0.044 #> M23 0.13 0.036 0.67 0.054 #> M24 -1.16 0.041 0.66 0.062 #> sigma_y 2.22 0.007 0.15 0.046
plot(MC_error(mod), ablinepars = list(lty = 2))