@@ -26,8 +26,8 @@ par(mgp = c(1.6, .6, 0), mar = c(2.6, 2.6, 2.6, .4), lwd = 1)
2626## Figure 3.1: Posteriors under the beta-binomial model
2727
2828To reproduce the posteriors in this figure, we simply need to plug in
29- respective counts into the expression for the posterior density and visualize
30- it accordingly.
29+ the respective counts into the expression for the posterior density
30+ and visualize it accordingly.
3131
3232``` {r, echo=-(1:2)}
3333if (pdfplots) {
@@ -53,8 +53,8 @@ for (p in trueprop) {
5353
5454In city A, 40 out of 400 questioned people would purchase a certain product, in
5555a rural community, only 4 out of 400. Assuming a uniform prior, we now compute
56- equal-tails intervals and highest posterior density (HPD) intervals. Note that R
57- is (generally) vectorized, so we can compute the equal-tails intervals without
56+ equal-tailed intervals and highest posterior density (HPD) intervals. Note that R
57+ is (generally) vectorized, so we can compute the equal-tailed intervals without
5858using a loop.
5959
6060``` {r}
@@ -70,7 +70,7 @@ bN <- N - SN + b
7070gamma <- .95
7171alpha <- 1 - gamma
7272
73- # Equal-tails credible intervals
73+ # Equal-tailed credible intervals
7474leftET <- qbeta(alpha/2, aN, bN)
7575rightET <- qbeta(1 - alpha/2, aN, bN)
7676
@@ -182,7 +182,7 @@ res <- cbind(lengthET = rightET - leftET, lengthHPD = rightHPD - leftHPD)
182182knitr::kable(round(res, 4))
183183```
184184
185- ## Figure 3.3: One-sided hypthesis testing
185+ ## Figure 3.3: One-sided hypothesis testing
186186
187187We now move forward to assessing visualizing the posterior probability of
188188$\vartheta$ (the proportion of defective items) being less than $1/20 = 0.05$
@@ -238,7 +238,7 @@ alongside their frequency of usage among a total of 100 million occurrences
238238(cf. < https://www.eapfoundation.com/vocab/general/bnccoca/ > ).
239239
240240``` {r}
241- library( BayesianLearningCode)
241+ data("words", package = " BayesianLearningCode" )
242242head(words)
243243```
244244
@@ -322,7 +322,7 @@ all(abs(post_lessinformative - post_lessinformative2) < 1e-10)
322322Summing up what we have so far.
323323
324324``` {r}
325- dirichlet_sd = function(gamma) {
325+ dirichlet_sd <- function(gamma) {
326326 mean <- gamma / sum(gamma)
327327 sd <- sqrt((mean * (1 - mean)) / (sum(gamma) + 1))
328328 sd
0 commit comments