library(mortAAR)
library(magrittr)
Data from four neolithic gallery graves in central Germany (Czarnetzki 1966).
<- gallery_graves td
Inspect the data. Show the first ten rows of the data set:
indnr | sex | age | site |
---|---|---|---|
2 | m | 20-30 | Niedertiefenbach |
7 | m | 20-30 | Niedertiefenbach |
9 | m | 40-50 | Niedertiefenbach |
9t | m | 50-60 | Niedertiefenbach |
23 | m | 20-30 | Niedertiefenbach |
30 | m | 20-30 | Niedertiefenbach |
39 | m | 20-30 | Niedertiefenbach |
45 | m | 20-30 | Niedertiefenbach |
58 | m | 30-40 | Niedertiefenbach |
69 | m | 20-30 | Niedertiefenbach |
Replace: “?” with NA
values.
%>% replace(td == "?", NA) -> td td
indnr | sex | age | site |
---|---|---|---|
2 | m | 20-30 | Niedertiefenbach |
7 | m | 20-30 | Niedertiefenbach |
9 | m | 40-50 | Niedertiefenbach |
9t | m | 50-60 | Niedertiefenbach |
23 | m | 20-30 | Niedertiefenbach |
30 | m | 20-30 | Niedertiefenbach |
39 | m | 20-30 | Niedertiefenbach |
45 | m | 20-30 | Niedertiefenbach |
58 | m | 30-40 | Niedertiefenbach |
69 | m | 20-30 | Niedertiefenbach |
Translate “inf_I,” “inf_I” and “juv” into numeric age ranges (Martin 1928, 580).
<- td %>%
td replace(td == "inf_I", "0-6") %>%
replace(td == "inf_II", "7-13") %>%
replace(td == "juv", "14-19")
indnr | sex | age | site |
---|---|---|---|
2 | m | 20-30 | Niedertiefenbach |
7 | m | 20-30 | Niedertiefenbach |
9 | m | 40-50 | Niedertiefenbach |
9t | m | 50-60 | Niedertiefenbach |
23 | m | 20-30 | Niedertiefenbach |
30 | m | 20-30 | Niedertiefenbach |
39 | m | 20-30 | Niedertiefenbach |
45 | m | 20-30 | Niedertiefenbach |
58 | m | 30-40 | Niedertiefenbach |
69 | m | 20-30 | Niedertiefenbach |
Remove rows that do not have age information.
<- td %>%
td ::filter(!is.na(age)) dplyr
indnr | sex | age | site |
---|---|---|---|
2 | m | 20-30 | Niedertiefenbach |
7 | m | 20-30 | Niedertiefenbach |
9 | m | 40-50 | Niedertiefenbach |
9t | m | 50-60 | Niedertiefenbach |
23 | m | 20-30 | Niedertiefenbach |
30 | m | 20-30 | Niedertiefenbach |
39 | m | 20-30 | Niedertiefenbach |
45 | m | 20-30 | Niedertiefenbach |
58 | m | 30-40 | Niedertiefenbach |
69 | m | 20-30 | Niedertiefenbach |
Make a decision on individual 139 from Niedertiefenbach with age less or equal 60.
$indnr == "139" & td$site == "Niedertiefenbach", ]$age <- "50-60" td[td
indnr | sex | age | site |
---|---|---|---|
2 | m | 20-30 | Niedertiefenbach |
7 | m | 20-30 | Niedertiefenbach |
9 | m | 40-50 | Niedertiefenbach |
9t | m | 50-60 | Niedertiefenbach |
23 | m | 20-30 | Niedertiefenbach |
30 | m | 20-30 | Niedertiefenbach |
39 | m | 20-30 | Niedertiefenbach |
45 | m | 20-30 | Niedertiefenbach |
58 | m | 30-40 | Niedertiefenbach |
69 | m | 20-30 | Niedertiefenbach |
Separate the age range column.
<- td %>%
td ::separate(age, c("from", "to")) tidyr
## Warning: Expected 2 pieces. Missing pieces filled with `NA` in 1 rows [35].
indnr | sex | from | to | site |
---|---|---|---|---|
2 | m | 20 | 30 | Niedertiefenbach |
7 | m | 20 | 30 | Niedertiefenbach |
9 | m | 40 | 50 | Niedertiefenbach |
9t | m | 50 | 60 | Niedertiefenbach |
23 | m | 20 | 30 | Niedertiefenbach |
30 | m | 20 | 30 | Niedertiefenbach |
39 | m | 20 | 30 | Niedertiefenbach |
45 | m | 20 | 30 | Niedertiefenbach |
58 | m | 30 | 40 | Niedertiefenbach |
69 | m | 20 | 30 | Niedertiefenbach |
Adjust variable types.
<- td %>%
td transform(
from = as.numeric(from),
to = as.numeric(to)
)
Control the flow of the analysis by exemplifying what the different variables of the input data stand for.
# tdlist <- td %>%
# plyr::dlply("site", identity)
<- prep.life.table(
td_prepared
td, dec = NA,
agebeg = "from",
ageend = "to",
group = "site",
method = "Standard",
agerange = "included"
)
<- td_prepared %>%
td_result life.table()
%>% plot(display = c("qx", "dx", "lx")) td_result
## Warning: Removed 1 row(s) containing missing values (geom_path).
%>% plot(display = c("ex", "rel_popx")) td_result
## Warning: Removed 1 row(s) containing missing values (geom_path).