-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvisit_model.stan
67 lines (47 loc) · 1.33 KB
/
visit_model.stan
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// A Poisson regression with effect of rodent_at_site, wet season, and
// varying intercepts by site and visit, to be used with visit-level data
data {
int<lower=0> N;
array[N] int n_Mna;
array[N] int rodent_at_site;
array[N] int wet_season;
array[N] real log_tot_traps;
int<lower=0> N_site;
array[N] int<lower=1, upper=N_site> site;
int<lower=0> N_visit;
array[N] int<lower=1, upper=N_visit> visit;
}
parameters {
real a; // intercept
real bR; // rodent presence effect
real bW; // wet season effect
// varying intercepts by site
vector[N_site] a_site;
real<lower=0> sigma_site;
// varying intercepts by visit
vector[N_visit] a_visit;
real<lower=0> sigma_visit;
}
model {
vector[N] lambda;
a ~ normal(-3.1, 1.1);
bR ~ normal(0, 1);
bW ~ normal(0, 1);
a_site ~ normal(0, sigma_site);
sigma_site ~ exponential(1);
a_visit ~ normal(0, sigma_visit);
sigma_visit ~ exponential(1);
for (i in 1:N) {
lambda[i] = a + bR * rodent_at_site[i] + bW * wet_season[i] +
a_site[site[i]] + a_visit[visit[i]] +
log_tot_traps[i];
n_Mna[i] ~ poisson_log(lambda[i]);
}
}
generated quantities {
vector[N] lambda;
for (i in 1:N) {
lambda[i] = a + bR * rodent_at_site[i] + bW * wet_season[i] +
a_site[site[i]] + a_visit[visit[i]];
}
}