Skip to content

Commit ff6ee12

Browse files
committed
Deploying to gh-pages from @ 5a00eff 🚀
1 parent f8be144 commit ff6ee12

7 files changed

Lines changed: 110 additions & 65 deletions

File tree

articles/Chapter06.html

Lines changed: 61 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

articles/Chapter06.md

Lines changed: 47 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,6 @@ with the 2.5% and 97.5% quantile of the posterior distribution.
143143
res_conj1 <- regression_conjugate(y, X, b0 = 0, B0 = 10)
144144
post.sd.conj1 = sqrt(diag((res_conj1$CN / res_conj1$cN) * res_conj1$BN))
145145

146-
res_conj2 <- regression_conjugate(y, X, b0 = 0, B0 = 1)
147-
post.sd.conj2 = sqrt(diag((res_conj2$CN / res_conj2$cN) * res_conj2$BN))
148-
149146
knitr::kable(round(cbind(
150147
qt(0.025, df = 2 * res_conj1$cN) * post.sd.conj1 + res_conj1$bN,
151148
res_conj1$bN,
@@ -159,42 +156,69 @@ knitr::kable(round(cbind(
159156
| Weeks | 0.245 | 0.837 | 1.429 |
160157
| Screens | 1.041 | 1.663 | 2.285 |
161158

162-
We plot the marginal posteriors (in blue) together with those under the
163-
improper prior.
159+
``` r
160+
161+
162+
res_conj2 <- regression_conjugate(y, X, b0 = 0, B0 = 1)
163+
post.sd.conj2 = sqrt(diag((res_conj2$CN / res_conj2$cN) * res_conj2$BN))
164+
165+
res_conj3<- regression_conjugate(y, X, b0 = 0, B0 = 0.1)
166+
post.sd.conj3 = sqrt(diag((res_conj3$CN / res_conj3$cN) * res_conj3$BN))
167+
```
168+
169+
We plot the marginal posteriors together with those under the improper
170+
prior.
164171

165172
``` r
166173
for (i in seq_len(nrow(beta.hat))) {
167174
curve(dt((x - beta.hat[i]) / post.sd[i], df = 2 * cN),
168-
from = beta.hat[i] - 4 * post.sd[i], to = beta.hat[i] + 4 * post.sd[i],
175+
from = beta.hat[i] - 4 * post.sd[i],
176+
to = beta.hat[i] + 4 * post.sd[i],
169177
ylab = "", xlab = "" , main = rownames(beta.hat)[i])
170-
curve(dt((x - res_conj1$bN[i]) / post.sd.conj1[i], df = 2 * res_conj1$cN),
178+
179+
curve(dt((x - res_conj1$bN[i]) / post.sd.conj1[i],
180+
df = 2 * res_conj1$cN),
171181
from = res_conj1$bN[i] - 4 * post.sd.conj1[i],
172-
to = res_conj1$bN[i] + 4 * post.sd.conj1[i],
182+
to = res_conj1$bN[i] + 4 * post.sd.conj1[i],
173183
add = TRUE, col = 2, lty = 2, lwd = 2)
174-
curve(dt((x - res_conj2$bN[i]) / post.sd.conj2[i], df = 2 * res_conj2$cN),
184+
185+
curve(dt((x - res_conj2$bN[i]) / post.sd.conj2[i],
186+
df = 2 * res_conj2$cN),
175187
from = res_conj2$bN[i] - 4 * post.sd.conj2[i],
176-
to = res_conj2$bN[i] + 4 * post.sd.conj2[i], add = TRUE, col = 3,
177-
lty = 4, lwd = 2)
178-
legend("topright", c("improper", "B0 = 10", "B0 = 1"),
179-
col = 1:3, lty = c(1, 2, 4), lwd = c(1, 2, 2))
188+
to = res_conj2$bN[i] + 4 * post.sd.conj2[i],
189+
add = TRUE, col = 3,lty = 3, lwd = 2)
190+
191+
curve(dt((x - res_conj3$bN[i]) / post.sd.conj3[i],
192+
df = 2 * res_conj3$cN),
193+
from = res_conj3$bN[i] - 4 * post.sd.conj3[i],
194+
to = res_conj3$bN[i] + 4 * post.sd.conj3[i],
195+
add = TRUE, col = 4,lty = 4, lwd = 2)
196+
197+
legend("topright", c("improper",
198+
expression(paste(lambda^2,"=", 10)),
199+
expression(paste(lambda^2, "=", 1)),
200+
expression(paste(lambda^2,"=", 0.1))),
201+
col = 1:4, lty = 1:4, lwd = c(1, 2, 2, 2))
180202
}
181203
```
182204

183205
![](Chapter06_files/figure-html/unnamed-chunk-9-1.png)
184206

185-
There is little difference to the improper prior for
186-
$B_{0} = 10\textbf{𝐈}$, however we see shrinkage to zero for
187-
$B_{0} = \textbf{𝐈}$. The effect of the prior isgiven by the weight
188-
matrix $\textbf{𝐖}$, which is computed for the prior
189-
\$\Normal\\\textbf{0}, \textbf{I}\\\$ below.
207+
There is little difference to the improper prior for the effects of
208+
Screens and Weeks, however the intercept intercept is shrunk to zero for
209+
$B_{0} = \textbf{𝐈}$ and even more for $B_{0} = 0.1\textbf{𝐈}$.
210+
211+
The effect of the prior is given by the weight matrix $\textbf{𝐖}$,
212+
which is computed for the prior \$\Normal\\\textbf{0}, \textbf{I}\\\$
213+
below.
190214

191215
``` r
192-
W <- res_conj2$BN %*% solve(diag(rep(1, d)))
216+
W <- res_conj3$BN %*% solve(diag(rep(1, d)))
193217
print(round(W, 3))
194-
#> [,1] [,2] [,3]
195-
#> Intercept 0.011 0 0
196-
#> Weeks 0.000 0 0
197-
#> Screens 0.000 0 0
218+
#> [,1] [,2] [,3]
219+
#> Intercept 0.01 0 0
220+
#> Weeks 0.00 0 0
221+
#> Screens 0.00 0 0
198222
```
199223

200224
We see that weight of the prior mean is much smaller for the intercept
44.3 KB
Loading
0 Bytes
Loading
-22 Bytes
Loading

pkgdown.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ articles:
1111
Chapter07: Chapter07.html
1212
Chapter08: Chapter08.html
1313
Chapter09: Chapter09.html
14-
last_built: 2025-12-04T22:44Z
14+
last_built: 2025-12-15T17:47Z
1515
urls:
1616
reference: https://gregorkastner.github.io/BayesianLearningCode/reference
1717
article: https://gregorkastner.github.io/BayesianLearningCode/articles

search.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)