Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating functionality for time and age varying model. #167

Open
sumalibajaj opened this issue Mar 13, 2024 · 1 comment
Open

Creating functionality for time and age varying model. #167

sumalibajaj opened this issue Mar 13, 2024 · 1 comment
Assignees

Comments

@sumalibajaj
Copy link
Collaborator

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)$.

@sumalibajaj sumalibajaj self-assigned this Mar 13, 2024
@ekamau
Copy link
Collaborator

ekamau commented May 15, 2024

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);
  
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants