Skip to content

Commit

Permalink
more apostrophes
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnnyDoorn committed Dec 7, 2023
1 parent 132becd commit fc3392f
Show file tree
Hide file tree
Showing 24 changed files with 43 additions and 43 deletions.
12 changes: 6 additions & 6 deletions 02-models.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ P(\text{8 heads out of 10} \mid \theta) = \frac{10!}{8! (10-8)!} \theta^8\left(1
\end{equation}
The last element to fill in is $\theta$. If we do so for Sarah, who postulates $\theta = 0.5$, we get `r round(dbinom(8, 10, 0.5), 4)`. For Paul, who postulates $\theta = 0.8$, we get `r round(dbinom(8, 10, 0.8), 4)`. If we do this for every possible outcome, and create a bar graph of each likelihood, we get the following two figures that illustrate what each model deems likely (the yellow bar indicates each models' likelihood of the example of 8 heads out of 10 flips):

```{r two-models-likelihoods-binomial, fig.cap='The likelihoods of all possible outcomes of 10 coin flips, under Sarahs model and under Pauls model. The yellow bar indicates the likelihood of the observed data (8 heads).', fig.align='center', out.width='90%', echo = FALSE}
```{r two-models-likelihoods-binomial, fig.cap="The likelihoods of all possible outcomes of 10 coin flips, under Sarah's model and under Paul's model. The yellow bar indicates the likelihood of the observed data (8 heads).", fig.align='center', out.width='90%', echo = FALSE}
#| label: fig-two-models-likelihoods-binomial
par(mfrow = c(1, 2), cex.main = 0.95)
cols <- viridis::viridis(6)
Expand Down Expand Up @@ -135,28 +135,28 @@ Lastly, but perhaps most importantly, we can also consider a model that tries to
par(mfrow = c(1, 2), cex.main = 0.95)
cols <- viridis::viridis(6)
plot(1, 1, type ="n", xlim = c(0,1), ylim = c(0,4), bty = "n", main = "Alex' Model",
plot(1, 1, type ="n", xlim = c(0,1), ylim = c(0,4), bty = "n", main = "Alex's Model",
las = 1, xlab = expression(theta), ylab = "Density")
# curve(tBetFun(x, 1, 1), add = TRUE, col = cols[4], lwd = 4)
mySeq <- seq(0, 1, length.out = 1e3)
polygon(x = c(mySeq, rev(mySeq)), y = c(rep(0, 1e3), tBetFun(mySeq, 1, 1, side = "neutral")), col = cols[4])
barplot(rep(1/11, 11), names.arg = 0:10, xlab = "Number of heads", ylab = "Likelihood",
main = "Likely Outcomes under Alex' Model", col = cols[4], ylim = c(0,0.32))
main = "Likely Outcomes under Alex's Model", col = cols[4], ylim = c(0,0.32))
barplot(c(rep(0, 8), 1/11), add = TRUE, col = cols[6])
# barplot(c(rep(0, 8), 1/11), add = TRUE, col = cols[6])
```

## More Model Comparisons {#sec-more-model-comparison}

We can apply the same principles from @sec-model-comparison to compare how well each of the additional models has predicted the observed data of 8 heads out of 10 coin flips. To do so, we can simply take the ratio of each of the yellow bars in the figures that depict how likely each model considers the various possible outcomes of 10 coin flips. For instance, Alex' model has a marginal likelihood of `r round((1/11), 4)` for 8 heads, whereas Betty's model has a marginal likelihood of `r round( (table(sampsU)/1e5)[9], 4)` for 8 heads. If we want to compare the predictions of Betty and Alex, we can look at the ratio of these values to obtain $\text{BF}_{AB} =$ `r round( round(1/11, 4)/ round((table(sampsU)/1e5)[9], 4), 1)`, which is equivalent to $\text{BF}_{BA} =$ `r round( round((table(sampsU)/1e5)[9], 4) / round(1/11, 4) , 1)`. This means that the data are about twice as likely under Betty's model than under Alex' model, which can be considered weak evidence in favor of Betty's model over Alex' model.
We can apply the same principles from @sec-model-comparison to compare how well each of the additional models has predicted the observed data of 8 heads out of 10 coin flips. To do so, we can simply take the ratio of each of the yellow bars in the figures that depict how likely each model considers the various possible outcomes of 10 coin flips. For instance, Alex's model has a marginal likelihood of `r round((1/11), 4)` for 8 heads, whereas Betty's model has a marginal likelihood of `r round( (table(sampsU)/1e5)[9], 4)` for 8 heads. If we want to compare the predictions of Betty and Alex, we can look at the ratio of these values to obtain $\text{BF}_{AB} =$ `r round( round(1/11, 4)/ round((table(sampsU)/1e5)[9], 4), 1)`, which is equivalent to $\text{BF}_{BA} =$ `r round( round((table(sampsU)/1e5)[9], 4) / round(1/11, 4) , 1)`. This means that the data are about twice as likely under Betty's model than under Alex's model, which can be considered weak evidence in favor of Betty's model over Alex's model.

If we were to use the betting analogy again, we could say that while both Alex and Betty had bet some money on the outcome of 8 heads, Betty had bet more money on this particular outcome than Alex, and is therefore rewarded more. Because Betty has a more specific belief (namely that the coin is biased towards heads), she had more money at her disposal for betting on the considered values (i.e., values between 0.5 and 1). In contrast, Alex played it very safely: they win some money for any outcome because they spread their betting money across all values. However, because of this, their reward is lower for having correctly predicted the observed data compared to someone who made a more specific bet on the observed data. The phenomenon of more specific models being rewarded more (when predicting well) than their non-specific competitor is known as **parsimony**, and will be discussed in more depth in Chapter 4.

A last model comparison we can make is to compare Alex' model to Sarah's model. In a typical (two-sided) statistical test about a proportion, this is the most often-used comparison: Sarah's model is considered to be the null model, and Alex' model is considered the two-sided alternative model. As we saw, Alex' marginal likelihood is `r round((1/11), 4)`, while Sarah's marginal likelihood is `r round(dbinom(8, 10, 0.5), 4)`, so the Bayes factor comparing these two models, $\text{BF}_{AS}$, equals `r round(round((1/11), 4) /round(dbinom(8, 10, 0.5), 4), 2)`. This means the data are about twice as likely under Alex' model compared to Sarah's model.
A last model comparison we can make is to compare Alex's model to Sarah's model. In a typical (two-sided) statistical test about a proportion, this is the most often-used comparison: Sarah's model is considered to be the null model, and Alex's model is considered the two-sided alternative model. As we saw, Alex's marginal likelihood is `r round((1/11), 4)`, while Sarah's marginal likelihood is `r round(dbinom(8, 10, 0.5), 4)`, so the Bayes factor comparing these two models, $\text{BF}_{AS}$, equals `r round(round((1/11), 4) /round(dbinom(8, 10, 0.5), 4), 2)`. This means the data are about twice as likely under Alex's model compared to Sarah's model.

As a bonus, when we know $\text{BF}_{BA}$ and $\text{BF}_{AS}$, we automatically know $\text{BF}_{BS}$. Since we know how much more likely the data are under Betty's model than under Alex' model (about 2 times), and how much more likely the data are under Alex' model than under Sarah's model (about 2 times), we also now know that Betty's model is about $2 \times 2 = 4$ times more likely than Sarah's model! This property it known as **transitivity**.
As a bonus, when we know $\text{BF}_{BA}$ and $\text{BF}_{AS}$, we automatically know $\text{BF}_{BS}$. Since we know how much more likely the data are under Betty's model than under Alex's model (about 2 times), and how much more likely the data are under Alex's model than under Sarah's model (about 2 times), we also now know that Betty's model is about $2 \times 2 = 4$ times more likely than Sarah's model! This property it known as **transitivity**.

## Concluding Thoughts

Expand Down
Loading

0 comments on commit fc3392f

Please sign in to comment.