Diff for /imach/src/imach.c between versions 1.21 and 1.22

version 1.21, 2002/02/21 18:42:24 version 1.22, 2002/02/22 17:54:20
Line 1 Line 1
      /* $Id$
 /*********************** Imach **************************************             Interpolate Markov Chain
   This program computes Healthy Life Expectancies from cross-longitudinal  
   data. Cross-longitudinal consist in a first survey ("cross") where    Short summary of the programme:
   individuals from different ages are interviewed on their health status   
   or degree of  disability. At least a second wave of interviews    This program computes Healthy Life Expectancies from
   ("longitudinal") should  measure each new individual health status.    cross-longitudinal data. Cross-longitudinal data consist in: -1- a
   Health expectancies are computed from the transistions observed between    first survey ("cross") where individuals from different ages are
   waves and are computed for each degree of severity of disability (number    interviewed on their health status or degree of disability (in the
   of life states). More degrees you consider, more time is necessary to    case of a health survey which is our main interest) -2- at least a
   reach the Maximum Likelihood of the parameters involved in the model.    second wave of interviews ("longitudinal") which measure each change
   The simplest model is the multinomial logistic model where pij is    (if any) in individual health status.  Health expectancies are
   the probabibility to be observed in state j at the second wave conditional    computed from the time spent in each health state according to a
   to be observed in state i at the first wave. Therefore the model is:    model. More health states you consider, more time is necessary to reach the
   log(pij/pii)= aij + bij*age+ cij*sex + etc , where 'age' is age and 'sex'    Maximum Likelihood of the parameters involved in the model.  The
   is a covariate. If you want to have a more complex model than "constant and    simplest model is the multinomial logistic model where pij is the
   age", you should modify the program where the markup    probabibility to be observed in state j at the second wave
     *Covariates have to be included here again* invites you to do it.    conditional to be observed in state i at the first wave. Therefore
   More covariates you add, less is the speed of the convergence.    the model is: log(pij/pii)= aij + bij*age+ cij*sex + etc , where
     'age' is age and 'sex' is a covariate. If you want to have a more
   The advantage that this computer programme claims, comes from that if the    complex model than "constant and age", you should modify the program
   delay between waves is not identical for each individual, or if some    where the markup *Covariates have to be included here again* invites
   individual missed an interview, the information is not rounded or lost, but    you to do it.  More covariates you add, slower the
   taken into account using an interpolation or extrapolation.    convergence.
   hPijx is the probability to be  
   observed in state i at age x+h conditional to the observed state i at age    The advantage of this computer programme, compared to a simple
   x. The delay 'h' can be split into an exact number (nh*stepm) of    multinomial logistic model, is clear when the delay between waves is not
   unobserved intermediate  states. This elementary transition (by month or    identical for each individual. Also, if a individual missed an
   quarter trimester, semester or year) is model as a multinomial logistic.    intermediate interview, the information is lost, but taken into
   The hPx matrix is simply the matrix product of nh*stepm elementary matrices    account using an interpolation or extrapolation.  
   and the contribution of each individual to the likelihood is simply hPijx.  
     hPijx is the probability to be observed in state i at age x+h
     conditional to the observed state i at age x. The delay 'h' can be
     split into an exact number (nh*stepm) of unobserved intermediate
     states. This elementary transition (by month or quarter trimester,
     semester or year) is model as a multinomial logistic.  The hPx
     matrix is simply the matrix product of nh*stepm elementary matrices
     and the contribution of each individual to the likelihood is simply
     hPijx.
   
   Also this programme outputs the covariance matrix of the parameters but also    Also this programme outputs the covariance matrix of the parameters but also
   of the life expectancies. It also computes the prevalence limits.    of the life expectancies. It also computes the prevalence limits.
Line 48 Line 56
 #include <unistd.h>  #include <unistd.h>
   
 #define MAXLINE 256  #define MAXLINE 256
   #define GNUPLOTPROGRAM "..\\gp37mgw\\wgnuplot"
 #define FILENAMELENGTH 80  #define FILENAMELENGTH 80
 /*#define DEBUG*/  /*#define DEBUG*/
 #define windows  #define windows
