clear all
clc
data=dataread1;

data(data(:,3)<3,3)=0;
data(data(:,3)>2,3)=1;

data(:,5)=data(:,5)/12;

[age sur den]=survivalrate;


realage1=floor(data(:,1));
realage2=floor(data(:,1)+data(:,5));


for i=1:size(data,1)
   
    rs1(i,1)=sur(age==realage1(i));
    rs2(i,1)=sur(age==realage2(i));
 
    realden(i,1)=den(age==realage2(i));
end

data=[data rs2./rs1 realden./rs1];

%data=[data ones(size(data,1),1) zeros(size(data,1),1)];


data1=data(data(:,7)>0&data(:,4)==1, :);  %diseased and died
data2=data(data(:,7)>0&data(:,4)==0, :);  %diseased but live (censored)
data3=data(data(:,7)==0&data(:,4)==1, :);  %not diseased but died 
data4=data(data(:,7)==0&data(:,4)==0, :);  %not diseased and live (censored)

%data2([5 6 7 8 9 10 ],:)=[];

 

 para0=[.5 .3 .5 1.8];
 
options = optimset('MaxFunEvals',2,'MaxIter',2,'TolFun',1.e-9,'TolX',1.e-11);

[para1, fval1]=fminsearch(@h1test,para0,options, data1,data2,data3,data4,data4(:,8),data3(:,9));

% para02=[.63 .54 1.81];
% 
% options = optimset('MaxFunEvals',208888,'MaxIter',208888,'TolFun',1.e-9,'TolX',1.e-9);
% 
% [para0, fval0]=fminsearch(@h0test,para02,options, time, delta); 
% 
% lr=2*(fval0-fval1)
% pval=chi2pdf(lr,1)
%save('h0.txt', 'para', 'fval1', '-ASCII');
%para1 =
% para1 =
% 
%     2.8966    9.7446    0.3073    1.2130
% 
% 
% fval1 =
% 
%   186.4725
% 






