13.7 Uncertainty intervals on states

We will look at the effect of missing data on the uncertainty intervals on estimates states using a DFA on the harbor seal dataset.

data(harborSealWA, package = "MARSS")
# the first column is year
matplot(harborSealWA[, 1], harborSealWA[, -1], type = "l", ylab = "Log abundance", 
    xlab = "")

Assume they are all observing a single trend.

seal.mod <- bayesdfa::fit_dfa(y = t(harborSealWA[, -1]), num_trends = 1, 
    chains = 1, iter = 1000)
pars <- rstan::extract(seal.mod$model)
pred_mean <- c(apply(pars$x, c(2, 3), mean))
pred_lo <- c(apply(pars$x, c(2, 3), quantile, 0.025))
pred_hi <- c(apply(pars$x, c(2, 3), quantile, 0.975))

plot(pred_mean, type = "l", lwd = 3, ylim = range(c(pred_mean, 
    pred_lo, pred_hi)), main = "Trend")
lines(pred_lo)
lines(pred_hi)
Estimated states and 95 percent credible intervals.

Figure 13.5: Estimated states and 95 percent credible intervals.