% Dopamine beta-hydroxylase Activity
% Postmortem brain specimens from nine chronic schizophrenic
% patients and nine control were assayed for activity of dopamine
% beta -hydroxylase (DBH), the enzyme responsible for the conversion 
% of dopamine to norepinephrine, Wyatt et al 1975.
% 
% The means and standard deviations of DBH activity in hippocampus 
% part of the brain are provided in the table. Assume that the data are coming 
% from two normally distributed and independent populations.
% 
% 
%                         Schizophrenic  & Control  
% Sample size  |  n_1 = 9 |  n_2 = 9  
% Sample mean |  bar X_1 = 35.5  |  \bar X_2 = 39.8 
% Sample standard deviation | s_1 = 6.93  | s_2 = 8.16  
% 
% (a) Test to determine if the mean activity is significantly lower
% for the schizophrenic subjects than for the control subjects. Use
% alpha=0.05.
% (b) Construct 99% confidence interval for the mean difference in
% enzyme activity between the two groups.
% 
% Solve the above in two ways (i) by assuming that  sigma_1 =
% \sigma_2  and (ii) without such an assumption.
% 
% Wyatt et al report that one of the control subjects with low DBH activity
% had unusually long death-to-morgue time (27 hours) and suggested
% excluding the subject from the study.
% The data for controls after exclusion were n_2 = 8,   bar X_2 = 41.2,  and
% s_2 = 7.52.
% Repeat the test in (a) and (b) with this control data.

n1 = 9;  n2 = 9;
X1bar = 35.5; X2bar = 39.8;
s1 = 6.93;  s2 = 8.16;

%(a1)
sp2 = (   (n1 -1 ) * s1^2 + (n2 - 1) * s2^2 )/(n1 + n2  - 2)

sp = sqrt(sp2)

t = (X1bar - X2bar)/(sp * sqrt(1/n1 + 1/n2) )

df1 = n1 + n2 -  2

tcrit = tinv(0.05, df1)

pval = tcdf(t, df1)

%(b2)
t995 = tinv(0.995, df1)

[X1bar - X2bar   -   t995 * sp * sqrt(1/n1 + 1/n2), ...
    X1bar - X2bar   +   t995* sp * sqrt(1/n1 + 1/n2)]


%(a2)
t = (X1bar - X2bar)/(sqrt(s1^2/n1 + s2^2/n2) )

df2=(s1^2 /n1 + s2^2 /n2)^2 /( (s1^2 /n1)^2 /(n1-1) + (s2^2 /n2)^2/(n2-1) )

tcrit = tinv(0.05, df2)

pval = tcdf(t, df2)

%(b2)
t995 = tinv(0.995, df2)

[X1bar - X2bar   -   t995 *  sqrt(s1^2/n1 + s2^2/n2), ...
    X1bar - X2bar   +   t995 * sqrt(s1^2/n1 + s2^2/n2)]

clear n2   X2bar  s2
n2 = 8;  X2bar = 41.2; s2 = 7.52;

%(aa1)
sp2 = (   (n1 -1) * s1^2 + (n2 - 1) * s2^2 )/(n1 + n2  - 2)

sp = sqrt(sp2)

t = (X1bar - X2bar)/(sp * sqrt(1/n1 + 1/n2) )

df1 = n1 + n2 -  2

tcrit = tinv(0.05, df1)

pval = tcdf(t, df1)

%(bb2)
tcri = tinv(0.995, df1)

[X1bar - X2bar   -   tcri * sp * sqrt(1/n1 + 1/n2), ...
    X1bar - X2bar   +   tcri * sp * sqrt(1/n1 + 1/n2)]


%(aa2)
t = (X1bar - X2bar)/(sqrt(s1^2/n1 + s2^2/n2) )

df2=(s1^2 /n1 + s2^2 /n2)^2 /( (s1^2 /n1)^2 /(n1-1) + (s2^2 /n2)^2/(n2-1) )

tcrit = tinv(0.05, df2)

pval = tcdf(t, df2)

%(bb2)
tcri = tinv(0.995, df2)

[X1bar - X2bar   -   tcri *  sqrt(s1^2/n1 + s2^2/n2), ...
    X1bar - X2bar   +   tcri * sqrt(s1^2/n1 + s2^2/n2)]




