Skip to content

Cumulative plots for diagnostics? #214

@catavallejos

Description

@catavallejos

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions