Skip to content

Instantly share code, notes, and snippets.

@jrnold
Created September 25, 2012 23:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrnold/3785113 to your computer and use it in GitHub Desktop.
Save jrnold/3785113 to your computer and use it in GitHub Desktop.
Generic functions for mcmcse package
## Monte Carlo Standard Error
## @export
setGeneric("mcse", function(x, ...) {
ret <- mcmcse::mcse(x, ...)
ifelse(is.na(ret), c(est=NA, se=NA), unlist(ret))
})
setMethod("mcse", "matrix", function(x, ...) {
t(apply(x, 2, mcse, ...))
})
setMethod("mcse", "array",
function(x, MARGIN=seq_along(dim(x))[-1], ...)
{
apply(x, MARGIN, mcse_q)
})
setMethod("mcse", "mcmc.list", function(x, ...) {
lapply(x, mcse, ...)
})
setMethod("mcse", "list", function(x, ...) {
lapply(x, mcse, ...)
})
## Monte Carlo standard error for Quantiles
## @export
setGeneric("mcseq", function(x, ...) {
ret <- mcmcse::mcse.q(x, ...)
ifelse(is.na(ret), c(est=NA, se=NA), unlist(ret))
})
setMethod("mcseq", "matrix", function(x, ...) {
t(apply(x, 2, mcseq, ...))
})
setMethod("mcseq", "array",
function(x, MARGIN=seq_along(dim(x))[-1], ...)
{
apply(x, MARGIN, mcseq)
})
setMethod("mcseq", "mcmc", function(x, ...) {
mcseq(as.matrix(x), ...)
})
setMethod("mcseq", "mcmc.list", function(x, ...) {
lapply(x, mcseq, ...)
})
setMethod("mcseq", "list", function(x, ...) {
lapply(x, mcseq, ...)
})
## Effective Sample Size (ESS)
## @export
setGeneric("ess", function(x, ...) {
mcmcse::ess(x, ...)
})
setMethod("ess", "matrix", function(x, ...) {
t(apply(x, 2, ess, ...))
})
setMethod("ess", "array",
function(x, MARGIN=seq_along(dim(x))[-1], ...)
{
apply(x, MARGIN, ess, ...)
})
setMethod("ess", "mcmc", function(x, ...) {
ess(as.matrix(x), ...)
})
setMethod("ess", "mcmc.list", function(x, ...) {
lapply(x, ess, ...)
})
setMethod("ess", "list", function(x, ...) {
lapply(x, ess, ...)
})
@jrnold
Copy link
Author

jrnold commented Sep 25, 2012

Generic functions wrapping mcse, mcse.q, and ess from the R package mcmcse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment