Skip to content

Commit 814254c

Browse files
committed
minor adaptation sampling the variance
1 parent 3ebe4b5 commit 814254c

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

vignettes/Chapter07.Rmd

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,14 +1134,6 @@ c0 <- C0 <- 0.01
11341134
cthetas <- c(.01, .1, 1)
11351135
11361136
# Allocate space for the draws
1137-
# Compute the epsilons recursively
1138-
eps <- filter(dat, -theta, "recursive", init = eps0)
1139-
1140-
# Sample sigma^2
1141-
cN <- c0 + (length(dat) + 1) / 2
1142-
CN <- C0 + 0.5 * (eps0^2 + sum(eps^2))
1143-
sigma2 <- rinvgamma(1, cN, CN)
1144-
11451137
# Sample theta via RW-MH
11461138
epsprop <- filter(dat, -thetaprop, "recursive", init = eps0)
11471139
@@ -1165,6 +1157,11 @@ for (i in seq_along(cthetas)) {
11651157
tmp <- 1 + sum(bs^2)
11661158
eps0 <- rnorm(1, -sum(as * bs) / tmp, sqrt(sigma2 / tmp))
11671159
1160+
# Sample sigma^2
1161+
eps <- filter(dat, -theta, "recursive", init = eps0)
1162+
cN <- c0 + (length(dat) + 1) / 2
1163+
CN <- C0 + 0.5 * (eps0^2 + sum(eps^2))
1164+
sigma2 <- rinvgamma(1, cN, CN)
11681165
11691166
if (log(runif(1)) < logR) {
11701167
theta <- thetaprop

0 commit comments

Comments
 (0)