Created
September 25, 2012 23:38
-
-
Save jrnold/3785113 to your computer and use it in GitHub Desktop.
Generic functions for mcmcse package
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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, ...) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Generic functions wrapping
mcse
,mcse.q
, andess
from the R package mcmcse.