| extract_acf | R Documentation |
Computes autocorrelation function (ACF) values for MCMC chains and returns them in a tidy data frame format.
extract_acf(object, pars = NULL, lags = 20, ...)
object |
A clmstan object |
pars |
Character vector of parameter names. If NULL (default), uses beta, c_transformed (except first), and beta0. |
lags |
Maximum number of lags to compute. Default is 20. |
... |
Additional arguments (ignored) |
The ACF measures how correlated each draw is with previous draws in the same chain. High autocorrelation at many lags indicates slow mixing and the need for more samples or reparameterization.
Ideally, ACF should drop to near zero within a few lags. Persistent high autocorrelation suggests the sampler is exploring the posterior slowly.
A data frame with columns:
parameter: Parameter name
chain: Chain number
lag: Lag value (0, 1, 2, ...)
acf: Autocorrelation value
## Not run:
fit <- clm_stan(rating ~ temp, data = wine)
acf_df <- extract_acf(fit)
head(acf_df)
# Plot ACF for specific parameters
library(ggplot2)
acf_df |>
dplyr::filter(parameter == "beta[1]") |>
ggplot(aes(x = lag, y = acf, color = factor(chain))) +
geom_line() +
geom_hline(yintercept = 0, linetype = "dashed")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.