---
title: "Life table correction"
output: rmarkdown::html_vignette
bibliography: ../inst/REFERENCES.bib
vignette: >
  %\VignetteIndexEntry{Life table correction}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

## Load libraries

```{r, message=FALSE}
library(mortAAR)
library(magrittr)
```

## Smoothing of data

Due to the nature of most anthropological ageing methods, life tables from archaeological series often contain artificial jumps in the data. To counteract this effect, mortAAR provides the option to interpolate values for adults by a monotonic cubic spline. Usual options will by '10', '15' or '20' which will interpolate the values for individuals of an age of 20 or older by 10-, 15- or 20-year cumulated values. This is to be used carefully, as diagnostic features of the life table might be smoothed and essentially removed. This option is only available when the methods `Standard` or `Equal5` in `prep.life.table` have been chosen.

As an example, we work with the Early Neolithic cemetery of Nitra. First, we prepare the data, calculate the life table and plot d<sub>x</sub>- and q<sub>x</sub>-diagrams. The age-classes 25-44 show a bimodal distribution which might be artificial. Furthermore, the curve sharply drops after 40 which also looks very unnatural.

```{r}
nitra_prep <- prep.life.table(nitra, method="Equal5", agebeg = "age_start", ageend = "age_end")
nitra_life <- life.table(nitra_prep)
plot(nitra_life, display=c("dx","qx"))
```

Next we test how the plot changes if the spline-option with 10 and 20 years is chosen. In both cases, the smoothing is only applied to the age groups 20 and above.

```{r}
nitra_life <- life.table(nitra_prep,option_spline = 10)
plot(nitra_life, display=c("dx","qx"))
nitra_life <- life.table(nitra_prep,option_spline = 20)
plot(nitra_life, display=c("dx","qx"))
```

As expected, applying the option leads to much smoother curves. However, for the 10-year-option, the oldest age group shows a local maximum which is not reflected in the original data and therefore is an artefact of the smoothing algorithm working on the available data. In this case, the 20-year-option seems to offer a better compromise between a much more natural looking curve and still trueness to the original data.

## Representativeness of data

Anthropological data from archaeological contexts is necessarily fragmentary. The question remains if this fragmentation leads to completely unreliable inferences when statistical methods are applied to it. K. M. Weiss [-@weiss_demography_1973, 46f.] and C. Masset and J.-P. Bocquet-Appel [-@masset_bocquet_1977; see also @herrmann_prahistorische_1990, 306f.] have therefore devised indices which check if the non-adult age groups are represented in proportions as can be expected from modern comparable data. Whether this is really applicable to archaeological data-sets is a matter of debate.

Weiss chose the mortality (q<sub>x</sub>) as deciding factor and claimed that (1) the probability of death of the age group 10-15 (<sub>5</sub>q<sub>10</sub>) should be lower than that of the group 15-20 (<sub>5</sub>q<sub>15</sub>) and that (2) the latter in turn should be lower than that of age group 0-5 (<sub>5</sub>q<sub>0</sub>).

In contrast, Bocquet-Appel and Masset took the raw number of dead (D<sub>x</sub>) and asserted that (1) the ratio of those having died between 5 and 10 (D<sub>5-10</sub>) and those died between 10 and 15 years (D<sub>10-15</sub>) should be equal or larger than 2 and that (2) the ratio of those having died between 5 and 15 (D<sub>5-15</sub>) and all adults (>= 20; D<sub>20+</sub>) should be 0.1 or larger.

If either of these prerequisites is not met, the results from such data should be treated with extreme caution as the mortality structure is different from that of known populations. Due to the specific nature of the indices, they only give meaningful results if 5-year-age categories have been chosen for the non-adults.

Quite recently, B. Taylor and M. Oxenham [-@taylor_oxenham_2024] added a comparison of Total fertility rates (TRF) according to different formulas which depend either on subadults or adults. The formualas Taylor and Oxenham used either weigh all individuals aged 0--14 against all individuals or all individuals aged 15--49 against all individuals aged 15+. The formulas differ from the original ones published by C. McFadden and M. Oxenham [-@mcfadden_oxenham_2018a] and B. Taylor et al. [-@taylor_et_al_2023] because the data basis is slighty different. If the results of the formulas deviate by more than 0.692 (the standard error of estimate, SEE), they conclude that there is a problem with the age structure. In contrast to the tests by Weiss and Masset and Bocquet-Appel, there is no need to divide the sample into 5-year-steps, as long as the limits at 15 and 50 years are respected.

As example, we use the data-set of the medieval cemetery of Schleswig.

