- Operating System: Mac
- brms Version: 2.14.4
I’d like to use fitted()
following a model with an autoregressive structure. However, the current results seem off. Here’s the example from the brms UG:
library(brms)
library(tidyverse)
data("LakeHuron")
LakeHuron <- as.data.frame(LakeHuron)
fit <- brm(x ~ ar(p = 2), data = LakeHuron)
summary(fit)
Family: gaussian
Links: mu = identity; sigma = identity
Formula: x ~ ar(p = 2)
Data: LakeHuron (Number of observations: 98)
Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
total post-warmup samples = 4000
Correlation Structures:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
ar[1] 1.07 0.10 0.88 1.26 1.00 1739 2187
ar[2] -0.25 0.10 -0.45 -0.06 1.00 1717 2018
Population-Level Effects:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
Intercept 579.24 0.40 578.52 580.17 1.00 2796 1625
Family Specific Parameters:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
sigma 0.72 0.05 0.63 0.83 1.00 2546 2209
Samples were drawn using sampling(NUTS). For each parameter, Bulk_ESS
and Tail_ESS are effective sample size measures, and Rhat is the potential
scale reduction factor on split chains (at convergence, Rhat = 1).
That part seems to work fine. Things look off, here.
fitted(fit) %>%
data.frame() %>%
bind_cols(LakeHuron) %>%
mutate(time = 1:n()) %>%
ggplot(aes(time, ymin = Q2.5, ymax = Q97.5)) +
geom_ribbon(alpha = 1/2) +
geom_line(aes(y = Estimate), color = "blue") +
geom_point(aes(y = x))
Seems like the fitted line should be shifted to the left. What am I missing?