
%5-HIAA Levels
% 
%  A rare and slow-growing form of cancer, carcinoid
% tumors, may develop anywhere in the body where neuroendocrine
% (hormone-producing) cells exist. Serotonin is one of the key body chemicals
% released by carcinoid tumors that are associated with carcinoid
% syndrome. The 5-hydroxyindoleacetic acid (5-HIAA) test is a 24-hour
% urine test that is specific to carcinoid tumors. Elevated levels of 5-HIAA,
% a byproduct of serotonin decomposition, can be detected from a urine
% sample.
% Ross and Roberts (1985) provide results of a case/control study of a morphologically
% specific type of carcinoid disorder that involves the mural
% and valvular endocardium on the right side of the heart, known as carcinoid
% heart disease. Out of a total of 36 subjects they investigate, urinary
% excretion of 5-hydroxyindoleacetic acid (5-HIAA) was measured on 28
% subjects, 16 cases with carcinoid hearth disease and 12 controls. The data
% (level of 5-HIAA in milligrams per 24 hours), also discussed in Dawson–
% Saunders and Trapp (1994), are provided in the table below.
% Patients: 263 288 432 890
%   450 1270 220 350
%   283 274 580 285
%   524 135 500 120
% Controls: 60 119 153 588
%   124 196 14 23
%   43 854 400 73
% Assuming that the data come from respective normal distributions, test
% the equality of means of the two populations versus the one-sided alternative.
% Assume equal population variances and tale alpha=0.05.
% 
% (b) Find 95% CI for the difference between population means
% 
% (c) What is the power of the test in (a) against te alternative mu1 - mu2 = 200
% 
% (d) What sample size ensires that the difference mu1 - mu2 = 200 will be
% found significant in one-sided testing with power 85%, if alpha is as in
% (a) and sigma=300.

Patients =[263 288 432 890 ...
      450 1270 220 350 ...
      283 274 580 285 ...
      524 135 500 120];
Controls = [60 119 153 588 ...
                   124 196 14 23 ...
                   43 854 400 73];
n1=length(Patients); n2=length(Controls);
X1bar = mean(Patients); X2bar=mean(Controls);
s1=std(Patients); s2=std(Controls);
sp = sqrt( ((n1-1)*s1^2 + (n2-1)* s2^2)/(n1 + n2 - 2));
t = (X1bar - X2bar)/(sp * sqrt(1/n1 + 1/n2)) %1.9406
%H1: mu1 > mu2
pval = 1 - tcdf(t, n1+n2-2) %0.0316
% CI for mu1- mu2
alpha=0.05 %for 95% CI 
[X1bar - X2bar - tinv(1-alpha/2, n1+n2-2) * sp * sqrt(1/n1 + 1/n2), ...
  X1bar - X2bar + tinv(1-alpha/2, n1+n2-2) * sp * sqrt(1/n1 + 1/n2)]
% -12.3488  429.1821

%%%
%H1: mu1 - mu2 = 200  (page 434)
Delta=200
1 - nctcdf(tinv(1-alpha,n1+n2-2), ...
n1+n2-2,Delta/(sp*sqrt(1/n1+1/n2)))
%56.69%

% What sample size is needed for power to be at least 85%?
% Delta = 200, alpha= 0.05, common sigma= 300.
sigma = 300;
ssize = 2 * sigma^2 *(norminv(0.95)+norminv(0.85))^2/(200^2)
% ssize =   32.3519  approx 33 each