
## com156b of august 2025
#  revisiting Odin \& children, check com120* of nilswork22

#  here: just the Bayesian part, for stk4021

p <- 0.514
y <- 6
upper <- 25 
Nval <- seq(1,upper,by=1)

## addendum: doing Bayes, same 1/(N+1) prior,
#  for y = 6, then y = 8

pival <- 1/(Nval+1)

y1 <- 6
post0val <- pival * dbinom(y1,Nval,p)
post6val <- post0val / sum(post0val) 

y2 <- 8
post0val <- pival * dbinom(y2,Nval,p)
post8val <- post0val / sum(post0val) 

par(bty="l")
par(cex.lab=1.4142) 

matplot(Nval,cbind(post6val,post8val),type="l",lwd=3,
   xlab="number of children",
   ylab="posterior, with y = 6 and y = 8")

# posterior means: 
sum(Nval * post6val) # 11.72
sum(Nval * post8val) # 15.42

# posterior medians: these are 11 and 15 
cbind(Nval,cumsum(post6val),cumsum(post8val))








