# Example 1: using arima.sim() to generate a stationary time series
nn <- 1000; set.seed(1)
tsdata <- data.frame(x2 = runif(nn))
ar.coef.1 <- rhobit(-2, inverse = TRUE) # Approx -0.8
ar.coef.2 <- rhobit( 1, inverse = TRUE) # Approx 0.5
tsdata <- transform(tsdata,
index = 1:nn,
TS1 = arima.sim(nn, model = list(ar = ar.coef.1),
sd = exp(1.0)),
TS2 = arima.sim(nn, model = list(ar = ar.coef.2),
sd = exp(1.0 + 2 * x2)))
fit1a <- vglm(cbind(TS1, TS2) ~ x2, AR1(zero = "rho", nodrift = TRUE),
data = tsdata, trace = TRUE)
coef(fit1a, matrix = TRUE)
summary(fit1a) # SEs are useful to know
# Example 2: another stationary time series
nn <- 1000
my.rho <- rhobit(-1.0, inverse = TRUE)
my.mu <- 2.5
my.sd <- exp(1)
tsdata <- data.frame(index = 1:nn, TS3 = runif(nn))
for (ii in 2:nn)
tsdata$TS3[ii] <- my.mu + my.rho * tsdata$TS3[ii-1] + rnorm(1, sd = my.sd)
tsdata <- tsdata[-(1:ceiling(nn/5)), ] # Remove the burn-in data:
fit2a <- vglm(TS3 ~ 1, AR1(type.likelihood = "conditional"),
data = tsdata, trace = TRUE)
coef(fit2a, matrix = TRUE)
summary(fit2a) # SEs are useful to know
Coef(fit2a)["rho"] # Estimate of rho for intercept-only models
my.rho
coef(fit2a)[1] # drift
my.mu # Should be the same
head(weights(fit2a, type= "prior")) # First one is effectively deleted
head(weights(fit2a, type= "working")) # Ditto
Run the code above in your browser using DataLab