Line 141  double ftol=FTOL; /* Tolerance for compu Line 150  double ftol=FTOL; /* Tolerance for compu
 double ftolhess; /* Tolerance for computing hessian */  double ftolhess; /* Tolerance for computing hessian */
   
 /**************** split *************************/  /**************** split *************************/
 static  int split( char *path, char *dirc, char *name )  static  int split( char *path, char *dirc, char *name, char *ext, char *finame )
 {  {
    char *s;                             /* pointer */     char *s;                             /* pointer */
    int  l1, l2;                         /* length counters */     int  l1, l2;                         /* length counters */
   
    l1 = strlen( path );                 /* length of path */     l1 = strlen( path );                 /* length of path */
    if ( l1 == 0 ) return( GLOCK_ERROR_NOPATH );     if ( l1 == 0 ) return( GLOCK_ERROR_NOPATH );
   #ifdef windows
    s = strrchr( path, '\\' );           /* find last / */     s = strrchr( path, '\\' );           /* find last / */
   #else
      s = strrchr( path, '/' );            /* find last / */
   #endif
    if ( s == NULL ) {                   /* no directory, so use current */     if ( s == NULL ) {                   /* no directory, so use current */
 #if     defined(__bsd__)                /* get current working directory */  #if     defined(__bsd__)                /* get current working directory */
       extern char       *getwd( );        extern char       *getwd( );
Line 171  static int split( char *path, char *dirc Line 184  static int split( char *path, char *dirc
       dirc[l1-l2] = 0;                  /* add zero */        dirc[l1-l2] = 0;                  /* add zero */
    }     }
    l1 = strlen( dirc );                 /* length of directory */     l1 = strlen( dirc );                 /* length of directory */
   #ifdef windows
    if ( dirc[l1-1] != '\\' ) { dirc[l1] = '\\'; dirc[l1+1] = 0; }     if ( dirc[l1-1] != '\\' ) { dirc[l1] = '\\'; dirc[l1+1] = 0; }
   #else
      if ( dirc[l1-1] != '/' ) { dirc[l1] = '/'; dirc[l1+1] = 0; }
   #endif
      s = strrchr( name, '.' );            /* find last / */
      s++;
      strcpy(ext,s);                       /* save extension */
      l1= strlen( name);
      l2= strlen( s)+1;
      strncpy( finame, name, l1-l2);
      finame[l1-l2]= 0;
    return( 0 );                         /* we're done */     return( 0 );                         /* we're done */
 }  }
   
Line 719  double **pmij(double **ps, double *cov, Line 743  double **pmij(double **ps, double *cov,
         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;*/
Line 1859  fclose(ficresprob); Line 1883  fclose(ficresprob);
 /**************** Main Program *****************/  /**************** Main Program *****************/
 /***********************************************/  /***********************************************/
   
 /*int main(int argc, char *argv[])*/  int main(int argc, char *argv[])
 int main()  
 {  {
   
   int i,j, k, n=MAXN,iter,m,size,cptcode, cptcod;    int i,j, k, n=MAXN,iter,m,size,cptcode, cptcod;
Line 1876  int main() Line 1899  int main()
   char line[MAXLINE], linepar[MAXLINE];    char line[MAXLINE], linepar[MAXLINE];
   char title[MAXLINE];    char title[MAXLINE];
   char optionfile[FILENAMELENGTH], datafile[FILENAMELENGTH],  filerespl[FILENAMELENGTH], optionfilehtm[FILENAMELENGTH];    char optionfile[FILENAMELENGTH], datafile[FILENAMELENGTH],  filerespl[FILENAMELENGTH], optionfilehtm[FILENAMELENGTH];
   char fileres[FILENAMELENGTH], filerespij[FILENAMELENGTH], filereso[FILENAMELENGTH], fileresf[FILENAMELENGTH];    char optionfilext[10], optionfilefiname[FILENAMELENGTH], optionfilegnuplot[FILENAMELENGTH], plotcmd[FILENAMELENGTH];
    
     char fileres[FILENAMELENGTH], filerespij[FILENAMELENGTH], filereso[FILENAMELENGTH], fileresf[FILENAMELENGTH];;
   
   char filerest[FILENAMELENGTH];    char filerest[FILENAMELENGTH];
   char fileregp[FILENAMELENGTH];    char fileregp[FILENAMELENGTH];
   char popfile[FILENAMELENGTH];    char popfile[FILENAMELENGTH];
Line 1909  int main() Line 1935  int main()
   double dateprev1, dateprev2,jproj1,mproj1,anproj1,jproj2,mproj2,anproj2,jprojmean,mprojmean,anprojmean, calagedate;    double dateprev1, dateprev2,jproj1,mproj1,anproj1,jproj2,mproj2,anproj2,jprojmean,mprojmean,anprojmean, calagedate;
   double yp,yp1,yp2;    double yp,yp1,yp2;
   
   char version[80]="Imach version 64b, May 2001, INED-EUROREVES ";    char version[80]="Imach version 0.7, February 2002, INED-EUROREVES ";
   char *alph[]={"a","a","b","c","d","e"}, str[4];    char *alph[]={"a","a","b","c","d","e"}, str[4];
   
   
Line 1924  int main() Line 1950  int main()
   gettimeofday(&start_time, (struct timezone*)0); */ /* at first time */    gettimeofday(&start_time, (struct timezone*)0); */ /* at first time */
   
   
   printf("\nIMACH, Version 0.7");    printf("\n%s",version);
   printf("\nEnter the parameter file name: ");    if(argc <=1){
       printf("\nEnter the parameter file name: ");
 #ifdef windows      scanf("%s",pathtot);
   scanf("%s",pathtot);    }
   getcwd(pathcd, size);    else{
       strcpy(pathtot,argv[1]);
     }
     /*if(getcwd(pathcd, 80)!= NULL)printf ("Error pathcd\n");*/
   /*cygwin_split_path(pathtot,path,optionfile);    /*cygwin_split_path(pathtot,path,optionfile);
     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(pathtot, path,optionfile);    split(pathtot,path,optionfile,optionfilext,optionfilefiname);
      printf("pathtot=%s, path=%s, optionfile=%s optionfilext=%s optionfilefiname=%s\n",pathtot,path,optionfile,optionfilext,optionfilefiname);
   chdir(path);    chdir(path);
   replace(pathc,path);    replace(pathc,path);
 #endif  
 #ifdef unix  
   scanf("%s",optionfile);  
 #endif  
   
 /*-------- arguments in the command line --------*/  /*-------- arguments in the command line --------*/
   
   strcpy(fileres,"r");    strcpy(fileres,"r");
   strcat(fileres, optionfile);    strcat(fileres, optionfilefiname);
     strcat(fileres,".txt");    /* Other files have txt extension */
   
   /*---------arguments file --------*/    /*---------arguments file --------*/
   
Line 2324  printf("Total number of individuals= %d, Line 2351  printf("Total number of individuals= %d,
        }         }
      }       }
    }     }
   
   
      /*for(i=1; i <=m ;i++){
        for(k=1; k <=cptcovn; k++){
          printf("i=%d k=%d %d %d",i,k,codtab[i][k], cptcoveff);
        }
        printf("\n");
      }
      scanf("%d",i);*/
         
    /* Calculates basic frequencies. Computes observed prevalence at single age     /* Calculates basic frequencies. Computes observed prevalence at single age
        and prints on file fileres'p'. */         and prints on file fileres'p'. */
Line 2423  printf("Total number of individuals= %d, Line 2459  printf("Total number of individuals= %d,
       bage = agemin;        bage = agemin;
       fage = agemax;        fage = agemax;
     }      }
      
     fprintf(ficres,"# agemin agemax for life expectancy.\n");      fprintf(ficres,"# agemin agemax for life expectancy, bage fage (if mle==0 ie no data nor Max likelihood).\n");
   
     fprintf(ficres,"agemin=%.0f agemax=%.0f bage=%.0f fage=%.0f\n",agemin,agemax,bage,fage);      fprintf(ficres,"agemin=%.0f agemax=%.0f bage=%.0f fage=%.0f\n",agemin,agemax,bage,fage);
     fprintf(ficparo,"agemin=%.0f agemax=%.0f bage=%.0f fage=%.0f\n",agemin,agemax,bage,fage);      fprintf(ficparo,"agemin=%.0f agemax=%.0f bage=%.0f fage=%.0f\n",agemin,agemax,bage,fage);
     
