fetch {demest} | R Documentation

## Extract estimates from model output.

### Description

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.

### Usage

    fetch(filename, where = character(), iterations = NULL, impute = TRUE)

### Arguments

`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 `TRUE`.

### Details

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.

### Value

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.

### References

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.

### See Also

`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`.

### Examples

    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))

[Package demest version 0.0.0.3.1 Index]