View source: R/query-functions.R
| fetch | R Documentation | 
Functions estimateModel, estimateCounts,
and estimateAccount, and their predict counterparts,
send their output to a simple database specified by filename.
Function fetch extracts estimates from this database.
fetch(filename, where = character(), iterations = NULL, impute = TRUE)
| filename | The filename used by the estimate function. | 
| where | A character vector describing the path to the item to be extracted. | 
| iterations | A vector of positive integers giving the iterations to be extracted if an item has multiple iterations. | 
| impute | Logical. Whether to impute missing values.
Defaults to  | 
Estimates are stored in a hierarchical structure.  The structure be viewed
with function listContents.  Function fetch uses
a description of the path through the hierarchical structure to locate
estimates.  The where argument to fetch is a character vector,
giving names of nodes in the hierarchy.  Partial matching is used with
the names of the nodes, so names can be shortened, provided they are still
long enough to uniquely identify a node.  (To make code self-documenting,
it is still best to use the full names in production code.)
Using the iterations to select a subset of iterations can be useful
if the object being extracted is large relative to memory or if calculations
are running slowly.
Where possible, estimateModel, estimateCounts,
and estimateAccount avoid imputing missing values during
model fitting, since the imputed values are typically highly correlated
with other unknown quantities, which can slow convergence.  If a batch
of estimates has missing values and if impute is TRUE the
missing values will be imputed at the time they are fetched.
Parameters that were estimated from the data typically have class
DemographicArray and have a dimension with
dimtype "iteration".  Other elements
stored in object have a variety of classes.
The weak identification of main effects and interactions is discussed in
Gelman, A. (2005). Analysis of variance: Why it is more important than ever. Annals of Statistics, 33(1):1-53.
and
Nelder, J. A. (1994). The statistics of linear models: Back to basics. Statistics and Computing. 4: 221-234.
fetch is used to extract output from functions 
estimateModel, estimateCounts,
and estimateAccount.  Function listContents
shows the internal structure of the output, which is useful for
constructing the where argument to fetch.
deaths <- demdata::VADeaths2
popn <- demdata::VAPopn
deaths <- round(deaths)
deaths <- Counts(deaths)
popn <- Counts(popn)
filename <- tempfile()
estimateModel(Model(y ~ Poisson(mean ~ age * sex)),
              y = deaths,
              exposure = popn,
              filename = filename,
              nBurnin = 20,
              nSim = 20,
              nChain = 2,
              parallel = FALSE)
## the model hasn't been run for long enough,
## but we'll extract some results anyway
## examine structure
listContents(filename)
## extract means from likelihood model
rate <- fetch(filename,
              where = c("model", "likelihood", "rate"))
plot(rate)
## only supply enough of component of 'where' to identify
rate <- fetch(filename,
              where = c("mo", "l", "r"))
## extract all iterations of intercept
fetch(filename,
      where = c("model", "prior", "(Intercept)"))
## extract every fifth iteration
fetch(filename,
      where = c("model", "prior", "(Intercept)"),
      iterations = seq(from = 5, by = 5, to = 40))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.