data { int N; // length of time series int M; // number of independent variables plus one matrix[N,M] X; // design matrix int y[N]; // time series data int P; // number of lagged observations int Q; // number of lagged conditional means } parameters { vector[M] eta; // intercept and slopes vector[Q] alpha; // slopes for lagged conditional means vector[P] beta; // slopes for lagged observations real beta0; } transformed parameters { // Initialise linear predictor vector[N] nu; nu = X * eta +beta0; // Add lagged conditional means for(i in 1:N){ // ar iteration if(P > 0) for ( j in 1:P )if(i > j) nu[i] += log(1+y[i-j]) * beta[j]; // ma iteration if(Q > 0) for ( j in 1:Q )if(i > j) nu[i] += nu[i-j] * alpha[j]; } } model { // regularising fixed priors for intercept and slopes target += normal_lpdf( eta | 0 , 1 ); target += normal_lpdf( alpha | 0 , 1 ); target += normal_lpdf( beta | 0 , 1 ); target += normal_lpdf( beta0 | 0 , 1 ); // likelihood w/ log-link target += poisson_log_lpmf( y | nu ); }