Learn R Programming

sanba (version 0.0.3)

plot.SANmcmc: Visual Check of the Convergence of the MCMC Output

Description

Plot method for objects of class SANmcmc. Check the convergence of the MCMC through visual inspection of the chains.

Usage

# S3 method for SANmcmc
plot(
  x,
  param = c("mu", "sigma2", "pi", "num_clust", "alpha", "beta"),
  show_density = TRUE,
  add_burnin = 0,
  show_convergence = TRUE,
  trunc_plot = 2,
  ...
)

Value

The function displays the traceplots and posterior density estimates of the parameters sampled in the MCMC algorithm.

Arguments

x

Object of class SANmcmc (usually, the result of a call to fit_CAM, fit_fiSAN, or fit_fSAN, used with the est_method = "MCMC" argument).

param

String with the names of the parameters to check. It can be one of "mu", "sigma2", "pi", "num_clust", "alpha", "beta".

show_density

Logical (default TRUE). Should a kernel estimate of the density be plotted?

add_burnin

Integer (default = 0). Additional number of observations to discard in the burn-in.

show_convergence

Logical (default TRUE). Should a superimposed red line of the cumulative mean be plotted?

trunc_plot

Integer (default = 10). For multidimensional parameters, the maximum number of components to be plotted.

...

Ignored.

Examples

Run this code
set.seed(123)
y <- c(rnorm(40,0,0.3), rnorm(20,5,0.3))
g <- c(rep(1,30), rep(2, 30))
out <- fit_fiSAN(y = y, group = g, "MCMC", mcmc_param = list(nrep = 500, burn = 200))
plot(out, param = "mu", trunc_plot = 2)
plot(out, param = "sigma2", trunc_plot = 2)
plot(out, param = "alpha", trunc_plot = 1)
plot(out, param = "alpha", add_burnin = 100)
plot(out, param = "pi", trunc_plot = 4, show_density = FALSE)

out <- fit_CAM(y = y, group = g, "MCMC",
mcmc_param = list(nrep = 500, burn = 200, seed= 1234))
plot(out, param = "mu", trunc_plot = 2)
plot(out, param = "sigma2", trunc_plot = 2)
plot(out, param = "alpha")
plot(out, param = "pi", trunc_plot = 2)
plot(out, param = "pi", trunc_plot = 5)
plot(out, param = "num_clust", trunc_plot = 5)
plot(out, param = "beta", trunc_plot = 2)

out <- fit_fSAN(y = y, group = g, "MCMC", mcmc_param = list(nrep = 500, burn = 200))
plot(out, param = "mu", trunc_plot = 2)
plot(out, param = "sigma2", trunc_plot = 2)
plot(out, param = "pi", trunc_plot = 4,
     show_convergence = FALSE, show_density = FALSE)

Run the code above in your browser using DataLab