You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The KS test for equivalence of mcmc and iid samples is sensitive specifically to correlation in the MCMC samples, i.e., it assumes that there are n independent samples and the test statistic biases the p-value (because the samples are non-independent).
An ad hoc way of doing this is just to thin to reduce correlation
It would be more stable to estimate the amount of correlation and then thin appropriately
The text was updated successfully, but these errors were encountered:
Here's code to find a reasonable thinning rate for an mcmclist object:
# find a thinning rate that sufficiently reduces autocorrelation in the samples
find_thinning <- function(draws, max_thin = 100, autocorr_threshold = 0.01) {
autocorr_list <- coda::autocorr(draws, lags = seq_len(max_thin))
autocorrs <- do.call(cbind, autocorr_list)
mean_autocorr <- rowMeans(autocorrs)
smallest_thin <- which(mean_autocorr < autocorr_threshold)[1]
if (is.na(smallest_thin)) {
smallest_thin <- max_thin
warning("could not find any thinning value that reduces mean autocorrelation to below the threshold, using the maximum thinning amount",
call. = FALSE)
}
smallest_thin
}
# # example
# x <- normal(0, 1)
# m <- model(x)
# draws <- mcmc(m)
# find_thinning(draws)
n
independent samples and the test statistic biases the p-value (because the samples are non-independent).The text was updated successfully, but these errors were encountered: