--- imach/src/imach.c 2006/04/28 17:23:28 1.126 +++ imach/src/imach.c 2006/04/28 18:11:50 1.127 @@ -1,6 +1,18 @@ -/* $Id: imach.c,v 1.126 2006/04/28 17:23:28 brouard Exp $ +/* $Id: imach.c,v 1.127 2006/04/28 18:11:50 brouard Exp $ $State: Exp $ $Log: imach.c,v $ + 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 @@ -371,11 +383,11 @@ extern int errno; #define ODIRSEPARATOR '/' #endif -/* $Id: imach.c,v 1.126 2006/04/28 17:23:28 brouard Exp $ */ +/* $Id: imach.c,v 1.127 2006/04/28 18:11:50 brouard Exp $ */ /* $State: Exp $ */ char version[]="Imach version 0.98h, April 2006, INED-EUROREVES-Institut de longevite "; -char fullversion[]="$Revision: 1.126 $ $Date: 2006/04/28 17:23:28 $"; +char fullversion[]="$Revision: 1.127 $ $Date: 2006/04/28 18:11:50 $"; char strstart[80]; char optionfilext[10], optionfilefiname[FILENAMELENGTH]; int erreur, nberr=0, nbwarn=0; /* Error number, number of errors number of warnings */ @@ -2467,7 +2479,7 @@ void tricode(int *Tvar, int **nbcode, in /*********** 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 */ @@ -2575,7 +2587,7 @@ 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 @@ -5739,18 +5751,24 @@ 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"); - 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; + 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); + } } - 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"); strcat(filerese,fileres); if((ficreseij=fopen(filerese,"w"))==NULL) { @@ -5759,6 +5777,37 @@ Interval (in months) between two waves: } printf("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"); strcat(fileresstde,fileres); @@ -5787,20 +5836,6 @@ Interval (in months) between two waves: printf("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(cptcod=1;cptcod<=ncodemax[cptcov];cptcod++){ k=k+1; @@ -5809,15 +5844,12 @@ Interval (in months) between two waves: fprintf(ficrest,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtab[k][j]]); fprintf(ficrest,"******\n"); - fprintf(ficreseij,"\n#****** "); fprintf(ficresstdeij,"\n#****** "); fprintf(ficrescveij,"\n#****** "); 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(ficrescveij,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtab[k][j]]); } - fprintf(ficreseij,"******\n"); fprintf(ficresstdeij,"******\n"); fprintf(ficrescveij,"******\n"); @@ -5828,8 +5860,7 @@ Interval (in months) between two waves: eij=ma3x(1,nlstate,1,nlstate,(int) bage, (int) fage); oldm=oldms;savm=savms; - evsij(fileres, eij, p, nlstate, stepm, (int) bage, (int)fage, oldm, savm, k, estepm, strstart); - cvevsij(fileres, eij, p, nlstate, stepm, (int) bage, (int)fage, oldm, savm, k, estepm, delti, matcov, strstart); + cvevsij(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); oldm=oldms;savm=savms; @@ -5886,7 +5917,6 @@ Interval (in months) between two waves: free_matrix(mint,1,maxwav,1,n); free_ivector(cod,1,n); free_ivector(tab,1,NCOVMAX); - fclose(ficreseij); fclose(ficresstdeij); fclose(ficrescveij); fclose(ficresvij);