CS计算机代考程序代写 # Posterior predictive checks for 8 schools example

# Posterior predictive checks for 8 schools example

# Section 6.5 in Gelman et al

# You have to run the code in ‘Example05b_HierarchicalNormal’ first!

yrep <- ytilde.sim maxie <- apply(yrep, 2, max) minny <- apply(yrep, 2, min) meany <- apply(yrep, 2, mean) devvy <- apply(yrep, 2, sd) op <- par(mfrow=c(2,2)) p.val <- mean(maxie >= max(y))
hist(maxie, breaks=30, xlab=”T(y)=max(y)”, main=paste(“P-value =”,p.val))
abline(v=max(y), lty=2)

p.val <- mean(minny >= min(y))
hist(minny, breaks=30, xlab=”T(y)=min(y)”, main=paste(“P-value =”,p.val))
abline(v=min(y), lty=2)

p.val <- mean(meany >= mean(y))
hist(meany, breaks=30, xlab=”T(y)=mean(y)”, main=paste(“P-value =”,p.val))
abline(v=mean(y), lty=2)

p.val <- mean(devvy >= sd(y))
hist(devvy, breaks=30, xlab=”T(y)=sd(y)”, main=paste(“P-value =”,p.val))
abline(v=sd(y), lty=2)

par(op) # Figure 6.12 on p. 161