View source: R/query-functions.R
fetchMCMC | R Documentation |
Create an object of class "mcmc.list"
, or a list of objects of
class "mcmc.list"
, which can be analysed using the diagnostic
functions in package coda.
fetchMCMC(filename, where = NULL, nSample = 25, sample = NULL, thinned = TRUE)
filename |
The name of the file where the output from the
|
where |
A character vector used to select a single parameter or batch of parameters. See below for details. |
nSample |
Number of parameters to be sampled from a batch of parameters. Defaults to 25. Ignored when batch has fewer than 25 parameters (including having only one parameter.) |
sample |
Indices of parameters to be sampled. An alternative
to |
thinned |
Logical. If |
If no where
argument is supplied, mcmc.list
objects are returned for every parameter or batch of parameters that were
estimated. If a where
argument is supplied, it must describe the
path to parameter or parameters. See fetch
for more on
specifying paths.
If a batch of parameters has many elements, then calculating MCMC
diagnositics for all those elements can be very slow.
To speed things up, when applied to a batch of parameters,
fetchMCMC
randomly selects only nSample
of these
parameters. nSample
defaults to 25.
Alternatively, the indices of the parameters to be selected
can be specified using the sample
argument.
See below for an example.
If thinned
is TRUE
, then the thin
argument in
coda function mcmc
is set to 1; otherwise
thin
is set to nThin
, extracted from object
.
If the model in question contains structural zeros (see Poisson
),
some parameters of the model may be undefined. These parameters are omitted
from the results, unless they are specifically requested via the
sample
argument.
A single object of class "mcmc.list"
, or a named list
of such objects.
Other functions for examining output from
calls to estimateModel
, estimateCounts
, and
estimateAccount
include fetch
,
fetchFiniteSD
, and listContents
.
library(demdata)
## fit model
deaths <- Counts(round(VADeaths2))
popn <- Counts(VAPopn)
filename <- tempfile()
estimateModel(Model(y ~ Poisson(mean ~ age)),
y = deaths,
exposure = popn,
filename = filename,
nBurnin = 20,
nSim = 20,
nChain = 2,
parallel = FALSE)
## create a list containing an "mcmc.list" object for
## every element of the results that was estimated
l <- fetchMCMC(filename)
names(l)
sapply(l, class)
## analyse using functions from 'coda'
## Not run:
library(coda)
plot(l$model.likelihood.rate)
plot(l$model.likelihood.rate, ask = FALSE)
plot(l$model.likelihood.rate, ask = FALSE, smooth = FALSE)
gelman.diag(l$model.likelihood.rate)
## End(Not run)
## create a single "mcmc.list" object
mean.mcmc <- fetchMCMC(filename,
where = c("model", "likelihood", "rate"))
## only write part of each name
mean.mcmc <- fetchMCMC(filename, where = c("mod", "like", "r"))
## sample 6 randomly-chosen values
mean.mcmc.5 <- fetchMCMC(filename,
where = c("model", "likelihood", "rate"),
nSample = 6)
## sample the first 5 values
mean.mcmc.5 <- fetchMCMC(filename,
where = c("model", "likelihood", "rate"),
sample = 1:5)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.