-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
152 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
data { | ||
int<lower=1> S; // Number of steps | ||
array[S] int<lower=0> N; // observations | ||
array[S] real T; // observations | ||
} | ||
|
||
parameters { | ||
real<lower=0> rho_r; // Parameter rho_r (rate for recoverN) | ||
real<lower=0> rho_s; // Parameter rho_s (rate for signal decaN) | ||
real<lower=T[1]> t0_r; // Parameter t_r (time shift) | ||
real<lower=T[1]> t_end; | ||
// real<lower=0, upper=1.5> f_s; | ||
} | ||
|
||
model { | ||
vector[S] mu; // Expected values for N given x | ||
vector[S] ns; | ||
vector[S] nr; | ||
|
||
// Priors | ||
// n0 ~ normal(N[1], 0.1 * N[1]); | ||
rho_r ~ normal(0, 1); // Prior for rho_r | ||
rho_s ~ normal(0, 1); // Prior for rho_s | ||
t0_r ~ normal(T[1], 1); // Prior for t_r | ||
t_end ~ normal(T[S], 1); | ||
|
||
for (i in 1:S) { | ||
if (T[i] >= t_end) { | ||
ns[i] = 1e-9; | ||
} else { | ||
ns[i] = exp(-rho_s * (T[i] - t_end)); | ||
} | ||
|
||
if (T[i] >= t0_r) { | ||
nr[i] = exp(rho_r * (T[i] - t0_r)); | ||
} else { | ||
nr[i] = 1e-9; | ||
} | ||
|
||
mu[i] = nr[i] + ns[i]; | ||
} | ||
|
||
// Likelihood (assuming normallN distributed noise) | ||
N ~ poisson(mu); | ||
} | ||
|
||
generated quantities { | ||
vector[S] log_lik; // Log-likelihood for each observation | ||
vector[S] ns; | ||
vector[S] nr; | ||
vector[S] yrep; // Expected values for N given x | ||
|
||
for (i in 1:S) { | ||
if (T[i] >= t_end) { | ||
ns[i] = 1e-9; | ||
} else { | ||
ns[i] = exp(-rho_s * (T[i] - t_end)); | ||
} | ||
|
||
if (T[i] >= t0_r) { | ||
nr[i] = exp(rho_r * (T[i] - t0_r)); | ||
} else { | ||
nr[i] = 1e-9; | ||
} | ||
yrep[i] = nr[i] + ns[i]; | ||
log_lik[i] = poisson_lpmf(N[i] | yrep[i]); // Log-likelihood calculation | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
data { | ||
int<lower=1> S; // Number of steps | ||
array[S] int<lower=0> N; // observations | ||
array[S] real T; // observations | ||
} | ||
|
||
parameters { | ||
real<lower=0> rho_r; // Parameter rho_r (rate for recoverN) | ||
real<lower=0> rho_s; // Parameter rho_s (rate for signal decaN) | ||
real<upper=T[1]> t0_r; // Parameter t_r (time shift) | ||
real<lower=T[1]> t_end; | ||
// real<lower=0, upper=1.5> f_s; | ||
} | ||
|
||
|
||
model { | ||
vector[S] mu; // Expected values for N given x | ||
vector[S] ns; | ||
vector[S] nr; | ||
|
||
// Priors | ||
// n0 ~ normal(N[1], 0.1 * N[1]); | ||
rho_r ~ normal(0, 1); // Prior for rho_r | ||
rho_s ~ normal(0, 1); // Prior for rho_s | ||
t0_r ~ normal(T[1], 1); // Prior for t_r | ||
t_end ~ normal(T[S], 1); | ||
|
||
for (i in 1:S) { | ||
if (T[i] >= t_end) { | ||
ns[i] = 1e-9; | ||
} else { | ||
ns[i] = exp(-rho_s * (T[i] - t_end)); | ||
} | ||
|
||
if (T[i] >= t0_r) { | ||
nr[i] = exp(rho_r * (T[i] - t0_r)); | ||
} else { | ||
nr[i] = 1e-9; | ||
} | ||
|
||
mu[i] = nr[i] + ns[i]; | ||
} | ||
|
||
// Likelihood (assuming normallN distributed noise) | ||
N ~ poisson(mu); | ||
} | ||
|
||
generated quantities { | ||
vector[S] log_lik; // Log-likelihood for each observation | ||
vector[S] ns; | ||
vector[S] nr; | ||
vector[S] yrep; // Expected values for N given x | ||
|
||
for (i in 1:S) { | ||
if (T[i] >= t_end) { | ||
ns[i] = 1e-9; | ||
} else { | ||
ns[i] = exp(-rho_s * (T[i] - t_end)); | ||
} | ||
|
||
if (T[i] >= t0_r) { | ||
nr[i] = exp(rho_r * (T[i] - t0_r)); | ||
} else { | ||
nr[i] = 1e-9; | ||
} | ||
yrep[i] = nr[i] + ns[i]; | ||
log_lik[i] = poisson_lpmf(N[i] | yrep[i]); // Log-likelihood calculation | ||
} | ||
} |