collapseIterations {dembase} | R Documentation

## Summarize iterations.

### Description

Collapse a dimension with `dimtype` `"iteration"`, typically replacing it with a much shorter dimension with dimtype `"quantile"`.

### Usage

    collapseIterations(object, FUN = quantile, ...)

    ## S4 method for signature 'DemographicArray'
    collapseIterations(object, FUN = quantile, ...)

### Arguments

`object` | Object of class `DemographicArray`.
`FUN` | A function. Defaults to `quantile`, though others can be used.
`...` | Further arguments, passed to `FUN`.

### Details

Many estimation and forecasting methods produce sets of simulation runs or iterations. When graphing or reporting results, it is typically necessary to reduce the full set of iterations to a set of summary values. Function `collapseIterations` carries out this reduction. By default, `collapseIterations` calculates quantiles. However, users can supply alternatives, including their own customized functions.

If `FUN` returns a vector, then the dimension with dimtype `"iteration"` is replaced by one with dimtype `"quantile"` or `"state"`. If `FUN` returns a single value, then the `"iteration"` dimension is dropped.

By default, function `quantile` uses quantiles `0, 0.25, 0.5, 0.75, 1`. Quantiles more useful for summarizing iterations, such as `0.025, 0.5, 0.975`, can be obtained by using a `prob` argument: see below for an example.

### See Also

`collapseCategories`, `collapseIntervals`, `collapseOrigDest`, `collapseDimension`, `dimtypes`, `dimscales`

### Examples

    x <- Counts(array(rpois(n = 20, lambda = c(8, 12)),
                      dim = c(2, 10),
                      dimnames = list(sex = c("Female", "Male"),
                          iteration = 1:10)))
    x
    collapseIterations(x)

    ## pass different values for 'prob' to 'quantile'
    collapseIterations(x, prob = c(0.025, 0.5, 0.975))

    ## summarize with a single value
    collapseIterations(x, FUN = mean)

    ## a user-defined function
    sumvals <- function(x) c(mean = mean(x), sd = sd(x))
    collapseIterations(x, FUN = sumvals)

[Package dembase version 0.0.0.119 Index]