ts1=[4.7  7  7  8.9 9.1];
cs1=[0  0 0 1 0];
% 
ts2=[6.1 7 9 10];
cs2=[1 0 0 1];

[p ch2]= manteltwo(ts1, cs1, ts2, cs2) 

% p =
% 
%     0.4147
% 
% 
% ch2 =
% 
%     0.6653
% 
% 
%% by hand

%  1  4 | 5        2  2 | 4     0  1 |  1      1  0 | 1      
%  0  4 | 4        1  2 | 3     1  1 |  2      0  1 | 1
%  -----  --        -----  --     -----  --       -----  --
%  1  8   9         3  4   7     1  2    3      1  1   2

% d1i   r1i - d1i   |  r1i        ai = d1i,  ei = r1i  *  d1/ri,  
% d2i   r2i - d2i   |  r2i        vi= r1i/ri  *  (1-r1i/ri) * (ri-di)/(ri-1) * di 
% ---------------      ----
%  di      ri - di     |   ri
% 
%  A=sum(ai) ; E=sum(ei), V=sum(vi)
%  
%  chisq= (A-E)^2/V
 
o=[1 2 0 1]
e=[5/9 12/7 1/3 1/2]
v=[20/81 24/49 2/9 1/4]

c=  [sum(o - e)]^2/sum(v)
1-chi2cdf(c, 1)
% c =
% 
%     0.6653
% 
% 
% ans =
% 
%     0.4147

z= sum(o-e)/sqrt(sum(v)) 
normcdf(z)
1-normcdf(z)

%%
ccor=  [sum(abs(o - e)-0.5)]^2/sum(v)
1-chi2cdf(ccor, 1)
% ccor =
% 
%     0.1576
% 
% 
% ans =
% 
%     0.6914
 x1= [ts1' cs1'];  x2=[ts2' cs2'];
logrank(x1, x2)
% LOG-RANK TEST FOR KAPLAN-MEIER SURVIVAL FUNCTIONS
%  
% --------------------------------------------------------------------------------
% UL			       S.E.	            	z		    p-value	  	alpha
% --------------------------------------------------------------------------------
% 0.89683			1.09951		0.36091		0.71817		0.050
% --------------------------------------------------------------------------------
% 		The survival functions are not statistically different
 