This repository has been archived by the owner on May 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
endodemog_surv.stan
50 lines (41 loc) · 2 KB
/
endodemog_surv.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
data {
int<lower=0> N; // number of observations
int<lower=0> K; // number of predictors
int<lower=0> nYear; // number of years
int<lower=0, upper=11> year_t[N]; // year of observation
int<lower=0> nEndo; // number of endo treatments
int<lower=1, upper=2> endo_index[N]; // index for endophyte effect
int<lower=0> nPlot; // number of plots
int<lower=0> plot[N]; // plot of observation
int<lower=0, upper=1> surv_t1[N]; // plant survival at time t+1 and target variable (response)
vector<lower=0>[N] logsize_t; // plant size at time t (predictor)
int<lower=0,upper=1> endo_01[N]; // plant endophyte status (predictor)
int<lower=0,upper=1> origin_01[N]; // plant origin status (predictor)
}
parameters {
vector[K] beta; // predictor parameters
vector[nYear] tau_year[nEndo]; // random year effect
real<lower=0> sigma_e[nEndo]; //year variance by endophyte effect
vector[nPlot] tau_plot; // random plot effect
real<lower=0> sigma_p; // plot variance effect
}
transformed parameters {
real mu[N]; // Linear Predictor
for(n in 1:N){
mu[n] = beta[1] + beta[2]*logsize_t[n] + beta[3]*endo_01[n] +beta[4]*origin_01[n]
+ beta[5]*logsize_t[n]*endo_01[n]
+ tau_year[endo_index[n],year_t[n]]
+ tau_plot[plot[n]];
}
}
model {
// Priors
beta ~ normal(0,100); // prior for predictor intercepts
tau_plot ~ normal(0,sigma_p); // prior for plot random effects
to_vector(tau_year[1]) ~ normal(0,sigma_e[1]); // prior for E- year random effects
to_vector(tau_year[2]) ~ normal(0,sigma_e[2]); // prior for E+ year random effects
// Likelihood
surv_t1 ~ bernoulli_logit(mu);
}
generated quantities{
}