Vignette >Basic usage<

Load libraries

library(mortAAR)
library(magrittr)

Make test data available

Data from four neolithic gallery graves in central Germany [@czarnetzki_menschlichen_1966].

td <- gallery_graves

Inspect the data. Show the first ten rows of the data set:

td %>% head(., n = 10) %>% knitr::kable()

Clean up data

Replace: "?" with NA values.

td %>% replace(td == "?", NA) -> td
td %>% head(., n = 10) %>% knitr::kable()

Translate "inf_I", "inf_I" and "juv" into numeric age ranges [@martin_lehrbuch_1928, pp. 580].

td <- td %>% 
  replace(td == "inf_I",  "0-6") %>%
  replace(td == "inf_II", "7-13") %>%
  replace(td == "juv",    "14-19")
td %>% head(., n = 10) %>% knitr::kable()

Remove rows that do not have age information.

td <- td %>%
  dplyr::filter(!is.na(age))
td %>% head(., n = 10) %>% knitr::kable()

Make a decision on individual 139 from Niedertiefenbach with age less or equal 60.

td[td$indnr == "139" & td$site == "Niedertiefenbach", ]$age <- "50-60"
td %>% head(n = 10) %>% knitr::kable()

Separate the age range column.

td <- td %>%
  tidyr::separate(age, c("from", "to"))
td %>% head(., n = 10) %>% knitr::kable()

Adjust variable types.

td <- td %>%
  transform(
    from = as.numeric(from),
    to = as.numeric(to)
  )

Analysis preparation

Control the flow of the analysis by exemplifying what the different variables of the input data stand for.

# tdlist <- td %>%
#   plyr::dlply("site", identity)

td_prepared <- prep.life.table(
  td, 
  dec = NA, 
  agebeg = "from",
  ageend = "to", 
  group = "site", 
  method = "Standard",
  agerange = "included"
)

Analysis

td_result <- td_prepared %>%
  life.table()

Plot

td_result %>% plot(display = c("qx", "dx", "lx"))
td_result %>% plot(display = c("ex", "rel_popx"))

References



Try the mortAAR package in your browser

Any scripts or data that you put into this service are public.

mortAAR documentation built on May 25, 2021, 1:07 a.m.