I am trying to work through https://rpruim.github.io/Kruschke-Notes/bayes-rule-and-the-grid-method.html and was confused about the normalized posterior and likelihood calculation
library(ggplot)
library(tidyverse)
library(ggformula)
library(triangle)
library(purrr)
x <- 1; n <- 4
CoinsGrid <-
expand.grid(
theta = seq(0, 1, by = 0.001)
) %>%
mutate(
prior = dtriangle(theta), # triangle distribution
likelihood = map_dbl(theta, ~ dbinom(x = x, size = n, .x)),
likelihood1 = likelihood / sum(likelihood) / 0.001, # "normalized"
posterior0 = prior * likelihood, # unnormalized
posterior = posterior0 / sum(posterior0) / 0.001 # normalized
)
gf_area( prior ~ theta, data = CoinsGrid, alpha = 0.3) %>%
gf_area( likelihood1 ~ theta, data = CoinsGrid, alpha = 0.3, fill = "green") %>%
gf_area( posterior ~ theta, data = CoinsGrid, alpha = 0.3, fill = "steelblue")
I understand why the normalization is needed but unable to get the intuition behind why the author dividing by 0.001?
likelihood1 = likelihood / sum(likelihood) / 0.001
My hunch is that it might be due of the grid size, but i appreciate any help wrt the intuition.