


%  PAS and Streptomycin Cures for Pulmonary Tuberculosis.}~
% Data released by British Medical Research Council in 1950 (analyzed also in Armitage and Berry, 1994)
% concern efficiency of para-amino-salicylic acid (PAS), streptomycin, and their combination on treatment of
% pulmonary tuberculosis. Outcomes of sputum culture test performed on the patients after the
% treatment are categorized as 'Positive Smear', 'Negative Smear \& Positive Culture', and 'Negative Smear \& Negative Culture'.
% 
% The table below summarizes findings on 273 treated patients with TB diagnosis.
% 
% {\footnotesize
% \begin{center}
% \begin{tabular}{|c||c c c||c|}
% \hline
%   &  Smear (+) & Smear (--) \& Culture (+) &  Smear (--) \& Culture (--) & Total  \\  \hline
% \hline
% PAS              &  56   &  30   &  13    &   99   \\
% Streptomycin     &  46   &  18   &  20    &   84   \\
% PAS \& Streptomycin &  37   &  18   &  35    &   90   \\ \hline \hline
% Total            & 139   &  66   &  68    &  273   \\ \hline
% \end{tabular}
% \end{center}
% }
% 
% (a) There are two factors here: Cure Combination and Sputum Results. Test the hypothesis
% of their independence. Find the $p$-value and compare it to the 5\% significance level.
% Find also the rejection region for the test and confirm that your decision made by $p$-value
% is consistent with the decision based on the rejection region considerations.
% 
% (b) If the factors were independent, how many patients you expect to see in
% the cell defined by PAS treatment and Positive Smear (cell in the intersection of 1st row and 1st column)?
% How many patients you expect to see in the cell defined by combination of treatments (PAS+Streptimycin)
% for which the response was Smear negative, Culture negative (cell in the intersection of 3rd row and 3rd column).
% Show your work.
% 
% 
% (c) Inspect the difference between observed and expected frequencies in the
% 3rd column (Smear negative, Culture negative), which represents a desirable outcome.
% Based on the signs and magnitudes of these differences, which of the three cures would you recommend?
% 

%(a)
D =[ ...
    56    30    13 ;  %99
    46    18    20 ;  %84
    37    18    35 ]; %90
%  139    66    68    273
 [chi2,pvalue,exp] = tablerxc(D)
 
%  chi2 = 17.6284
%  pvalue = 0.0015
%  exp =
%    50.4066   23.9341   24.6593
%    42.7692   20.3077   20.9231
%    45.8242   21.7582   22.4176


%(b)  
e11 = 99 * 139/273  %  50.4066
e33 = 90 *  68/273  %  22.4176

%(c)
[13 20 35] - [24.6593 20.9231 22.4176]
% -11.6593   -0.9231   12.5824
% Recommend combination PAS + Streptomycin (PS). For the desirable 
% outcome (column 3) the observed frequency of PS exceeds the expected.
% This means that PS is most effective cure. Analogously, the PAS alone
% is the least effective.