R/estimHI_3FDR.R

Defines functions estimHI_3FDR

Documented in estimHI_3FDR

#' Computation of Health Indicators
#'
#' This function computes many health indicators under several scenarios of intervention in risk factor distribution for a given year.
#'
#' @param t year of the projections for health indicators.
#' @param intervention 0 = no change; 1 = risk factor prevalence and incidence considered as null. Default is \code{0}.
#' @param year_intervention year of the intervention in risk factor distribution takes place. Default is \code{NULL}.
#' @param nb_people number of people whose trajectory will be simulated for each generation. Default is \code{100}.
#' @param nb_iter number of iterations for the algorithm. Default is \code{0}.
#' @param data_pop data source for demographics data.
#' @param gender gender for computation. \code{"W"} for women and \code{"M"} for men. Default is \code{"W"}.
#' @param data_a01_values data source for the incidence of disease.
#' @param data_a02_values data source for the mortality of healthy subjects.
#' @param data_theta01_1_values data source for the relative risks associated with the exposure 1 for disease.
#' @param data_theta01_2_values data source for the relative risks associated with the exposure 2 for disease.
#' @param data_theta01_3_values data source for the relative risks associated with the exposure 3 for disease.
#' @param data_theta02_1_values data source for the relative risks associated with the exposure 1 for mortality among healthy subjects.
#' @param data_theta02_2_values data source for the relative risks associated with the exposure 2 for mortality among healthy subjects.
#' @param data_theta02_3_values data source for the relative risks associated with the exposure 3 for mortality among healthy subjects.
#' @param data_theta12_1_values data source for the relative risks associated with the exposure 1 for mortality among diseased subjects.
#' @param data_theta12_2_values data source for the relative risks associated with the exposure 2 for mortality among diseased subjects.
#' @param data_theta12_3_values data source for the relative risks associated with the exposure 3 for mortality among diseased subjects.
#' @param data_prev_0_values data source for the prevalence of the exposition 0.
#' @param data_prev_1_values data source for the prevalence of the exposition 1.
#' @param data_prev_2_values data source for the prevalence of the exposition 2.
#' @param data_prev_3_values data source for the prevalence of the exposition 3.
#' @param data_prev_4_values data source for the prevalence of the exposition 4.
#' @param data_prev_5_values data source for the prevalence of the exposition 5.
#' @param data_prev_6_values data source for the prevalence of the exposition 6.
#' @param data_prev_7_values data source for the prevalence of the exposition 7.
#' @param data_incid_0_values data source for the incidence of the exposition 0.
#' @param data_incid_1_values data source for the incidence of the exposition 1.
#' @param data_incid_3_values data source for the incidence of the exposition 3.
#' @param data_incid_5_values data source for the incidence of the exposition 5.
#' @param data_rr_DvsND_values data source for the relative risks associated with the disease for mortality.
#' @param data_a01 variability of data source for the incidence of disease.
#' @param data_a02 variability of data source for the mortality of healthy subjects.
#' @param data_theta01_1 variability of data source for the relative risks associated with the exposure 1 for disease.
#' @param data_theta01_2 variability of data source for the relative risks associated with the exposure 2 for disease.
#' @param data_theta01_3 variability of data source for the relative risks associated with the exposure 3 for disease.
#' @param data_theta02_1 variability of data source for the relative risks associated with the exposure 1 for mortality among healthy subjects.
#' @param data_theta02_2 variability of data source for the relative risks associated with the exposure 2 for mortality among healthy subjects.
#' @param data_theta02_3 variability of data source for the relative risks associated with the exposure 3 for mortality among healthy subjects.
#' @param data_theta12_1 variability of data source for the relative risks associated with the exposure 1 for mortality among diseased subjects.
#' @param data_theta12_2 variability of data source for the relative risks associated with the exposure 2 for mortality among diseased subjects.
#' @param data_theta12_3 variability of data source for the relative risks associated with the exposure 3 for mortality among diseased subjects.
#' @param data_prev_0 variability of data source for the prevalence of the exposition 0.
#' @param data_prev_1 variability of data source for the prevalence of the exposition 1.
#' @param data_prev_2 variability of data source for the prevalence of the exposition 2.
#' @param data_prev_3 variability of data source for the prevalence of the exposition 3.
#' @param data_prev_4 variability of data source for the prevalence of the exposition 4.
#' @param data_prev_5 variability of data source for the prevalence of the exposition 5.
#' @param data_prev_6 variability of data source for the prevalence of the exposition 6.
#' @param data_prev_7 variability of data source for the prevalence of the exposition 7.
#' @param data_incid_0 variability of data source for the incidence of the exposition 0.
#' @param data_incid_1 variability of data source for the incidence of the exposition 1.
#' @param data_incid_3 variability of data source for the incidence of the exposition 3.
#' @param data_incid_5 variability of data source for the incidence of the exposition 5.
#' @param data_rr_DvsND variability of data source for the relative risks associated with the disease for mortality.
#' @param Ncpus The number of processors available. Default is \code{"1"}.
#'
#' @return a list containing the health indicators
#'
#' @export
#'
#' @examples
#' estimHI_3FDR(t = 2040,
#' intervention = 1,
#' year_intervention = 2020,
#' nb_people = 10000,
#' nb_iter = 100,
#' data_pop = pop,
#' gender = "W",
#' data_a01_values = a01_constant_values,
#' data_a02_values = a02_constant_values,
#' data_theta01_1_values = theta01_cas_1_6_values,
#' data_theta01_2_values = theta01_cas_1_6_values,
#' data_theta01_3_values = theta01_cas_1_6_values,
#' data_theta02_1_values = theta02_increase_values,
#' data_theta02_2_values = theta02_increase_values,
#' data_theta02_3_values = theta02_increase_values,
#' data_theta12_1_values = theta02_increase_values,
#' data_theta12_2_values = theta02_increase_values,
#' data_theta12_3_values = theta02_increase_values,
#' data_prev_0_values <- prevconso_values,
#' data_prev_1_values <- prevconso_values,
#' data_prev_2_values <- prevconso_values,
#' data_prev_3_values <- prevconso_values,
#' data_prev_4_values <- prevconso_values,
#' data_prev_5_values <- prevconso_values,
#' data_prev_6_values <- prevconso_values,
#' data_prev_7_values <- prevconso_values,
#' data_incid_0_values <- incidconso_values,
#' data_incid_1_values <- incidconso_values,
#' data_incid_3_values <- incidconso_values,
#' data_incid_5_values <- incidconso_values,
#' data_rr_DvsND_values = rr_DvsND_values,
#' data_a01 = a01_constant,
#' data_a02 = a02_constant,
#' data_theta01_1 = theta01_cas_1_6,
#' data_theta01_2 = theta01_cas_1_6,
#' data_theta01_3 = theta01_cas_1_6,
#' data_theta02_1 = theta02_increase,
#' data_theta02_2 = theta02_increase,
#' data_theta02_3 = theta02_increase,
#' data_theta12_1 = theta02_increase,
#' data_theta12_2 = theta02_increase,
#' data_theta12_3 = theta02_increase,
#' data_prev_0 = prevconso,
#' data_prev_1 = prevconso,
#' data_prev_2 = prevconso,
#' data_prev_3 = prevconso,
#' data_prev_4 = prevconso,
#' data_prev_5 = prevconso,
#' data_prev_6 = prevconso,
#' data_prev_7 = prevconso,
#' data_incid_0 = incidconso,
#' data_incid_1 = incidconso,
#' data_incid_3 = incidconso,
#' data_incid_5 = incidconso,
#' data_rr_DvsND = rr_DvsND,
#' Ncpus = 1)
estimHI_3FDR <- function(t,
                         intervention = 0,
                         year_intervention = NULL,
                         nb_people = 100,
                         nb_iter = 0,
                         data_pop,
                         gender = "W",
                         data_a01_values,
                         data_a02_values,
                         data_theta01_1_values,
                         data_theta01_2_values,
                         data_theta01_3_values,
                         data_theta02_1_values,
                         data_theta02_2_values,
                         data_theta02_3_values,
                         data_theta12_1_values,
                         data_theta12_2_values,
                         data_theta12_3_values,
                         data_prev_0_values,
                         data_prev_1_values,
                         data_prev_2_values,
                         data_prev_3_values,
                         data_prev_4_values,
                         data_prev_5_values,
                         data_prev_6_values,
                         data_prev_7_values,
                         data_incid_0_values,
                         data_incid_1_values,
                         data_incid_3_values,
                         data_incid_5_values,
                         data_rr_DvsND_values,
                         data_a01,
                         data_a02,
                         data_theta01_1,
                         data_theta01_2,
                         data_theta01_3,
                         data_theta02_1,
                         data_theta02_2,
                         data_theta02_3,
                         data_theta12_1,
                         data_theta12_2,
                         data_theta12_3,
                         data_prev_0,
                         data_prev_1,
                         data_prev_2,
                         data_prev_3,
                         data_prev_4,
                         data_prev_5,
                         data_prev_6,
                         data_prev_7,
                         data_incid_0,
                         data_incid_1,
                         data_incid_3,
                         data_incid_5,
                         data_rr_DvsND,
                         Ncpus = 1)

