|
|
| version 1.98, 2004/05/16 15:05:56 | version 1.101, 2004/09/15 10:38:38 |
|---|---|
| Line 1 | Line 1 |
| /* $Id$ | /* $Id$ |
| $State$ | $State$ |
| $Log$ | $Log$ |
| Revision 1.101 2004/09/15 10:38:38 brouard | |
| Fix on curr_time | |
| Revision 1.100 2004/07/12 18:29:06 brouard | |
| Add version for Mac OS X. Just define UNIX in Makefile | |
| Revision 1.99 2004/06/05 08:57:40 brouard | |
| *** empty log message *** | |
| Revision 1.98 2004/05/16 15:05:56 brouard | Revision 1.98 2004/05/16 15:05:56 brouard |
| New version 0.97 . First attempt to estimate force of mortality | New version 0.97 . First attempt to estimate force of mortality |
| directly from the data i.e. without the need of knowing the health | directly from the data i.e. without the need of knowing the health |
| Line 196 | Line 205 |
| #include <stdlib.h> | #include <stdlib.h> |
| #include <unistd.h> | #include <unistd.h> |
| #include <sys/time.h> | /* #include <sys/time.h> */ |
| #include <time.h> | #include <time.h> |
| #include "timeval.h" | #include "timeval.h" |
| Line 224 | Line 233 |
| #define AGESUP 130 | #define AGESUP 130 |
| #define AGEBASE 40 | #define AGEBASE 40 |
| #define AGEGOMP 10. /* Minimal age for Gompertz adjustment */ | #define AGEGOMP 10. /* Minimal age for Gompertz adjustment */ |
| #ifdef unix | #ifdef UNIX |
| #define DIRSEPARATOR '/' | #define DIRSEPARATOR '/' |
| #define ODIRSEPARATOR '\\' | #define ODIRSEPARATOR '\\' |
| #else | #else |
| Line 235 | Line 244 |
| /* $Id$ */ | /* $Id$ */ |
| /* $State$ */ | /* $State$ */ |
| char version[]="Imach version 0.70, May 2004, INED-EUROREVES "; | char version[]="Imach version 0.97b, May 2004, INED-EUROREVES "; |
| char fullversion[]="$Revision$ $Date$"; | char fullversion[]="$Revision$ $Date$"; |
| int erreur, nberr=0, nbwarn=0; /* Error number, number of errors number of warnings */ | int erreur, nberr=0, nbwarn=0; /* Error number, number of errors number of warnings */ |
| int nvar; | int nvar; |
| Line 356 double ftolhess; /* Tolerance for comput | Line 365 double ftolhess; /* Tolerance for comput |
| /**************** split *************************/ | /**************** split *************************/ |
| static int split( char *path, char *dirc, char *name, char *ext, char *finame ) | static int split( char *path, char *dirc, char *name, char *ext, char *finame ) |
| { | { |
| /* From a file name with full path (either Unix or Windows) we extract the directory (dirc) | |
| the name of the file (name), its extension only (ext) and its first part of the name (finame) | |
| */ | |
| char *ss; /* pointer */ | char *ss; /* pointer */ |
| int l1, l2; /* length counters */ | int l1, l2; /* length counters */ |
| Line 387 static int split( char *path, char *dirc | Line 399 static int split( char *path, char *dirc |
| #endif | #endif |
| */ | */ |
| ss = strrchr( name, '.' ); /* find last / */ | ss = strrchr( name, '.' ); /* find last / */ |
| ss++; | if (ss >0){ |
| strcpy(ext,ss); /* save extension */ | ss++; |
| l1= strlen( name); | strcpy(ext,ss); /* save extension */ |
| l2= strlen(ss)+1; | l1= strlen( name); |
| strncpy( finame, name, l1-l2); | l2= strlen(ss)+1; |
| finame[l1-l2]= 0; | strncpy( finame, name, l1-l2); |
| finame[l1-l2]= 0; | |
| } | |
| return( 0 ); /* we're done */ | return( 0 ); /* we're done */ |
| } | } |
| Line 868 void powell(double p[], double **xi, int | Line 882 void powell(double p[], double **xi, int |
| fprintf(ficrespow,"\n");fflush(ficrespow); | fprintf(ficrespow,"\n");fflush(ficrespow); |
| if(*iter <=3){ | if(*iter <=3){ |
| tm = *localtime(&curr_time.tv_sec); | tm = *localtime(&curr_time.tv_sec); |
| strcpy(strcurr,asctime(&tmf)); | strcpy(strcurr,asctime(&tm)); |
| /* asctime_r(&tm,strcurr); */ | /* asctime_r(&tm,strcurr); */ |
| forecast_time=curr_time; | forecast_time=curr_time; |
| itmp = strlen(strcurr); | itmp = strlen(strcurr); |
| if(strcurr[itmp-1]=='\n') | if(strcurr[itmp-1]=='\n') /* Windows outputs with a new line */ |
| strcurr[itmp-1]='\0'; | strcurr[itmp-1]='\0'; |
| printf("\nConsidering the time needed for this last iteration #%d: %ld seconds,\n",*iter,curr_time.tv_sec-last_time.tv_sec); | printf("\nConsidering the time needed for this last iteration #%d: %ld seconds,\n",*iter,curr_time.tv_sec-last_time.tv_sec); |
| fprintf(ficlog,"\nConsidering the time needed for this last iteration #%d: %ld seconds,\n",*iter,curr_time.tv_sec-last_time.tv_sec); | fprintf(ficlog,"\nConsidering the time needed for this last iteration #%d: %ld seconds,\n",*iter,curr_time.tv_sec-last_time.tv_sec); |
| Line 884 void powell(double p[], double **xi, int | Line 898 void powell(double p[], double **xi, int |
| itmp = strlen(strfor); | itmp = strlen(strfor); |
| if(strfor[itmp-1]=='\n') | if(strfor[itmp-1]=='\n') |
| strfor[itmp-1]='\0'; | strfor[itmp-1]='\0'; |
| printf(" - if your program needs %d iterations to converge, convergence will be \n reached in %s or\n on %s (current time is %s);\n",niterf, asc_diff_time(forecast_time.tv_sec-curr_time.tv_sec,tmpout),strfor,strcurr); | printf(" - if your program needs %d iterations to converge, convergence will be \n reached in %s i.e.\n on %s (current time is %s);\n",niterf, asc_diff_time(forecast_time.tv_sec-curr_time.tv_sec,tmpout),strfor,strcurr); |
| fprintf(ficlog," - if your program needs %d iterations to converge, convergence will be \n reached in %s or\n on %s (current time is %s);\n",niterf, asc_diff_time(forecast_time.tv_sec-curr_time.tv_sec,tmpout),strfor,strcurr); | fprintf(ficlog," - if your program needs %d iterations to converge, convergence will be \n reached in %s i.e.\n on %s (current time is %s);\n",niterf, asc_diff_time(forecast_time.tv_sec-curr_time.tv_sec,tmpout),strfor,strcurr); |
| } | } |
| } | } |
| for (i=1;i<=n;i++) { | for (i=1;i<=n;i++) { |
| Line 1050 double **pmij(double **ps, double *cov, | Line 1064 double **pmij(double **ps, double *cov, |
| int i,j,j1, nc, ii, jj; | int i,j,j1, nc, ii, jj; |
| for(i=1; i<= nlstate; i++){ | for(i=1; i<= nlstate; i++){ |
| for(j=1; j<i;j++){ | for(j=1; j<i;j++){ |
| for (nc=1, s2=0.;nc <=ncovmodel; nc++){ | for (nc=1, s2=0.;nc <=ncovmodel; nc++){ |
| /*s2 += param[i][j][nc]*cov[nc];*/ | /*s2 += param[i][j][nc]*cov[nc];*/ |
| s2 += x[(i-1)*nlstate*ncovmodel+(j-1)*ncovmodel+nc+(i-1)*(ndeath-1)*ncovmodel]*cov[nc]; | s2 += x[(i-1)*nlstate*ncovmodel+(j-1)*ncovmodel+nc+(i-1)*(ndeath-1)*ncovmodel]*cov[nc]; |
| /*printf("Int j<i s1=%.17e, s2=%.17e\n",s1,s2);*/ | /* printf("Int j<i s1=%.17e, s2=%.17e\n",s1,s2); */ |
| } | } |
| ps[i][j]=s2; | ps[i][j]=s2; |
| /*printf("s1=%.17e, s2=%.17e\n",s1,s2);*/ | /* printf("s1=%.17e, s2=%.17e\n",s1,s2); */ |
| } | } |
| for(j=i+1; j<=nlstate+ndeath;j++){ | for(j=i+1; j<=nlstate+ndeath;j++){ |
| for (nc=1, s2=0.;nc <=ncovmodel; nc++){ | for (nc=1, s2=0.;nc <=ncovmodel; nc++){ |
| s2 += x[(i-1)*nlstate*ncovmodel+(j-2)*ncovmodel+nc+(i-1)*(ndeath-1)*ncovmodel]*cov[nc]; | s2 += x[(i-1)*nlstate*ncovmodel+(j-2)*ncovmodel+nc+(i-1)*(ndeath-1)*ncovmodel]*cov[nc]; |
| /*printf("Int j>i s1=%.17e, s2=%.17e %lx %lx\n",s1,s2,s1,s2);*/ | /* printf("Int j>i s1=%.17e, s2=%.17e %lx %lx\n",s1,s2,s1,s2); */ |
| } | |
| ps[i][j]=s2; | |
| } | } |
| ps[i][j]=s2; | |
| } | } |
| } | |
| /*ps[3][2]=1;*/ | /*ps[3][2]=1;*/ |
| for(i=1; i<= nlstate; i++){ | for(i=1; i<= nlstate; i++){ |
| s1=0; | s1=0; |
| for(j=1; j<i; j++) | for(j=1; j<i; j++) |
| s1+=exp(ps[i][j]); | s1+=exp(ps[i][j]); |
| for(j=i+1; j<=nlstate+ndeath; j++) | for(j=i+1; j<=nlstate+ndeath; j++) |
| s1+=exp(ps[i][j]); | s1+=exp(ps[i][j]); |
| ps[i][i]=1./(s1+1.); | ps[i][i]=1./(s1+1.); |
| for(j=1; j<i; j++) | for(j=1; j<i; j++) |
| ps[i][j]= exp(ps[i][j])*ps[i][i]; | ps[i][j]= exp(ps[i][j])*ps[i][i]; |
| for(j=i+1; j<=nlstate+ndeath; j++) | for(j=i+1; j<=nlstate+ndeath; j++) |
| ps[i][j]= exp(ps[i][j])*ps[i][i]; | ps[i][j]= exp(ps[i][j])*ps[i][i]; |
| /* ps[i][nlstate+1]=1.-s1- ps[i][i];*/ /* Sum should be 1 */ | /* ps[i][nlstate+1]=1.-s1- ps[i][i];*/ /* Sum should be 1 */ |
| } /* end i */ | } /* end i */ |
| for(ii=nlstate+1; ii<= nlstate+ndeath; ii++){ | for(ii=nlstate+1; ii<= nlstate+ndeath; ii++){ |
| for(jj=1; jj<= nlstate+ndeath; jj++){ | for(jj=1; jj<= nlstate+ndeath; jj++){ |
| ps[ii][jj]=0; | ps[ii][jj]=0; |
| ps[ii][ii]=1; | ps[ii][ii]=1; |
| } | |
| } | } |
| } | |
| /* for(ii=1; ii<= nlstate+ndeath; ii++){ | /* for(ii=1; ii<= nlstate+ndeath; ii++){ */ |
| for(jj=1; jj<= nlstate+ndeath; jj++){ | /* for(jj=1; jj<= nlstate+ndeath; jj++){ */ |
| printf("%lf ",ps[ii][jj]); | /* printf("ddd %lf ",ps[ii][jj]); */ |
| } | /* } */ |
| printf("\n "); | /* printf("\n "); */ |
| } | /* } */ |
| printf("\n ");printf("%lf ",cov[2]);*/ | /* printf("\n ");printf("%lf ",cov[2]); */ |
| /* | /* |
| for(i=1; i<= npar; i++) printf("%f ",x[i]); | for(i=1; i<= npar; i++) printf("%f ",x[i]); |
| goto end;*/ | goto end;*/ |
| return ps; | return ps; |
| } | } |
| Line 1224 double func( double *x) | Line 1238 double func( double *x) |
| } /* end mult */ | } /* end mult */ |
| /*lli=log(out[s[mw[mi][i]][i]][s[mw[mi+1][i]][i]]);*/ /* Original formula */ | /*lli=log(out[s[mw[mi][i]][i]][s[mw[mi+1][i]][i]]);*/ /* Original formula */ |
| /* But now since version 0.9 we anticipate for bias and large stepm. | /* But now since version 0.9 we anticipate for bias at large stepm. |
| * If stepm is larger than one month (smallest stepm) and if the exact delay | * If stepm is larger than one month (smallest stepm) and if the exact delay |
| * (in months) between two waves is not a multiple of stepm, we rounded to | * (in months) between two waves is not a multiple of stepm, we rounded to |
| * the nearest (and in case of equal distance, to the lowest) interval but now | * the nearest (and in case of equal distance, to the lowest) interval but now |
| * we keep into memory the bias bh[mi][i] and also the previous matrix product | * we keep into memory the bias bh[mi][i] and also the previous matrix product |
| * (i.e to dh[mi][i]-1) saved in 'savm'. The we inter(extra)polate the | * (i.e to dh[mi][i]-1) saved in 'savm'. Then we inter(extra)polate the |
| * probability in order to take into account the bias as a fraction of the way | * probability in order to take into account the bias as a fraction of the way |
| * from savm to out if bh is neagtive or even beyond if bh is positive. bh varies | * from savm to out if bh is negative or even beyond if bh is positive. bh varies |
| * -stepm/2 to stepm/2 . | * -stepm/2 to stepm/2 . |
| * For stepm=1 the results are the same as for previous versions of Imach. | * For stepm=1 the results are the same as for previous versions of Imach. |
| * For stepm > 1 the results are less biased than in previous versions. | * For stepm > 1 the results are less biased than in previous versions. |
| Line 1239 double func( double *x) | Line 1253 double func( double *x) |
| s1=s[mw[mi][i]][i]; | s1=s[mw[mi][i]][i]; |
| s2=s[mw[mi+1][i]][i]; | s2=s[mw[mi+1][i]][i]; |
| bbh=(double)bh[mi][i]/(double)stepm; | bbh=(double)bh[mi][i]/(double)stepm; |
| /* bias is positive if real duration | /* bias bh is positive if real duration |
| * is higher than the multiple of stepm and negative otherwise. | * is higher than the multiple of stepm and negative otherwise. |
| */ | */ |
| /* lli= (savm[s1][s2]>1.e-8 ?(1.+bbh)*log(out[s1][s2])- bbh*log(savm[s1][s2]):log((1.+bbh)*out[s1][s2]));*/ | /* lli= (savm[s1][s2]>1.e-8 ?(1.+bbh)*log(out[s1][s2])- bbh*log(savm[s1][s2]):log((1.+bbh)*out[s1][s2]));*/ |
| if( s2 > nlstate){ | if( s2 > nlstate){ |
| /* i.e. if s2 is a death state and if the date of death is known then the contribution | /* i.e. if s2 is a death state and if the date of death is known then the contribution |
| to the likelihood is the probability to die between last step unit time and current | to the likelihood is the probability to die between last step unit time and current |
| step unit time, which is also the differences between probability to die before dh | step unit time, which is also equal to probability to die before dh |
| and probability to die before dh-stepm . | minus probability to die before dh-stepm . |
| In version up to 0.92 likelihood was computed | In version up to 0.92 likelihood was computed |
| as if date of death was unknown. Death was treated as any other | as if date of death was unknown. Death was treated as any other |
| health state: the date of the interview describes the actual state | health state: the date of the interview describes the actual state |
| Line 4003 int main(int argc, char *argv[]) | Line 4017 int main(int argc, char *argv[]) |
| int *indx; | int *indx; |
| char line[MAXLINE], linepar[MAXLINE]; | char line[MAXLINE], linepar[MAXLINE]; |
| char path[MAXLINE],pathc[MAXLINE],pathcd[MAXLINE],pathtot[MAXLINE],model[MAXLINE]; | char path[MAXLINE],pathc[MAXLINE],pathcd[MAXLINE],pathtot[MAXLINE],model[MAXLINE]; |
| char pathr[MAXLINE]; | char pathr[MAXLINE], pathimach[MAXLINE]; |
| int firstobs=1, lastobs=10; | int firstobs=1, lastobs=10; |
| int sdeb, sfin; /* Status at beginning and end */ | int sdeb, sfin; /* Status at beginning and end */ |
| int c, h , cpt,l; | int c, h , cpt,l; |
| Line 4089 int main(int argc, char *argv[]) | Line 4103 int main(int argc, char *argv[]) |
| printf("pathtot=%s, path=%s, optionfile=%s\n",pathtot,path,optionfile);*/ | printf("pathtot=%s, path=%s, optionfile=%s\n",pathtot,path,optionfile);*/ |
| /* cutv(path,optionfile,pathtot,'\\');*/ | /* cutv(path,optionfile,pathtot,'\\');*/ |
| split(argv[0],pathimach,optionfile,optionfilext,optionfilefiname); | |
| /* strcpy(pathimach,argv[0]); */ | |
| split(pathtot,path,optionfile,optionfilext,optionfilefiname); | split(pathtot,path,optionfile,optionfilext,optionfilefiname); |
| printf("pathtot=%s,\npath=%s,\noptionfile=%s \noptionfilext=%s \noptionfilefiname=%s\n",pathtot,path,optionfile,optionfilext,optionfilefiname); | printf("pathimach=%s, pathtot=%s,\npath=%s,\noptionfile=%s \noptionfilext=%s \noptionfilefiname=%s\n",pathimach,pathtot,path,optionfile,optionfilext,optionfilefiname); |
| chdir(path); | chdir(path); |
| strcpy(command,"mkdir "); | strcpy(command,"mkdir "); |
| strcat(command,optionfilefiname); | strcat(command,optionfilefiname); |
| Line 4115 int main(int argc, char *argv[]) | Line 4131 int main(int argc, char *argv[]) |
| } | } |
| fprintf(ficlog,"Log filename:%s\n",filelog); | fprintf(ficlog,"Log filename:%s\n",filelog); |
| fprintf(ficlog,"\n%s\n%s",version,fullversion); | fprintf(ficlog,"\n%s\n%s",version,fullversion); |
| fprintf(ficlog,"\nEnter the parameter file name: "); | fprintf(ficlog,"\nEnter the parameter file name: \n"); |
| fprintf(ficlog,"pathtot=%s\n\ | fprintf(ficlog,"pathimach=%s\npathtot=%s\n\ |
| path=%s \n\ | path=%s \n\ |
| optionfile=%s\n\ | optionfile=%s\n\ |
| optionfilext=%s\n\ | optionfilext=%s\n\ |
| optionfilefiname=%s\n",pathtot,path,optionfile,optionfilext,optionfilefiname); | optionfilefiname=%s\n",pathimach,pathtot,path,optionfile,optionfilext,optionfilefiname); |
| printf("Local time (at start):%s",strstart); | printf("Local time (at start):%s",strstart); |
| fprintf(ficlog,"Local time (at start): %s",strstart); | fprintf(ficlog,"Local time (at start): %s",strstart); |
| Line 5411 Interval (in months) between two waves: | Line 5427 Interval (in months) between two waves: |
| /*------ End -----------*/ | /*------ End -----------*/ |
| chdir(path); | chdir(path); |
| strcpy(plotcmd,GNUPLOTPROGRAM); | strcpy(plotcmd,"\""); |
| strcat(plotcmd,pathimach); | |
| strcat(plotcmd,GNUPLOTPROGRAM); | |
| strcat(plotcmd,"\""); | |
| strcat(plotcmd," "); | strcat(plotcmd," "); |
| strcat(plotcmd,optionfilegnuplot); | strcat(plotcmd,optionfilegnuplot); |
| printf("Starting graphs with: %s",plotcmd);fflush(stdout); | printf("Starting graphs with: %s",plotcmd);fflush(stdout); |
| Line 5424 Interval (in months) between two waves: | Line 5443 Interval (in months) between two waves: |
| printf("\nType e to edit output files, g to graph again and q for exiting: "); | printf("\nType e to edit output files, g to graph again and q for exiting: "); |
| scanf("%s",z); | scanf("%s",z); |
| /* if (z[0] == 'c') system("./imach"); */ | /* if (z[0] == 'c') system("./imach"); */ |
| if (z[0] == 'e') system(optionfilehtm); | if (z[0] == 'e') { |
| printf("Starting browser with: %s",optionfilehtm);fflush(stdout); | |
| system(optionfilehtm); | |
| } | |
| else if (z[0] == 'g') system(plotcmd); | else if (z[0] == 'g') system(plotcmd); |
| else if (z[0] == 'q') exit(0); | else if (z[0] == 'q') exit(0); |
| } | } |