```{r}
schleswig <- life.table(schleswig_ma[c("a", "Dx")])
lt.representativity(schleswig)
```

The result is a dataframe where the individual conditions with the actual results are listed. The last column provides the verdict if the respective condition is met or not. In the case of the Schleswig cemetery, only the Weiss criterium (1) and the Bocquet-Appel/Masset criterium (2) is `TRUE`, the other three are `FALSE`. Therefore, it can be argued that the Schleswig data is not representative of a complete once-living population. However, it might be that the Bocquet-Appel/Masset criterium (1) is too conservative as only two individuals would have to have died at this age to bring the ratio above 2 [@herrmann_prahistorische_1990, 307]. P. Sellier [-@sellier_1989, 23] has even argued that the ratio should be 1.5 instead of 2. In this case, both criteria of Bocquet-Appel and Masset would be met for the Schleswig cemetery.

## Correction of life table data after Bocquet-Appel and Masset

It is generally assumed that most skeletal populations lack the youngest age group. Life tables resulting from such populations will necessarily be misleading as they lead to believe that the mortality of younger children was lower than it actually was and that life expectancy was higher. For correcting these missing individuals, Masset and Bocquet-Appel [-@masset_bocquet_1977; see also @herrmann_prahistorische_1990, 307] conceived of several calculations based on regression analyses of modern comparable mortality data. Despite the fact that these recommendations are more than 40 years old, they still surface in text books [e. g. @grupe_et_al_2015, 418--419]. However, the applicability of these indices to archaeological data is debatable and does not necessarily lead to reliable results. Therefore, the correction needs to be weighted carefully and ideally only after the representativeness of the base data has been checked with function `lt.representativity`.

The equations conceived by Masset and Bocquet-Appel are relatively complex. Life expectancy at the time of birth is computed as follows: 

$e^0_x = 78.721 * log_{10} \sqrt{\frac{D_{20+}}{ D_{5-14}}} - 3.384 \pm 1.503$

The equation will strive towards 75 years of life expectancy when there is a ratio of adults to 5--14-year old of 100 to 1 as the term $log_{10} \sqrt{\frac{D_{20+}}{ D_{5-14}}})$ will then tend towards 1. Higher numbers of non-adults will likewise lead to lower life expectancy values.

The probability of death in the first and the first five years is similarly constructed:

$_1q_0 = 0.568 * \sqrt{log_{10}(\frac{200*D_{5-14}}{D_{20+}}}) - 0.438 \pm 0.016$

$_5q_0 = 1.154 * \sqrt{log_{10}(\frac{200*D_{5-14}}{D_{20+}}}) - 1.014 \pm 0.041$


The corrected Schleswig data^[The values differ from that published by Herrmann et al. [-@herrmann_prahistorische_1990, 307] because here no correction of the age group 5--10 years was applied.] are as follows:

```{r}
schleswig <- life.table(schleswig_ma[c("a", "Dx")])
lt.correction(schleswig)
```

Apart from the corrected life table, it also lists -- as separate data.frame -- the indices ($e^0$, $_1q_0$ and $_5q_0$) computed by the formulas of Masset and Bocquet-Appel. Compare this to the uncorrected values:

```{r}
life.table(schleswig_ma[c("a", "Dx")])
```

With the uncorrected data, the youngest age group (years 0--4) 'only' comprises around 20% of the population. However, according to the formulas by Masset and Bocquet-Appel, this number should be more than doubled (46%). This would mean that in reality nearly 50% of the individuals died before they reached their 5^th^ birthday. Applying this value to the life table, the number of individuals increases from 247 to 368 and at the same time the life expectancy at birth decreases from 30.7 to 21.1 years. Please note that this value differs somehow from that which is computed by the formula by Masset and Bocquet-Appel (22.5 years). This is easily explainable as the life expectancy of the life table includes _all_ individuals. However, the value of 21.1 years is still in the range of 21.0 to 24.1 years (see indices) given by Masset and Bocquet-Appel.

```{r}
lt.representativity(lt.correction(schleswig)$life_table_corr)
```

Because the correction only applies to the youngest age group, it has no effects on the tests for representativeness by Weiss and Masset and Bocquet-Appel. The correction, however, affects the test by Taylor et al. Now, the Total fertility rate based on the subadult index is much closer to the value computed from the individuals aged 15 and above. As the difference is below 0.692, the test now would not suspect a biased population. This might be taken as hint that the 'true' TFR-value is closer to 7 than to 4 and that the correction by Masset and Bocquet-Appel was both necessary and arrived at good estimates.

## References
