%\VignetteIndexEntry{Years of life lost (YLL)}

\documentclass[a4paper, twoside, 12pt]{report}

\newcommand{\Title}{Years of Life Lost (YLL)
  to disease:\\Diabetes in DK as example}
\newcommand{\Tit}{YLL}
\newcommand{\Version}{2}
\newcommand{\Dates}{June 2024}
\newcommand{\Where}{SDC}
\newcommand{\Homepage}{\url{https://bendixcarstensen.com/Epi/}}
\newcommand{\Faculty}{\begin{tabular}{rl}
Bendix Carstensen
  & Steno Diabetes Center Copenhagen, Herlev, Denmark\\
  & {\small \& Department of Biostatistics,
               University of Copenhagen} \\
  & \texttt{b@bxc.dk}\\
  & \url{https://BendixCarstensen.com/} \\[1em]
                      \end{tabular}}

\input{topreport}
\renewcommand{\rwpre}{./05yll}

\chapter{Technicalities and theory}

\section{Technicalities}
First we set some graphics parameters for convenience and load the
packages needed:
\begin{Schunk}
\begin{Sinput}
> options(width = 90,
+         show.signif.stars = FALSE,
+         SweaveHooks=list(fig = function()
+                          par(mar = c(3, 3, 1, 1),
+                              mgp = c(3, 1, 0) / 1.6,
+                              las = 1,
+                             lend = "butt",
+                              bty = "n")))
> library(Epi)
> library(popEpi)
> library(survival)
> clear()
\end{Sinput}
\end{Schunk}
% must be after clear() because 'anfang' is used at the end
\begin{Schunk}
\begin{Soutput}
     R   Epi   popEpi
 4.5.3  2.64   0.4.14
\end{Soutput}
\end{Schunk}

\section{About this vignette}

This vignette for the \texttt{Epi} package describes the probabilistic
and demographic background for and technical implementation of the
\texttt{erl} and \texttt{yll} functions that computes the expected
residual life time and years of life lost in an illness-death model.

\section{Years of life lost (YLL)}

\ldots to diabetes or any other disease for that matter.

The general concept in calculation of ``years lost to\ldots'' is the
comparison of the expected lifetime between two groups of persons; one
with and one without disease (in this example DM). The expected
lifetime is the area under the survival curve, so basically the
exercise requires that two survival curves that are deemed relevant be
available.

The years of life lost is therefore just the area between the survival
curves for those ``Well'', $S_W(t)$, and for those ``Diseased'',
$S_D(t)$:
\[
  \YLL = \int_0^\infty S_W(t) - S_D(t) \dif t
\]
The time $t$ could of course be age, but it could also be ``time after
age 50'' and the survival curves compared would then be survival
curves \emph{conditional} on survival till age 50, and the YLL would
be the years of life lost for a 50 year old person with diabetes
relative to a 50 year old person without diabetes.

If we are referring to the expected lifetime we will more precisely use
the label expected residual lifetime, ERL.

\section{Constructing the survival curves}

YLL can be computed in two different ways, depending on the way the
survival curve and hence the expected lifetime of a person
\emph{without} diabetes is computed:
\begin{itemize}
\item Assume that the ``Well'' persons are \emph{immune} to disease
  --- using only the non-DM mortality rates throughout for calculation
  of expected life time.
\item Assume that the ``Well'' persons \emph{can} acquire the disease and
  thereby see an increased mortality, thus involving all three rates
  shown in figure \ref{fig:states}.
\end{itemize}
The former gives a higher YLL because the comparison is to persons
assumed immune to DM (and yet with the same mortality as non-immune
prior to diagnosis), the latter gives a more realistic picture of the
comparison of group of persons with and without diabetes at a given
age that can be interpreted in the real world.

The differences can be illustrated by figure \ref{fig:states}; the
immune approach corresponds to an assumption of $\lambda(t)=0$ in the
calculation of the survival curve for a person in the ``Well'' state.

Calculation of the survival of a diseased person already in the ``DM''
state is unaffected by assumptions about $\lambda$.

We can illustrate the states and transitions using \texttt{boxes}:
\begin{Schunk}
\begin{Sinput}
> library(Epi)
> TM <- matrix(NA, 4, 4)
> rownames(TM) <-
+ colnames(TM) <- c("Well", "DM", "Dead", "Dead(DM)")
> TM[1, 2:3] <- TM[2, 4] <- 1
> TM
\end{Sinput}
\begin{Soutput}
         Well DM Dead Dead(DM)
Well       NA  1    1       NA
DM         NA NA   NA        1
Dead       NA NA   NA       NA
Dead(DM)   NA NA   NA       NA
\end{Soutput}
\begin{Sinput}
> zz <- boxes(TM, boxpos = list(x = c(20, 80, 20, 80),
+                               y = c(80, 80, 20, 20)),
+                 wm = 1.5,
+                 hm = 4)
\end{Sinput}
\end{Schunk}
We can edit the output from \texttt{boxes} to get the proper
annotation of the transition rates:
\begin{Schunk}
\begin{Sinput}
> zz$Arrowtext <- c(expression(lambda(a)),
+                   expression(mu[W](a)),
+                   expression(mu[D][M](a,d)))
> boxes.MS(zz)
\end{Sinput}
\end{Schunk}
\insfig{states}{0.7}{Illness-death model describing diabetes incidence
  and -mortality and functions of age and duration}

\subsection{Total mortality --- a shortcut?}

A practical crude shortcut could be to compare the ERL in the diabetic
population to the ERL for the \emph{entire} population (that is using
the total mortality ignoring diabetes status).

Note however that this approach also counts the mortality of persons
that acquired the disease earlier, thus making the comparison
population on average more ill than the population we aim at, namely
those well at a given time, which only then become more gradually ill.

How large these effects are can however be empirically explored, as we
shall do later.

\subsection{Disease duration}

In the exposition above there is no explicit provision for the effect of
disease duration, but if we were able to devise mortality rates for
any combination of age and duration, this could be taken into account.

There are however severe limitations in this as we in principle would
want to have duration effects as long as the age-effects --- in
principle for all $(a, d)$ where $d\leq A$, where $A$ is the age at
which we condition. So even if we were only to compute ERL from
age, say, 40 we would still need duration effects up to 60 years
(namely to age 100).

The incorporation of duration effects is in principle trivial from a
computational point of view, but we would be forced to entertain
models predicting duration effects way beyond what is actually
observed disease duration in any practical case.

\subsection{Computing integrals}

The practical calculations of survival curves, ERL and YLL involves
calculation of (cumulative) integrals of rates and functions of these
as we shall see below. This is easy if we have a closed form
expression of the function, so its value may be computed at any time
point --- this will be the case if we model rates by smooth parametric
functions.

Computing the (cumulative) integral of a function is done as follows:
\begin{itemize}
\item Compute the value of the function (mortality rate for example)
  at the midpoints of a sequence of narrow equidistant intervals ---
  for example one- or three month intervals of age, say.
\item Take the cumulative sum of these values multiplied by the
  interval length --- this will be a very close approximation to the
  cumulative integral evaluated at the end of each interval.
\item If the intervals are really small (like 1/100 year), the
  distinction between the value at the middle and at the end of each
  interval becomes irrelevant.
\end{itemize}
Note that in the above it is assumed that the rates are given in units
corresponding to the interval length --- or more precisely, as the
cumulative rates over the interval.

\section{Survival functions in the illness-death model}

The survival functions for persons in the ``Well'' state can be
computed under two fundamentally different scenarios, depending on
whether persons in the ``Well'' state are assumed to be immune to the
disease ($\lambda(a)=0$) or not.

\subsection{Immune approach}

In this case both survival functions for person in the two states are
the usual simple transformation of the cumulative mortality rates:
\[
 S_W(a) = \exp\left(-\int_0^a\!\!\mu_W(u) \dif u \right), \qquad
 S_D(a) = \exp\left(-\int_0^a\!\!\mu_D(u) \dif u \right)
\]

\subsubsection{Conditional survival functions}

If we want the \emph{conditional} survival functions given survival to
age $A$, say, they are just:
\[
 S_W(a|A) = S_W(a)/S_W(A), \qquad S_D(a|A) = S_D(a)/S_D(A)
\]

\subsection{Non-immune approach}

For a diseased person, the survival function in this states is the same
as above, but the survival function for a person without disease (at
age 0) is (see figure \ref{fig:states}):
\[
S(a) = \ptxt{Well}\!(a) + \ptxt{DM}\!(a)
\]
In the appendix of the paper \cite{Carstensen.2008c} is an indication
of how to compute the probability of being in any of the four states
shown in figure \ref{fig:states}, which I shall repeat here:

In terms of the rates, the probability of being in the ``Well'' box is
simply the probability of escaping both death (at a rate of $\mu_W(a)$)
and diabetes (at a rate of $\lambda(a)$):
\[
   \ptxt{Well}(a)  = \exp\left(\!-\int_0^a\!\!\mu_W(u)+\lambda(u) \right) \dif u
\]
The probability of being alive with diabetes at age $a$, is computed given that
 diabetes occurred at age $s$ ($s<a$) and then integrated over $s$ from $0$
 to $a$:
\begin{align*}
 \ptxt{DM}(a) = \int_0^a\!\! & \ptxt{survive to $s$, DM diagnosed at $s$} \\
                & \times \ptxt{survive with DM from $s$ to $a$} \dif s \\
              = \int_0^a\!\! & \lambda(s)
                           \exp\left(\!-\int_0^s\!\!\mu_W(u)+\lambda(u) \dif u \right) \\
                & \times \exp\left(\!-\int_s^a\!\!\mu_D(u) \dif u \right) \dif s
\end{align*}
Sometimes we will use a version where the mortality among diabetes
patients depend both on age $a$ and duration of diabetes, $d$,
$\mu_D(a, d)$, in which case we get:
\begin{align*}
 \ptxt{DM}(a) = \int_0^a \! & \lambda(s)
                \exp\left(-\int_0^s\!\mu_W(u)+\lambda(u) \dif u \right) \\
                & \times \exp\left(-\int_s^a\!\mu_D(u, u-s) \dif u \right) \dif s
\end{align*}
because the integration variable $u$ is the age-scale and the second
integral refers to mortality among persons diagnosed at age $s$, that
is, with duration $u-s$ at age $u$.

The option of using duration-dependent mortality rates among diseased
individuals is not implemented yet.

\subsubsection{Conditional survival functions}

Unlike the immune approach, the conditional survival function in the
more realistic case is not just a ratio of the unconditional to the
value at the conditioning age, $A$, say. This would amount to
conditioning on being merely \emph{alive} at age $A$, but what we want
is to condition on being in the ``Well'' state at age $A$.

The formulae for the conditional probabilities of being either in
``Well'' or ``DM'', given being in ``Well'' at age $A$ are basically
replicates of the unconditional, albeit with changes in integration
limits:
\begin{align*}
\ptxt{Well|Well at $A$}(a) &= \exp\left(-\int_A^a \! \mu_W(u)+\lambda(u) \right) \dif u \\
  \ptxt{DM|Well at $A$}(a) &= \int_A^a \! \lambda(s)
                               \exp\left(-\int_A^s\!\mu_W(u)+\lambda(u) \dif u \right) \\
                           & \qquad \times \exp\left(-\int_s^a\!\mu_D(u, u-s) \dif u \right) \dif s
\end{align*}
The calculation of these conditional survival functions is implemented
but not allowing for duration-dependence. Thus it is only implemented
assuming $\mu_D(a, d)=\mu_D(a)$.

\chapter{Analyses for DM in Denmark}

The rates we use as basis for the following calculations are derived
from the NDR, where we have omitted the blood-glucose criteria,
because there is compelling evidence that these have quite a low
specificity (particularly in the younger ages among women), and do
not substantially contribute to the sensitivity.

As noted above the calculations of YLL requires access to
(age-specific) rates of incidence of DM and mortality for persons with
and without DM.

\section{Modeling mortality and incidence data}

We read in the dataset of DM and population mortality and incidence, \texttt{DMepi}:
\begin{Schunk}
\begin{Sinput}
> data(DMepi)
\end{Sinput}
\end{Schunk}
The dataset \texttt{DMepi} contains diabetes events, deaths and
person-years for persons without diabetes and deaths and person-years
for persons with diabetes, classified by age (\texttt{A}) and calendar
year (\texttt{P}):
\begin{Schunk}
\begin{Sinput}
> str(DMepi)
\end{Sinput}
\begin{Soutput}
'data.frame':	4200 obs. of  8 variables:
 $ sex : Factor w/ 2 levels "M","F": 1 1 1 1 1 1 1 1 1 1 ...
 $ A   : num  0 0 0 0 0 0 0 0 0 0 ...
 $ P   : num  1996 1997 1998 1999 2000 ...
 $ D.DM: num  0 0 0 0 0 0 0 0 0 0 ...
 $ Y.DM: num  0.484 0.64 1.641 0.552 2.507 ...
 $ X   : num  1 2 4 4 4 1 1 3 4 1 ...
 $ D.nD: num  28 19 20 11 21 16 21 15 16 16 ...
 $ Y.nD: num  35469 35085 34240 34056 34002 ...
\end{Soutput}
\begin{Sinput}
> head(DMepi)
\end{Sinput}
\begin{Soutput}
  sex A    P D.DM      Y.DM X D.nD     Y.nD
2   M 0 1996    0 0.4839151 1   28 35468.92
3   M 0 1997    0 0.6399726 2   19 35085.18
4   M 0 1998    0 1.6406571 4   20 34240.14
5   M 0 1999    0 0.5523614 4   11 34055.52
6   M 0 2000    0 2.5065024 4   21 34002.22
7   M 0 2001    0 0.1184120 1   16 34177.39
\end{Soutput}
\end{Schunk}
For each combination of sex, age, period and date of birth in 1 year
age groups, we have the person-years in the ``Well'' (\texttt{Y.nD})
and the ``DM'' (\texttt{Y.DM}) states, as well as the number of deaths
from these (\texttt{D.nD}, \texttt{D.DM}) and the number of incident
diabetes cases from the ``Well'' state (\texttt{X}).

In order to compute the years of life lost to diabetes and how this
has changed over time, we fit models for the mortality and incidence
of both groups (and of course, separately for men and women). The
models we use will be age-period-cohort models \cite{Carstensen.2007a}
providing estimated mortality rates for ages 0--99 and dates
1.1.1996--1.1.2016.

First we transform the age and period variables to reflect the mean
age and period in each of the Lexis triangles. We also compute the
total number of deaths and amount of risk time, as we are going to
model the total mortality as well. Finally we restrict the dataset to
ages over 30 only:
\begin{Schunk}
\begin{Sinput}
> DMepi <- transform(subset(DMepi, A > 30),
+                    A = A + 0.5,
+                    P = P + 0.5,
+                  D.T = D.nD + D.DM,
+                  Y.T = Y.nD + Y.DM)
> head(DMepi)
\end{Sinput}
\begin{Soutput}
    sex    A      P D.DM     Y.DM  X D.nD     Y.nD D.T      Y.T
684   M 31.5 1996.5    0 305.9671 29   51 44161.83  51 44467.80
685   M 31.5 1997.5    2 326.2074 31   54 45508.64  56 45834.85
686   M 31.5 1998.5    2 340.1759 34   46 44954.45  48 45294.63
687   M 31.5 1999.5    5 330.9918 24   39 41148.97  44 41479.96
688   M 31.5 2000.5    1 332.0876 41   26 39027.30  27 39359.39
689   M 31.5 2001.5    2 310.8467 35   33 37975.78  35 38286.63
\end{Soutput}
\end{Schunk}
With the correct age and period coding in the Lexis triangles, we fit
models for the mortalities and incidences. Note that we for
comparative purposes also fit a model for the \emph{total} mortality,
ignoring the
\begin{Schunk}
\begin{Sinput}
> # Knots used in all models
> (a.kn <- seq(40, 95, , 6))
\end{Sinput}
\begin{Soutput}
[1] 40 51 62 73 84 95
\end{Soutput}
\begin{Sinput}
> (p.kn <- seq(1997, 2015, , 4))
\end{Sinput}
\begin{Soutput}
[1] 1997 2003 2009 2015
\end{Soutput}
\begin{Sinput}
> (c.kn <- seq(1910, 1976, , 6))
\end{Sinput}
\begin{Soutput}
[1] 1910.0 1923.2 1936.4 1949.6 1962.8 1976.0
\end{Soutput}
\begin{Sinput}
> # Check the number of events between knots
> ae <- xtabs(cbind(D.nD, D.DM, X) ~ cut(A, c(30, a.kn, Inf)) + sex, data=DMepi)
> ftable(addmargins(ae, 1), col.vars=3:2)
\end{Sinput}
\begin{Soutput}
                               D.nD          D.DM             X       
                         sex      M      F      M      F      M      F
cut(A, c(30, a.kn, Inf))                                              
(30,40]                        7784   3924    486    223  10095   8151
(40,51]                       23432  14290   2558   1259  32986  22480
(51,62]                       55971  37306   9788   4695  58896  38864
(62,73]                      101481  76530  24769  13197  57990  44699
(73,84]                      155762 148617  34639  27535  30628  32158
(84,95]                      112373 187674  18702  27540   6554  10661
(95,Inf]                       9424  31075    981   2898    170    451
Sum                          466227 499416  91923  77347 197319 157464
\end{Soutput}
\begin{Sinput}
> pe <- xtabs(cbind(D.nD, D.DM, X) ~ cut(P, c(1990, p.kn, Inf)) + sex, data=DMepi)
> ftable(addmargins(pe, 1), col.vars=3:2)
\end{Sinput}
\begin{Soutput}
                                 D.nD          D.DM             X       
                           sex      M      F      M      F      M      F
cut(P, c(1990, p.kn, Inf))                                              
(1990,1997]                     26103  26841   3158   2949   6655   5546
(1997,2003]                    146216 157184  21503  19367  46654  38553
(2003,2009]                    133236 143847  25403  21957  59119  47791
(2009,2015]                    121330 130112  30492  24132  64980  50568
(2015,Inf]                      39342  41432  11367   8942  19911  15006
Sum                            466227 499416  91923  77347 197319 157464
\end{Soutput}
\begin{Sinput}
> ce <- xtabs(cbind(D.nD, D.DM, X) ~ cut(P-A, c(-Inf, c.kn, Inf)) + sex, data=DMepi)
> ftable(addmargins(ce, 1), col.vars=3:2)
\end{Sinput}
\begin{Soutput}
                                     D.nD          D.DM             X       
                               sex      M      F      M      F      M      F
cut(P - A, c(-Inf, c.kn, Inf))                                              
(-Inf,1.91e+03]                     19679  49020   2004   4446    599   1416
(1.91e+03,1.92e+03]                129799 189192  19780  26870  10665  15275
(1.92e+03,1.94e+03]                158953 152454  35667  28471  37850  36659
(1.94e+03,1.95e+03]                 99058  72432  25494  13074  71489  50631
(1.95e+03,1.96e+03]                 44129  28315   7534   3731  51750  34255
(1.96e+03,1.98e+03]                 13598   7484   1373    720  22942  17689
(1.98e+03, Inf]                      1011    519     71     35   2024   1539
Sum                                466227 499416  91923  77347 197319 157464
\end{Soutput}
\begin{Sinput}
> # Fit an APC-model for all transitions, separately for men and women
> mW.m <- glm(cbind(D.nD, Y.nD) ~ -1 + Ns(    A, knots=a.kn, int=TRUE) +
+                                      Ns(P    , knots=p.kn, ref=2005) +
+                                      Ns(P - A, knots=c.kn, ref=1950),
+             family = poisreg,
+               data = subset(DMepi, sex=="M"))
> mD.m <- update(mW.m, cbind(D.DM, Y.DM) ~ .)
> mT.m <- update(mW.m, cbind(D.T , Y.T ) ~ .)
> lW.m <- update(mW.m, cbind(X   , Y.nD) ~ .)
> # Model for women
> mW.f <- update(mW.m, data = subset(DMepi, sex == "F"))
> mD.f <- update(mD.m, data = subset(DMepi, sex == "F"))
> mT.f <- update(mT.m, data = subset(DMepi, sex == "F"))
> lW.f <- update(lW.m, data = subset(DMepi, sex == "F"))
\end{Sinput}
\end{Schunk}

\section{Residual life time and years lost to DM}

We now collect the estimated years of life lost classified by method
(immunity assumption or not), sex, age and calendar time:
\begin{Schunk}
\begin{Sinput}
> a.ref <- 30:90
> p.ref <- 1996:2016
> aYLL <- NArray(list(type = c("Imm", "Tot", "Sus"),
+                        sex = levels(DMepi$sex),
+                        age = a.ref,
+                       date = p.ref))
> str(aYLL)
\end{Sinput}
\begin{Soutput}
 logi [1:3, 1:2, 1:61, 1:21] NA NA NA NA NA NA ...
 - attr(*, "dimnames")=List of 4
  ..$ type: chr [1:3] "Imm" "Tot" "Sus"
  ..$ sex : chr [1:2] "M" "F"
  ..$ age : chr [1:61] "30" "31" "32" "33" ...
  ..$ date: chr [1:21] "1996" "1997" "1998" "1999" ...
\end{Soutput}
\begin{Sinput}
> system.time(
+ for(ip in p.ref)
+    {
+    nd <- data.frame(A = seq(30, 90, 0.2)+0.1,
+                      P = ip,
+                   Y.nD = 1,
+                   Y.DM = 1,
+                   Y.T  = 1)
+    muW.m <- ci.pred(mW.m, nd)[, 1]
+    muD.m <- ci.pred(mD.m, nd)[, 1]
+    muT.m <- ci.pred(mT.m, nd)[, 1]
+    lam.m <- ci.pred(lW.m, nd)[, 1]
+    muW.f <- ci.pred(mW.f, nd)[, 1]
+    muD.f <- ci.pred(mD.f, nd)[, 1]
+    muT.f <- ci.pred(mT.f, nd)[, 1]
+    lam.f <- ci.pred(lW.f, nd)[, 1]
+    aYLL["Imm", "M", , paste(ip)] <- yll(int=0.2, muW.m, muD.m, lam=NULL,
+                                       A=a.ref, age.in=30, note=FALSE)[-1]
+    aYLL["Imm", "F", , paste(ip)] <- yll(int=0.2, muW.f, muD.f, lam=NULL,
+                                       A=a.ref, age.in=30, note=FALSE)[-1]
+    aYLL["Tot", "M", , paste(ip)] <- yll(int=0.2, muT.m, muD.m, lam=NULL,
+                                       A=a.ref, age.in=30, note=FALSE)[-1]
+    aYLL["Tot", "F", , paste(ip)] <- yll(int=0.2, muT.f, muD.f, lam=NULL,
+                                       A=a.ref, age.in=30, note=FALSE)[-1]
+    aYLL["Sus", "M", , paste(ip)] <- yll(int=0.2, muW.m, muD.m, lam=lam.m,
+                                       A=a.ref, age.in=30, note=FALSE)[-1]
+    aYLL["Sus", "F", , paste(ip)] <- yll(int=0.2, muW.f, muD.f, lam=lam.f,
+                                       A=a.ref, age.in=30, note=FALSE)[-1]
+    })
\end{Sinput}
\begin{Soutput}
  bruger   system forløbet 
   12.82     2.28    15.88 
\end{Soutput}
\begin{Sinput}
> round(ftable(aYLL[, , seq(1, 61, 10), ], col.vars=c(3, 2)), 1)
\end{Sinput}
\begin{Soutput}
          age   30        40        50        60        70        80        90     
          sex    M    F    M    F    M    F    M    F    M    F    M    F    M    F
type date                                                                          
Imm  1996     11.3 10.3  9.4  9.2  7.5  7.7  5.5  6.0  3.4  3.8  1.5  1.6  0.0  0.0
     1997     11.2 10.0  9.3  9.0  7.4  7.5  5.4  5.8  3.4  3.8  1.5  1.6  0.0  0.0
     1998     11.0  9.8  9.2  8.7  7.3  7.3  5.4  5.6  3.4  3.6  1.5  1.5  0.0  0.0
     1999     10.9  9.5  9.1  8.5  7.2  7.1  5.3  5.4  3.3  3.5  1.4  1.5  0.0  0.0
     2000     10.7  9.2  9.0  8.3  7.1  6.9  5.2  5.2  3.3  3.4  1.4  1.4  0.0  0.0
     2001     10.4  9.0  8.8  8.0  6.9  6.7  5.1  5.1  3.2  3.3  1.4  1.4  0.0  0.0
     2002     10.2  8.7  8.6  7.8  6.8  6.4  5.0  4.9  3.2  3.2  1.4  1.3  0.0  0.0
     2003      9.9  8.4  8.4  7.5  6.6  6.2  4.8  4.7  3.1  3.0  1.3  1.3  0.0  0.0
     2004      9.6  8.1  8.1  7.2  6.4  6.0  4.7  4.5  2.9  2.9  1.2  1.2  0.0  0.0
     2005      9.2  7.7  7.8  7.0  6.1  5.7  4.5  4.2  2.8  2.7  1.2  1.2  0.0  0.0
     2006      8.8  7.4  7.5  6.7  5.9  5.5  4.3  4.0  2.7  2.6  1.1  1.1  0.0  0.0
     2007      8.4  7.1  7.2  6.4  5.7  5.3  4.1  3.8  2.5  2.4  1.0  1.0  0.0  0.0
     2008      8.1  6.9  6.9  6.2  5.5  5.1  3.9  3.7  2.4  2.3  1.0  1.0  0.0  0.0
     2009      7.8  6.6  6.7  6.0  5.3  4.9  3.8  3.5  2.3  2.2  0.9  0.9  0.0  0.0
     2010      7.6  6.5  6.6  5.9  5.2  4.8  3.7  3.5  2.3  2.1  0.9  0.9  0.0  0.0
     2011      7.5  6.3  6.5  5.8  5.1  4.8  3.7  3.4  2.2  2.0  0.9  0.8  0.0  0.0
     2012      7.4  6.3  6.4  5.7  5.1  4.7  3.6  3.4  2.2  2.0  0.9  0.8  0.0  0.0
     2013      7.3  6.2  6.4  5.7  5.1  4.7  3.7  3.3  2.2  2.0  0.9  0.8  0.0  0.0
     2014      7.3  6.2  6.4  5.7  5.1  4.7  3.7  3.4  2.3  2.0  0.9  0.8  0.0  0.0
     2015      7.3  6.1  6.4  5.7  5.2  4.7  3.7  3.4  2.3  2.0  0.9  0.8  0.0  0.0
     2016      7.2  6.1  6.4  5.6  5.2  4.7  3.8  3.4  2.3  2.0  0.9  0.8  0.0  0.0
Tot  1996     10.8  9.9  8.9  8.8  6.9  7.3  5.1  5.6  3.1  3.6  1.4  1.5  0.0  0.0
     1997     10.6  9.6  8.8  8.5  6.8  7.1  5.0  5.4  3.1  3.5  1.3  1.4  0.0  0.0
     1998     10.4  9.3  8.6  8.3  6.7  6.9  4.9  5.2  3.1  3.4  1.3  1.4  0.0  0.0
     1999     10.2  9.0  8.5  8.0  6.6  6.7  4.8  5.0  3.0  3.2  1.3  1.4  0.0  0.0
     2000     10.0  8.8  8.3  7.8  6.4  6.4  4.7  4.8  2.9  3.1  1.3  1.3  0.0  0.0
     2001      9.8  8.5  8.1  7.6  6.3  6.2  4.6  4.7  2.9  3.0  1.2  1.3  0.0  0.0
     2002      9.5  8.2  7.9  7.3  6.1  6.0  4.4  4.5  2.8  2.9  1.2  1.2  0.0  0.0
     2003      9.2  7.9  7.7  7.0  5.9  5.7  4.3  4.3  2.7  2.7  1.2  1.2  0.0  0.0
     2004      8.8  7.6  7.4  6.8  5.7  5.5  4.1  4.1  2.6  2.6  1.1  1.1  0.0  0.0
     2005      8.5  7.2  7.1  6.5  5.5  5.3  3.9  3.8  2.4  2.4  1.0  1.0  0.0  0.0
     2006      8.1  6.9  6.8  6.2  5.2  5.0  3.7  3.6  2.3  2.3  1.0  1.0  0.0  0.0
     2007      7.7  6.6  6.5  5.9  5.0  4.8  3.5  3.5  2.2  2.1  0.9  0.9  0.0  0.0
     2008      7.4  6.4  6.2  5.7  4.8  4.6  3.4  3.3  2.1  2.0  0.9  0.8  0.0  0.0
     2009      7.1  6.1  6.0  5.5  4.6  4.5  3.2  3.2  2.0  1.9  0.8  0.8  0.0  0.0
     2010      6.9  6.0  5.9  5.4  4.5  4.4  3.1  3.1  1.9  1.8  0.8  0.8  0.0  0.0
     2011      6.7  5.9  5.7  5.3  4.4  4.3  3.1  3.0  1.8  1.8  0.8  0.7  0.0  0.0
     2012      6.6  5.8  5.7  5.2  4.4  4.3  3.0  3.0  1.8  1.7  0.7  0.7  0.0  0.0
     2013      6.6  5.7  5.6  5.2  4.4  4.2  3.0  2.9  1.8  1.7  0.7  0.7  0.0  0.0
     2014      6.5  5.6  5.6  5.2  4.4  4.2  3.0  2.9  1.8  1.7  0.7  0.7  0.0  0.0
     2015      6.4  5.6  5.6  5.1  4.4  4.2  3.1  2.9  1.8  1.7  0.7  0.7  0.0  0.0
     2016      6.4  5.6  5.5  5.1  4.4  4.2  3.1  3.0  1.8  1.7  0.7  0.6  0.0  0.0
Sus  1996     10.4  9.6  8.5  8.5  6.7  7.2  5.0  5.6  3.2  3.7  1.4  1.6  0.0  0.0
     1997     10.2  9.3  8.4  8.3  6.6  6.9  5.0  5.4  3.2  3.6  1.4  1.5  0.0  0.0
     1998     10.0  9.0  8.3  8.0  6.5  6.7  4.9  5.2  3.2  3.5  1.4  1.5  0.0  0.0
     1999      9.8  8.7  8.1  7.8  6.4  6.5  4.8  5.0  3.1  3.4  1.4  1.4  0.0  0.0
     2000      9.6  8.5  8.0  7.6  6.3  6.3  4.7  4.8  3.1  3.2  1.4  1.4  0.0  0.0
     2001      9.4  8.2  7.8  7.3  6.1  6.1  4.6  4.6  3.0  3.1  1.3  1.4  0.0  0.0
     2002      9.1  7.9  7.6  7.1  6.0  5.8  4.5  4.5  2.9  3.0  1.3  1.3  0.0  0.0
     2003      8.8  7.6  7.4  6.8  5.8  5.6  4.3  4.3  2.8  2.8  1.3  1.2  0.0  0.0
     2004      8.4  7.3  7.1  6.5  5.6  5.4  4.1  4.0  2.7  2.7  1.2  1.2  0.0  0.0
     2005      8.1  6.9  6.8  6.2  5.3  5.1  4.0  3.8  2.6  2.5  1.1  1.1  0.0  0.0
     2006      7.7  6.6  6.5  6.0  5.1  4.9  3.8  3.6  2.5  2.4  1.1  1.1  0.0  0.0
     2007      7.4  6.3  6.2  5.7  4.9  4.7  3.6  3.5  2.3  2.2  1.0  1.0  0.0  0.0
     2008      7.0  6.1  6.0  5.5  4.7  4.5  3.4  3.3  2.2  2.1  1.0  0.9  0.0  0.0
     2009      6.8  5.9  5.8  5.4  4.5  4.4  3.3  3.2  2.1  2.0  0.9  0.9  0.0  0.0
     2010      6.6  5.8  5.6  5.2  4.4  4.3  3.2  3.1  2.1  2.0  0.9  0.8  0.0  0.0
     2011      6.5  5.7  5.6  5.2  4.4  4.3  3.2  3.1  2.0  1.9  0.9  0.8  0.0  0.0
     2012      6.4  5.6  5.5  5.1  4.4  4.3  3.2  3.1  2.0  1.9  0.9  0.8  0.0  0.0
     2013      6.4  5.6  5.5  5.1  4.4  4.3  3.2  3.1  2.1  1.9  0.9  0.8  0.0  0.0
     2014      6.4  5.5  5.5  5.1  4.5  4.3  3.3  3.1  2.1  1.9  0.9  0.8  0.0  0.0
     2015      6.4  5.5  5.6  5.1  4.5  4.3  3.3  3.1  2.1  1.9  0.9  0.8  0.0  0.0
     2016      6.4  5.5  5.6  5.1  4.6  4.3  3.4  3.1  2.1  1.9  0.9  0.7  0.0  0.0
\end{Soutput}
\end{Schunk}
We now have the relevant points for the graph showing YLL to diabetes
for men and women by age, and calendar year, both under the immunity
and susceptibility models for the calculation of YLL.
\begin{Schunk}
\begin{Sinput}
> plyll <- function(wh, xtxt){
+ par(mfrow = c(1, 2),
+       mar = c(3, 3, 1, 1),
+       mgp = c(3, 1, 0) / 1.6,
+       bty = "n",
+       las = 1)
+ matplot(a.ref, aYLL[wh, "M", , ],
+          type="l", lty=1, col="blue", lwd=1:2,
+          ylim=c(0, 12), xlab="Age",
+          ylab=paste0("Years lost to DM", xtxt),
+          yaxs="i")
+ abline(v=50, h=1:11, col=gray(0.7))
+ text(90, 11.5, "Men", col="blue", adj=1)
+ text(40, aYLL[wh, "M", "40", "1996"], "1996", adj=c(0, 0), col="blue")
+ text(43, aYLL[wh, "M", "44", "2016"], "2016", adj=c(1, 1), col="blue")
+ 
+ matplot(a.ref, aYLL[wh, "F", , ],
+          type="l", lty=1, col="red", lwd=1:2,
+          ylim=c(0, 12), xlab="Age",
+          ylab=paste0("Years lost to DM", xtxt),
+          yaxs="i")
+ abline(v=50, h=1:11, col=gray(0.7))
+ text(90, 11.5, "Women", col="red", adj=1)
+ text(40, aYLL[wh, "F", "40", "1996"], "1996", adj=c(0, 0), col="red")
+ text(43, aYLL[wh, "F", "44", "2016"], "2016", adj=c(1, 1), col="red")
+ }
> plyll("Imm", " - immunity assumption")
\end{Sinput}
\end{Schunk}
\begin{Schunk}
\begin{Sinput}
> plyll("Tot", " - total mortality refernce")
\end{Sinput}
\end{Schunk}
\begin{Schunk}
\begin{Sinput}
> plyll("Sus", " - susceptibility assumed")
\end{Sinput}
\end{Schunk}
\begin{figure}[h]
  \centering
  \includegraphics[width=\textwidth]{05yll-imm}
  \caption{Years of life lost to DM: the difference in expected
    residual life time at different ages between persons with and
    without diabetes, assuming the persons without diabetes at a given
    age remain free from diabetes (immunity assumption --- not
    reasonable). The lines refer to date of evaluation; the top lines
    refer to 1996-1-1 the bottom ones to 2016-1-1. Blue curves are
    men, red women.}
  \label{fig:imm}
\end{figure}

\begin{figure}[h]
  \centering
  \includegraphics[width=\textwidth]{05yll-sus}
  \caption{Years of life lost to DM: the difference in expected
    residual life time at different ages between persons with and
    without diabetes, allowing the persons without diabetes at a given
    age to contract diabetes and thus be subject to higher
    mortality. The lines refer to date of evaluation; the top lines
    refer to 1996-1-1 the bottom ones to 2016-1-1. Blue curves are
    men, red women.}
  \label{fig:sus}
\end{figure}

\begin{figure}[h]
  \centering
  \includegraphics[width=\textwidth]{05yll-tot}
  \caption{Years of life lost to DM: the difference in expected
    residual life time at different ages between persons with and
    without diabetes. Allowance for susceptibility is approximated by
    using the total population mortality instead of non-DM
    mortality. The lines refer to date of evaluation; the top lines
    refer to 1996-1-1 the bottom ones to 2016-1-1. Blue curves are
    men, red women.}
  \label{fig:tot}
\end{figure}

From figure \ref{fig:sus} we see that for men aged 50 the years lost to
diabetes has decreased from 6.5 to 4.5 years
and for women from 4 to 4 years; so a greater improvement for women.

\begin{Schunk}
\begin{Soutput}
  Start time: 2026-04-13, 14:02:49 
    End time: 2026-04-13, 14:03:06 
Elapsed time: 0.28 minutes
\end{Soutput}
\end{Schunk}

\bibliographystyle{plain}

\begin{thebibliography}{1}

\bibitem{Carstensen.2007a}
B~Carstensen.
\newblock Age-{P}eriod-{C}ohort models for the {L}exis diagram.
\newblock {\em Statistics in Medicine}, 26(15):3018--3045, 2007.

\bibitem{Carstensen.2008c}
B~Carstensen, JK~Kristensen, P~Ottosen, and K~Borch-Johnsen.
\newblock The {D}anish {N}ational {D}iabetes {R}egister: {T}rends in incidence,
  prevalence and mortality.
\newblock {\em Diabetologia}, 51:2187--2196, 2008.

\end{thebibliography}

\addcontentsline{toc}{chapter}{References}

\end{document}
