# The poisson autogression model # models integer valued time series using a GLM type approach. # This model is studied in Fokianos, Rahbek and Tjostheim (2009) # parameters need to be positive in this specification poisson.autoregressive = function(d1,a,b,n,n0){ m = (n+n0) y <- rep(1,m) lambda <- rep(1,m) for(i in c(2:m)){ lambda[i] = (d1+a*lambda[i-1]+b*y[i-1]) y[i] = rpois(1,lambda = lambda[i]) } y = y[-c(1:n0)] return(y) } test1 = poisson.autoregressive(d1=1,a=0.6, b=0.3, n0=100, n=200) # Make acf plots to check the correlation par(mfrow=c(2,1)) plot(c(1:200),test1,col="blue") acf(test1) # without the a component test2 = poisson.autoregressive(d1=1,a=0, b=0.9, n0=100, n=200) # Make acf plots to check the correlation #par(mfrow=c(2,1)) plot(c(1:200),test2,col="blue") acf(test2) ################################# # Next we give a model that allows for negative correlation and negative parameters. # This model is studied in Fokianos and Tjostheim (2011) poisson.autoregressive.log = function(d1,a,b,n,n0){ m = (n+n0) y <- rep(1,m) lambda <- rep(1,m) eta <- rep(1,m) for(i in c(2:m)){ eta[i] = (d1+a*eta[i-1]+b*log(1+y[i-1])) lambda[i] = exp(eta[i]) y[i] = rpois(1,lambda = lambda[i]) } y = y[-c(1:n0)] return(y) } test3 = poisson.autoregressive.log(d1=0.5,a=-0.5, b=-0.25, n0=100, n=200) # Make acf plots to check the correlation par(mfrow=c(2,1)) plot(c(1:200),test3,col="blue") acf(test3)