{

  ### Year of projection

  set.seed(0)

  year_proj <- t

  ### Incidence of disease on non exposed peoples

  a010 <- matrix(c(0),
                 nrow=40*nb_iter,
                 ncol=132,
                 byrow=T);
  colnames(a010) <- c("age",1950:2080)

  a010[,1] <- c(66:105)

  for (a in 2:ncol(a010)){

    a010[,a] <- as.numeric(data_a01[which(data_a01[,1] != 65 & data_a01[,2]%in%(gender)),a+1]) / (data_prev_0[which(data_prev_0[,1] != 65 & data_prev_0[,3]%in%(gender)),2] + data_theta01_1[which(data_theta01_1[,1] != 65 & data_theta01_1[,3]%in%(gender)),2]*data_prev_1[which(data_prev_1[,1] != 65 & data_prev_1[,3]%in%(gender)),2] + data_theta01_2[which(data_theta01_2[,1] != 65 & data_theta01_2[,3]%in%(gender)),2]*data_prev_2[which(data_prev_2[,1] != 65 & data_prev_2[,3]%in%(gender)),2] + data_theta01_3[which(data_theta01_3[,1] != 65 & data_theta01_3[,3]%in%(gender)),2]*data_prev_3[which(data_prev_3[,1] != 65 & data_prev_3[,3]%in%(gender)),2] + data_theta01_1[which(data_theta01_1[,1] != 65 & data_theta01_1[,3]%in%(gender)),2]*data_theta01_2[which(data_theta01_2[,1] != 65 & data_theta01_2[,3]%in%(gender)),2]*data_prev_4[which(data_prev_4[,1] != 65 & data_prev_4[,3]%in%(gender)),2] + data_theta01_1[which(data_theta01_1[,1] != 65 & data_theta01_1[,3]%in%(gender)),2]*data_theta01_3[which(data_theta01_3[,1] != 65 & data_theta01_3[,3]%in%(gender)),2]*data_prev_5[which(data_prev_5[,1] != 65 & data_prev_5[,3]%in%(gender)),2] + data_theta01_2[which(data_theta01_2[,1] != 65 & data_theta01_2[,3]%in%(gender)),2]*data_theta01_3[which(data_theta01_3[,1] != 65 & data_theta01_3[,3]%in%(gender)),2]*data_prev_6[which(data_prev_6[,1] != 65 & data_prev_6[,3]%in%(gender)),2] + data_theta01_1[which(data_theta01_1[,1] != 65 & data_theta01_1[,3]%in%(gender)),2]*data_theta01_2[which(data_theta01_2[,1] != 65 & data_theta01_2[,3]%in%(gender)),2]*data_theta01_3[which(data_theta01_3[,1] != 65 & data_theta01_3[,3]%in%(gender)),2]*data_prev_7[which(data_prev_7[,1] != 65 & data_prev_7[,3]%in%(gender)),2]);

  }

  ### Incidence of disease on exposed peoples

  a011 <- matrix(c(0),
                 nrow=40*nb_iter,
                 ncol=132,
                 byrow=T);
  colnames(a011) <- c("age",1950:2080)

  a011[,1] <- c(66:105)
  a011[,-1] <- a010[,-1]*data_theta01_1[which(data_theta01_1[,1] != 65 & data_theta01_1[,3]%in%(gender)),2];

  a012 <- matrix(c(0),
                 nrow=40*nb_iter,
                 ncol=132,
                 byrow=T);
  colnames(a012) <- c("age",1950:2080)

  a012[,1] <- c(66:105)
  a012[,-1] <- a010[,-1]*data_theta01_2[which(data_theta01_2[,1] != 65 & data_theta01_2[,3]%in%(gender)),2];

  a013 <- matrix(c(0),
                 nrow=40*nb_iter,
                 ncol=132,
                 byrow=T);
  colnames(a013) <- c("age",1950:2080)

  a013[,1] <- c(66:105)
  a013[,-1] <- a010[,-1]*data_theta01_3[which(data_theta01_3[,1] != 65 & data_theta01_3[,3]%in%(gender)),2];

  a014 <- matrix(c(0),
                 nrow=40*nb_iter,
                 ncol=132,
                 byrow=T);
  colnames(a014) <- c("age",1950:2080)

  a014[,1] <- c(66:105)
  a014[,-1] <- a010[,-1]*data_theta01_1[which(data_theta01_1[,1] != 65 & data_theta01_1[,3]%in%(gender)),2]*data_theta01_2[which(data_theta01_2[,1] != 65 & data_theta01_2[,3]%in%(gender)),2];

  a015 <- matrix(c(0),
                 nrow=40*nb_iter,
                 ncol=132,
                 byrow=T);
  colnames(a015) <- c("age",1950:2080)

  a015[,1] <- c(66:105)
  a015[,-1] <- a010[,-1]*data_theta01_1[which(data_theta01_1[,1] != 65 & data_theta01_1[,3]%in%(gender)),2]*data_theta01_3[which(data_theta01_3[,1] != 65 & data_theta01_3[,3]%in%(gender)),2];

  a016 <- matrix(c(0),
                 nrow=40*nb_iter,
                 ncol=132,
                 byrow=T);
  colnames(a016) <- c("age",1950:2080)

  a016[,1] <- c(66:105)
  a016[,-1] <- a010[,-1]*data_theta01_2[which(data_theta01_2[,1] != 65 & data_theta01_2[,3]%in%(gender)),2]*data_theta01_3[which(data_theta01_3[,1] != 65 & data_theta01_3[,3]%in%(gender)),2];

  a017 <- matrix(c(0),
                 nrow=40*nb_iter,
                 ncol=132,
                 byrow=T);
  colnames(a017) <- c("age",1950:2080)

  a017[,1] <- c(66:105)
  a017[,-1] <- a010[,-1]*data_theta01_1[which(data_theta01_1[,1] != 65 & data_theta01_1[,3]%in%(gender)),2]*data_theta01_2[which(data_theta01_2[,1] != 65 & data_theta01_2[,3]%in%(gender)),2]*data_theta01_3[which(data_theta01_3[,1] != 65 & data_theta01_3[,3]%in%(gender)),2];

  ### Global incidence of disease

  a01_global <- matrix(c(0),
                       nrow=40*nb_iter,
                       ncol=132,
                       byrow=T);
  colnames(a01_global) <- c("age",1950:2080)

  a01_global[,1] <- c(66:105)
  a01_global[,-1] <- data_prev_0[which(data_prev_0[,1] != 65 & data_prev_0[,3]%in%(gender)),2]*a010[,-1] + data_prev_1[which(data_prev_1[,1] != 65 & data_prev_1[,3]%in%(gender)),2]*a010[,-1]*data_theta01_1[which(data_theta01_1[,1] != 65 & data_theta01_1[,3]%in%(gender)),2] + data_prev_2[which(data_prev_2[,1] != 65 & data_prev_2[,3]%in%(gender)),2]*a010[,-1]*data_theta01_2[which(data_theta01_2[,1] != 65 & data_theta01_2[,3]%in%(gender)),2] + data_prev_3[which(data_prev_3[,1] != 65 & data_prev_3[,3]%in%(gender)),2]*a010[,-1]*data_theta01_3[which(data_theta01_3[,1] != 65 & data_theta01_3[,3]%in%(gender)),2] + data_prev_4[which(data_prev_4[,1] != 65 & data_prev_4[,3]%in%(gender)),2]*a010[,-1]*data_theta01_1[which(data_theta01_1[,1] != 65 & data_theta01_1[,3]%in%(gender)),2]*data_theta01_2[which(data_theta01_2[,1] != 65 & data_theta01_2[,3]%in%(gender)),2] + data_prev_5[which(data_prev_5[,1] != 65 & data_prev_5[,3]%in%(gender)),2]*a010[,-1]*data_theta01_1[which(data_theta01_1[,1] != 65 & data_theta01_1[,3]%in%(gender)),2]*data_theta01_3[which(data_theta01_3[,1] != 65 & data_theta01_3[,3]%in%(gender)),2] + data_prev_6[which(data_prev_6[,1] != 65 & data_prev_6[,3]%in%(gender)),2]*a010[,-1]*data_theta01_2[which(data_theta01_2[,1] != 65 & data_theta01_2[,3]%in%(gender)),2]*data_theta01_3[which(data_theta01_3[,1] != 65 & data_theta01_3[,3]%in%(gender)),2] + data_prev_7[which(data_prev_7[,1] != 65 & data_prev_7[,3]%in%(gender)),2]*a010[,-1]*data_theta01_1[which(data_theta01_1[,1] != 65 & data_theta01_1[,3]%in%(gender)),2]*data_theta01_2[which(data_theta01_2[,1] != 65 & data_theta01_2[,3]%in%(gender)),2]*data_theta01_3[which(data_theta01_3[,1] != 65 & data_theta01_3[,3]%in%(gender)),2];

  ### Mortality of healthy subjects on non exposed peoples

  a020 <- matrix(c(0),
                 nrow=40*nb_iter,
                 ncol=132,
                 byrow=T);
  colnames(a020) <- c("age",1950:2080)

  a020[,1] <- c(66:105)

  for (a in 2:ncol(a020)){

    a020[,a] <- as.numeric(data_a02[which(data_a02[,1] != 65 & data_a02[,2]%in%(gender)),a+1]) / (data_prev_0[which(data_prev_0[,1] != 65 & data_prev_0[,3]%in%(gender)),2] + data_theta02_1[which(data_theta02_1[,1] != 65 & data_theta02_1[,3]%in%(gender)),2]*data_prev_1[which(data_prev_1[,1] != 65 & data_prev_1[,3]%in%(gender)),2] + data_theta02_2[which(data_theta02_2[,1] != 65 & data_theta02_2[,3]%in%(gender)),2]*data_prev_2[which(data_prev_2[,1] != 65 & data_prev_2[,3]%in%(gender)),2] + data_theta02_3[which(data_theta02_3[,1] != 65 & data_theta02_3[,3]%in%(gender)),2]*data_prev_3[which(data_prev_3[,1] != 65 & data_prev_3[,3]%in%(gender)),2] + data_theta02_1[which(data_theta02_1[,1] != 65 & data_theta02_1[,3]%in%(gender)),2]*data_theta02_2[which(data_theta02_2[,1] != 65 & data_theta02_2[,3]%in%(gender)),2]*data_prev_4[which(data_prev_4[,1] != 65 & data_prev_4[,3]%in%(gender)),2] + data_theta02_1[which(data_theta02_1[,1] != 65 & data_theta02_1[,3]%in%(gender)),2]*data_theta02_3[which(data_theta02_3[,1] != 65 & data_theta02_3[,3]%in%(gender)),2]*data_prev_5[which(data_prev_5[,1] != 65 & data_prev_5[,3]%in%(gender)),2] + data_theta02_2[which(data_theta02_2[,1] != 65 & data_theta02_2[,3]%in%(gender)),2]*data_theta02_3[which(data_theta02_3[,1] != 65 & data_theta02_3[,3]%in%(gender)),2]*data_prev_6[which(data_prev_6[,1] != 65 & data_prev_6[,3]%in%(gender)),2] + data_theta02_1[which(data_theta02_1[,1] != 65 & data_theta02_1[,3]%in%(gender)),2]*data_theta02_2[which(data_theta02_2[,1] != 65 & data_theta02_2[,3]%in%(gender)),2]*data_theta02_3[which(data_theta02_3[,1] != 65 & data_theta02_3[,3]%in%(gender)),2]*data_prev_7[which(data_prev_7[,1] != 65 & data_prev_7[,3]%in%(gender)),2]);

  }

  ### Mortality of healthy subjects on exposed peoples

  a021 <- matrix(c(0),
                 nrow=40*nb_iter,
                 ncol=132,
                 byrow=T);
  colnames(a021) <- c("age",1950:2080)

  a021[,1] <- c(66:105)
  a021[,-1] <- a020[,-1]*data_theta02_1[which(data_theta02_1[,1] != 65 & data_theta02_1[,3]%in%(gender)),2];

  a022 <- matrix(c(0),
                 nrow=40*nb_iter,
                 ncol=132,
                 byrow=T);
  colnames(a022) <- c("age",1950:2080)

  a022[,1] <- c(66:105)
  a022[,-1] <- a020[,-1]*data_theta02_2[which(data_theta02_2[,1] != 65 & data_theta02_2[,3]%in%(gender)),2];

  a023 <- matrix(c(0),
                 nrow=40*nb_iter,
                 ncol=132,
                 byrow=T);
  colnames(a023) <- c("age",1950:2080)

  a023[,1] <- c(66:105)
  a023[,-1] <- a020[,-1]*data_theta02_3[which(data_theta02_3[,1] != 65 & data_theta02_3[,3]%in%(gender)),2];

  a024 <- matrix(c(0),
                 nrow=40*nb_iter,
                 ncol=132,
                 byrow=T);
  colnames(a024) <- c("age",1950:2080)

  a024[,1] <- c(66:105)
  a024[,-1] <- a020[,-1]*data_theta02_1[which(data_theta02_1[,1] != 65 & data_theta02_1[,3]%in%(gender)),2]*data_theta02_2[which(data_theta02_2[,1] != 65 & data_theta02_2[,3]%in%(gender)),2];

  a025 <- matrix(c(0),
                 nrow=40*nb_iter,
                 ncol=132,
                 byrow=T);
  colnames(a025) <- c("age",1950:2080)

  a025[,1] <- c(66:105)
  a025[,-1] <- a020[,-1]*data_theta02_1[which(data_theta02_1[,1] != 65 & data_theta02_1[,3]%in%(gender)),2]*data_theta02_3[which(data_theta02_3[,1] != 65 & data_theta02_3[,3]%in%(gender)),2];

  a026 <- matrix(c(0),
                 nrow=40*nb_iter,
                 ncol=132,
                 byrow=T);
  colnames(a026) <- c("age",1950:2080)

  a026[,1] <- c(66:105)
  a026[,-1] <- a020[,-1]*data_theta02_2[which(data_theta02_2[,1] != 65 & data_theta02_2[,3]%in%(gender)),2]*data_theta02_3[which(data_theta02_3[,1] != 65 & data_theta02_3[,3]%in%(gender)),2];

  a027 <- matrix(c(0),
                 nrow=40*nb_iter,
                 ncol=132,
                 byrow=T);
  colnames(a027) <- c("age",1950:2080)

  a027[,1] <- c(66:105)
  a027[,-1] <- a020[,-1]*data_theta02_1[which(data_theta02_1[,1] != 65 & data_theta02_1[,3]%in%(gender)),2]*data_theta02_2[which(data_theta02_2[,1] != 65 & data_theta02_2[,3]%in%(gender)),2]*data_theta02_3[which(data_theta02_3[,1] != 65 & data_theta02_3[,3]%in%(gender)),2];

  ### Global mortality of healthy subjects

  a02_global <- matrix(c(0),
                       nrow=40*nb_iter,
                       ncol=132,
                       byrow=T);
  colnames(a02_global) <- c("age",1950:2080)

  a02_global[,1] <- c(66:105)
  a02_global[,-1] <- data_prev_0[which(data_prev_0[,1] != 65 & data_prev_0[,3]%in%(gender)),2]*a020[,-1] + data_prev_1[which(data_prev_1[,1] != 65 & data_prev_1[,3]%in%(gender)),2]*a020[,-1]*data_theta02_1[which(data_theta02_1[,1] != 65 & data_theta02_1[,3]%in%(gender)),2] + data_prev_2[which(data_prev_2[,1] != 65 & data_prev_2[,3]%in%(gender)),2]*a020[,-1]*data_theta02_2[which(data_theta02_2[,1] != 65 & data_theta02_2[,3]%in%(gender)),2] + data_prev_3[which(data_prev_3[,1] != 65 & data_prev_3[,3]%in%(gender)),2]*a020[,-1]*data_theta02_3[which(data_theta02_3[,1] != 65 & data_theta02_3[,3]%in%(gender)),2] + data_prev_4[which(data_prev_4[,1] != 65 & data_prev_4[,3]%in%(gender)),2]*a020[,-1]*data_theta02_1[which(data_theta02_1[,1] != 65 & data_theta02_1[,3]%in%(gender)),2]*data_theta02_2[which(data_theta02_2[,1] != 65 & data_theta02_2[,3]%in%(gender)),2] + data_prev_5[which(data_prev_5[,1] != 65 & data_prev_5[,3]%in%(gender)),2]*a020[,-1]*data_theta02_1[which(data_theta02_1[,1] != 65 & data_theta02_1[,3]%in%(gender)),2]*data_theta02_3[which(data_theta02_3[,1] != 65 & data_theta02_3[,3]%in%(gender)),2] + data_prev_6[which(data_prev_6[,1] != 65 & data_prev_6[,3]%in%(gender)),2]*a020[,-1]*data_theta02_2[which(data_theta02_2[,1] != 65 & data_theta02_2[,3]%in%(gender)),2]*data_theta02_3[which(data_theta02_3[,1] != 65 & data_theta02_3[,3]%in%(gender)),2] + data_prev_7[which(data_prev_7[,1] != 65 & data_prev_7[,3]%in%(gender)),2]*a020[,-1]*data_theta02_1[which(data_theta02_1[,1] != 65 & data_theta02_1[,3]%in%(gender)),2]*data_theta02_2[which(data_theta02_2[,1] != 65 & data_theta02_2[,3]%in%(gender)),2]*data_theta02_3[which(data_theta02_3[,1] != 65 & data_theta02_3[,3]%in%(gender)),2];

  ### Relative risks associated with the disease for mortality

  RR <- matrix(c(0),
               nrow=40*nb_iter,
               ncol=2,
               byrow=T);
  colnames(RR) <- c("age","rr_DvsND")

  RR[,1] <- c(66:105)
  RR[,2] <- data_rr_DvsND[which(data_rr_DvsND[,1] != 65 & data_rr_DvsND[,3]%in%(gender)),2];

  ### Mortality of diseased subjects on non exposed peoples

  a120 <- matrix(c(0),
                 nrow=40*nb_iter,
                 ncol=132,
                 byrow=T);
  colnames(a120) <- c("age",1950:2080)

  a120[,1] <- c(66:105)

  for (a in 2:ncol(a120)){

    a120[,a] <- as.numeric(RR[,2])*as.numeric(data_a02[which(data_a02[,1] != 65 & data_a02[,2]%in%(gender)),a+1]) / (data_prev_0[which(data_prev_0[,1] != 65 & data_prev_0[,3]%in%(gender)),2] + data_theta12_1[which(data_theta12_1[,1] != 65 & data_theta12_1[,3]%in%(gender)),2]*data_prev_1[which(data_prev_1[,1] != 65 & data_prev_1[,3]%in%(gender)),2] + data_theta12_2[which(data_theta12_2[,1] != 65 & data_theta12_2[,3]%in%(gender)),2]*data_prev_2[which(data_prev_2[,1] != 65 & data_prev_2[,3]%in%(gender)),2] + data_theta12_3[which(data_theta12_3[,1] != 65 & data_theta12_3[,3]%in%(gender)),2]*data_prev_3[which(data_prev_3[,1] != 65 & data_prev_3[,3]%in%(gender)),2] + data_theta12_1[which(data_theta12_1[,1] != 65 & data_theta12_1[,3]%in%(gender)),2]*data_theta12_2[which(data_theta12_2[,1] != 65 & data_theta12_2[,3]%in%(gender)),2]*data_prev_4[which(data_prev_4[,1] != 65 & data_prev_4[,3]%in%(gender)),2] + data_theta12_1[which(data_theta12_1[,1] != 65 & data_theta12_1[,3]%in%(gender)),2]*data_theta12_3[which(data_theta12_3[,1] != 65 & data_theta12_3[,3]%in%(gender)),2]*data_prev_5[which(data_prev_5[,1] != 65 & data_prev_5[,3]%in%(gender)),2] + data_theta12_2[which(data_theta12_2[,1] != 65 & data_theta12_2[,3]%in%(gender)),2]*data_theta12_3[which(data_theta12_3[,1] != 65 & data_theta12_3[,3]%in%(gender)),2]*data_prev_6[which(data_prev_6[,1] != 65 & data_prev_6[,3]%in%(gender)),2] + data_theta12_1[which(data_theta12_1[,1] != 65 & data_theta12_1[,3]%in%(gender)),2]*data_theta12_2[which(data_theta12_2[,1] != 65 & data_theta12_2[,3]%in%(gender)),2]*data_theta12_3[which(data_theta12_3[,1] != 65 & data_theta12_3[,3]%in%(gender)),2]*data_prev_7[which(data_prev_7[,1] != 65 & data_prev_7[,3]%in%(gender)),2]);

  }

  ### Mortality of diseased subjects on exposed peoples

  a121 <- matrix(c(0),
                 nrow=40*nb_iter,
                 ncol=132,
                 byrow=T);
  colnames(a121) <- c("age",1950:2080)

  a121[,1] <- c(66:105)
  a121[,-1] <- a120[,-1]*data_theta12_1[which(data_theta12_1[,1] != 65 & data_theta12_1[,3]%in%(gender)),2];

  a122 <- matrix(c(0),
                 nrow=40*nb_iter,
                 ncol=132,
                 byrow=T);
  colnames(a122) <- c("age",1950:2080)

  a122[,1] <- c(66:105)
  a122[,-1] <- a120[,-1]*data_theta12_2[which(data_theta12_2[,1] != 65 & data_theta12_2[,3]%in%(gender)),2];

  a123 <- matrix(c(0),
                 nrow=40*nb_iter,
                 ncol=132,
                 byrow=T);
  colnames(a123) <- c("age",1950:2080)

  a123[,1] <- c(66:105)
  a123[,-1] <- a120[,-1]*data_theta12_3[which(data_theta12_3[,1] != 65 & data_theta12_3[,3]%in%(gender)),2];

  a124 <- matrix(c(0),
                 nrow=40*nb_iter,
                 ncol=132,
                 byrow=T);
  colnames(a124) <- c("age",1950:2080)

  a124[,1] <- c(66:105)
  a124[,-1] <- a120[,-1]*data_theta12_1[which(data_theta12_1[,1] != 65 & data_theta12_1[,3]%in%(gender)),2]*data_theta12_2[which(data_theta12_2[,1] != 65 & data_theta12_2[,3]%in%(gender)),2];

  a125 <- matrix(c(0),
                 nrow=40*nb_iter,
                 ncol=132,
                 byrow=T);
  colnames(a125) <- c("age",1950:2080)

  a125[,1] <- c(66:105)
  a125[,-1] <- a120[,-1]*data_theta12_1[which(data_theta12_1[,1] != 65 & data_theta12_1[,3]%in%(gender)),2]*data_theta12_3[which(data_theta12_3[,1] != 65 & data_theta12_3[,3]%in%(gender)),2];

  a126 <- matrix(c(0),
                 nrow=40*nb_iter,
                 ncol=132,
                 byrow=T);
  colnames(a126) <- c("age",1950:2080)

  a126[,1] <- c(66:105)
  a126[,-1] <- a120[,-1]*data_theta12_2[which(data_theta12_2[,1] != 65 & data_theta12_2[,3]%in%(gender)),2]*data_theta12_3[which(data_theta12_3[,1] != 65 & data_theta12_3[,3]%in%(gender)),2];

  a127 <- matrix(c(0),
                 nrow=40*nb_iter,
                 ncol=132,
                 byrow=T);
  colnames(a127) <- c("age",1950:2080)

  a127[,1] <- c(66:105)
  a127[,-1] <- a120[,-1]*data_theta12_1[which(data_theta12_1[,1] != 65 & data_theta12_1[,3]%in%(gender)),2]*data_theta12_2[which(data_theta12_2[,1] != 65 & data_theta12_2[,3]%in%(gender)),2]*data_theta12_3[which(data_theta12_3[,1] != 65 & data_theta12_3[,3]%in%(gender)),2];

  ### Global mortality of diseased subjects

  a12_global <- matrix(c(0),
                       nrow=40*nb_iter,
                       ncol=132,
                       byrow=T);
  colnames(a12_global) <- c("age",1950:2080)

  a12_global[,1] <- c(66:105)
  a12_global[,-1] <- data_prev_0[which(data_prev_0[,1] != 65 & data_prev_0[,3]%in%(gender)),2]*a120[,-1] + data_prev_1[which(data_prev_1[,1] != 65 & data_prev_1[,3]%in%(gender)),2]*a120[,-1]*data_theta12_1[which(data_theta12_1[,1] != 65 & data_theta12_1[,3]%in%(gender)),2] + data_prev_2[which(data_prev_2[,1] != 65 & data_prev_2[,3]%in%(gender)),2]*a120[,-1]*data_theta12_2[which(data_theta12_2[,1] != 65 & data_theta12_2[,3]%in%(gender)),2] + data_prev_3[which(data_prev_3[,1] != 65 & data_prev_3[,3]%in%(gender)),2]*a120[,-1]*data_theta12_3[which(data_theta12_3[,1] != 65 & data_theta12_3[,3]%in%(gender)),2] + data_prev_4[which(data_prev_4[,1] != 65 & data_prev_4[,3]%in%(gender)),2]*a120[,-1]*data_theta12_1[which(data_theta12_1[,1] != 65 & data_theta12_1[,3]%in%(gender)),2]*data_theta12_2[which(data_theta12_2[,1] != 65 & data_theta12_2[,3]%in%(gender)),2] + data_prev_5[which(data_prev_5[,1] != 65 & data_prev_5[,3]%in%(gender)),2]*a120[,-1]*data_theta12_1[which(data_theta12_1[,1] != 65 & data_theta12_1[,3]%in%(gender)),2]*data_theta12_3[which(data_theta12_3[,1] != 65 & data_theta12_3[,3]%in%(gender)),2] + data_prev_6[which(data_prev_6[,1] != 65 & data_prev_6[,3]%in%(gender)),2]*a120[,-1]*data_theta12_2[which(data_theta12_2[,1] != 65 & data_theta12_2[,3]%in%(gender)),2]*data_theta12_3[which(data_theta12_3[,1] != 65 & data_theta12_3[,3]%in%(gender)),2] + data_prev_7[which(data_prev_7[,1] != 65 & data_prev_7[,3]%in%(gender)),2]*a120[,-1]*data_theta12_1[which(data_theta12_1[,1] != 65 & data_theta12_1[,3]%in%(gender)),2]*data_theta12_2[which(data_theta12_2[,1] != 65 & data_theta12_2[,3]%in%(gender)),2]*data_theta12_3[which(data_theta12_3[,1] != 65 & data_theta12_3[,3]%in%(gender)),2];

  ### Variability of parameters

  ### Incidence of disease on non exposed peoples

  a010_values <- matrix(c(0),
                 nrow=40,
                 ncol=132,
                 byrow=T);
  colnames(a010_values) <- c("age",1950:2080)

  a010_values[,1] <- c(66:105)

  for (a in 2:ncol(a010_values)){

    a010_values[,a] <- as.numeric(data_a01_values[which(data_a01_values[,1] != 65 & data_a01_values[,2]%in%(gender)),a+1]) / (data_prev_0_values[which(data_prev_0_values[,1] != 65 & data_prev_0_values[,3]%in%(gender)),2] + data_theta01_1_values[which(data_theta01_1_values[,1] != 65 & data_theta01_1_values[,3]%in%(gender)),2]*data_prev_1_values[which(data_prev_1_values[,1] != 65 & data_prev_1_values[,3]%in%(gender)),2] + data_theta01_2_values[which(data_theta01_2_values[,1] != 65 & data_theta01_2_values[,3]%in%(gender)),2]*data_prev_2_values[which(data_prev_2_values[,1] != 65 & data_prev_2_values[,3]%in%(gender)),2] + data_theta01_3_values[which(data_theta01_3_values[,1] != 65 & data_theta01_3_values[,3]%in%(gender)),2]*data_prev_3_values[which(data_prev_3_values[,1] != 65 & data_prev_3_values[,3]%in%(gender)),2] + data_theta01_1_values[which(data_theta01_1_values[,1] != 65 & data_theta01_1_values[,3]%in%(gender)),2]*data_theta01_2_values[which(data_theta01_2_values[,1] != 65 & data_theta01_2_values[,3]%in%(gender)),2]*data_prev_4_values[which(data_prev_4_values[,1] != 65 & data_prev_4_values[,3]%in%(gender)),2] + data_theta01_1_values[which(data_theta01_1_values[,1] != 65 & data_theta01_1_values[,3]%in%(gender)),2]*data_theta01_3_values[which(data_theta01_3_values[,1] != 65 & data_theta01_3_values[,3]%in%(gender)),2]*data_prev_5_values[which(data_prev_5_values[,1] != 65 & data_prev_5_values[,3]%in%(gender)),2] + data_theta01_2_values[which(data_theta01_2_values[,1] != 65 & data_theta01_2_values[,3]%in%(gender)),2]*data_theta01_3_values[which(data_theta01_3_values[,1] != 65 & data_theta01_3_values[,3]%in%(gender)),2]*data_prev_6_values[which(data_prev_6_values[,1] != 65 & data_prev_6_values[,3]%in%(gender)),2] + data_theta01_1_values[which(data_theta01_1_values[,1] != 65 & data_theta01_1_values[,3]%in%(gender)),2]*data_theta01_2_values[which(data_theta01_2_values[,1] != 65 & data_theta01_2_values[,3]%in%(gender)),2]*data_theta01_3_values[which(data_theta01_3_values[,1] != 65 & data_theta01_3_values[,3]%in%(gender)),2]*data_prev_7_values[which(data_prev_7_values[,1] != 65 & data_prev_7_values[,3]%in%(gender)),2]);

  }

  ### Incidence of disease on exposed peoples

  a011_values <- matrix(c(0),
                 nrow=40,
                 ncol=132,
                 byrow=T);
  colnames(a011_values) <- c("age",1950:2080)

  a011_values[,1] <- c(66:105)
  a011_values[,-1] <- a010_values[,-1]*data_theta01_1_values[which(data_theta01_1_values[,1] != 65 & data_theta01_1_values[,3]%in%(gender)),2];

  a012_values <- matrix(c(0),
                 nrow=40,
                 ncol=132,
                 byrow=T);
  colnames(a012_values) <- c("age",1950:2080)

  a012_values[,1] <- c(66:105)
  a012_values[,-1] <- a010_values[,-1]*data_theta01_2_values[which(data_theta01_2_values[,1] != 65 & data_theta01_2_values[,3]%in%(gender)),2];

  a013_values <- matrix(c(0),
                 nrow=40,
                 ncol=132,
                 byrow=T);
  colnames(a013_values) <- c("age",1950:2080)

  a013_values[,1] <- c(66:105)
  a013_values[,-1] <- a010_values[,-1]*data_theta01_3_values[which(data_theta01_3_values[,1] != 65 & data_theta01_3_values[,3]%in%(gender)),2];

  a014_values <- matrix(c(0),
                 nrow=40,
                 ncol=132,
                 byrow=T);
  colnames(a014_values) <- c("age",1950:2080)

  a014_values[,1] <- c(66:105)
  a014_values[,-1] <- a010_values[,-1]*data_theta01_1_values[which(data_theta01_1_values[,1] != 65 & data_theta01_1_values[,3]%in%(gender)),2]*data_theta01_2_values[which(data_theta01_2_values[,1] != 65 & data_theta01_2_values[,3]%in%(gender)),2];

  a015_values <- matrix(c(0),
                 nrow=40,
                 ncol=132,
                 byrow=T);
  colnames(a015_values) <- c("age",1950:2080)

  a015_values[,1] <- c(66:105)
  a015_values[,-1] <- a010_values[,-1]*data_theta01_1_values[which(data_theta01_1_values[,1] != 65 & data_theta01_1_values[,3]%in%(gender)),2]*data_theta01_3_values[which(data_theta01_3_values[,1] != 65 & data_theta01_3_values[,3]%in%(gender)),2];

  a016_values <- matrix(c(0),
                 nrow=40,
                 ncol=132,
                 byrow=T);
  colnames(a016_values) <- c("age",1950:2080)

  a016_values[,1] <- c(66:105)
  a016_values[,-1] <- a010_values[,-1]*data_theta01_2_values[which(data_theta01_2_values[,1] != 65 & data_theta01_2_values[,3]%in%(gender)),2]*data_theta01_3_values[which(data_theta01_3_values[,1] != 65 & data_theta01_3_values[,3]%in%(gender)),2];

  a017_values <- matrix(c(0),
                 nrow=40,
                 ncol=132,
                 byrow=T);
  colnames(a017_values) <- c("age",1950:2080)

  a017_values[,1] <- c(66:105)
  a017_values[,-1] <- a010_values[,-1]*data_theta01_1_values[which(data_theta01_1_values[,1] != 65 & data_theta01_1_values[,3]%in%(gender)),2]*data_theta01_2_values[which(data_theta01_2_values[,1] != 65 & data_theta01_2_values[,3]%in%(gender)),2]*data_theta01_3_values[which(data_theta01_3_values[,1] != 65 & data_theta01_3_values[,3]%in%(gender)),2];

  ### Global incidence of disease

  a01_global_values <- matrix(c(0),
                       nrow=40,
                       ncol=132,
                       byrow=T);
  colnames(a01_global_values) <- c("age",1950:2080)

  a01_global_values[,1] <- c(66:105)
  a01_global_values[,-1] <- data_prev_0_values[which(data_prev_0_values[,1] != 65 & data_prev_0_values[,3]%in%(gender)),2]*a010_values[,-1] + data_prev_1_values[which(data_prev_1_values[,1] != 65 & data_prev_1_values[,3]%in%(gender)),2]*a010_values[,-1]*data_theta01_1_values[which(data_theta01_1_values[,1] != 65 & data_theta01_1_values[,3]%in%(gender)),2] + data_prev_2_values[which(data_prev_2_values[,1] != 65 & data_prev_2_values[,3]%in%(gender)),2]*a010_values[,-1]*data_theta01_2_values[which(data_theta01_2_values[,1] != 65 & data_theta01_2_values[,3]%in%(gender)),2] + data_prev_3_values[which(data_prev_3_values[,1] != 65 & data_prev_3_values[,3]%in%(gender)),2]*a010_values[,-1]*data_theta01_3_values[which(data_theta01_3_values[,1] != 65 & data_theta01_3_values[,3]%in%(gender)),2] + data_prev_4_values[which(data_prev_4_values[,1] != 65 & data_prev_4_values[,3]%in%(gender)),2]*a010_values[,-1]*data_theta01_1_values[which(data_theta01_1_values[,1] != 65 & data_theta01_1_values[,3]%in%(gender)),2]*data_theta01_2_values[which(data_theta01_2_values[,1] != 65 & data_theta01_2_values[,3]%in%(gender)),2] + data_prev_5_values[which(data_prev_5_values[,1] != 65 & data_prev_5_values[,3]%in%(gender)),2]*a010_values[,-1]*data_theta01_1_values[which(data_theta01_1_values[,1] != 65 & data_theta01_1_values[,3]%in%(gender)),2]*data_theta01_3_values[which(data_theta01_3_values[,1] != 65 & data_theta01_3_values[,3]%in%(gender)),2] + data_prev_6_values[which(data_prev_6_values[,1] != 65 & data_prev_6_values[,3]%in%(gender)),2]*a010_values[,-1]*data_theta01_2_values[which(data_theta01_2_values[,1] != 65 & data_theta01_2_values[,3]%in%(gender)),2]*data_theta01_3_values[which(data_theta01_3_values[,1] != 65 & data_theta01_3_values[,3]%in%(gender)),2] + data_prev_7_values[which(data_prev_7_values[,1] != 65 & data_prev_7_values[,3]%in%(gender)),2]*a010_values[,-1]*data_theta01_1_values[which(data_theta01_1_values[,1] != 65 & data_theta01_1_values[,3]%in%(gender)),2]*data_theta01_2_values[which(data_theta01_2_values[,1] != 65 & data_theta01_2_values[,3]%in%(gender)),2]*data_theta01_3_values[which(data_theta01_3_values[,1] != 65 & data_theta01_3_values[,3]%in%(gender)),2];

  ### Mortality of healthy subjects on non exposed peoples

  a020_values <- matrix(c(0),
                 nrow=40,
                 ncol=132,
                 byrow=T);
  colnames(a020_values) <- c("age",1950:2080)

  a020_values[,1] <- c(66:105)

  for (a in 2:ncol(a020_values)){

    a020_values[,a] <- as.numeric(data_a02_values[which(data_a02_values[,1] != 65 & data_a02_values[,2]%in%(gender)),a+1]) / (data_prev_0_values[which(data_prev_0_values[,1] != 65 & data_prev_0_values[,3]%in%(gender)),2] + data_theta02_1_values[which(data_theta02_1_values[,1] != 65 & data_theta02_1_values[,3]%in%(gender)),2]*data_prev_1_values[which(data_prev_1_values[,1] != 65 & data_prev_1_values[,3]%in%(gender)),2] + data_theta02_2_values[which(data_theta02_2_values[,1] != 65 & data_theta02_2_values[,3]%in%(gender)),2]*data_prev_2_values[which(data_prev_2_values[,1] != 65 & data_prev_2_values[,3]%in%(gender)),2] + data_theta02_3_values[which(data_theta02_3_values[,1] != 65 & data_theta02_3_values[,3]%in%(gender)),2]*data_prev_3_values[which(data_prev_3_values[,1] != 65 & data_prev_3_values[,3]%in%(gender)),2] + data_theta02_1_values[which(data_theta02_1_values[,1] != 65 & data_theta02_1_values[,3]%in%(gender)),2]*data_theta02_2_values[which(data_theta02_2_values[,1] != 65 & data_theta02_2_values[,3]%in%(gender)),2]*data_prev_4_values[which(data_prev_4_values[,1] != 65 & data_prev_4_values[,3]%in%(gender)),2] + data_theta02_1_values[which(data_theta02_1_values[,1] != 65 & data_theta02_1_values[,3]%in%(gender)),2]*data_theta02_3_values[which(data_theta02_3_values[,1] != 65 & data_theta02_3_values[,3]%in%(gender)),2]*data_prev_5_values[which(data_prev_5_values[,1] != 65 & data_prev_5_values[,3]%in%(gender)),2] + data_theta02_2_values[which(data_theta02_2_values[,1] != 65 & data_theta02_2_values[,3]%in%(gender)),2]*data_theta02_3_values[which(data_theta02_3_values[,1] != 65 & data_theta02_3_values[,3]%in%(gender)),2]*data_prev_6_values[which(data_prev_6_values[,1] != 65 & data_prev_6_values[,3]%in%(gender)),2] + data_theta02_1_values[which(data_theta02_1_values[,1] != 65 & data_theta02_1_values[,3]%in%(gender)),2]*data_theta02_2_values[which(data_theta02_2_values[,1] != 65 & data_theta02_2_values[,3]%in%(gender)),2]*data_theta02_3_values[which(data_theta02_3_values[,1] != 65 & data_theta02_3_values[,3]%in%(gender)),2]*data_prev_7_values[which(data_prev_7_values[,1] != 65 & data_prev_7_values[,3]%in%(gender)),2]);

  }

  ### Mortality of healthy subjects on exposed peoples

  a021_values <- matrix(c(0),
                 nrow=40,
                 ncol=132,
                 byrow=T);
  colnames(a021_values) <- c("age",1950:2080)

  a021_values[,1] <- c(66:105)
  a021_values[,-1] <- a020_values[,-1]*data_theta02_1_values[which(data_theta02_1_values[,1] != 65 & data_theta02_1_values[,3]%in%(gender)),2];

  a022_values <- matrix(c(0),
                 nrow=40,
                 ncol=132,
                 byrow=T);
  colnames(a022_values) <- c("age",1950:2080)

  a022_values[,1] <- c(66:105)
  a022_values[,-1] <- a020_values[,-1]*data_theta02_2_values[which(data_theta02_2_values[,1] != 65 & data_theta02_2_values[,3]%in%(gender)),2];

  a023_values <- matrix(c(0),
                 nrow=40,
                 ncol=132,
                 byrow=T);
  colnames(a023_values) <- c("age",1950:2080)

  a023_values[,1] <- c(66:105)
  a023_values[,-1] <- a020_values[,-1]*data_theta02_3_values[which(data_theta02_3_values[,1] != 65 & data_theta02_3_values[,3]%in%(gender)),2];

  a024_values <- matrix(c(0),
                 nrow=40,
                 ncol=132,
                 byrow=T);
  colnames(a024_values) <- c("age",1950:2080)

  a024_values[,1] <- c(66:105)
  a024_values[,-1] <- a020_values[,-1]*data_theta02_1_values[which(data_theta02_1_values[,1] != 65 & data_theta02_1_values[,3]%in%(gender)),2]*data_theta02_2_values[which(data_theta02_2_values[,1] != 65 & data_theta02_2_values[,3]%in%(gender)),2];

  a025_values <- matrix(c(0),
                 nrow=40,
                 ncol=132,
                 byrow=T);
  colnames(a025_values) <- c("age",1950:2080)

  a025_values[,1] <- c(66:105)
  a025_values[,-1] <- a020_values[,-1]*data_theta02_1_values[which(data_theta02_1_values[,1] != 65 & data_theta02_1_values[,3]%in%(gender)),2]*data_theta02_3_values[which(data_theta02_3_values[,1] != 65 & data_theta02_3_values[,3]%in%(gender)),2];

  a026_values <- matrix(c(0),
                 nrow=40,
                 ncol=132,
                 byrow=T);
  colnames(a026_values) <- c("age",1950:2080)

  a026_values[,1] <- c(66:105)
  a026_values[,-1] <- a020_values[,-1]*data_theta02_2_values[which(data_theta02_2_values[,1] != 65 & data_theta02_2_values[,3]%in%(gender)),2]*data_theta02_3_values[which(data_theta02_3_values[,1] != 65 & data_theta02_3_values[,3]%in%(gender)),2];

  a027_values <- matrix(c(0),
                 nrow=40,
                 ncol=132,
                 byrow=T);
  colnames(a027_values) <- c("age",1950:2080)

  a027_values[,1] <- c(66:105)
  a027_values[,-1] <- a020_values[,-1]*data_theta02_1_values[which(data_theta02_1_values[,1] != 65 & data_theta02_1_values[,3]%in%(gender)),2]*data_theta02_2_values[which(data_theta02_2_values[,1] != 65 & data_theta02_2_values[,3]%in%(gender)),2]*data_theta02_3_values[which(data_theta02_3_values[,1] != 65 & data_theta02_3_values[,3]%in%(gender)),2];

  ### Global mortality of healthy subjects

  a02_global_values <- matrix(c(0),
                       nrow=40,
                       ncol=132,
                       byrow=T);
  colnames(a02_global_values) <- c("age",1950:2080)

  a02_global_values[,1] <- c(66:105)
  a02_global_values[,-1] <- data_prev_0_values[which(data_prev_0_values[,1] != 65 & data_prev_0_values[,3]%in%(gender)),2]*a020_values[,-1] + data_prev_1_values[which(data_prev_1_values[,1] != 65 & data_prev_1_values[,3]%in%(gender)),2]*a020_values[,-1]*data_theta02_1_values[which(data_theta02_1_values[,1] != 65 & data_theta02_1_values[,3]%in%(gender)),2] + data_prev_2_values[which(data_prev_2_values[,1] != 65 & data_prev_2_values[,3]%in%(gender)),2]*a020_values[,-1]*data_theta02_2_values[which(data_theta02_2_values[,1] != 65 & data_theta02_2_values[,3]%in%(gender)),2] + data_prev_3_values[which(data_prev_3_values[,1] != 65 & data_prev_3_values[,3]%in%(gender)),2]*a020_values[,-1]*data_theta02_3_values[which(data_theta02_3_values[,1] != 65 & data_theta02_3_values[,3]%in%(gender)),2] + data_prev_4_values[which(data_prev_4_values[,1] != 65 & data_prev_4_values[,3]%in%(gender)),2]*a020_values[,-1]*data_theta02_1_values[which(data_theta02_1_values[,1] != 65 & data_theta02_1_values[,3]%in%(gender)),2]*data_theta02_2_values[which(data_theta02_2_values[,1] != 65 & data_theta02_2_values[,3]%in%(gender)),2] + data_prev_5_values[which(data_prev_5_values[,1] != 65 & data_prev_5_values[,3]%in%(gender)),2]*a020_values[,-1]*data_theta02_1_values[which(data_theta02_1_values[,1] != 65 & data_theta02_1_values[,3]%in%(gender)),2]*data_theta02_3_values[which(data_theta02_3_values[,1] != 65 & data_theta02_3_values[,3]%in%(gender)),2] + data_prev_6_values[which(data_prev_6_values[,1] != 65 & data_prev_6_values[,3]%in%(gender)),2]*a020_values[,-1]*data_theta02_2_values[which(data_theta02_2_values[,1] != 65 & data_theta02_2_values[,3]%in%(gender)),2]*data_theta02_3_values[which(data_theta02_3_values[,1] != 65 & data_theta02_3_values[,3]%in%(gender)),2] + data_prev_7_values[which(data_prev_7_values[,1] != 65 & data_prev_7_values[,3]%in%(gender)),2]*a020_values[,-1]*data_theta02_1_values[which(data_theta02_1_values[,1] != 65 & data_theta02_1_values[,3]%in%(gender)),2]*data_theta02_2_values[which(data_theta02_2_values[,1] != 65 & data_theta02_2_values[,3]%in%(gender)),2]*data_theta02_3_values[which(data_theta02_3_values[,1] != 65 & data_theta02_3_values[,3]%in%(gender)),2];

  ### Relative risks associated with the disease for mortality

  RR_values <- matrix(c(0),
               nrow=40,
               ncol=2,
               byrow=T);
  colnames(RR_values) <- c("age","rr_DvsND")

  RR_values[,1] <- c(66:105)
  RR_values[,2] <- data_rr_DvsND_values[which(data_rr_DvsND_values[,1] != 65 & data_rr_DvsND_values[,3]%in%(gender)),2];

  ### Mortality of diseased subjects on non exposed peoples

  a120_values <- matrix(c(0),
                 nrow=40,
                 ncol=132,
                 byrow=T);
  colnames(a120_values) <- c("age",1950:2080)

  a120_values[,1] <- c(66:105)

  for (a in 2:ncol(a120_values)){

    a120_values[,a] <- as.numeric(RR_values[,2])*as.numeric(data_a02_values[which(data_a02_values[,1] != 65 & data_a02_values[,2]%in%(gender)),a+1]) / (data_prev_0_values[which(data_prev_0_values[,1] != 65 & data_prev_0_values[,3]%in%(gender)),2] + data_theta12_1_values[which(data_theta12_1_values[,1] != 65 & data_theta12_1_values[,3]%in%(gender)),2]*data_prev_1_values[which(data_prev_1_values[,1] != 65 & data_prev_1_values[,3]%in%(gender)),2] + data_theta12_2_values[which(data_theta12_2_values[,1] != 65 & data_theta12_2_values[,3]%in%(gender)),2]*data_prev_2_values[which(data_prev_2_values[,1] != 65 & data_prev_2_values[,3]%in%(gender)),2] + data_theta12_3_values[which(data_theta12_3_values[,1] != 65 & data_theta12_3_values[,3]%in%(gender)),2]*data_prev_3_values[which(data_prev_3_values[,1] != 65 & data_prev_3_values[,3]%in%(gender)),2] + data_theta12_1_values[which(data_theta12_1_values[,1] != 65 & data_theta12_1_values[,3]%in%(gender)),2]*data_theta12_2_values[which(data_theta12_2_values[,1] != 65 & data_theta12_2_values[,3]%in%(gender)),2]*data_prev_4_values[which(data_prev_4_values[,1] != 65 & data_prev_4_values[,3]%in%(gender)),2] + data_theta12_1_values[which(data_theta12_1_values[,1] != 65 & data_theta12_1_values[,3]%in%(gender)),2]*data_theta12_3_values[which(data_theta12_3_values[,1] != 65 & data_theta12_3_values[,3]%in%(gender)),2]*data_prev_5_values[which(data_prev_5_values[,1] != 65 & data_prev_5_values[,3]%in%(gender)),2] + data_theta12_2_values[which(data_theta12_2_values[,1] != 65 & data_theta12_2_values[,3]%in%(gender)),2]*data_theta12_3_values[which(data_theta12_3_values[,1] != 65 & data_theta12_3_values[,3]%in%(gender)),2]*data_prev_6_values[which(data_prev_6_values[,1] != 65 & data_prev_6_values[,3]%in%(gender)),2] + data_theta12_1_values[which(data_theta12_1_values[,1] != 65 & data_theta12_1_values[,3]%in%(gender)),2]*data_theta12_2_values[which(data_theta12_2_values[,1] != 65 & data_theta12_2_values[,3]%in%(gender)),2]*data_theta12_3_values[which(data_theta12_3_values[,1] != 65 & data_theta12_3_values[,3]%in%(gender)),2]*data_prev_7_values[which(data_prev_7_values[,1] != 65 & data_prev_7_values[,3]%in%(gender)),2]);

  }

  ### Mortality of diseased subjects on exposed peoples

  a121_values <- matrix(c(0),
                 nrow=40,
                 ncol=132,
                 byrow=T);
  colnames(a121_values) <- c("age",1950:2080)

  a121_values[,1] <- c(66:105)
  a121_values[,-1] <- a120_values[,-1]*data_theta12_1_values[which(data_theta12_1_values[,1] != 65 & data_theta12_1_values[,3]%in%(gender)),2];

  a122_values <- matrix(c(0),
                 nrow=40,
                 ncol=132,
                 byrow=T);
  colnames(a122_values) <- c("age",1950:2080)

  a122_values[,1] <- c(66:105)
  a122_values[,-1] <- a120_values[,-1]*data_theta12_2_values[which(data_theta12_2_values[,1] != 65 & data_theta12_2_values[,3]%in%(gender)),2];

  a123_values <- matrix(c(0),
                 nrow=40,
                 ncol=132,
                 byrow=T);
  colnames(a123_values) <- c("age",1950:2080)

  a123_values[,1] <- c(66:105)
  a123_values[,-1] <- a120_values[,-1]*data_theta12_3_values[which(data_theta12_3_values[,1] != 65 & data_theta12_3_values[,3]%in%(gender)),2];

  a124_values <- matrix(c(0),
                 nrow=40,
                 ncol=132,
                 byrow=T);
  colnames(a124_values) <- c("age",1950:2080)

  a124_values[,1] <- c(66:105)
  a124_values[,-1] <- a120_values[,-1]*data_theta12_1_values[which(data_theta12_1_values[,1] != 65 & data_theta12_1_values[,3]%in%(gender)),2]*data_theta12_2_values[which(data_theta12_2_values[,1] != 65 & data_theta12_2_values[,3]%in%(gender)),2];

  a125_values <- matrix(c(0),
                 nrow=40,
                 ncol=132,
                 byrow=T);
  colnames(a125_values) <- c("age",1950:2080)

  a125_values[,1] <- c(66:105)
  a125_values[,-1] <- a120_values[,-1]*data_theta12_1_values[which(data_theta12_1_values[,1] != 65 & data_theta12_1_values[,3]%in%(gender)),2]*data_theta12_3_values[which(data_theta12_3_values[,1] != 65 & data_theta12_3_values[,3]%in%(gender)),2];

  a126_values <- matrix(c(0),
                 nrow=40,
                 ncol=132,
                 byrow=T);
  colnames(a126_values) <- c("age",1950:2080)

  a126_values[,1] <- c(66:105)
  a126_values[,-1] <- a120_values[,-1]*data_theta12_2_values[which(data_theta12_2_values[,1] != 65 & data_theta12_2_values[,3]%in%(gender)),2]*data_theta12_3_values[which(data_theta12_3_values[,1] != 65 & data_theta12_3_values[,3]%in%(gender)),2];

  a127_values <- matrix(c(0),
                 nrow=40,
                 ncol=132,
                 byrow=T);
  colnames(a127_values) <- c("age",1950:2080)

  a127_values[,1] <- c(66:105)
  a127_values[,-1] <- a120_values[,-1]*data_theta12_1_values[which(data_theta12_1_values[,1] != 65 & data_theta12_1_values[,3]%in%(gender)),2]*data_theta12_2_values[which(data_theta12_2_values[,1] != 65 & data_theta12_2_values[,3]%in%(gender)),2]*data_theta12_3_values[which(data_theta12_3_values[,1] != 65 & data_theta12_3_values[,3]%in%(gender)),2];

  ### Global mortality of diseased subjects

  a12_global_values <- matrix(c(0),
                       nrow=40,
                       ncol=132,
                       byrow=T);
  colnames(a12_global_values) <- c("age",1950:2080)

  a12_global_values[,1] <- c(66:105)
  a12_global_values[,-1] <- data_prev_0_values[which(data_prev_0_values[,1] != 65 & data_prev_0_values[,3]%in%(gender)),2]*a120_values[,-1] + data_prev_1_values[which(data_prev_1_values[,1] != 65 & data_prev_1_values[,3]%in%(gender)),2]*a120_values[,-1]*data_theta12_1_values[which(data_theta12_1_values[,1] != 65 & data_theta12_1_values[,3]%in%(gender)),2] + data_prev_2_values[which(data_prev_2_values[,1] != 65 & data_prev_2_values[,3]%in%(gender)),2]*a120_values[,-1]*data_theta12_2_values[which(data_theta12_2_values[,1] != 65 & data_theta12_2_values[,3]%in%(gender)),2] + data_prev_3_values[which(data_prev_3_values[,1] != 65 & data_prev_3_values[,3]%in%(gender)),2]*a120_values[,-1]*data_theta12_3_values[which(data_theta12_3_values[,1] != 65 & data_theta12_3_values[,3]%in%(gender)),2] + data_prev_4_values[which(data_prev_4_values[,1] != 65 & data_prev_4_values[,3]%in%(gender)),2]*a120_values[,-1]*data_theta12_1_values[which(data_theta12_1_values[,1] != 65 & data_theta12_1_values[,3]%in%(gender)),2]*data_theta12_2_values[which(data_theta12_2_values[,1] != 65 & data_theta12_2_values[,3]%in%(gender)),2] + data_prev_5_values[which(data_prev_5_values[,1] != 65 & data_prev_5_values[,3]%in%(gender)),2]*a120_values[,-1]*data_theta12_1_values[which(data_theta12_1_values[,1] != 65 & data_theta12_1_values[,3]%in%(gender)),2]*data_theta12_3_values[which(data_theta12_3_values[,1] != 65 & data_theta12_3_values[,3]%in%(gender)),2] + data_prev_6_values[which(data_prev_6_values[,1] != 65 & data_prev_6_values[,3]%in%(gender)),2]*a120_values[,-1]*data_theta12_2_values[which(data_theta12_2_values[,1] != 65 & data_theta12_2_values[,3]%in%(gender)),2]*data_theta12_3_values[which(data_theta12_3_values[,1] != 65 & data_theta12_3_values[,3]%in%(gender)),2] + data_prev_7_values[which(data_prev_7_values[,1] != 65 & data_prev_7_values[,3]%in%(gender)),2]*a120_values[,-1]*data_theta12_1_values[which(data_theta12_1_values[,1] != 65 & data_theta12_1_values[,3]%in%(gender)),2]*data_theta12_2_values[which(data_theta12_2_values[,1] != 65 & data_theta12_2_values[,3]%in%(gender)),2]*data_theta12_3_values[which(data_theta12_3_values[,1] != 65 & data_theta12_3_values[,3]%in%(gender)),2];

  ### Matrix for results of health indicators

  ### Overall life-expectancy

  esp_vie_gen <- matrix(c(0),
                        nrow=100-65+1,
                        ncol=2+nb_iter,
                        byrow = T);
  esp_vie_gen[,1] <- c(65:100);

  ### Overall life-expectancy on exposed peoples

  esp_vie_gen_conso <- matrix(c(0),
                              nrow=100-65+1,
                              ncol=2+nb_iter,
                              byrow = T);
  esp_vie_gen_conso[,1] <- c(65:100);

  ### Overall life-expectancy on non exposed peoples

  esp_vie_gen_nonconso <- matrix(c(0),
                                 nrow=100-65+1,
                                 ncol=2+nb_iter,
                                 byrow = T);
  esp_vie_gen_nonconso[,1] <- c(65:100);

  ### Life-expectancy without disease

  esp_vie_sans_mal <- matrix(c(0), # matrice de calcul des espérances de vie à chaque âge
                             nrow=100-65+1,
                             ncol=2+nb_iter,
                             byrow = T);
  esp_vie_sans_mal[,1] <- c(65:100);

  ### Life-expectancy without disease on exposed peoples

  esp_vie_sans_mal_conso <- matrix(c(0),
                                   nrow=100-65+1,
                                   ncol=2+nb_iter,
                                   byrow = T);
  esp_vie_sans_mal_conso[,1] <- c(65:100);

  ### Life-expectancy without disease on non exposed peoples

  esp_vie_sans_mal_nonconso <- matrix(c(0),
                                      nrow=100-65+1,
                                      ncol=2+nb_iter,
                                      byrow = T);
  esp_vie_sans_mal_nonconso[,1] <- c(65:100);

  ### Life-expectancy for diseased subject

  esp_vie_mal <- matrix(c(0),
                        nrow=100-65+1,
                        ncol=2+nb_iter,
                        byrow = T);
  esp_vie_mal[,1] <- c(65:100);

  ### Life-expectancy for diseased subject on exposed peoples

  esp_vie_mal_conso <- matrix(c(0),
                              nrow=100-65+1,
                              ncol=2+nb_iter,
                              byrow = T);
  esp_vie_mal_conso[,1] <- c(65:100);

  ### Life-expectancy for diseased subject on non exposed peoples

  esp_vie_mal_nonconso <- matrix(c(0),
                                 nrow=100-65+1,
                                 ncol=2+nb_iter,
                                 byrow = T);
  esp_vie_mal_nonconso[,1] <- c(65:100);

  ### Life-expectancy for non-diseased subject

  esp_vie_non_mal <- matrix(c(0),
                            nrow=100-65+1,
                            ncol=2+nb_iter,
                            byrow = T);
  esp_vie_non_mal[,1] <- c(65:100);

  ### Life-expectancy for non-diseased subject on exposed peoples

  esp_vie_non_mal_conso <- matrix(c(0),
                                  nrow=100-65+1,
                                  ncol=2+nb_iter,
                                  byrow = T);
  esp_vie_non_mal_conso[,1] <- c(65:100);

  ### Life-expectancy for non-diseased subject on non exposed peoples

  esp_vie_non_mal_nonconso <- matrix(c(0),
                                     nrow=100-65+1,
                                     ncol=2+nb_iter,
                                     byrow = T);
  esp_vie_non_mal_nonconso[,1] <- c(65:100);

  ### Number of exposed peoples at least one time

  prevalence <- matrix(c(0),
                       nrow=99-65+1,
                       ncol=2+nb_iter,
                       byrow=T);
  prevalence[,1] <- c(65:99);

  ### Rate of exposed peoples at least one time

  taux_prevalence <- matrix(c(0),
                            nrow=99-65+1,
                            ncol=2+nb_iter,
                            byrow=T);
  taux_prevalence[,1] <- c(65:99);

  ### Number of living peoples

  survie <- matrix(c(0),
                   nrow=99-65+1,
                   ncol=2+nb_iter,
                   byrow=T);
  survie[,1] <- c(65:99);

  ### Rate of living peoples a given

  taux_survivants <- matrix(c(0),
                            nrow=99-65+1,
                            ncol=2+nb_iter,
                            byrow=T);
  taux_survivants[,1] <- c(65:99);

  ### Mean number of years spent with disease

  nb_moy_dem <- matrix(c(0),
                       nrow=100-65+1,
                       ncol=2+nb_iter,
                       byrow = T);
  nb_moy_dem[,1] <- c(65:100);

  ### Mean number of years spent with disease on exposed peoples

  nb_moy_dem_conso <- matrix(c(0),
                             nrow=100-65+1,
                             ncol=2+nb_iter,
                             byrow = T);
  nb_moy_dem_conso[,1] <- c(65:100);

  ### Mean number of years spent with disease on non exposed peoples

  nb_moy_dem_nonconso <- matrix(c(0),
                                nrow=100-65+1,
                                ncol=2+nb_iter,
                                byrow = T);
  nb_moy_dem_nonconso[,1] <- c(65:100);

  ### Life-long probability of disease

  prb_dem <- matrix(c(0),
                    nrow=99-65+1,
                    ncol=2+nb_iter,
                    byrow=T);
  prb_dem[,1] <- c(65:99);

  ###	Average age at disease onset

  age_dem <- matrix(c(0),
                    nrow=99-65+1,
                    ncol=2+nb_iter,
                    byrow=T);
  age_dem[,1] <- c(65:99);

  ### Mean number of years of exposition

  moy_conso <- matrix(c(0),
                      nrow=99-65+1,
                      ncol=2+nb_iter,
                      byrow=T);
  moy_conso[,1] <- c(65:99);

  ### Number of exposed peoples at least one time

  prevalence_conso <- matrix(c(0),
                             nrow=105-65+1,
                             ncol=2+nb_iter,
                             byrow=T);
  prevalence_conso[,1] <- c(65:105);

  ### Mortality rate

  quotient_mortalite <- matrix(c(0),
                               nrow=99-65+1,
                               ncol=2+nb_iter,
                               byrow=T);
  quotient_mortalite[,1] <- c(65:99);


  ##############################
  ########## ESSAIS ############
  ##############################


  ### Dementia incidence

  incid_demence <- matrix(c(0),
                          nrow=105-66+1,
                          ncol=105-65+2,
                          byrow=T);
  incid_demence[,1] <- c(66:105);

  ### Mortality incidence

  incid_mort_Dem <- matrix(c(0),
                           nrow=105-66+1,
                           ncol=105-65+2,
                           byrow=T);
  incid_mort_Dem[,1] <- c(66:105);

  incid_mort_NoD <- matrix(c(0),
                           nrow=105-66+1,
                           ncol=105-65+2,
                           byrow=T);
  incid_mort_NoD[,1] <- c(66:105);

  ### Non exposed prevalence

  prevalence_noe <- matrix(c(0),
                           nrow=105-65+1,
                           ncol=105-65+2,
                           byrow=T);
  prevalence_noe[,1] <- c(65:105);

  ### Physical inactivity prevalence

  prevalence_ina <- matrix(c(0),
                           nrow=105-65+1,
                           ncol=105-65+2,
                           byrow=T);
  prevalence_ina[,1] <- c(65:105);

  ### Hypertension prevalence

  prevalence_hta <- matrix(c(0),
                           nrow=105-65+1,
                           ncol=105-65+2,
                           byrow=T);
  prevalence_hta[,1] <- c(65:105);

  ### Diabete prevalence

  prevalence_dia <- matrix(c(0),
                           nrow=105-65+1,
                           ncol=105-65+2,
                           byrow=T);
  prevalence_dia[,1] <- c(65:105);

  ### Expositions prevalence

  prevalence_exp0 <- matrix(c(0),
                           nrow=105-65+1,
                           ncol=105-65+2,
                           byrow=T);
  prevalence_exp0[,1] <- c(65:105);

  prevalence_exp1 <- matrix(c(0),
                            nrow=105-65+1,
                            ncol=105-65+2,
                            byrow=T);
  prevalence_exp1[,1] <- c(65:105);

  prevalence_exp2 <- matrix(c(0),
                            nrow=105-65+1,
                            ncol=105-65+2,
                            byrow=T);
  prevalence_exp2[,1] <- c(65:105);

  prevalence_exp3 <- matrix(c(0),
                            nrow=105-65+1,
                            ncol=105-65+2,
                            byrow=T);
  prevalence_exp3[,1] <- c(65:105);

  prevalence_exp4 <- matrix(c(0),
                            nrow=105-65+1,
                            ncol=105-65+2,
                            byrow=T);
  prevalence_exp4[,1] <- c(65:105);

  prevalence_exp5 <- matrix(c(0),
                            nrow=105-65+1,
                            ncol=105-65+2,
                            byrow=T);
  prevalence_exp5[,1] <- c(65:105);

  prevalence_exp6 <- matrix(c(0),
                            nrow=105-65+1,
                            ncol=105-65+2,
                            byrow=T);
  prevalence_exp6[,1] <- c(65:105);

  prevalence_exp7 <- matrix(c(0),
                            nrow=105-65+1,
                            ncol=105-65+2,
                            byrow=T);
  prevalence_exp7[,1] <- c(65:105);

  prop_dem_diabet <- matrix(c(0),
                            nrow=105-66+1,
                            ncol=105-65+2,
                            byrow=T);
  prop_dem_diabet[,1] <- c(66:105);

  prop_dem_hypert <- matrix(c(0),
                            nrow=105-66+1,
                            ncol=105-65+2,
                            byrow=T);
  prop_dem_hypert[,1] <- c(66:105);

  prop_dem_inacti <- matrix(c(0),
                            nrow=105-66+1,
                            ncol=105-65+2,
                            byrow=T);
  prop_dem_inacti[,1] <- c(66:105);

  prop_dem_global <- matrix(c(0),
                            nrow=105-66+1,
                            ncol=105-65+2,
                            byrow=T);
  prop_dem_global[,1] <- c(66:105);

  #####################################################################################
  #####################################################################################
  #####################################################################################
  #####################################################################################
  #####################################################################################

  ### Computation with estimated parameters

  for (age in 65:105) { # for each generation

    an_naiss <- year_proj-age; # year of birth

    an0 <- an_naiss + 65; # first year at risk

    annee <- an0; # year of estimation

    data_prev_0_values_ND <- data_prev_0_values
    data_prev_0_values_D <- data_prev_0_values
    data_prev_1_values_ND <- data_prev_1_values
    data_prev_1_values_D <- data_prev_1_values
    data_prev_2_values_ND <- data_prev_2_values
    data_prev_2_values_D <- data_prev_2_values
    data_prev_3_values_ND <- data_prev_3_values
    data_prev_3_values_D <- data_prev_3_values
    data_prev_4_values_ND <- data_prev_4_values
    data_prev_4_values_D <- data_prev_4_values
    data_prev_5_values_ND <- data_prev_5_values
    data_prev_5_values_D <- data_prev_5_values
    data_prev_6_values_ND <- data_prev_6_values
    data_prev_6_values_D <- data_prev_6_values
    data_prev_7_values_ND <- data_prev_7_values
    data_prev_7_values_D <- data_prev_7_values

    a010_values <- matrix(c(0),
                          nrow=40,
                          ncol=132,
                          byrow=T);
    colnames(a010_values) <- c("age",1950:2080)

    a010_values[,1] <- c(66:105)

    a011_values <- matrix(c(0),
                          nrow=40,
                          ncol=132,
                          byrow=T);
    colnames(a011_values) <- c("age",1950:2080)

    a011_values[,1] <- c(66:105)

    a012_values <- matrix(c(0),
                          nrow=40,
                          ncol=132,
                          byrow=T);
    colnames(a012_values) <- c("age",1950:2080)

    a012_values[,1] <- c(66:105)

    a013_values <- matrix(c(0),
                          nrow=40,
                          ncol=132,
                          byrow=T);
    colnames(a013_values) <- c("age",1950:2080)

    a013_values[,1] <- c(66:105)

    a014_values <- matrix(c(0),
                          nrow=40,
                          ncol=132,
                          byrow=T);
    colnames(a014_values) <- c("age",1950:2080)

    a014_values[,1] <- c(66:105)

    a015_values <- matrix(c(0),
                          nrow=40,
                          ncol=132,
                          byrow=T);
    colnames(a015_values) <- c("age",1950:2080)

    a015_values[,1] <- c(66:105)

    a016_values <- matrix(c(0),
                          nrow=40,
                          ncol=132,
                          byrow=T);
    colnames(a016_values) <- c("age",1950:2080)

    a016_values[,1] <- c(66:105)

    a017_values <- matrix(c(0),
                          nrow=40,
                          ncol=132,
                          byrow=T);
    colnames(a017_values) <- c("age",1950:2080)

    a017_values[,1] <- c(66:105)

    a01_global_values <- matrix(c(0),
                                nrow=40,
                                ncol=132,
                                byrow=T);
    colnames(a01_global_values) <- c("age",1950:2080)

    a01_global_values[,1] <- c(66:105)

    a020_values <- matrix(c(0),
                          nrow=40,
                          ncol=132,
                          byrow=T);
    colnames(a020_values) <- c("age",1950:2080)

    a020_values[,1] <- c(66:105)

    a021_values <- matrix(c(0),
                          nrow=40,
                          ncol=132,
                          byrow=T);
    colnames(a021_values) <- c("age",1950:2080)

    a021_values[,1] <- c(66:105)

    a022_values <- matrix(c(0),
                          nrow=40,
                          ncol=132,
                          byrow=T);
    colnames(a022_values) <- c("age",1950:2080)

    a022_values[,1] <- c(66:105)

    a023_values <- matrix(c(0),
                          nrow=40,
                          ncol=132,
                          byrow=T);
    colnames(a023_values) <- c("age",1950:2080)

    a023_values[,1] <- c(66:105)

    a024_values <- matrix(c(0),
                          nrow=40,
                          ncol=132,
                          byrow=T);
    colnames(a024_values) <- c("age",1950:2080)

    a024_values[,1] <- c(66:105)

    a025_values <- matrix(c(0),
                          nrow=40,
                          ncol=132,
                          byrow=T);
    colnames(a025_values) <- c("age",1950:2080)

    a025_values[,1] <- c(66:105)

    a026_values <- matrix(c(0),
                          nrow=40,
                          ncol=132,
                          byrow=T);
    colnames(a026_values) <- c("age",1950:2080)

    a026_values[,1] <- c(66:105)

    a027_values <- matrix(c(0),
                          nrow=40,
                          ncol=132,
                          byrow=T);
    colnames(a027_values) <- c("age",1950:2080)

    a027_values[,1] <- c(66:105)

    a02_global_values <- matrix(c(0),
                                nrow=40,
                                ncol=132,
                                byrow=T);
    colnames(a02_global_values) <- c("age",1950:2080)

    a02_global_values[,1] <- c(66:105)

    a120_values <- matrix(c(0),
                          nrow=40,
                          ncol=132,
                          byrow=T);
    colnames(a120_values) <- c("age",1950:2080)

    a120_values[,1] <- c(66:105)

    a121_values <- matrix(c(0),
                          nrow=40,
                          ncol=132,
                          byrow=T);
    colnames(a121_values) <- c("age",1950:2080)

    a121_values[,1] <- c(66:105)

    a122_values <- matrix(c(0),
                          nrow=40,
                          ncol=132,
                          byrow=T);
    colnames(a122_values) <- c("age",1950:2080)

    a122_values[,1] <- c(66:105)

    a123_values <- matrix(c(0),
                          nrow=40,
                          ncol=132,
                          byrow=T);
    colnames(a123_values) <- c("age",1950:2080)

    a123_values[,1] <- c(66:105)

    a124_values <- matrix(c(0),
                          nrow=40,
                          ncol=132,
                          byrow=T);
    colnames(a124_values) <- c("age",1950:2080)

    a124_values[,1] <- c(66:105)

    a125_values <- matrix(c(0),
                          nrow=40,
                          ncol=132,
                          byrow=T);
    colnames(a125_values) <- c("age",1950:2080)

    a125_values[,1] <- c(66:105)

    a126_values <- matrix(c(0),
                          nrow=40,
                          ncol=132,
                          byrow=T);
    colnames(a126_values) <- c("age",1950:2080)

    a126_values[,1] <- c(66:105)

    a127_values <- matrix(c(0),
                          nrow=40,
                          ncol=132,
                          byrow=T);
    colnames(a127_values) <- c("age",1950:2080)

    a127_values[,1] <- c(66:105)

    a12_global_values <- matrix(c(0),
                                nrow=40,
                                ncol=132,
                                byrow=T);
    colnames(a12_global_values) <- c("age",1950:2080)

    a12_global_values[,1] <- c(66:105)

    RR_values <- matrix(c(0),
                        nrow=40,
                        ncol=2,
                        byrow=T);
    colnames(RR_values) <- c("age","rr_DvsND")

    RR_values[,1] <- c(66:105)

    etat <- matrix(c(0), # initial state (non diseased)
                   nrow=nb_people,
                   ncol=105-65+1,
                   byrow=T);

    colnames(etat) <- c(65:105);

    # RUN 1

    for (i in 1:nrow(etat)) {

      alea0 <- runif(1, 0, 1);

      if (alea0 <= data_prev_0_values[which(data_prev_0_values[,1]%in%(65) & data_prev_0_values[,3]%in%(gender)),2]) {

        etat[i,1] <- "00" # non diseased and non exposed

      } else {

        if (alea0 <= data_prev_0_values[which(data_prev_0_values[,1]%in%(65) & data_prev_0_values[,3]%in%(gender)),2]+data_prev_1_values[which(data_prev_1_values[,1]%in%(65) & data_prev_1_values[,3]%in%(gender)),2]) {

          etat[i,1] <- "01" # non diseased and exposed 1

        } else {

          if (alea0 <= data_prev_0_values[which(data_prev_0_values[,1]%in%(65) & data_prev_0_values[,3]%in%(gender)),2]+data_prev_1_values[which(data_prev_1_values[,1]%in%(65) & data_prev_1_values[,3]%in%(gender)),2]+data_prev_2_values[which(data_prev_2_values[,1]%in%(65) & data_prev_2_values[,3]%in%(gender)),2]) {

            etat[i,1] <- "02" # non diseased and exposed 2

          } else {

            if (alea0 <= data_prev_0_values[which(data_prev_0_values[,1]%in%(65) & data_prev_0_values[,3]%in%(gender)),2]+data_prev_1_values[which(data_prev_1_values[,1]%in%(65) & data_prev_1_values[,3]%in%(gender)),2]+data_prev_2_values[which(data_prev_2_values[,1]%in%(65) & data_prev_2_values[,3]%in%(gender)),2]+data_prev_3_values[which(data_prev_3_values[,1]%in%(65) & data_prev_3_values[,3]%in%(gender)),2]) {

              etat[i,1] <- "03" # non diseased and exposed 3

            } else {

              if (alea0 <= data_prev_0_values[which(data_prev_0_values[,1]%in%(65) & data_prev_0_values[,3]%in%(gender)),2]+data_prev_1_values[which(data_prev_1_values[,1]%in%(65) & data_prev_1_values[,3]%in%(gender)),2]+data_prev_2_values[which(data_prev_2_values[,1]%in%(65) & data_prev_2_values[,3]%in%(gender)),2]+data_prev_3_values[which(data_prev_3_values[,1]%in%(65) & data_prev_3_values[,3]%in%(gender)),2]+data_prev_4_values[which(data_prev_4_values[,1]%in%(65) & data_prev_4_values[,3]%in%(gender)),2]) {

                etat[i,1] <- "04" # non diseased and exposed 4

              } else {

                if (alea0 <= data_prev_0_values[which(data_prev_0_values[,1]%in%(65) & data_prev_0_values[,3]%in%(gender)),2]+data_prev_1_values[which(data_prev_1_values[,1]%in%(65) & data_prev_1_values[,3]%in%(gender)),2]+data_prev_2_values[which(data_prev_2_values[,1]%in%(65) & data_prev_2_values[,3]%in%(gender)),2]+data_prev_3_values[which(data_prev_3_values[,1]%in%(65) & data_prev_3_values[,3]%in%(gender)),2]+data_prev_4_values[which(data_prev_4_values[,1]%in%(65) & data_prev_4_values[,3]%in%(gender)),2]+data_prev_5_values[which(data_prev_5_values[,1]%in%(65) & data_prev_5_values[,3]%in%(gender)),2]) {

                  etat[i,1] <- "05" # non diseased and exposed 5

                } else {

                  if (alea0 <= data_prev_0_values[which(data_prev_0_values[,1]%in%(65) & data_prev_0_values[,3]%in%(gender)),2]+data_prev_1_values[which(data_prev_1_values[,1]%in%(65) & data_prev_1_values[,3]%in%(gender)),2]+data_prev_2_values[which(data_prev_2_values[,1]%in%(65) & data_prev_2_values[,3]%in%(gender)),2]+data_prev_3_values[which(data_prev_3_values[,1]%in%(65) & data_prev_3_values[,3]%in%(gender)),2]+data_prev_4_values[which(data_prev_4_values[,1]%in%(65) & data_prev_4_values[,3]%in%(gender)),2]+data_prev_5_values[which(data_prev_5_values[,1]%in%(65) & data_prev_5_values[,3]%in%(gender)),2]+data_prev_6_values[which(data_prev_6_values[,1]%in%(65) & data_prev_6_values[,3]%in%(gender)),2]) {

                    etat[i,1] <- "06" # non diseased and exposed 6

                  } else {

                    etat[i,1] <- "07" # non diseased and exposed 7

                  }

                }

              }

            }

          }

        }

      }

    };

    for (j in 2:ncol(etat)) { # for each people

      for (i in 1:nrow(etat)) { # for each age

        alea <- runif(1, 0, 1);

        alea0 <- runif(1, 0, 1);

        if (etat[i,j-1] == "00") {

          if (alea0 <= data_incid_0_values[which(data_incid_0_values[,1]%in%(j-1+65) & data_incid_0_values[,3]%in%(gender)),2]) {

            etat[i,j] <- "02"; # non diseased and exposed 2

          } else {

            etat[i,j] <- "00"; # non diseased and non exposed

          }

        } else {

          if (etat[i,j-1] == "01") {

            if (alea0 <= data_incid_1_values[which(data_incid_1_values[,1]%in%(j-1+65) & data_incid_1_values[,3]%in%(gender)),2]) {

              etat[i,j] <- "04"; # non diseased and exposed 4

            } else {

              etat[i,j] <- "01"; # non diseased and exposed 1

            }

          } else {

            if (etat[i,j-1] == "03") {

              if (alea0 <= data_incid_3_values[which(data_incid_3_values[,1]%in%(j-1+65) & data_incid_3_values[,3]%in%(gender)),2]) {

                etat[i,j] <- "06"; # non diseased and exposed 6

              } else {

                etat[i,j] <- "03"; # non diseased and exposed 3

              }

            } else {

              if (etat[i,j-1] == "05") {

                if (alea0 <= data_incid_5_values[which(data_incid_5_values[,1]%in%(j-1+65) & data_incid_5_values[,3]%in%(gender)),2]) {

                  etat[i,j] <- "07"; # non diseased and exposed 7

                } else {

                  etat[i,j] <- "05"; # non diseased and exposed 5

                }

              } else {

                if (etat[i,j-1] == "02") {

                  etat[i,j] <- "02"; # non diseased and exposed 2

                } else {

                  if (etat[i,j-1] == "04") {

                    etat[i,j] <- "04"; # non diseased and exposed 4

                  } else {

                    if (etat[i,j-1] == "06") {

                      etat[i,j] <- "06"; # non diseased and exposed 6

                    } else {

                      if (etat[i,j-1] == "07") {

                        etat[i,j] <- "07"; # non diseased and exposed 7

                      } else {

                        if (etat[i,j-1] == "10") {

                          if (alea0 <= data_incid_0_values[which(data_incid_0_values[,1]%in%(j-1+65) & data_incid_0_values[,3]%in%(gender)),2]) {

                            etat[i,j] <- "12"; # diseased and exposed 2

                          } else {

                            etat[i,j] <- "10"; # diseased and non exposed

                          }

                        } else {

                          if (etat[i,j-1] == "11") {

                            if (alea0 <= data_incid_1_values[which(data_incid_1_values[,1]%in%(j-1+65) & data_incid_1_values[,3]%in%(gender)),2]) {

                              etat[i,j] <- "14"; # diseased and exposed 4

                            } else {

                              etat[i,j] <- "11"; # diseased and exposed 1

                            }

                          } else {

                            if (etat[i,j-1] == "13") {

                              if (alea0 <= data_incid_3_values[which(data_incid_3_values[,1]%in%(j-1+65) & data_incid_3_values[,3]%in%(gender)),2]) {

                                etat[i,j] <- "16"; # diseased and exposed 6

                              } else {

                                etat[i,j] <- "13"; # diseased and exposed 3

                              }

                            } else {

                              if (etat[i,j-1] == "15") {

                                if (alea0 <= data_incid_5_values[which(data_incid_5_values[,1]%in%(j-1+65) & data_incid_5_values[,3]%in%(gender)),2]) {

                                  etat[i,j] <- "17"; # diseased and exposed 7

                                } else {

                                  etat[i,j] <- "15"; # diseased and exposed 5

                                }

                              } else {

                                if (etat[i,j-1] == "12") {

                                  etat[i,j] <- "12"; # diseased and exposed 2

                                } else {

                                  if (etat[i,j-1] == "14") {

                                    etat[i,j] <- "14"; # diseased and exposed 4

                                  } else {

                                    if (etat[i,j-1] == "16") {

                                      etat[i,j] <- "16"; # diseased and exposed 6

                                    } else {

                                      if (etat[i,j-1] == "17") {

                                        etat[i,j] <- "17"; # diseased and exposed 7

                                      } else {

                                        etat[i,j] <- etat[i,j-1]

                                      }

                                    }

                                  }

                                }

                              }

                            }

                          }

                        }

                      }

                    }

                  }

                }

              }

            }

          }

        }

      }

      if (sum(etat[,j]%in%("00"))!=0) {

        data_prev_0_values_ND[which(data_prev_0_values_ND[,1]%in%(j+64) & data_prev_0_values_ND[,3]%in%(gender)),2] <- sum(etat[,j]%in%("00"))/sum(etat[,j]%in%(c("00","01","02","03","04","05","06","07")))

      }

      if (sum(etat[,j]%in%("10"))!=0) {

        data_prev_0_values_D[which(data_prev_0_values_D[,1]%in%(j+64) & data_prev_0_values_D[,3]%in%(gender)),2] <- sum(etat[,j]%in%("10"))/sum(etat[,j]%in%(c("10","11","12","13","14","15","16","17")))

      }

      if (sum(etat[,j]%in%("01"))!=0) {

        data_prev_1_values_ND[which(data_prev_1_values_ND[,1]%in%(j+64) & data_prev_1_values_ND[,3]%in%(gender)),2] <- sum(etat[,j]%in%("01"))/sum(etat[,j]%in%(c("00","01","02","03","04","05","06","07")))

      }

      if (sum(etat[,j]%in%("11"))!=0) {

        data_prev_1_values_D[which(data_prev_1_values_D[,1]%in%(j+64) & data_prev_1_values_D[,3]%in%(gender)),2] <- sum(etat[,j]%in%("11"))/sum(etat[,j]%in%(c("10","11","12","13","14","15","16","17")))

      }

      if (sum(etat[,j]%in%("02"))!=0) {

        data_prev_2_values_ND[which(data_prev_2_values_ND[,1]%in%(j+64) & data_prev_2_values_ND[,3]%in%(gender)),2] <- sum(etat[,j]%in%("02"))/sum(etat[,j]%in%(c("00","01","02","03","04","05","06","07")))

      }

      if (sum(etat[,j]%in%("12"))!=0) {

        data_prev_2_values_D[which(data_prev_2_values_D[,1]%in%(j+64) & data_prev_2_values_D[,3]%in%(gender)),2] <- sum(etat[,j]%in%("12"))/sum(etat[,j]%in%(c("10","11","12","13","14","15","16","17")))

      }

      if (sum(etat[,j]%in%("03"))!=0) {

        data_prev_3_values_ND[which(data_prev_3_values_ND[,1]%in%(j+64) & data_prev_3_values_ND[,3]%in%(gender)),2] <- sum(etat[,j]%in%("03"))/sum(etat[,j]%in%(c("00","01","02","03","04","05","06","07")))

      }

      if (sum(etat[,j]%in%("13"))!=0) {

        data_prev_3_values_D[which(data_prev_3_values_D[,1]%in%(j+64) & data_prev_3_values_D[,3]%in%(gender)),2] <- sum(etat[,j]%in%("13"))/sum(etat[,j]%in%(c("10","11","12","13","14","15","16","17")))

      }

      if (sum(etat[,j]%in%("04"))!=0) {

        data_prev_4_values_ND[which(data_prev_4_values_ND[,1]%in%(j+64) & data_prev_4_values_ND[,3]%in%(gender)),2] <- sum(etat[,j]%in%("04"))/sum(etat[,j]%in%(c("00","01","02","03","04","05","06","07")))

      }

      if (sum(etat[,j]%in%("14"))!=0) {

        data_prev_4_values_D[which(data_prev_4_values_D[,1]%in%(j+64) & data_prev_4_values_D[,3]%in%(gender)),2] <- sum(etat[,j]%in%("14"))/sum(etat[,j]%in%(c("10","11","12","13","14","15","16","17")))

      }

      if (sum(etat[,j]%in%("05"))!=0) {

        data_prev_5_values_ND[which(data_prev_5_values_ND[,1]%in%(j+64) & data_prev_5_values_ND[,3]%in%(gender)),2] <- sum(etat[,j]%in%("05"))/sum(etat[,j]%in%(c("00","01","02","03","04","05","06","07")))

      }

      if (sum(etat[,j]%in%("15"))!=0) {

        data_prev_5_values_D[which(data_prev_5_values_D[,1]%in%(j+64) & data_prev_5_values_D[,3]%in%(gender)),2] <- sum(etat[,j]%in%("15"))/sum(etat[,j]%in%(c("10","11","12","13","14","15","16","17")))

      }

      if (sum(etat[,j]%in%("06"))!=0) {

        data_prev_6_values_ND[which(data_prev_6_values_ND[,1]%in%(j+64) & data_prev_6_values_ND[,3]%in%(gender)),2] <- sum(etat[,j]%in%("06"))/sum(etat[,j]%in%(c("00","01","02","03","04","05","06","07")))

      }

      if (sum(etat[,j]%in%("16"))!=0) {

        data_prev_6_values_D[which(data_prev_6_values_D[,1]%in%(j+64) & data_prev_6_values_D[,3]%in%(gender)),2] <- sum(etat[,j]%in%("16"))/sum(etat[,j]%in%(c("10","11","12","13","14","15","16","17")))

      }

      if (sum(etat[,j]%in%("07"))!=0) {

        data_prev_7_values_ND[which(data_prev_7_values_ND[,1]%in%(j+64) & data_prev_7_values_ND[,3]%in%(gender)),2] <- sum(etat[,j]%in%("07"))/sum(etat[,j]%in%(c("00","01","02","03","04","05","06","07")))

      }

      if (sum(etat[,j]%in%("17"))!=0) {

        data_prev_7_values_D[which(data_prev_7_values_D[,1]%in%(j+64) & data_prev_7_values_D[,3]%in%(gender)),2] <- sum(etat[,j]%in%("17"))/sum(etat[,j]%in%(c("10","11","12","13","14","15","16","17")))

      }

      ### Incidence of disease on non exposed peoples

      for (a in 2:ncol(a010_values)){

        a010_values[,a] <- as.numeric(data_a01_values[which(data_a01_values[,1] != 65 & data_a01_values[,2]%in%(gender)),a+1]) / (data_prev_0_values_ND[which(data_prev_0_values_ND[,1] != 65 & data_prev_0_values_ND[,3]%in%(gender)),2] + data_theta01_1_values[which(data_theta01_1_values[,1] != 65 & data_theta01_1_values[,3]%in%(gender)),2]*data_prev_1_values_ND[which(data_prev_1_values_ND[,1] != 65 & data_prev_1_values_ND[,3]%in%(gender)),2] + data_theta01_2_values[which(data_theta01_2_values[,1] != 65 & data_theta01_2_values[,3]%in%(gender)),2]*data_prev_2_values_ND[which(data_prev_2_values_ND[,1] != 65 & data_prev_2_values_ND[,3]%in%(gender)),2] + data_theta01_3_values[which(data_theta01_3_values[,1] != 65 & data_theta01_3_values[,3]%in%(gender)),2]*data_prev_3_values_ND[which(data_prev_3_values_ND[,1] != 65 & data_prev_3_values_ND[,3]%in%(gender)),2] + data_theta01_1_values[which(data_theta01_1_values[,1] != 65 & data_theta01_1_values[,3]%in%(gender)),2]*data_theta01_2_values[which(data_theta01_2_values[,1] != 65 & data_theta01_2_values[,3]%in%(gender)),2]*data_prev_4_values_ND[which(data_prev_4_values_ND[,1] != 65 & data_prev_4_values_ND[,3]%in%(gender)),2] + data_theta01_1_values[which(data_theta01_1_values[,1] != 65 & data_theta01_1_values[,3]%in%(gender)),2]*data_theta01_3_values[which(data_theta01_3_values[,1] != 65 & data_theta01_3_values[,3]%in%(gender)),2]*data_prev_5_values_ND[which(data_prev_5_values_ND[,1] != 65 & data_prev_5_values_ND[,3]%in%(gender)),2] + data_theta01_2_values[which(data_theta01_2_values[,1] != 65 & data_theta01_2_values[,3]%in%(gender)),2]*data_theta01_3_values[which(data_theta01_3_values[,1] != 65 & data_theta01_3_values[,3]%in%(gender)),2]*data_prev_6_values_ND[which(data_prev_6_values_ND[,1] != 65 & data_prev_6_values_ND[,3]%in%(gender)),2] + data_theta01_1_values[which(data_theta01_1_values[,1] != 65 & data_theta01_1_values[,3]%in%(gender)),2]*data_theta01_2_values[which(data_theta01_2_values[,1] != 65 & data_theta01_2_values[,3]%in%(gender)),2]*data_theta01_3_values[which(data_theta01_3_values[,1] != 65 & data_theta01_3_values[,3]%in%(gender)),2]*data_prev_7_values_ND[which(data_prev_7_values_ND[,1] != 65 & data_prev_7_values_ND[,3]%in%(gender)),2]);

      }

      ### Incidence of disease on exposed peoples

      a011_values[,-1] <- a010_values[,-1]*data_theta01_1_values[which(data_theta01_1_values[,1] != 65 & data_theta01_1_values[,3]%in%(gender)),2];

      a012_values[,-1] <- a010_values[,-1]*data_theta01_2_values[which(data_theta01_2_values[,1] != 65 & data_theta01_2_values[,3]%in%(gender)),2];

      a013_values[,-1] <- a010_values[,-1]*data_theta01_3_values[which(data_theta01_3_values[,1] != 65 & data_theta01_3_values[,3]%in%(gender)),2];

      a014_values[,-1] <- a010_values[,-1]*data_theta01_1_values[which(data_theta01_1_values[,1] != 65 & data_theta01_1_values[,3]%in%(gender)),2]*data_theta01_2_values[which(data_theta01_2_values[,1] != 65 & data_theta01_2_values[,3]%in%(gender)),2];

      a015_values[,-1] <- a010_values[,-1]*data_theta01_1_values[which(data_theta01_1_values[,1] != 65 & data_theta01_1_values[,3]%in%(gender)),2]*data_theta01_3_values[which(data_theta01_3_values[,1] != 65 & data_theta01_3_values[,3]%in%(gender)),2];

      a016_values[,-1] <- a010_values[,-1]*data_theta01_2_values[which(data_theta01_2_values[,1] != 65 & data_theta01_2_values[,3]%in%(gender)),2]*data_theta01_3_values[which(data_theta01_3_values[,1] != 65 & data_theta01_3_values[,3]%in%(gender)),2];

      a017_values[,-1] <- a010_values[,-1]*data_theta01_1_values[which(data_theta01_1_values[,1] != 65 & data_theta01_1_values[,3]%in%(gender)),2]*data_theta01_2_values[which(data_theta01_2_values[,1] != 65 & data_theta01_2_values[,3]%in%(gender)),2]*data_theta01_3_values[which(data_theta01_3_values[,1] != 65 & data_theta01_3_values[,3]%in%(gender)),2];

      ### Global incidence of disease

      a01_global_values[,-1] <- data_prev_0_values_ND[which(data_prev_0_values_ND[,1] != 65 & data_prev_0_values_ND[,3]%in%(gender)),2]*a010_values[,-1] + data_prev_1_values_ND[which(data_prev_1_values_ND[,1] != 65 & data_prev_1_values_ND[,3]%in%(gender)),2]*a010_values[,-1]*data_theta01_1_values[which(data_theta01_1_values[,1] != 65 & data_theta01_1_values[,3]%in%(gender)),2] + data_prev_2_values_ND[which(data_prev_2_values_ND[,1] != 65 & data_prev_2_values_ND[,3]%in%(gender)),2]*a010_values[,-1]*data_theta01_2_values[which(data_theta01_2_values[,1] != 65 & data_theta01_2_values[,3]%in%(gender)),2] + data_prev_3_values_ND[which(data_prev_3_values_ND[,1] != 65 & data_prev_3_values_ND[,3]%in%(gender)),2]*a010_values[,-1]*data_theta01_3_values[which(data_theta01_3_values[,1] != 65 & data_theta01_3_values[,3]%in%(gender)),2] + data_prev_4_values_ND[which(data_prev_4_values_ND[,1] != 65 & data_prev_4_values_ND[,3]%in%(gender)),2]*a010_values[,-1]*data_theta01_1_values[which(data_theta01_1_values[,1] != 65 & data_theta01_1_values[,3]%in%(gender)),2]*data_theta01_2_values[which(data_theta01_2_values[,1] != 65 & data_theta01_2_values[,3]%in%(gender)),2] + data_prev_5_values_ND[which(data_prev_5_values_ND[,1] != 65 & data_prev_5_values_ND[,3]%in%(gender)),2]*a010_values[,-1]*data_theta01_1_values[which(data_theta01_1_values[,1] != 65 & data_theta01_1_values[,3]%in%(gender)),2]*data_theta01_3_values[which(data_theta01_3_values[,1] != 65 & data_theta01_3_values[,3]%in%(gender)),2] + data_prev_6_values_ND[which(data_prev_6_values_ND[,1] != 65 & data_prev_6_values_ND[,3]%in%(gender)),2]*a010_values[,-1]*data_theta01_2_values[which(data_theta01_2_values[,1] != 65 & data_theta01_2_values[,3]%in%(gender)),2]*data_theta01_3_values[which(data_theta01_3_values[,1] != 65 & data_theta01_3_values[,3]%in%(gender)),2] + data_prev_7_values_ND[which(data_prev_7_values_ND[,1] != 65 & data_prev_7_values_ND[,3]%in%(gender)),2]*a010_values[,-1]*data_theta01_1_values[which(data_theta01_1_values[,1] != 65 & data_theta01_1_values[,3]%in%(gender)),2]*data_theta01_2_values[which(data_theta01_2_values[,1] != 65 & data_theta01_2_values[,3]%in%(gender)),2]*data_theta01_3_values[which(data_theta01_3_values[,1] != 65 & data_theta01_3_values[,3]%in%(gender)),2];

      ### Mortality of healthy subjects on non exposed peoples

      for (a in 2:ncol(a020_values)){

        a020_values[,a] <- as.numeric(data_a02_values[which(data_a02_values[,1] != 65 & data_a02_values[,2]%in%(gender)),a+1]) / (data_prev_0_values_ND[which(data_prev_0_values_ND[,1] != 65 & data_prev_0_values_ND[,3]%in%(gender)),2] + data_theta02_1_values[which(data_theta02_1_values[,1] != 65 & data_theta02_1_values[,3]%in%(gender)),2]*data_prev_1_values_ND[which(data_prev_1_values_ND[,1] != 65 & data_prev_1_values_ND[,3]%in%(gender)),2] + data_theta02_2_values[which(data_theta02_2_values[,1] != 65 & data_theta02_2_values[,3]%in%(gender)),2]*data_prev_2_values_ND[which(data_prev_2_values_ND[,1] != 65 & data_prev_2_values_ND[,3]%in%(gender)),2] + data_theta02_3_values[which(data_theta02_3_values[,1] != 65 & data_theta02_3_values[,3]%in%(gender)),2]*data_prev_3_values_ND[which(data_prev_3_values_ND[,1] != 65 & data_prev_3_values_ND[,3]%in%(gender)),2] + data_theta02_1_values[which(data_theta02_1_values[,1] != 65 & data_theta02_1_values[,3]%in%(gender)),2]*data_theta02_2_values[which(data_theta02_2_values[,1] != 65 & data_theta02_2_values[,3]%in%(gender)),2]*data_prev_4_values_ND[which(data_prev_4_values_ND[,1] != 65 & data_prev_4_values_ND[,3]%in%(gender)),2] + data_theta02_1_values[which(data_theta02_1_values[,1] != 65 & data_theta02_1_values[,3]%in%(gender)),2]*data_theta02_3_values[which(data_theta02_3_values[,1] != 65 & data_theta02_3_values[,3]%in%(gender)),2]*data_prev_5_values_ND[which(data_prev_5_values_ND[,1] != 65 & data_prev_5_values_ND[,3]%in%(gender)),2] + data_theta02_2_values[which(data_theta02_2_values[,1] != 65 & data_theta02_2_values[,3]%in%(gender)),2]*data_theta02_3_values[which(data_theta02_3_values[,1] != 65 & data_theta02_3_values[,3]%in%(gender)),2]*data_prev_6_values_ND[which(data_prev_6_values_ND[,1] != 65 & data_prev_6_values_ND[,3]%in%(gender)),2] + data_theta02_1_values[which(data_theta02_1_values[,1] != 65 & data_theta02_1_values[,3]%in%(gender)),2]*data_theta02_2_values[which(data_theta02_2_values[,1] != 65 & data_theta02_2_values[,3]%in%(gender)),2]*data_theta02_3_values[which(data_theta02_3_values[,1] != 65 & data_theta02_3_values[,3]%in%(gender)),2]*data_prev_7_values_ND[which(data_prev_7_values_ND[,1] != 65 & data_prev_7_values_ND[,3]%in%(gender)),2]);

      }

      ### Mortality of healthy subjects on exposed peoples

      a021_values[,-1] <- a020_values[,-1]*data_theta02_1_values[which(data_theta02_1_values[,1] != 65 & data_theta02_1_values[,3]%in%(gender)),2];

      a022_values[,-1] <- a020_values[,-1]*data_theta02_2_values[which(data_theta02_2_values[,1] != 65 & data_theta02_2_values[,3]%in%(gender)),2];

      a023_values[,-1] <- a020_values[,-1]*data_theta02_3_values[which(data_theta02_3_values[,1] != 65 & data_theta02_3_values[,3]%in%(gender)),2];

      a024_values[,-1] <- a020_values[,-1]*data_theta02_1_values[which(data_theta02_1_values[,1] != 65 & data_theta02_1_values[,3]%in%(gender)),2]*data_theta02_2_values[which(data_theta02_2_values[,1] != 65 & data_theta02_2_values[,3]%in%(gender)),2];

      a025_values[,-1] <- a020_values[,-1]*data_theta02_1_values[which(data_theta02_1_values[,1] != 65 & data_theta02_1_values[,3]%in%(gender)),2]*data_theta02_3_values[which(data_theta02_3_values[,1] != 65 & data_theta02_3_values[,3]%in%(gender)),2];

      a026_values[,-1] <- a020_values[,-1]*data_theta02_2_values[which(data_theta02_2_values[,1] != 65 & data_theta02_2_values[,3]%in%(gender)),2]*data_theta02_3_values[which(data_theta02_3_values[,1] != 65 & data_theta02_3_values[,3]%in%(gender)),2];

      a027_values[,-1] <- a020_values[,-1]*data_theta02_1_values[which(data_theta02_1_values[,1] != 65 & data_theta02_1_values[,3]%in%(gender)),2]*data_theta02_2_values[which(data_theta02_2_values[,1] != 65 & data_theta02_2_values[,3]%in%(gender)),2]*data_theta02_3_values[which(data_theta02_3_values[,1] != 65 & data_theta02_3_values[,3]%in%(gender)),2];

      ### Global mortality of healthy subjects

      a02_global_values[,-1] <- data_prev_0_values_ND[which(data_prev_0_values_ND[,1] != 65 & data_prev_0_values_ND[,3]%in%(gender)),2]*a020_values[,-1] + data_prev_1_values_ND[which(data_prev_1_values_ND[,1] != 65 & data_prev_1_values_ND[,3]%in%(gender)),2]*a020_values[,-1]*data_theta02_1_values[which(data_theta02_1_values[,1] != 65 & data_theta02_1_values[,3]%in%(gender)),2] + data_prev_2_values_ND[which(data_prev_2_values_ND[,1] != 65 & data_prev_2_values_ND[,3]%in%(gender)),2]*a020_values[,-1]*data_theta02_2_values[which(data_theta02_2_values[,1] != 65 & data_theta02_2_values[,3]%in%(gender)),2] + data_prev_3_values_ND[which(data_prev_3_values_ND[,1] != 65 & data_prev_3_values_ND[,3]%in%(gender)),2]*a020_values[,-1]*data_theta02_3_values[which(data_theta02_3_values[,1] != 65 & data_theta02_3_values[,3]%in%(gender)),2] + data_prev_4_values_ND[which(data_prev_4_values_ND[,1] != 65 & data_prev_4_values_ND[,3]%in%(gender)),2]*a020_values[,-1]*data_theta02_1_values[which(data_theta02_1_values[,1] != 65 & data_theta02_1_values[,3]%in%(gender)),2]*data_theta02_2_values[which(data_theta02_2_values[,1] != 65 & data_theta02_2_values[,3]%in%(gender)),2] + data_prev_5_values_ND[which(data_prev_5_values_ND[,1] != 65 & data_prev_5_values_ND[,3]%in%(gender)),2]*a020_values[,-1]*data_theta02_1_values[which(data_theta02_1_values[,1] != 65 & data_theta02_1_values[,3]%in%(gender)),2]*data_theta02_3_values[which(data_theta02_3_values[,1] != 65 & data_theta02_3_values[,3]%in%(gender)),2] + data_prev_6_values_ND[which(data_prev_6_values_ND[,1] != 65 & data_prev_6_values_ND[,3]%in%(gender)),2]*a020_values[,-1]*data_theta02_2_values[which(data_theta02_2_values[,1] != 65 & data_theta02_2_values[,3]%in%(gender)),2]*data_theta02_3_values[which(data_theta02_3_values[,1] != 65 & data_theta02_3_values[,3]%in%(gender)),2] + data_prev_7_values_ND[which(data_prev_7_values_ND[,1] != 65 & data_prev_7_values_ND[,3]%in%(gender)),2]*a020_values[,-1]*data_theta02_1_values[which(data_theta02_1_values[,1] != 65 & data_theta02_1_values[,3]%in%(gender)),2]*data_theta02_2_values[which(data_theta02_2_values[,1] != 65 & data_theta02_2_values[,3]%in%(gender)),2]*data_theta02_3_values[which(data_theta02_3_values[,1] != 65 & data_theta02_3_values[,3]%in%(gender)),2];

      ### Relative risks associated with the disease for mortality

      RR_values[,2] <- data_rr_DvsND_values[which(data_rr_DvsND_values[,1] != 65 & data_rr_DvsND_values[,3]%in%(gender)),2];

      ### Mortality of diseased subjects on non exposed peoples

      for (a in 2:ncol(a120_values)){

        a120_values[,a] <- as.numeric(RR_values[,2])*as.numeric(data_a02_values[which(data_a02_values[,1] != 65 & data_a02_values[,2]%in%(gender)),a+1]) / (data_prev_0_values_D[which(data_prev_0_values_D[,1] != 65 & data_prev_0_values_D[,3]%in%(gender)),2] + data_theta12_1_values[which(data_theta12_1_values[,1] != 65 & data_theta12_1_values[,3]%in%(gender)),2]*data_prev_1_values_D[which(data_prev_1_values_D[,1] != 65 & data_prev_1_values_D[,3]%in%(gender)),2] + data_theta12_2_values[which(data_theta12_2_values[,1] != 65 & data_theta12_2_values[,3]%in%(gender)),2]*data_prev_2_values_D[which(data_prev_2_values_D[,1] != 65 & data_prev_2_values_D[,3]%in%(gender)),2] + data_theta12_3_values[which(data_theta12_3_values[,1] != 65 & data_theta12_3_values[,3]%in%(gender)),2]*data_prev_3_values_D[which(data_prev_3_values_D[,1] != 65 & data_prev_3_values_D[,3]%in%(gender)),2] + data_theta12_1_values[which(data_theta12_1_values[,1] != 65 & data_theta12_1_values[,3]%in%(gender)),2]*data_theta12_2_values[which(data_theta12_2_values[,1] != 65 & data_theta12_2_values[,3]%in%(gender)),2]*data_prev_4_values_D[which(data_prev_4_values_D[,1] != 65 & data_prev_4_values_D[,3]%in%(gender)),2] + data_theta12_1_values[which(data_theta12_1_values[,1] != 65 & data_theta12_1_values[,3]%in%(gender)),2]*data_theta12_3_values[which(data_theta12_3_values[,1] != 65 & data_theta12_3_values[,3]%in%(gender)),2]*data_prev_5_values_D[which(data_prev_5_values_D[,1] != 65 & data_prev_5_values_D[,3]%in%(gender)),2] + data_theta12_2_values[which(data_theta12_2_values[,1] != 65 & data_theta12_2_values[,3]%in%(gender)),2]*data_theta12_3_values[which(data_theta12_3_values[,1] != 65 & data_theta12_3_values[,3]%in%(gender)),2]*data_prev_6_values_D[which(data_prev_6_values_D[,1] != 65 & data_prev_6_values_D[,3]%in%(gender)),2] + data_theta12_1_values[which(data_theta12_1_values[,1] != 65 & data_theta12_1_values[,3]%in%(gender)),2]*data_theta12_2_values[which(data_theta12_2_values[,1] != 65 & data_theta12_2_values[,3]%in%(gender)),2]*data_theta12_3_values[which(data_theta12_3_values[,1] != 65 & data_theta12_3_values[,3]%in%(gender)),2]*data_prev_7_values_D[which(data_prev_7_values_D[,1] != 65 & data_prev_7_values_D[,3]%in%(gender)),2]);

      }

      ### Mortality of diseased subjects on exposed peoples

      a121_values[,-1] <- a120_values[,-1]*data_theta12_1_values[which(data_theta12_1_values[,1] != 65 & data_theta12_1_values[,3]%in%(gender)),2];

      a122_values[,-1] <- a120_values[,-1]*data_theta12_2_values[which(data_theta12_2_values[,1] != 65 & data_theta12_2_values[,3]%in%(gender)),2];

      a123_values[,-1] <- a120_values[,-1]*data_theta12_3_values[which(data_theta12_3_values[,1] != 65 & data_theta12_3_values[,3]%in%(gender)),2];

      a124_values[,-1] <- a120_values[,-1]*data_theta12_1_values[which(data_theta12_1_values[,1] != 65 & data_theta12_1_values[,3]%in%(gender)),2]*data_theta12_2_values[which(data_theta12_2_values[,1] != 65 & data_theta12_2_values[,3]%in%(gender)),2];

      a125_values[,-1] <- a120_values[,-1]*data_theta12_1_values[which(data_theta12_1_values[,1] != 65 & data_theta12_1_values[,3]%in%(gender)),2]*data_theta12_3_values[which(data_theta12_3_values[,1] != 65 & data_theta12_3_values[,3]%in%(gender)),2];

      a126_values[,-1] <- a120_values[,-1]*data_theta12_2_values[which(data_theta12_2_values[,1] != 65 & data_theta12_2_values[,3]%in%(gender)),2]*data_theta12_3_values[which(data_theta12_3_values[,1] != 65 & data_theta12_3_values[,3]%in%(gender)),2];

      a127_values[,-1] <- a120_values[,-1]*data_theta12_1_values[which(data_theta12_1_values[,1] != 65 & data_theta12_1_values[,3]%in%(gender)),2]*data_theta12_2_values[which(data_theta12_2_values[,1] != 65 & data_theta12_2_values[,3]%in%(gender)),2]*data_theta12_3_values[which(data_theta12_3_values[,1] != 65 & data_theta12_3_values[,3]%in%(gender)),2];

      ### Global mortality of diseased subjects

      a12_global_values[,-1] <- data_prev_0_values_D[which(data_prev_0_values_D[,1] != 65 & data_prev_0_values_D[,3]%in%(gender)),2]*a120_values[,-1] + data_prev_1_values_D[which(data_prev_1_values_D[,1] != 65 & data_prev_1_values_D[,3]%in%(gender)),2]*a120_values[,-1]*data_theta12_1_values[which(data_theta12_1_values[,1] != 65 & data_theta12_1_values[,3]%in%(gender)),2] + data_prev_2_values_D[which(data_prev_2_values_D[,1] != 65 & data_prev_2_values_D[,3]%in%(gender)),2]*a120_values[,-1]*data_theta12_2_values[which(data_theta12_2_values[,1] != 65 & data_theta12_2_values[,3]%in%(gender)),2] + data_prev_3_values_D[which(data_prev_3_values_D[,1] != 65 & data_prev_3_values_D[,3]%in%(gender)),2]*a120_values[,-1]*data_theta12_3_values[which(data_theta12_3_values[,1] != 65 & data_theta12_3_values[,3]%in%(gender)),2] + data_prev_4_values_D[which(data_prev_4_values_D[,1] != 65 & data_prev_4_values_D[,3]%in%(gender)),2]*a120_values[,-1]*data_theta12_1_values[which(data_theta12_1_values[,1] != 65 & data_theta12_1_values[,3]%in%(gender)),2]*data_theta12_2_values[which(data_theta12_2_values[,1] != 65 & data_theta12_2_values[,3]%in%(gender)),2] + data_prev_5_values_D[which(data_prev_5_values_D[,1] != 65 & data_prev_5_values_D[,3]%in%(gender)),2]*a120_values[,-1]*data_theta12_1_values[which(data_theta12_1_values[,1] != 65 & data_theta12_1_values[,3]%in%(gender)),2]*data_theta12_3_values[which(data_theta12_3_values[,1] != 65 & data_theta12_3_values[,3]%in%(gender)),2] + data_prev_6_values_D[which(data_prev_6_values_D[,1] != 65 & data_prev_6_values_D[,3]%in%(gender)),2]*a120_values[,-1]*data_theta12_2_values[which(data_theta12_2_values[,1] != 65 & data_theta12_2_values[,3]%in%(gender)),2]*data_theta12_3_values[which(data_theta12_3_values[,1] != 65 & data_theta12_3_values[,3]%in%(gender)),2] + data_prev_7_values_D[which(data_prev_7_values_D[,1] != 65 & data_prev_7_values_D[,3]%in%(gender)),2]*a120_values[,-1]*data_theta12_1_values[which(data_theta12_1_values[,1] != 65 & data_theta12_1_values[,3]%in%(gender)),2]*data_theta12_2_values[which(data_theta12_2_values[,1] != 65 & data_theta12_2_values[,3]%in%(gender)),2]*data_theta12_3_values[which(data_theta12_3_values[,1] != 65 & data_theta12_3_values[,3]%in%(gender)),2];

      for (i in 1:nrow(etat)) { # for each age

        alea <- runif(1, 0, 1);

        alea0 <- runif(1, 0, 1);

        if (etat[i,j] == "00") {

          a01 <- a010_values;
          a02 <- a020_values;

          if (alea <= a02[j-1,j+(an0-1950)+1]) {

            etat[i,j] <- "20"; # dead (with non exposed state)

          } else {

            if (alea <= a01[j-1,j+(an0-1950)+1] + a02[j-1,j+(an0-1950)+1]) {

              etat[i,j] <- "10"; # diseased and non exposed

            } else {

              etat[i,j] <- "00"; # non diseased and non exposed

            }

          }

        } else {

          if (etat[i,j] == "01") {

            a01 <- a011_values;
            a02 <- a021_values;

            if (alea <= a02[j-1,j+(an0-1950)+1]) {

              etat[i,j] <- "21"; # dead (with exposed state 1)

            } else {

              if (alea <= a01[j-1,j+(an0-1950)+1] + a02[j-1,j+(an0-1950)+1]) {

                etat[i,j] <- "11"; # diseased and exposed 1

              } else {

                etat[i,j] <- "01"; # non diseased and exposed 1

              }

            }

          } else {

            if (etat[i,j] == "02") {

              a01 <- a012_values;
              a02 <- a022_values;

              if (alea <= a02[j-1,j+(an0-1950)+1]) {

                etat[i,j] <- "22"; # dead (with exposed state 2)

              } else {

                if (alea <= a01[j-1,j+(an0-1950)+1] + a02[j-1,j+(an0-1950)+1]) {

                  etat[i,j] <- "12"; # diseased and exposed 2

                } else {

                  etat[i,j] <- "02"; # non diseased and exposed 2

                }

              }

            } else {

              if (etat[i,j] == "03") {

                a01 <- a013_values;
                a02 <- a023_values;

                if (alea <= a02[j-1,j+(an0-1950)+1]) {

                  etat[i,j] <- "23"; # dead (with exposed state 3)

                } else {

                  if (alea <= a01[j-1,j+(an0-1950)+1] + a02[j-1,j+(an0-1950)+1]) {

                    etat[i,j] <- "13"; # diseased and exposed 3

                  } else {

                    etat[i,j] <- "03"; # non diseased and exposed 3

                  }

                }

              } else {

                if (etat[i,j] == "04") {

                  a01 <- a014_values;
                  a02 <- a024_values;

                  if (alea <= a02[j-1,j+(an0-1950)+1]) {

                    etat[i,j] <- "24"; # dead (with exposed state 4)

                  } else {

                    if (alea <= a01[j-1,j+(an0-1950)+1] + a02[j-1,j+(an0-1950)+1]) {

                      etat[i,j] <- "14"; # diseased and exposed 4

                    } else {

                      etat[i,j] <- "04"; # non diseased and exposed 4

                    }

                  };

                } else {

                  if (etat[i,j] == "05") {

                    a01 <- a015_values;
                    a02 <- a025_values;

                    if (alea <= a02[j-1,j+(an0-1950)+1]) {

                      etat[i,j] <- "25"; # dead (with exposed state 5)

                    } else {

                      if (alea <= a01[j-1,j+(an0-1950)+1] + a02[j-1,j+(an0-1950)+1]) {

                        etat[i,j] <- "15"; # diseased and exposed 5

                      } else {

                        etat[i,j] <- "05"; # non diseased and exposed 5

                      }

                    }

                  } else {

                    if (etat[i,j] == "06") {

                      a01 <- a016_values;
                      a02 <- a026_values;

                      if (alea <= a02[j-1,j+(an0-1950)+1]) {

                        etat[i,j] <- "26"; # dead (with exposed state 6)

                      } else {

                        if (alea <= a01[j-1,j+(an0-1950)+1] + a02[j-1,j+(an0-1950)+1]) {

                          etat[i,j] <- "16"; # diseased and exposed 6

                        } else {

                          etat[i,j] <- "06"; # non diseased and exposed 6

                        }

                      };

                    } else {

                      if (etat[i,j] == "07") {

                        a01 <- a017_values;
                        a02 <- a027_values;

                        if (alea <= a02[j-1,j+(an0-1950)+1]) {

                          etat[i,j] <- "27"; # dead (with exposed state 7)

                        } else {

                          if (alea <= a01[j-1,j+(an0-1950)+1] + a02[j-1,j+(an0-1950)+1]) {

                            etat[i,j] <- "17"; # diseased and exposed 7

                          } else {

                            etat[i,j] <- "07"; # non diseased and exposed 7

                          }

                        };

                      } else {

                        if (etat[i,j] == "10") {

                          a12 <- a120_values;

                          if (alea <= a12[j-1,j+(an0-1950)+1]) {

                            etat[i,j] <- "20";

                          } else {

                            etat[i,j] <- "10";

                          }

                        } else {

                          if (etat[i,j] == "11") {

                            a12 <- a121_values;

                            if (alea <= a12[j-1,j+(an0-1950)+1]) {

                              etat[i,j] <- "21";

                            } else {

                              etat[i,j] <- "11";

                            }

                          } else {

                            if (etat[i,j] == "12") {

                              a12 <- a122_values;

                              if (alea <= a12[j-1,j+(an0-1950)+1]) {

                                etat[i,j] <- "22";

                              } else {

                                etat[i,j] <- "12";

                              }

                            } else {

                              if (etat[i,j] == "13") {

                                a12 <- a123_values;

                                if (alea <= a12[j-1,j+(an0-1950)+1]) {

                                  etat[i,j] <- "23";

                                } else {

                                  etat[i,j] <- "13";

                                }

                              } else {

                                if (etat[i,j] == "14") {

                                  a12 <- a124_values;

                                  if (alea <= a12[j-1,j+(an0-1950)+1]) {

                                    etat[i,j] <- "24";

                                  } else {

                                    etat[i,j] <- "14";

                                  }

                                } else {

                                  if (etat[i,j] == "15") {

                                    a12 <- a125_values;

                                    if (alea <= a12[j-1,j+(an0-1950)+1]) {

                                      etat[i,j] <- "25";

                                    } else {

                                      etat[i,j] <- "15";

                                    }

                                  } else {

                                    if (etat[i,j] == "16") {

                                      a12 <- a126_values;

                                      if (alea <= a12[j-1,j+(an0-1950)+1]) {

                                        etat[i,j] <- "26";

                                      } else {

                                        etat[i,j] <- "16";

                                      }

                                    } else {

                                      if (etat[i,j] == "17") {

                                        a12 <- a127_values;

                                        if (alea <= a12[j-1,j+(an0-1950)+1]) {

                                          etat[i,j] <- "27";

                                        } else {

                                          etat[i,j] <- "17";

                                        }

                                      } else {

                                        etat[i,j] <- etat[i,j]

                                      }

                                    }

                                  }

                                }

                              }

                            }

                          }

                        }

                      }

                    }

                  }

                }

              }

            }

          }

        }

      }

    }

    # RUN 2

    for (i in 1:nrow(etat)) {

      if (intervention==1) {

        if (annee < year_intervention) {

          intervention_prev_0_values <- data_prev_0_values
          intervention_prev_1_values <- data_prev_1_values
          intervention_prev_2_values <- data_prev_2_values
          intervention_prev_3_values <- data_prev_3_values
          intervention_prev_4_values <- data_prev_4_values
          intervention_prev_5_values <- data_prev_5_values
          intervention_prev_6_values <- data_prev_6_values
          intervention_prev_7_values <- data_prev_7_values

        } else {

          intervention_prev_0_values <- data_prev_0_values
          intervention_prev_0_values[,2] <- 1

          intervention_prev_1_values <- data_prev_1_values
          intervention_prev_1_values[,2] <- 0

          intervention_prev_2_values <- data_prev_2_values
          intervention_prev_2_values[,2] <- 0

          intervention_prev_3_values <- data_prev_3_values
          intervention_prev_3_values[,2] <- 0

          intervention_prev_4_values <- data_prev_4_values
          intervention_prev_4_values[,2] <- 0

          intervention_prev_5_values <- data_prev_5_values
          intervention_prev_5_values[,2] <- 0

          intervention_prev_6_values <- data_prev_6_values
          intervention_prev_6_values[,2] <- 0

          intervention_prev_7_values <- data_prev_7_values
          intervention_prev_7_values[,2] <- 0

        }

      }

      alea0 <- runif(1, 0, 1);

      if (alea0 <= intervention_prev_0_values[which(intervention_prev_0_values[,1]%in%(65) & intervention_prev_0_values[,3]%in%(gender)),2]) {

        etat[i,1] <- "00" # non diseased and non exposed

      } else {

        if (alea0 <= intervention_prev_0_values[which(intervention_prev_0_values[,1]%in%(65) & intervention_prev_0_values[,3]%in%(gender)),2]+intervention_prev_1_values[which(intervention_prev_1_values[,1]%in%(65) & intervention_prev_1_values[,3]%in%(gender)),2]) {

          etat[i,1] <- "01" # non diseased and exposed 1

        } else {

          if (alea0 <= intervention_prev_0_values[which(intervention_prev_0_values[,1]%in%(65) & intervention_prev_0_values[,3]%in%(gender)),2]+intervention_prev_1_values[which(intervention_prev_1_values[,1]%in%(65) & intervention_prev_1_values[,3]%in%(gender)),2]+intervention_prev_2_values[which(intervention_prev_2_values[,1]%in%(65) & intervention_prev_2_values[,3]%in%(gender)),2]) {

            etat[i,1] <- "02" # non diseased and exposed 2

          } else {

            if (alea0 <= intervention_prev_0_values[which(intervention_prev_0_values[,1]%in%(65) & intervention_prev_0_values[,3]%in%(gender)),2]+intervention_prev_1_values[which(intervention_prev_1_values[,1]%in%(65) & intervention_prev_1_values[,3]%in%(gender)),2]+intervention_prev_2_values[which(intervention_prev_2_values[,1]%in%(65) & intervention_prev_2_values[,3]%in%(gender)),2]+intervention_prev_3_values[which(intervention_prev_3_values[,1]%in%(65) & intervention_prev_3_values[,3]%in%(gender)),2]) {

              etat[i,1] <- "03" # non diseased and exposed 3

            } else {

              if (alea0 <= intervention_prev_0_values[which(intervention_prev_0_values[,1]%in%(65) & intervention_prev_0_values[,3]%in%(gender)),2]+intervention_prev_1_values[which(intervention_prev_1_values[,1]%in%(65) & intervention_prev_1_values[,3]%in%(gender)),2]+intervention_prev_2_values[which(intervention_prev_2_values[,1]%in%(65) & intervention_prev_2_values[,3]%in%(gender)),2]+intervention_prev_3_values[which(intervention_prev_3_values[,1]%in%(65) & intervention_prev_3_values[,3]%in%(gender)),2]+intervention_prev_4_values[which(intervention_prev_4_values[,1]%in%(65) & intervention_prev_4_values[,3]%in%(gender)),2]) {

                etat[i,1] <- "04" # non diseased and exposed 4

              } else {

                if (alea0 <= intervention_prev_0_values[which(intervention_prev_0_values[,1]%in%(65) & intervention_prev_0_values[,3]%in%(gender)),2]+intervention_prev_1_values[which(intervention_prev_1_values[,1]%in%(65) & intervention_prev_1_values[,3]%in%(gender)),2]+intervention_prev_2_values[which(intervention_prev_2_values[,1]%in%(65) & intervention_prev_2_values[,3]%in%(gender)),2]+intervention_prev_3_values[which(intervention_prev_3_values[,1]%in%(65) & intervention_prev_3_values[,3]%in%(gender)),2]+intervention_prev_4_values[which(intervention_prev_4_values[,1]%in%(65) & intervention_prev_4_values[,3]%in%(gender)),2]+intervention_prev_5_values[which(intervention_prev_5_values[,1]%in%(65) & intervention_prev_5_values[,3]%in%(gender)),2]) {

                  etat[i,1] <- "05" # non diseased and exposed 5

                } else {

                  if (alea0 <= intervention_prev_0_values[which(intervention_prev_0_values[,1]%in%(65) & intervention_prev_0_values[,3]%in%(gender)),2]+intervention_prev_1_values[which(intervention_prev_1_values[,1]%in%(65) & intervention_prev_1_values[,3]%in%(gender)),2]+intervention_prev_2_values[which(intervention_prev_2_values[,1]%in%(65) & intervention_prev_2_values[,3]%in%(gender)),2]+intervention_prev_3_values[which(intervention_prev_3_values[,1]%in%(65) & intervention_prev_3_values[,3]%in%(gender)),2]+intervention_prev_4_values[which(intervention_prev_4_values[,1]%in%(65) & intervention_prev_4_values[,3]%in%(gender)),2]+intervention_prev_5_values[which(intervention_prev_5_values[,1]%in%(65) & intervention_prev_5_values[,3]%in%(gender)),2]+intervention_prev_6_values[which(intervention_prev_6_values[,1]%in%(65) & intervention_prev_6_values[,3]%in%(gender)),2]) {

                    etat[i,1] <- "06" # non diseased and exposed 6

                  } else {

                    etat[i,1] <- "07" # non diseased and exposed 7

                  }

                }

              }

            }

          }

        }

      }

    };

    for (j in 2:ncol(etat)) { # for each people

      if (intervention==1) {

        if (annee+j-1 < year_intervention) {

          intervention_incid_0_values <- data_incid_0_values
          intervention_incid_1_values <- data_incid_1_values
          intervention_incid_3_values <- data_incid_3_values
          intervention_incid_5_values <- data_incid_5_values

        } else {

          intervention_incid_0_values <- data_incid_0_values
          intervention_incid_0_values[,2] <- 0

          intervention_incid_1_values <- data_incid_1_values
          intervention_incid_1_values[,2] <- 0

          intervention_incid_3_values <- data_incid_3_values
          intervention_incid_3_values[,2] <- 0

          intervention_incid_5_values <- data_incid_5_values
          intervention_incid_5_values[,2] <- 0

        }

      }

      for (i in 1:nrow(etat)) { # for each age

        alea <- runif(1, 0, 1);

        alea0 <- runif(1, 0, 1);

        if (etat[i,j-1] == "00") {

          if (alea0 <= intervention_incid_0_values[which(intervention_incid_0_values[,1]%in%(j-1+65) & intervention_incid_0_values[,3]%in%(gender)),2]) {

            etat[i,j] <- "02"; # non diseased and exposed 2

          } else {

            etat[i,j] <- "00"; # non diseased and non exposed

          }

        } else {

          if (etat[i,j-1] == "01") {

            if (alea0 <= intervention_incid_1_values[which(intervention_incid_1_values[,1]%in%(j-1+65) & intervention_incid_1_values[,3]%in%(gender)),2]) {

              etat[i,j] <- "04"; # non diseased and exposed 4

            } else {

              etat[i,j] <- "01"; # non diseased and exposed 1

            }

          } else {

            if (etat[i,j-1] == "03") {

              if (alea0 <= intervention_incid_3_values[which(intervention_incid_3_values[,1]%in%(j-1+65) & intervention_incid_3_values[,3]%in%(gender)),2]) {

                etat[i,j] <- "06"; # non diseased and exposed 6

              } else {

                etat[i,j] <- "03"; # non diseased and exposed 3

              }

            } else {

              if (etat[i,j-1] == "05") {

                if (alea0 <= intervention_incid_5_values[which(intervention_incid_5_values[,1]%in%(j-1+65) & intervention_incid_5_values[,3]%in%(gender)),2]) {

                  etat[i,j] <- "07"; # non diseased and exposed 7

                } else {

                  etat[i,j] <- "05"; # non diseased and exposed 5

                }

              } else {

                if (etat[i,j-1] == "02") {

                  etat[i,j] <- "02"; # non diseased and exposed 2

                } else {

                  if (etat[i,j-1] == "04") {

                    etat[i,j] <- "04"; # non diseased and exposed 4

                  } else {

                    if (etat[i,j-1] == "06") {

                      etat[i,j] <- "06"; # non diseased and exposed 6

                    } else {

                      if (etat[i,j-1] == "07") {

                        etat[i,j] <- "07"; # non diseased and exposed 7

                      } else {

                        if (etat[i,j-1] == "10") {

                          if (alea0 <= intervention_incid_0_values[which(intervention_incid_0_values[,1]%in%(j-1+65) & intervention_incid_0_values[,3]%in%(gender)),2]) {

                            etat[i,j] <- "12"; # diseased and exposed 2

                          } else {

                            etat[i,j] <- "10"; # diseased and non exposed

                          }

                        } else {

                          if (etat[i,j-1] == "11") {

                            if (alea0 <= intervention_incid_1_values[which(intervention_incid_1_values[,1]%in%(j-1+65) & intervention_incid_1_values[,3]%in%(gender)),2]) {

                              etat[i,j] <- "14"; # diseased and exposed 4

                            } else {

                              etat[i,j] <- "11"; # diseased and exposed 1

                            }

                          } else {

                            if (etat[i,j-1] == "13") {

                              if (alea0 <= intervention_incid_3_values[which(intervention_incid_3_values[,1]%in%(j-1+65) & intervention_incid_3_values[,3]%in%(gender)),2]) {

                                etat[i,j] <- "16"; # diseased and exposed 6

                              } else {

                                etat[i,j] <- "13"; # diseased and exposed 3

                              }

                            } else {

                              if (etat[i,j-1] == "15") {

                                if (alea0 <= intervention_incid_5_values[which(intervention_incid_5_values[,1]%in%(j-1+65) & intervention_incid_5_values[,3]%in%(gender)),2]) {

                                  etat[i,j] <- "17"; # diseased and exposed 7

                                } else {

                                  etat[i,j] <- "15"; # diseased and exposed 5

                                }

                              } else {

                                if (etat[i,j-1] == "12") {

                                  etat[i,j] <- "12"; # diseased and exposed 2

                                } else {

                                  if (etat[i,j-1] == "14") {

                                    etat[i,j] <- "14"; # diseased and exposed 4

                                  } else {

                                    if (etat[i,j-1] == "16") {

                                      etat[i,j] <- "16"; # diseased and exposed 6

                                    } else {

                                      if (etat[i,j-1] == "17") {

                                        etat[i,j] <- "17"; # diseased and exposed 7

                                      } else {

                                        etat[i,j] <- etat[i,j-1]

                                      }

                                    }

                                  }

                                }

                              }

                            }

                          }

                        }

                      }

                    }

                  }

                }

              }

            }

          }

        }

      }

      for (i in 1:nrow(etat)) { # for each age

        alea <- runif(1, 0, 1);

        alea0 <- runif(1, 0, 1);

        if (etat[i,j] == "00") {

          a01 <- a010_values;
          a02 <- a020_values;

          if (alea <= a02[j-1,j+(an0-1950)+1]) {

            etat[i,j] <- "20"; # dead (with non exposed state)

          } else {

            if (alea <= a01[j-1,j+(an0-1950)+1] + a02[j-1,j+(an0-1950)+1]) {

              etat[i,j] <- "10"; # diseased and non exposed

            } else {

              etat[i,j] <- "00"; # non diseased and non exposed

            }

          }

        } else {

          if (etat[i,j] == "01") {

            a01 <- a011_values;
            a02 <- a021_values;

            if (alea <= a02[j-1,j+(an0-1950)+1]) {

              etat[i,j] <- "21"; # dead (with exposed state 1)

            } else {

              if (alea <= a01[j-1,j+(an0-1950)+1] + a02[j-1,j+(an0-1950)+1]) {

                etat[i,j] <- "11"; # diseased and exposed 1

              } else {

                etat[i,j] <- "01"; # non diseased and exposed 1

              }

            }

          } else {

            if (etat[i,j] == "02") {

              a01 <- a012_values;
              a02 <- a022_values;

              if (alea <= a02[j-1,j+(an0-1950)+1]) {

                etat[i,j] <- "22"; # dead (with exposed state 2)

              } else {

                if (alea <= a01[j-1,j+(an0-1950)+1] + a02[j-1,j+(an0-1950)+1]) {

                  etat[i,j] <- "12"; # diseased and exposed 2

                } else {

                  etat[i,j] <- "02"; # non diseased and exposed 2

                }

              }

            } else {

              if (etat[i,j] == "03") {

                a01 <- a013_values;
                a02 <- a023_values;

                if (alea <= a02[j-1,j+(an0-1950)+1]) {

                  etat[i,j] <- "23"; # dead (with exposed state 3)

                } else {

                  if (alea <= a01[j-1,j+(an0-1950)+1] + a02[j-1,j+(an0-1950)+1]) {

                    etat[i,j] <- "13"; # diseased and exposed 3

                  } else {

                    etat[i,j] <- "03"; # non diseased and exposed 3

                  }

                }

              } else {

                if (etat[i,j] == "04") {

                  a01 <- a014_values;
                  a02 <- a024_values;

                  if (alea <= a02[j-1,j+(an0-1950)+1]) {

                    etat[i,j] <- "24"; # dead (with exposed state 4)

                  } else {

                    if (alea <= a01[j-1,j+(an0-1950)+1] + a02[j-1,j+