as_vital {vital}R Documentation

Coerce to a vital object

Description

A vital object is a type of tsibble that contains vital statistics such as births, deaths, and population counts, and mortality and fertility rates. It is a tsibble with a special class that allows for special methods to be used. The object has an attribute that stores variables names needed for some functions, including age, sex, births, deaths and population.

Usage

as_vital(x, ...)

## S3 method for class 'demogdata'
as_vital(x, sex_groups = TRUE, ...)

## S3 method for class 'tbl_ts'
as_vital(
  x,
  .age = NULL,
  .sex = NULL,
  .deaths = NULL,
  .births = NULL,
  .population = NULL,
  reorder = FALSE,
  ...
)

## S3 method for class 'data.frame'
as_vital(
  x,
  key = NULL,
  index,
  .age = NULL,
  .sex = NULL,
  .deaths = NULL,
  .births = NULL,
  .population = NULL,
  reorder = TRUE,
  ...
)

Arguments

x

Object to be coerced to a vital format.

...

Other arguments passed to tsibble::as_tsibble()

sex_groups

Logical variable indicating if the groups denote sexes

.age

Character string with name of age variable

.sex

Character string with name of sex variable

.deaths

Character string with name of deaths variable

.births

Character string with name of births variable

.population

Character string with name of population variable

reorder

Logical indicating if the variables should be reordered.

key

Variable(s) that uniquely determine time indices. NULL for empty key, and c() for multiple variables. It works with tidy selector (e.g. tidyselect::starts_with()).

index

A variable to specify the time index variable.

Value

A tsibble with class vital.

Author(s)

Rob J Hyndman

See Also

tsibble::tsibble()

Examples


# coerce demogdata object to vital
as_vital(demography::fr.mort)

# create a vital with only age as a key
tibble::tibble(
  year = rep(2010:2015, 100),
  age = rep(0:99, each = 6),
  mx = runif(600, 0, 1)
) |>
  as_vital(
    index = year,
    key = age,
    .age = "age"
  )

[Package vital version 1.1.0 Index]