Skip to content

Commit

Permalink
Daily model included
Browse files Browse the repository at this point in the history
  • Loading branch information
EamonConway committed Jun 7, 2024
1 parent 7ff9820 commit 83bade8
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions daily.stan
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// The input data is a vector 'D' of length 'N' containing daily data.
functions {
real pc_phi_lpdf(real x, real lambda){
return -1.5*log(x) + log(lambda/2.0) - lambda/sqrt(x);
}
}


data {
int<lower=0> N_days;
int<lower=0> D[N_days];
int<lower=0> N_generation;
vector<lower=0>[N_generation] g;
real R0;
real I0;
real alpha;
real beta;
real lambda;
}

transformed data {
}

parameters {
vector<lower=0>[N_days] R_T;
real<lower=0> sigma_R;
real<lower=0> R_0;
real<lower = 0> phi;
real<lower=0> I_negT;
}

transformed parameters {
vector<lower=0>[N_days] mu;
real<lower=0.0> generation_value = 0.0;
mu[1] = D[1];
for(t in 1:N_days){
// Calculate the value of mu
generation_value = 0.0;
for(s in 1:N_generation){
if((t-s)>0){
generation_value+=g[s]*D[t-s];
}else{
generation_value+=g[s]*I_negT;
}
}
mu[t] = R_T[t]*generation_value;
}
}

model {
// Set the priors of interest.
phi ~ pc_phi(lambda);
I_negT ~ normal(I0,sqrt(I0)) T[0,];
sigma_R ~ inv_gamma(alpha,beta);
R_0 ~ normal(R0,4.0) T[0,];
R_T[1] ~ normal(R_0,sigma_R) T[0,];
R_T[2:N_days] ~ normal(R_T[1:N_days-1],sigma_R);
// Data
D ~ neg_binomial_2(mu,phi);
}

generated quantities {
}

0 comments on commit 83bade8

Please sign in to comment.