Statistical-Functions {dembase} | R Documentation

## Existing statistical functions.

### Description

Existing statistical functions give the same result when used with a `DemographicArray` array as they would with an ordinary `array` - except when the demographic array has a dimension with `dimtype` `"iteration"` or `"quantile"`. When there is an `"iteration"` dimension, the calculations are repeated once for each iteration, so that the return value is also a demographic array with an `"iteration"` dimension.

### Usage

    ## S4 method for signature 'DemographicArrayOrNumeric'
    Summary(x, ..., na.rm = FALSE)

    ## S4 method for signature 'DemographicArray'
    mad(
      x,
      center = median(x),
      constant = 1.4826,
      na.rm = FALSE,
      low = FALSE,
      high = FALSE
    )

    ## S4 method for signature 'DemographicArray'
    mean(x, ...)

    ## S4 method for signature 'DemographicArray'
    median(x, na.rm = FALSE, ...)

### Arguments

`x` | Typically an object of class `DemographicArray`.
`...` | Other arguments.
`na.rm` | Logical. Whether to remove missing values before calculating.
`center` | Function used to calculate central value. Defaults to `median`.
`constant` | See documentation for `mad`.
`low` | See documentation for `mad`.
`high` | See documentation for `mad`.

### Details

When called on an ordinary array, the functions all return a single number, except for `range`, which returns 2. When called on a demographic array with an `"iteration"` dimension, `range` returns a demographic array with a dimension called `"range"`, in addition to the `"iteration"` dimension.

When a demographic array has a dimension with `dimtype` `"quantile"`, applying statistical functions typically does not make sense, and an error is raised. It is generally better to work with the original array, with the complete set of iterations, and to reduce to quantiles once the calculations are complete.

### Value

Numeric, if `x` does not contain an `"iteration"` dimension, and `Counts` or `Values` if it does.

### See Also

Iteration and quantile dimensions are described in the documentation for `dimtypes`. To remove iteration dimensions (by summarising across them) use `collapseIterations`.

### Examples

    ## no iteration dimension
    x1 <- Counts(array(1:4,
                       dim = 4,
                       dimnames = list(region = c("A", "B", "C", "D"))))
    ## with iteration dimension
    x2 <- Counts(array(c(1:4, 0:3, 2:5),
                       dim = c(4, 3),
                       dimnames = list(region = c("A", "B", "C", "D"),
                                       iteration = 1:3)))
    x1
    x2
    sum(x1)
    sum(x2)
    range(x1)
    range(x2)

[Package dembase version 0.0.0.119 Index]