Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cumulative plots for diagnostics? #214

Open
catavallejos opened this issue Oct 26, 2020 · 2 comments
Open

Cumulative plots for diagnostics? #214

catavallejos opened this issue Oct 26, 2020 · 2 comments

Comments

@catavallejos
Copy link
Owner

catavallejos commented Oct 26, 2020

Nothing really urgent, but may be useful.

Eg.

cumulative_median <- function(y) {
  n <- length(y)
  out <- sapply(seq_len(n), function(x) median(y[seq_len(x)]))
  return(out)
}

cumulative_HPD <- function(y) {
  n <- length(y)
  out <- sapply(seq_len(n)[-1], function(x) coda::HPDinterval(coda::mcmc(y[seq_len(x)])))
  return(out)
}

cumulative_plot <- function(chain) {
  
  Median <- cumulative_median(chain)
  HPD <- cumulative_HPD(chain)
  plot(Median, type = "l", ylim = range(HPD))
  lines(HPD[1,], col = "red")
  lines(HPD[2,], col = "red")
  abline(h = median(chain), col = "blue")
}
chain <- rnorm(1000)
cumulative_plot(chain)

@catavallejos
Copy link
Owner Author

Just posting here so that I don't loose the code. May never be implemented

@alanocallaghan
Copy link
Collaborator

Nice plot, I may borrow and adapt this code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants