clear all
disp('Plasma Ascorbic Acid Level  2')
% Comparisons of Sattrerthwaite-Welch, Cochran-Cox and Patel's approaches to
% Behrens-Fisher Problem
%
%From the blood samples, the following plasma ascorbic acid values of
% each subject were determined in milligrams per 100 milliliters:
nonsmo = [0.97 0.72 1.00 0.81 0.62 1.32 1.24 0.99 ...
                     0.90 0.74 0.88 0.94 1.06 0.86 0.85 0.58 0.57...
                     0.64 0.98 1.09 0.92 0.78 1.24 1.18];
 smo = [ 0.48 0.71 0.98 0.68 1.18 1.36 0.78 1.64];
 X1bar = mean(nonsmo) 
 s1 = std(nonsmo)
 n1 = length(nonsmo)
 X2bar = mean(smo)
 s2 = std(smo)
 n2= length(smo)
 ndf = (s1^2/n1 + s2^2/n2 )^2 /( (s1^2 /n1)^2/(n1-1) + (s2^2/n2)^2 /(n2-1) )
t = (X1bar - X2bar)/sqrt( s1^2/n1 + s2^2/n2 )
pval = tcdf(t,ndf)
% ndf = 8.3892;   t =-0.4457;   pval = 0.3336
%Cochran-Cox
aa = @(alpha)  (s1^2/n1 * tinv(1-alpha, n1-1)  + ...
           s2^2/n2 * tinv(1-alpha, n2-1) )/(s1^2/n1 + s2^2/n2)  - t
1-fzero(aa, 0.5)  %pval1=0.3343
% Patel

%%
%WinBUGS
model{
prec1 <- n1/(exp(ls1)*exp(ls1))
prec2 <- n2/(exp(ls2)*exp(ls2))
X1b ~ dnorm(mu1, prec1)
X2b ~ dnorm(mu2, prec2)
mu1~ dflat()
mu2~ dflat()
ls1 ~ dflat()
ls2~ dflat()

d <- mu1 - mu2

pval <- step(d + 0.4457) 
}

list( X1b=0.9117,
n1 = 24,
X2b =0.9763,
n2 =  8)





list(mu1=0, mu2=0, ls1=1, ls2=1)




