Displaying 1 result from an estimated 1 matches for "ybar1".
Did you mean:
bar1
2010 Jul 18
2
loop troubles
...em is I want to have elements from
the previous posterior to be the new prior and now I cant figure out how to
do the code below in a loop. The data below is dummy data, I used a starting
mu of 1, and starting precision of 0.
bayes.analysis.treat<-function(mu0,p0){
n1 = 5
n2 = 10
n3 = 15
ybar1 = 12
ybar2 = 13
ybar3 = 14
sd1 = 2
sd2 = 3
sd3 = 4
#posterior 1
var1 = sd1^2 #sample variance
p1 = n1/var1 #sample precision
p1n = p0+p1
mu1 = ((p0)/(p1n)*mu0)+((p1)/(p1n))*ybar1
sigma1 = 1/sqrt(p1n)
#posterior 2
var2 = sd2^2 #sample variance
p2 = n2/var2 #sample precision
p2n = p1n+...