### Use of the Bolstad R library # Bayesian inference for the Normal mean mu, sigma^2 known, # one sample of size n, conjugate Normal prior library(Bolstad) help(normnp) # normal prior # normnp(x, m.x = 0, s.x = 1, sigma.x = NULL, n.mu = 100, ret = FALSE) ####################################################################### ## generate a sample of 20 observations from a N(-0.5,1) population x = rnorm(20,-0.5,1) ####################################################################### ## find the posterior density with a N(0,1) prior on mu, sigma^2 = 1 normnp(x,sigma=1) ####################################################################### ## find the posterior density with N(0.5,3) prior on mu, sigma^2 = 1 normnp(x,0.5,3,1) ####################################################################### ## Find the posterior density for mu, given a random sample of 4 ## observations from N(mu,sigma^2=1), y = [2.99, 5.56, 2.83, 3.47], ## and a N(3,sd=2)$ prior for mu, sigma^2 = 1 y = c(2.99,5.56,2.83,3.47) normnp(y,3,2,1)