
10.3 Testing the Equality of Normal Means When Samples Are Paired 371
% UB = 8.6628
% 95% CI is [4.0472, 8.6628]
Alternatively, if one uses d1=after-baseline, then care must be taken about
the “direction” of H
1
and p-value calculations. The rejection region will be
(
−∞,−1.7291) and the 95% confidence interval [−8.6628,−4.0472].
A Bayesian solution is given next.
model{
for(i in 1:n){
d[i] <- baseline[i] - after[i]
d[i] ~ dnorm(mu, prec)
}
mu ~ dnorm(0, 0.00001)
pH1 <- step(mu-0)
prec ~ dgamma(0.001, 0.001)
sigma2 <- 1/prec;
sigma <- 1/sqrt(prec)
}
DATA
list(n=20,
baseline = c(5.9, 7.6, 12.8, 16.5, 6.1, 14.4, 6.6,
5.4, 9.6, 11.6 ,11.1, 15.6, 9.6, 15.2, 21, 5.9,
10, 12.2, 20.2, 6.2),
after = c(5.2, 12.2, 4.6, 4, 0.4 , 3.8, 1.2, 3.1, 3.5,
4.9, 11.1, 8.4, 5.8, 5, 6.4, 0, 2.7, 5.1, 4.8, 4.2))
INITS
list(mu=0, prec=1)
mean sd MC error val2.5pc median val97.5pc start sample
pH1 1.0 0.0 3.162E-13 1.0 1.0 1.0 1001 100000
mu 6.352 1.169 0.003657 4.043 6.351 8.666 1001 100000
prec 0.04108 0.01339 4.498E-5 0.01927 0.03959 0.07149 1001 100000
sigma 5.142 0.8912 0.003126 3.74 5.026 7.203 1001 100000
sigma2 27.23 10.0 0.03528 13.99 25.26 51.88 1001 100000
Let us compare the classical and Bayesian solutions. The estimator for the
difference between population means is 6.3550 in the classical case and 6.352
in the Bayesian case. The standard deviations of the difference are close as
well: the classical is 4.9309/
p
20 =1.1026 and the Bayesian is 1.169.
The 95% confidence interval for the difference is [4.0472,8.6628], while the
95% credible set is [4.043,8.666].
The posterior probability of H
1
is approx. 1, while the classical p-value
(support for H
0
) is 0.000007439.
This closeness of results is expected given that the priors
mu
∼
dnorm(0,0.00001)
and prec∼dgamma(0.001,0.001) are noninformative.