version 1.124, 2006/03/22 17:13:53
|
version 1.127, 2006/04/28 18:11:50
|
Line 1
|
Line 1
|
/* $Id$ |
/* $Id$ |
$State$ |
$State$ |
$Log$ |
$Log$ |
|
Revision 1.127 2006/04/28 18:11:50 brouard |
|
(Module): Yes the sum of survivors was wrong since |
|
imach-114 because nhstepm was no more computed in the age |
|
loop. Now we define nhstepma in the age loop. |
|
(Module): In order to speed up (in case of numerous covariates) we |
|
compute health expectancies (without variances) in a first step |
|
and then all the health expectancies with variances or standard |
|
deviation (needs data from the Hessian matrices) which slows the |
|
computation. |
|
In the future we should be able to stop the program is only health |
|
expectancies and graph are needed without standard deviations. |
|
|
|
Revision 1.126 2006/04/28 17:23:28 brouard |
|
(Module): Yes the sum of survivors was wrong since |
|
imach-114 because nhstepm was no more computed in the age |
|
loop. Now we define nhstepma in the age loop. |
|
Version 0.98h |
|
|
|
Revision 1.125 2006/04/04 15:20:31 lievre |
|
Errors in calculation of health expectancies. Age was not initialized. |
|
Forecasting file added. |
|
|
Revision 1.124 2006/03/22 17:13:53 lievre |
Revision 1.124 2006/03/22 17:13:53 lievre |
Parameters are printed with %lf instead of %f (more numbers after the comma). |
Parameters are printed with %lf instead of %f (more numbers after the comma). |
The log-likelihood is printed in the log file |
The log-likelihood is printed in the log file |
Line 364 extern int errno;
|
Line 386 extern int errno;
|
/* $Id$ */ |
/* $Id$ */ |
/* $State$ */ |
/* $State$ */ |
|
|
char version[]="Imach version 0.98g, March 2006, INED-EUROREVES-Institut de longevite "; |
char version[]="Imach version 0.98h, April 2006, INED-EUROREVES-Institut de longevite "; |
char fullversion[]="$Revision$ $Date$"; |
char fullversion[]="$Revision$ $Date$"; |
char strstart[80]; |
char strstart[80]; |
char optionfilext[10], optionfilefiname[FILENAMELENGTH]; |
char optionfilext[10], optionfilefiname[FILENAMELENGTH]; |
Line 2097 void freqsummary(char fileres[], int ia
|
Line 2119 void freqsummary(char fileres[], int ia
|
for(i=iagemin; i <= iagemax+3; i++){ |
for(i=iagemin; i <= iagemax+3; i++){ |
if(i==iagemax+3){ |
if(i==iagemax+3){ |
fprintf(ficlog,"Total"); |
fprintf(ficlog,"Total"); |
fprintf(fichtm,"<br>Total<br>"); |
|
}else{ |
}else{ |
if(first==1){ |
if(first==1){ |
first=0; |
first=0; |
Line 2458 void tricode(int *Tvar, int **nbcode, in
|
Line 2479 void tricode(int *Tvar, int **nbcode, in
|
|
|
/*********** Health Expectancies ****************/ |
/*********** Health Expectancies ****************/ |
|
|
void evsij(char fileres[], double ***eij, double x[], int nlstate, int stepm, int bage, int fage, double **oldm, double **savm, int cij, int estepm,char strstart[] ) |
void evsij(double ***eij, double x[], int nlstate, int stepm, int bage, int fage, double **oldm, double **savm, int cij, int estepm,char strstart[] ) |
|
|
{ |
{ |
/* Health expectancies, no variances */ |
/* Health expectancies, no variances */ |
int i, j, nhstepm, hstepm, h, nstepm, k, cptj, cptj2, i2, j2; |
int i, j, nhstepm, hstepm, h, nstepm, k, cptj, cptj2, i2, j2; |
|
int nhstepma, nstepma; /* Decreasing with age */ |
double age, agelim, hf; |
double age, agelim, hf; |
double ***p3mat; |
double ***p3mat; |
double eip; |
double eip; |
Line 2509 void evsij(char fileres[], double ***eij
|
Line 2531 void evsij(char fileres[], double ***eij
|
hstepm=hstepm/stepm; /* Typically in stepm units, if stepm=6 & estepm=24 , = 24/6 months = 4 */ |
hstepm=hstepm/stepm; /* Typically in stepm units, if stepm=6 & estepm=24 , = 24/6 months = 4 */ |
|
|
agelim=AGESUP; |
agelim=AGESUP; |
/* nhstepm age range expressed in number of stepm */ |
/* If stepm=6 months */ |
nstepm=(int) rint((agelim-age)*YEARM/stepm); |
/* Computed by stepm unit matrices, product of hstepm matrices, stored |
|
in an array of nhstepm length: nhstepm=10, hstepm=4, stepm=6 months */ |
|
|
|
/* nhstepm age range expressed in number of stepm */ |
|
nstepm=(int) rint((agelim-bage)*YEARM/stepm); /* Biggest nstepm */ |
/* Typically if 20 years nstepm = 20*12/6=40 stepm */ |
/* Typically if 20 years nstepm = 20*12/6=40 stepm */ |
/* if (stepm >= YEARM) hstepm=1;*/ |
/* if (stepm >= YEARM) hstepm=1;*/ |
nhstepm = nstepm/hstepm;/* Expressed in hstepm, typically nhstepm=40/4=10 */ |
nhstepm = nstepm/hstepm;/* Expressed in hstepm, typically nhstepm=40/4=10 */ |
p3mat=ma3x(1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm); |
p3mat=ma3x(1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm); |
|
|
for (age=bage; age<=fage; age ++){ /* If stepm=6 months */ |
for (age=bage; age<=fage; age ++){ |
/* Computed by stepm unit matrices, product of hstepm matrices, stored |
nstepma=(int) rint((agelim-bage)*YEARM/stepm); /* Biggest nstepm */ |
in an array of nhstepm length: nhstepm=10, hstepm=4, stepm=6 months */ |
/* Typically if 20 years nstepm = 20*12/6=40 stepm */ |
|
/* if (stepm >= YEARM) hstepm=1;*/ |
|
nhstepma = nstepma/hstepm;/* Expressed in hstepm, typically nhstepma=40/4=10 */ |
|
|
|
/* If stepm=6 months */ |
|
/* Computed by stepm unit matrices, product of hstepma matrices, stored |
|
in an array of nhstepma length: nhstepma=10, hstepm=4, stepm=6 months */ |
|
|
hpxij(p3mat,nhstepm,age,hstepm,x,nlstate,stepm,oldm, savm, cij); |
hpxij(p3mat,nhstepma,age,hstepm,x,nlstate,stepm,oldm, savm, cij); |
|
|
hf=hstepm*stepm/YEARM; /* Duration of hstepm expressed in year unit. */ |
hf=hstepm*stepm/YEARM; /* Duration of hstepm expressed in year unit. */ |
|
|
Line 2555 void evsij(char fileres[], double ***eij
|
Line 2587 void evsij(char fileres[], double ***eij
|
|
|
} |
} |
|
|
void cvevsij(char fileres[], double ***eij, double x[], int nlstate, int stepm, int bage, int fage, double **oldm, double **savm, int cij, int estepm,double delti[],double **matcov,char strstart[] ) |
void cvevsij(double ***eij, double x[], int nlstate, int stepm, int bage, int fage, double **oldm, double **savm, int cij, int estepm,double delti[],double **matcov,char strstart[] ) |
|
|
{ |
{ |
/* Covariances of health expectancies eij and of total life expectancies according |
/* Covariances of health expectancies eij and of total life expectancies according |
to initial status i, ei. . |
to initial status i, ei. . |
*/ |
*/ |
int i, j, nhstepm, hstepm, h, nstepm, k, cptj, cptj2, i2, j2, ij, ji; |
int i, j, nhstepm, hstepm, h, nstepm, k, cptj, cptj2, i2, j2, ij, ji; |
|
int nhstepma, nstepma; /* Decreasing with age */ |
double age, agelim, hf; |
double age, agelim, hf; |
double ***p3matp, ***p3matm, ***varhe; |
double ***p3matp, ***p3matm, ***varhe; |
double **dnewm,**doldm; |
double **dnewm,**doldm; |
Line 2635 void cvevsij(char fileres[], double ***e
|
Line 2668 void cvevsij(char fileres[], double ***e
|
/* If stepm=6 months */ |
/* If stepm=6 months */ |
/* nhstepm age range expressed in number of stepm */ |
/* nhstepm age range expressed in number of stepm */ |
agelim=AGESUP; |
agelim=AGESUP; |
nstepm=(int) rint((agelim-age)*YEARM/stepm); |
nstepm=(int) rint((agelim-bage)*YEARM/stepm); |
/* Typically if 20 years nstepm = 20*12/6=40 stepm */ |
/* Typically if 20 years nstepm = 20*12/6=40 stepm */ |
/* if (stepm >= YEARM) hstepm=1;*/ |
/* if (stepm >= YEARM) hstepm=1;*/ |
nhstepm = nstepm/hstepm;/* Expressed in hstepm, typically nhstepm=40/4=10 */ |
nhstepm = nstepm/hstepm;/* Expressed in hstepm, typically nhstepm=40/4=10 */ |
Line 2648 void cvevsij(char fileres[], double ***e
|
Line 2681 void cvevsij(char fileres[], double ***e
|
gm=matrix(0,nhstepm,1,nlstate*nlstate); |
gm=matrix(0,nhstepm,1,nlstate*nlstate); |
|
|
for (age=bage; age<=fage; age ++){ |
for (age=bage; age<=fage; age ++){ |
|
nstepma=(int) rint((agelim-bage)*YEARM/stepm); /* Biggest nstepm */ |
/* Computed by stepm unit matrices, product of hstepm matrices, stored |
/* Typically if 20 years nstepm = 20*12/6=40 stepm */ |
in an array of nhstepm length: nhstepm=10, hstepm=4, stepm=6 months */ |
/* if (stepm >= YEARM) hstepm=1;*/ |
|
nhstepma = nstepma/hstepm;/* Expressed in hstepm, typically nhstepma=40/4=10 */ |
|
|
|
/* If stepm=6 months */ |
|
/* Computed by stepm unit matrices, product of hstepma matrices, stored |
|
in an array of nhstepma length: nhstepma=10, hstepm=4, stepm=6 months */ |
|
|
hf=hstepm*stepm/YEARM; /* Duration of hstepm expressed in year unit. */ |
hf=hstepm*stepm/YEARM; /* Duration of hstepm expressed in year unit. */ |
|
|
/* Computing Variances of health expectancies */ |
/* Computing Variances of health expectancies */ |
Line 2702 void cvevsij(char fileres[], double ***e
|
Line 2740 void cvevsij(char fileres[], double ***e
|
varhe[ij][ji][(int)age] += doldm[ij][ji]*hf*hf; |
varhe[ij][ji][(int)age] += doldm[ij][ji]*hf*hf; |
} |
} |
} |
} |
|
|
/* Computing expectancies */ |
/* Computing expectancies */ |
hpxij(p3matm,nhstepm,age,hstepm,x,nlstate,stepm,oldm, savm, cij); |
hpxij(p3matm,nhstepm,age,hstepm,x,nlstate,stepm,oldm, savm, cij); |
for(i=1; i<=nlstate;i++) |
for(i=1; i<=nlstate;i++) |
Line 3485 void printinghtml(char fileres[], char t
|
Line 3524 void printinghtml(char fileres[], char t
|
subdirf2(fileres,"pl"),subdirf2(fileres,"pl")); |
subdirf2(fileres,"pl"),subdirf2(fileres,"pl")); |
fprintf(fichtm,"\ |
fprintf(fichtm,"\ |
- (a) Life expectancies by health status at initial age, (b) health expectancies by health status at initial age: ei., eij . If one or more covariate are included, specific tables for each value of the covariate are output in sequences within the same file (estepm=%2d months): \ |
- (a) Life expectancies by health status at initial age, (b) health expectancies by health status at initial age: ei., eij . If one or more covariate are included, specific tables for each value of the covariate are output in sequences within the same file (estepm=%2d months): \ |
<a href=\"%s\">%s</a> <br>\n</li>", |
<a href=\"%s\">%s</a> <br>\n", |
estepm,subdirf2(fileres,"e"),subdirf2(fileres,"e")); |
estepm,subdirf2(fileres,"e"),subdirf2(fileres,"e")); |
|
fprintf(fichtm,"\ |
|
- Population projections by age and states: \ |
|
<a href=\"%s\">%s</a> <br>\n</li>", subdirf2(fileres,"f"),subdirf2(fileres,"f")); |
|
|
fprintf(fichtm," \n<ul><li><b>Graphs</b></li><p>"); |
fprintf(fichtm," \n<ul><li><b>Graphs</b></li><p>"); |
|
|
Line 5710 Interval (in months) between two waves:
|
Line 5751 Interval (in months) between two waves:
|
} |
} |
|
|
|
|
/*---------- Health expectancies and variances ------------*/ |
/* Computes prevalence between agemin (i.e minimal age computed) and no more ageminpar */ |
|
|
strcpy(filerest,"t"); |
prevalence(probs, agemin, agemax, s, agev, nlstate, imx, Tvar, nbcode, ncodemax, mint, anint, dateprev1, dateprev2, firstpass, lastpass); |
strcat(filerest,fileres); |
/* printf("ageminpar=%f, agemax=%f, s[lastpass][imx]=%d, agev[lastpass][imx]=%f, nlstate=%d, imx=%d, mint[lastpass][imx]=%f, anint[lastpass][imx]=%f,dateprev1=%f, dateprev2=%f, firstpass=%d, lastpass=%d\n",\ |
if((ficrest=fopen(filerest,"w"))==NULL) { |
ageminpar, agemax, s[lastpass][imx], agev[lastpass][imx], nlstate, imx, mint[lastpass][imx],anint[lastpass][imx], dateprev1, dateprev2, firstpass, lastpass); |
printf("Problem with total LE resultfile: %s\n", filerest);goto end; |
*/ |
fprintf(ficlog,"Problem with total LE resultfile: %s\n", filerest);goto end; |
|
|
if (mobilav!=0) { |
|
mobaverage= ma3x(1, AGESUP,1,NCOVMAX, 1,NCOVMAX); |
|
if (movingaverage(probs, bage, fage, mobaverage,mobilav)!=0){ |
|
fprintf(ficlog," Error in movingaverage mobilav=%d\n",mobilav); |
|
printf(" Error in movingaverage mobilav=%d\n",mobilav); |
|
} |
} |
} |
printf("Computing Total Life expectancies with their standard errors: file '%s' \n", filerest); |
|
fprintf(ficlog,"Computing Total Life expectancies with their standard errors: file '%s' \n", filerest); |
|
|
|
|
|
|
/*---------- Health expectancies, no variances ------------*/ |
|
|
strcpy(filerese,"e"); |
strcpy(filerese,"e"); |
strcat(filerese,fileres); |
strcat(filerese,fileres); |
if((ficreseij=fopen(filerese,"w"))==NULL) { |
if((ficreseij=fopen(filerese,"w"))==NULL) { |
Line 5730 Interval (in months) between two waves:
|
Line 5777 Interval (in months) between two waves:
|
} |
} |
printf("Computing Health Expectancies: result on file '%s' \n", filerese); |
printf("Computing Health Expectancies: result on file '%s' \n", filerese); |
fprintf(ficlog,"Computing Health Expectancies: result on file '%s' \n", filerese); |
fprintf(ficlog,"Computing Health Expectancies: result on file '%s' \n", filerese); |
|
for(cptcov=1,k=0;cptcov<=i1;cptcov++){ |
|
for(cptcod=1;cptcod<=ncodemax[cptcov];cptcod++){ |
|
k=k+1; |
|
fprintf(ficreseij,"\n#****** "); |
|
for(j=1;j<=cptcoveff;j++) { |
|
fprintf(ficreseij,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtab[k][j]]); |
|
} |
|
fprintf(ficreseij,"******\n"); |
|
|
|
eij=ma3x(1,nlstate,1,nlstate,(int) bage, (int) fage); |
|
oldm=oldms;savm=savms; |
|
evsij(eij, p, nlstate, stepm, (int) bage, (int)fage, oldm, savm, k, estepm, strstart); |
|
|
|
free_ma3x(eij,1,nlstate,1,nlstate,(int) bage, (int)fage); |
|
} |
|
} |
|
fclose(ficreseij); |
|
|
|
|
|
/*---------- Health expectancies and variances ------------*/ |
|
|
|
|
|
strcpy(filerest,"t"); |
|
strcat(filerest,fileres); |
|
if((ficrest=fopen(filerest,"w"))==NULL) { |
|
printf("Problem with total LE resultfile: %s\n", filerest);goto end; |
|
fprintf(ficlog,"Problem with total LE resultfile: %s\n", filerest);goto end; |
|
} |
|
printf("Computing Total Life expectancies with their standard errors: file '%s' \n", filerest); |
|
fprintf(ficlog,"Computing Total Life expectancies with their standard errors: file '%s' \n", filerest); |
|
|
|
|
strcpy(fileresstde,"stde"); |
strcpy(fileresstde,"stde"); |
strcat(fileresstde,fileres); |
strcat(fileresstde,fileres); |
Line 5758 Interval (in months) between two waves:
|
Line 5836 Interval (in months) between two waves:
|
printf("Computing Variance-covariance of DFLEs: file '%s' \n", fileresv); |
printf("Computing Variance-covariance of DFLEs: file '%s' \n", fileresv); |
fprintf(ficlog,"Computing Variance-covariance of DFLEs: file '%s' \n", fileresv); |
fprintf(ficlog,"Computing Variance-covariance of DFLEs: file '%s' \n", fileresv); |
|
|
/* Computes prevalence between agemin (i.e minimal age computed) and no more ageminpar */ |
|
prevalence(probs, agemin, agemax, s, agev, nlstate, imx, Tvar, nbcode, ncodemax, mint, anint, dateprev1, dateprev2, firstpass, lastpass); |
|
/* printf("ageminpar=%f, agemax=%f, s[lastpass][imx]=%d, agev[lastpass][imx]=%f, nlstate=%d, imx=%d, mint[lastpass][imx]=%f, anint[lastpass][imx]=%f,dateprev1=%f, dateprev2=%f, firstpass=%d, lastpass=%d\n",\ |
|
ageminpar, agemax, s[lastpass][imx], agev[lastpass][imx], nlstate, imx, mint[lastpass][imx],anint[lastpass][imx], dateprev1, dateprev2, firstpass, lastpass); |
|
*/ |
|
|
|
if (mobilav!=0) { |
|
mobaverage= ma3x(1, AGESUP,1,NCOVMAX, 1,NCOVMAX); |
|
if (movingaverage(probs, bage, fage, mobaverage,mobilav)!=0){ |
|
fprintf(ficlog," Error in movingaverage mobilav=%d\n",mobilav); |
|
printf(" Error in movingaverage mobilav=%d\n",mobilav); |
|
} |
|
} |
|
|
|
for(cptcov=1,k=0;cptcov<=i1;cptcov++){ |
for(cptcov=1,k=0;cptcov<=i1;cptcov++){ |
for(cptcod=1;cptcod<=ncodemax[cptcov];cptcod++){ |
for(cptcod=1;cptcod<=ncodemax[cptcov];cptcod++){ |
k=k+1; |
k=k+1; |
Line 5780 Interval (in months) between two waves:
|
Line 5844 Interval (in months) between two waves:
|
fprintf(ficrest,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtab[k][j]]); |
fprintf(ficrest,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtab[k][j]]); |
fprintf(ficrest,"******\n"); |
fprintf(ficrest,"******\n"); |
|
|
fprintf(ficreseij,"\n#****** "); |
|
fprintf(ficresstdeij,"\n#****** "); |
fprintf(ficresstdeij,"\n#****** "); |
fprintf(ficrescveij,"\n#****** "); |
fprintf(ficrescveij,"\n#****** "); |
for(j=1;j<=cptcoveff;j++) { |
for(j=1;j<=cptcoveff;j++) { |
fprintf(ficreseij,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtab[k][j]]); |
|
fprintf(ficresstdeij,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtab[k][j]]); |
fprintf(ficresstdeij,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtab[k][j]]); |
fprintf(ficrescveij,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtab[k][j]]); |
fprintf(ficrescveij,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtab[k][j]]); |
} |
} |
fprintf(ficreseij,"******\n"); |
|
fprintf(ficresstdeij,"******\n"); |
fprintf(ficresstdeij,"******\n"); |
fprintf(ficrescveij,"******\n"); |
fprintf(ficrescveij,"******\n"); |
|
|
Line 5799 Interval (in months) between two waves:
|
Line 5860 Interval (in months) between two waves:
|
|
|
eij=ma3x(1,nlstate,1,nlstate,(int) bage, (int) fage); |
eij=ma3x(1,nlstate,1,nlstate,(int) bage, (int) fage); |
oldm=oldms;savm=savms; |
oldm=oldms;savm=savms; |
evsij(fileres, eij, p, nlstate, stepm, (int) bage, (int)fage, oldm, savm, k, estepm, strstart); |
cvevsij(eij, p, nlstate, stepm, (int) bage, (int)fage, oldm, savm, k, estepm, delti, matcov, strstart); |
cvevsij(fileres, eij, p, nlstate, stepm, (int) bage, (int)fage, oldm, savm, k, estepm, delti, matcov, strstart); |
|
|
|
vareij=ma3x(1,nlstate,1,nlstate,(int) bage, (int) fage); |
vareij=ma3x(1,nlstate,1,nlstate,(int) bage, (int) fage); |
oldm=oldms;savm=savms; |
oldm=oldms;savm=savms; |
Line 5857 Interval (in months) between two waves:
|
Line 5917 Interval (in months) between two waves:
|
free_matrix(mint,1,maxwav,1,n); |
free_matrix(mint,1,maxwav,1,n); |
free_ivector(cod,1,n); |
free_ivector(cod,1,n); |
free_ivector(tab,1,NCOVMAX); |
free_ivector(tab,1,NCOVMAX); |
fclose(ficreseij); |
|
fclose(ficresstdeij); |
fclose(ficresstdeij); |
fclose(ficrescveij); |
fclose(ficrescveij); |
fclose(ficresvij); |
fclose(ficresvij); |