Line 2470  fprintf(ficres,"popforecast=%d popfile=% Line 2505  fprintf(ficres,"popforecast=%d popfile=%
   
  freqsummary(fileres, agemin, agemax, s, agev, nlstate, imx,Tvar,nbcode, ncodemax,mint,anint,dateprev1,dateprev2);   freqsummary(fileres, agemin, agemax, s, agev, nlstate, imx,Tvar,nbcode, ncodemax,mint,anint,dateprev1,dateprev2);
   
  /*------------ gnuplot -------------*/     
 chdir(pathcd);      /*------------ gnuplot -------------*/
   if((ficgp=fopen("graph.plt","w"))==NULL) {      /*chdir(pathcd);*/
     printf("Problem with file graph.gp");goto end;      strcpy(optionfilegnuplot,optionfilefiname);
   }      strcat(optionfilegnuplot,".plt");
       if((ficgp=fopen(optionfilegnuplot,"w"))==NULL) {
         printf("Problem with file %s",optionfilegnuplot);goto end;
       }
 #ifdef windows  #ifdef windows
   fprintf(ficgp,"cd \"%s\" \n",pathc);      fprintf(ficgp,"cd \"%s\" \n",pathc);
 #endif  #endif
 m=pow(2,cptcoveff);  m=pow(2,cptcoveff);
     
Line 3122  strcpy(fileresvpl,"vpl"); Line 3160  strcpy(fileresvpl,"vpl");
   
  end:   end:
 #ifdef windows  #ifdef windows
  chdir(pathcd);    /* chdir(pathcd);*/
 #endif  #endif
     /*system("wgnuplot graph.plt");*/
  system("..\\gp37mgw\\wgnuplot graph.plt");   /*system("../gp37mgw/wgnuplot graph.plt");*/
    /*system("cd ../gp37mgw");*/
    /* system("..\\gp37mgw\\wgnuplot graph.plt");*/
    strcpy(plotcmd,GNUPLOTPROGRAM);
    strcat(plotcmd," ");
    strcat(plotcmd,optionfilegnuplot);
    system(plotcmd);
   
 #ifdef windows  #ifdef windows
   while (z[0] != 'q') {    while (z[0] != 'q') {
     chdir(pathcd);      chdir(path);
     printf("\nType e to edit output files, c to start again, and q for exiting: ");      printf("\nType e to edit output files, c to start again, and q for exiting: ");
     scanf("%s",z);      scanf("%s",z);
     if (z[0] == 'c') system("./imach");      if (z[0] == 'c') system("./imach");

Removed from v.1.21  
changed lines
  Added in v.1.22


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>