epiverse-trace / serofoi

Estimates the Force-of-Infection of a given pathogen from population based sero-prevalence studies
https://epiverse-trace.github.io/serofoi/
Other
17 stars 4 forks source link

Creating functionality for time and age varying model. #167

Open sumalibajaj opened 8 months ago

sumalibajaj commented 8 months ago

We will consider a simplified case where the age and time specific FOI $\lambda=\lambda(a, t)$ is a product of an age-specific pattern and one that varies by time, $\lambda(a, t)=u(a) v(t)$.

ekamau commented 5 months ago

draft of time and age model in stan

// without seroreversion assumption!
// with estimated age and time rates

functions {
  real prob_seropos_calculate(vector time_rate, vector age_rate, int age){

    real prob_infected;
    vector[age] v_vector = tail(time_rate, age);
    for(i in 1:age){
      real sum_foi = 0;
      for(j in 1:i){
        real foi = (age_rate[j] * v_vector[j]);
        sum_foi += foi;
      }
      prob_infected = 1-exp(-sum_foi);
    }

    return prob_infected;
  }

  vector probability_seropos(vector time_rate, vector age_rate, int N) {

    vector[N] prob_seropos;

    for(n in 1:N) {
      prob_seropos[n] = prob_seropos_calculate(time_rate, age_rate, n);
    }

    return prob_seropos;
  }

}

data {
  int<lower=0> N;
  int<lower=0> age_max;
  int ages[N];
  int n_pos[N];
  int total[N];

}

parameters {
  vector<lower=0>[age_max] age_rate;
  vector<lower=0>[age_max] time_rate;

}

transformed parameters {
  vector[N] probability_age;
  vector[N] probability_age2;

  for(n in 1:N) {
    probability_age2[n] = prob_seropos_calculate(time_rate, age_rate, n);
  }

  probability_age = probability_seropos(time_rate, age_rate, N);

}

model {
  // priors
  age_rate ~ beta(2,5); // cauchy(0,1);
  time_rate ~ beta(2,5); // cauchy(0,1);

  // likelihood
  n_pos ~ binomial(total, probability_age);
}

generated quantities {
  int pos_pred[N];

  pos_pred = binomial_rng(total, probability_age);

}