Skip to content

Commit 8c8a439

Browse files
author
Bob Carpenter
committed
added geometric lag (Koyck) model example with sim
1 parent c51aea4 commit 8c8a439

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

misc/garch/koyck-sim.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
library("rstan");
2+
T <- 200;
3+
x <- rnorm(T,0,1);
4+
alpha <- -1.25;
5+
beta <- 0.75;
6+
lambda <- 0.6;
7+
sigma <- 0.5;
8+
9+
y <- rep(NA,T);
10+
y[1] <- rnorm(1,alpha + beta * x[1],sigma);
11+
for (t in 2:T)
12+
y[t] <- rnorm(1,alpha + beta * x[t] + lambda * y[t-1], sigma);
13+
14+
fit <- stan(file="koyck.stan", data=c("T","y","x"), iter=500, chains=4, fit=fit);

misc/garch/koyck.stan

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// geometric lag time-series (Koyck 1951)
2+
//
3+
// http://en.wikipedia.org/wiki/Distributed_lag
4+
5+
data {
6+
int<lower=0> T; // number of time points
7+
real y[T]; // output at time t
8+
real x[T]; // predictor for time t
9+
}
10+
parameters {
11+
real alpha; // intercept
12+
real beta; // slope
13+
real <lower=0, upper=1> lambda; // lag
14+
real <lower=0> sigma; // noise scale
15+
}
16+
model {
17+
alpha ~ cauchy(0,5);
18+
beta ~ cauchy(0,5);
19+
lambda ~ uniform(0,1);
20+
sigma ~ cauchy(0,5);
21+
for (t in 2:T)
22+
y[t] ~ normal(alpha + beta * x[t] + lambda * y[t-1],
23+
sigma);
24+
}
25+

0 commit comments

Comments
 (0)