---
title: "Computational details of demographic functions"
author: "C. Dutang and G.A. Spedicato"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output: rmarkdown::html_vignette
bibliography: lifecontingenciesBiblio.bib
vignette: >
  %\VignetteIndexEntry{Computational details of demographic functions} 
  %!\VignetteEncoding{UTF-8}
  \usepackage[utf8]{inputenc}
  %\VignetteEngine{knitr::rmarkdown}
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE,
                      collapse = TRUE,
                      comment = "#>")
```

# Survival probabilities

For notation details, see [@bowers1997actuarial].

Using the well-known relation ${}_{s+u}p_y={}_up_{y+s} \times {}_sp_y$, we compute ${}_tp_{x}$ as for all $x,t\in\mathbb R_+$
$$
{}_tp_{x} = \frac{{}_{t+\epsilon_x}p_{\lfloor x\rfloor}
}{{}_{\epsilon_x}p_{\lfloor x\rfloor}}
 = \frac{{}_{\lfloor u\rfloor}p_{\lfloor x\rfloor} \times {}_{\epsilon_u}p_{\lfloor x\rfloor+\lfloor u\rfloor}
 }{{}_{\epsilon_x}p_{\lfloor x\rfloor}}
$$
with $\epsilon_x=x - \lfloor x\rfloor$, $u=t+\epsilon_x$ and $\epsilon_u=u-\lfloor u\rfloor$.


Then we estimate ${}_np_{m}$ as for all $n,m\in\mathbb N$
$$
{}_np_{m} = \frac{l_{n+m}}{l_m}.
$$

We interpolate fractional age probabilities by three classical assumptions
for all $y \in [0,1), m\in\mathbb N$
$$
{}_{y}p_{m} =
\left\{
\begin{array}{ll}
1 - y (1-p_{m}) & \text{if uniform distribution} \\
(p_{m})^y & \text{if constant force} \\
\frac{p_{m}}{1-(1-y)(1-p_{m})} & \text{if hyperbolic distribution} \\
\end{array}
\right. 
$$

# Examples of non-integer times
```{r}
library(lifecontingencies)
data("soa08Act")
pXt <- Vectorize(lifecontingencies:::pxtold, "x")
pxT <- Vectorize(lifecontingencies:::pxtold, "t")
pxtvect <- pxt

z <- 1:6/3
#non integer time
cbind(t=z, pxtvect(soa08Act, x=100, t=z, fractional = "lin"), pxT(object=soa08Act, x=100, t=z, fractional = "lin"))
cbind(t=z, pxtvect(soa08Act, x=100, t=z, fractional = "hyp"), pxT(object=soa08Act, x=100, t=z, fractional = "hyp"))
cbind(t=z, pxtvect(soa08Act, x=100, t=z, fractional = "exp"), pxT(object=soa08Act, x=100, t=z, fractional = "exp"))
```


# Examples of non-integer ages

```{r}
x <- 50+0:6/6
#non-integer age
cbind(x=x, pxtvect(soa08Act, x=x, t=1, fractional = "lin"), pXt(object=soa08Act, x=x, t=1, fractional = "lin"))
cbind(x=x, pxtvect(soa08Act, x=x, t=1, fractional = "hyp"), pXt(object=soa08Act, x=x, t=1, fractional = "hyp"))
cbind(x=x, pxtvect(soa08Act, x=x, t=1, fractional = "exp"), pXt(object=soa08Act, x=x, t=1, fractional = "exp"))
```

# Examples of large ages
```{r}
x <- 135:145
#high-age
cbind(x=x, pxtvect(soa08Act, x=x, t=1), pXt(object=soa08Act, x=x, t=1))
```

