Diff for /imach064/src/imach.c between versions 1.2 and 1.4

version 1.2, 2001/03/13 18:10:26 version 1.4, 2001/05/02 17:34:41
Line 59 Line 59
 #define NLSTATEMAX 8 /* Maximum number of live states (for func) */  #define NLSTATEMAX 8 /* Maximum number of live states (for func) */
 #define NDEATHMAX 8 /* Maximum number of dead states (for func) */  #define NDEATHMAX 8 /* Maximum number of dead states (for func) */
 #define NCOVMAX 8 /* Maximum number of covariates */  #define NCOVMAX 8 /* Maximum number of covariates */
 #define MAXN 80000  #define MAXN 20000
 #define YEARM 12. /* Number of months per year */  #define YEARM 12. /* Number of months per year */
 #define AGESUP 130  #define AGESUP 130
 #define AGEBASE 40  #define AGEBASE 40
Line 168  void cutv(char *u,char *v, char*t, char Line 168  void cutv(char *u,char *v, char*t, char
 {  {
   int i,lg,j,p;    int i,lg,j,p;
   i=0;    i=0;
   if (t[0]== occ) p=0;  
   for(j=0; j<=strlen(t)-1; j++) {    for(j=0; j<=strlen(t)-1; j++) {
     if((t[j]!= occ) && (t[j+1]==occ)) p=j+1;      if((t[j]!= occ) && (t[j+1]== occ)) p=j+1;
   }    }
   
   lg=strlen(t);    lg=strlen(t);
Line 184  void cutv(char *u,char *v, char*t, char Line 183  void cutv(char *u,char *v, char*t, char
   }    }
 }  }
   
   
 /********************** nrerror ********************/  /********************** nrerror ********************/
   
 void nrerror(char error_text[])  void nrerror(char error_text[])
Line 805  printf(" %d\n",s[4][i]); Line 803  printf(" %d\n",s[4][i]);
           cov[1]=1.;            cov[1]=1.;
           cov[2]=agev[mw[mi][i]][i]+d*stepm/YEARM;            cov[2]=agev[mw[mi][i]][i]+d*stepm/YEARM;
           if (cptcovn>0){            if (cptcovn>0){
             for (k=1; k<=cptcovn;k++) {              for (k=1; k<=cptcovn;k++) cov[2+k]=covar[1+k-1][i];
               cov[2+k]=covar[Tvar[k]][i];  
               /* printf("k=%d cptcovn=%d %lf\n",k,cptcovn,covar[Tvar[k]][i]);*/  
             }  
             }              }
           out=matprod2(newm,oldm,1,nlstate+ndeath,1,nlstate+ndeath,            out=matprod2(newm,oldm,1,nlstate+ndeath,1,nlstate+ndeath,
                        1,nlstate+ndeath,pmij(pmmij,cov,ncovmodel,x,nlstate));                         1,nlstate+ndeath,pmij(pmmij,cov,ncovmodel,x,nlstate));
           savm=oldm;            savm=oldm;
           oldm=newm;            oldm=newm;
   
   
       } /* end mult */        } /* end mult */
         
       lli=log(out[s[mw[mi][i]][i]][s[mw[mi+1][i]][i]]);        lli=log(out[s[mw[mi][i]][i]][s[mw[mi+1][i]][i]]);
Line 827  printf(" %d\n",s[4][i]); Line 824  printf(" %d\n",s[4][i]);
   for(k=1,l=0.; k<=nlstate; k++) l += ll[k];    for(k=1,l=0.; k<=nlstate; k++) l += ll[k];
   /* printf("l1=%f l2=%f ",ll[1],ll[2]); */    /* printf("l1=%f l2=%f ",ll[1],ll[2]); */
   l= l*ipmx/sw; /* To get the same order of magnitude as if weight=1 for every body */    l= l*ipmx/sw; /* To get the same order of magnitude as if weight=1 for every body */
   
   return -l;    return -l;
 }  }
   
Line 983  double hessii( double x[], double delta, Line 979  double hessii( double x[], double delta,
     }      }
   }    }
   delti[theta]=delts;    delti[theta]=delts;
   return res;      return res;
    
 }  }
   
 double hessij( double x[], double delti[], int thetai,int thetaj)  double hessij( double x[], double delti[], int thetai,int thetaj)
Line 1252  float sum=0.; Line 1249  float sum=0.;
         }          }
         else{          else{
           j= rint( (agev[mw[mi+1][i]][i]*12 - agev[mw[mi][i]][i]*12));            j= rint( (agev[mw[mi+1][i]][i]*12 - agev[mw[mi][i]][i]*12));
           /*printf("i=%d agevi+1=%lf agevi=%lf j=%d\n", i,agev[mw[mi+1][i]][i],agev[mw[mi][i]][i],j);*/  
   
           k=k+1;            k=k+1;
           if (j >= jmax) jmax=j;            if (j >= jmax) jmax=j;
           else if (j <= jmin)jmin=j;            else if (j <= jmin)jmin=j;
Line 1594  int main() Line 1589  int main()
   double ***eij, ***vareij;    double ***eij, ***vareij;
   double **varpl; /* Variances of prevalence limits by age */    double **varpl; /* Variances of prevalence limits by age */
   double *epj, vepp;    double *epj, vepp;
   char version[80]="Imach version 62c, May 1999, INED-EUROREVES ";    char version[80]="Imach version 0.64, May 2000, INED-EUROREVES ";
   char *alph[]={"a","a","b","c","d","e"}, str[4];    char *alph[]={"a","a","b","c","d","e"}, str[4];
   char z[1]="c", occ;    char z[1]="c", occ;
 #include <sys/time.h>  #include <sys/time.h>
Line 1606  int main() Line 1601  int main()
   gettimeofday(&start_time, (struct timezone*)0); */ /* at first time */    gettimeofday(&start_time, (struct timezone*)0); */ /* at first time */
   
   
   printf("\nIMACH, Version 0.63");    printf("\nIMACH, Version 0.64a");
   printf("\nEnter the parameter file name: ");    printf("\nEnter the parameter file name: ");
   
 #ifdef windows  #ifdef windows
   scanf("%s",pathtot);    scanf("%s",pathtot);
   getcwd(pathcd, size);    cygwin_split_path(pathtot,path,optionfile);
        printf("pathtot=%s, path=%s, optionfile=%s\n",pathtot,path,optionfile);
        chdir(path);
    
     /*size=30;
     getcwd(pathcd, size);  
     printf("pathcd=%s, path=%s, optionfile=%s\n",pathcd,path,optionfile);
   cutv(path,optionfile,pathtot,'\\');    cutv(path,optionfile,pathtot,'\\');
   chdir(path);    chdir(path);
   replace(pathc,path);    replace(pathc,path);
     printf("pathtot=%s, path=%s, optionfile=%s\n",pathtot,path,optionfile);
     */
 #endif  #endif
 #ifdef unix  #ifdef unix
   scanf("%s",optionfile);    scanf("%s",optionfile);
Line 1777  int main() Line 1780  int main()
     s=imatrix(1,maxwav+1,1,n);      s=imatrix(1,maxwav+1,1,n);
     adl=imatrix(1,maxwav+1,1,n);          adl=imatrix(1,maxwav+1,1,n);    
     tab=ivector(1,NCOVMAX);      tab=ivector(1,NCOVMAX);
     ncodemax=ivector(1,NCOVMAX);      ncodemax=ivector(1,8);
   
     i=1;      i=1;
     while (fgets(line, MAXLINE, fic) != NULL)    {      while (fgets(line, MAXLINE, fic) != NULL)    {
Line 1802  int main() Line 1805  int main()
         }          }
         num[i]=atol(stra);          num[i]=atol(stra);
   
         /* printf("%d %.lf %.lf %.lf %.lf/%.lf %.lf/%.lf %.lf/%.lf %d %.lf/%.lf %d %.lf/%.lf %d %.lf/%.lf %d\n",num[i],(covar[1][i]), (covar[2][i]), (weight[i]), (moisnais[i]), (annais[i]), (moisdc[i]), (andc[i]), (mint[1][i]), (anint[1][i]), (s[1][i]),  (mint[2][i]), (anint[2][i]), (s[2][i]),  (mint[3][i]), (anint[3][i]), (s[3][i]),  (mint[4][i]), (anint[4][i]), (s[4][i]));*/          /*printf("%d %.lf %.lf %.lf %.lf/%.lf %.lf/%.lf %.lf/%.lf %d %.lf/%.lf %d %.lf/%.lf %d %.lf/%.lf %d %.lf/%.lf %d %.lf/%.lf %d\n",num[i],(covar[1][i]), (covar[2][i]), (weight[i]), (moisnais[i]), (annais[i]), (moisdc[i]), (andc[i]), (mint[1][i]), (anint[1][i]), (s[1][i]),  (mint[2][i]), (anint[2][i]), (s[2][i]),  (mint[3][i]), (anint[3][i]), (s[3][i]),  (mint[4][i]), (anint[4][i]), (s[4][i]),  (mint[5][i]), (anint[5][i]), (s[5][i]),  (mint[6][i]), (anint[6][i]), (s[6][i]));*/
   
         /*printf("%d %.lf %.lf %.lf %.lf %.lf %.lf/%.lf %.lf/%.lf %.lf/%.lf %d %.lf/%.lf %d\n",num[i],(covar[1][i]), (covar[2][i]),(covar[3][i]), (covar[4][i]), (weight[i]), (moisnais[i]), (annais[i]), (moisdc[i]), (andc[i]), (mint[1][i]), (anint[1][i]), (s[1][i]),  (mint[2][i]), (anint[2][i]), (s[2][i]));*/  
   
         i=i+1;          i=i+1;
       }        }
     }      }
     /*scanf("%d",i);*/  
   
       /*scanf("%d",i);*/
   imx=i-1; /* Number of individuals */    imx=i-1; /* Number of individuals */
    
   /* Calculation of the number of parameter from char model*/    /* Calculation of the number of parameter from char model*/
   Tvar=ivector(1,8);        Tvar=ivector(1,8);    
         
Line 1820  int main() Line 1821  int main()
     j=0;      j=0;
     j=nbocc(model,'+');      j=nbocc(model,'+');
     cptcovn=j+1;      cptcovn=j+1;
       
     strcpy(modelsav,model);      strcpy(modelsav,model);
     if (j==0) {      if (j==0) {
       cutv(stra,strb,modelsav,'V'); Tvar[1]=atoi(strb);        cutv(stra,strb,modelsav,'V'); Tvar[1]=atoi(strb);
Line 1835  int main() Line 1836  int main()
           for (k=1; k<=lastobs;k++)            for (k=1; k<=lastobs;k++)
             covar[ncov+1][k]=covar[atoi(stre)][k]*covar[atoi(strc)][k];              covar[ncov+1][k]=covar[atoi(stre)][k]*covar[atoi(strc)][k];
         }          }
         else {          else {cutv(strd,strc,strb,'V');
           cutv(strd,strc,strb,'V');          Tvar[i+1]=atoi(strc);
           Tvar[i+1]=atoi(strc);  
         }          }
         strcpy(modelsav,stra);            strcpy(modelsav,stra);  
       }        }
       /*cutv(strd,strc,stra,'V');*/        cutv(strd,strc,stra,'V');
       Tvar[1]=atoi(strc);        Tvar[1]=atoi(strc);
     }      }
   }    }
   /*printf("tvar=%d ",Tvar[1]);*/    /*printf("tvar=%d ",Tvar[1]);
   /*scanf("%d ",i);*/    scanf("%d ",i);*/
     fclose(fic);      fclose(fic);
   
     if (weightopt != 1) { /* Maximisation without weights*/      if (weightopt != 1) { /* Maximisation without weights*/
Line 1858  int main() Line 1858  int main()
     for (i=1; i<=imx; i++)  {      for (i=1; i<=imx; i++)  {
       agedc[i]=(moisdc[i]/12.+andc[i])-(moisnais[i]/12.+annais[i]);        agedc[i]=(moisdc[i]/12.+andc[i])-(moisnais[i]/12.+annais[i]);
       for(m=1; (m<= maxwav); m++){        for(m=1; (m<= maxwav); m++){
         if (mint[m][i]==99 || anint[m][i]==9999) s[m][i]=-1;    
         if(s[m][i] >0){          if(s[m][i] >0){
           if (s[m][i] == nlstate+1) {            if (s[m][i] == nlstate+1) {
             if(agedc[i]>0)              if(agedc[i]>0)
Line 1871  int main() Line 1870  int main()
           }            }
           else if(s[m][i] !=9){ /* Should no more exist */            else if(s[m][i] !=9){ /* Should no more exist */
             agev[m][i]=(mint[m][i]/12.+1./24.+anint[m][i])-(moisnais[i]/12.+1./24.+annais[i]);              agev[m][i]=(mint[m][i]/12.+1./24.+anint[m][i])-(moisnais[i]/12.+1./24.+annais[i]);
             if(mint[m][i]==99 || anint[m][i]==9999){              if(mint[m][i]==99 || anint[m][i]==9999)
               agev[m][i]=1;                agev[m][i]=1;
               /* printf("i=%d m=%d agev=%lf \n",i,m, agev[m][i]);    */  
             }  
             else if(agev[m][i] <agemin){              else if(agev[m][i] <agemin){
               agemin=agev[m][i];                agemin=agev[m][i];
               /*printf(" Min anint[%d][%d]=%.2f annais[%d]=%.2f, agemin=%.2f\n",m,i,anint[m][i], i,annais[i], agemin);*/                /*printf(" Min anint[%d][%d]=%.2f annais[%d]=%.2f, agemin=%.2f\n",m,i,anint[m][i], i,annais[i], agemin);*/
Line 1950  Tcode=ivector(1,100); Line 1947  Tcode=ivector(1,100);
        printf("i=%d k=%d %d ",i,k,codtab[i][k]);         printf("i=%d k=%d %d ",i,k,codtab[i][k]);
      }       }
      printf("\n");       printf("\n");
    }     }*/
   scanf("%d",i);*/     /*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'. */
   freqsummary(fileres, agemin, agemax, s, agev, nlstate, imx,Tvar,nbcode, ncodemax);    freqsummary(fileres, agemin, agemax, s, agev, nlstate, imx,Tvar,nbcode, ncodemax);
   
   
     /*scanf("%d ",i);*/
   
   
     pmmij= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */      pmmij= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */
     oldms= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */      oldms= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */
     newms= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */      newms= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */
Line 1966  Tcode=ivector(1,100); Line 1967  Tcode=ivector(1,100);
     /* For Powell, parameters are in a vector p[] starting at p[1]      /* For Powell, parameters are in a vector p[] starting at p[1]
        so we point p on param[1][1] so that p[1] maps on param[1][1][1] */         so we point p on param[1][1] so that p[1] maps on param[1][1][1] */
     p=param[1][1]; /* *(*(*(param +1)+1)+0) */      p=param[1][1]; /* *(*(*(param +1)+1)+0) */
     /*scanf("%d",i);*/     
     mlikeli(ficres,p, npar, ncovmodel, nlstate, ftol, func);      mlikeli(ficres,p, npar, ncovmodel, nlstate, ftol, func);
   
         
Line 2053  Tcode=ivector(1,100); Line 2054  Tcode=ivector(1,100);
 /*------------ gnuplot -------------*/  /*------------ gnuplot -------------*/
 chdir(pathcd);  chdir(pathcd);
   if((ficgp=fopen("graph.plt","w"))==NULL) {    if((ficgp=fopen("graph.plt","w"))==NULL) {
     printf("Problem with file graph.gp");goto end;      printf("Problem with file graph.plt");goto end;
   }    }
 #ifdef windows  #ifdef windows
   fprintf(ficgp,"cd \"%s\" \n",pathc);    fprintf(ficgp,"cd \"%s\" \n",pathc);
Line 2125  fprintf(ficgp,"\nset out \"v%s%d%d.gif\" Line 2126  fprintf(ficgp,"\nset out \"v%s%d%d.gif\"
     
   /*3eme*/    /*3eme*/
   
   for (k1=1; k1<= m ; k1 ++) {     for (k1=1; k1<= m ; k1 ++) {
     for (cpt=1; cpt<= nlstate ; cpt ++) {      for (cpt=1; cpt<= nlstate ; cpt ++) {
       k=2+nlstate*(cpt-1);        k=2+nlstate*(cpt-1);
       fprintf(ficgp,"set ter gif small size 400,300\nplot [%.f:%.f] \"e%s\" every :::%d::%d u 1:%d t \"e%d1\" w l",agemin,fage,fileres,k1-1,k1-1,k,cpt);        fprintf(ficgp,"set ter gif small size 400,300\nplot [%.f:%.f] \"e%s\" every :::%d::%d u 1:%d t \"e%d1\" w l",agemin,fage,fileres,k1-1,k1-1,k,cpt);
Line 2134  fprintf(ficgp,"\nset out \"v%s%d%d.gif\" Line 2135  fprintf(ficgp,"\nset out \"v%s%d%d.gif\"
       }        }
       fprintf(ficgp,"\nset out \"exp%s%d%d.gif\" \nreplot\n\n",strtok(optionfile, "."),cpt,k1);        fprintf(ficgp,"\nset out \"exp%s%d%d.gif\" \nreplot\n\n",strtok(optionfile, "."),cpt,k1);
     }      }
   }     }
     
   /* CV preval stat */    /* CV preval stat */
   for (k1=1; k1<= m ; k1 ++) {      for (k1=1; k1<= m ; k1 ++) {
     for (cpt=1; cpt<nlstate ; cpt ++) {      for (cpt=1; cpt<nlstate ; cpt ++) {
       k=3;        k=3;
       fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability\" \nset ter gif small size 400,300\nplot [%.f:%.f] \"pij%s\" u ($1==%d ? ($3):1/0):($%d/($%d",agemin,agemax,fileres,k1,k+cpt+1,k+1);        fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability\" \nset ter gif small size 400,300\nplot [%.f:%.f] \"pij%s\" u ($1==%d ? ($3):1/0):($%d/($%d",agemin,agemax,fileres,k1,k+cpt+1,k+1);
Line 2155  fprintf(ficgp,"\nset out \"v%s%d%d.gif\" Line 2156  fprintf(ficgp,"\nset out \"v%s%d%d.gif\"
       fprintf(ficgp,"set out \"p%s%d%d.gif\" \nreplot\n\n",strtok(optionfile, "."),cpt,k1);        fprintf(ficgp,"set out \"p%s%d%d.gif\" \nreplot\n\n",strtok(optionfile, "."),cpt,k1);
     }      }
   }    }
    
   /* proba elementaires */    /* proba elementaires */
   for(i=1,jk=1; i <=nlstate; i++){    for(i=1,jk=1; i <=nlstate; i++){
     for(k=1; k <=(nlstate+ndeath); k++){      for(k=1; k <=(nlstate+ndeath); k++){
Line 2192  fprintf(ficgp,"\nset out \"v%s%d%d.gif\" Line 2193  fprintf(ficgp,"\nset out \"v%s%d%d.gif\"
   }    }
 fprintf(ficgp,"\nset out \"pe%s%d.gif\" \nreplot\n\n",strtok(optionfile, "."),jk);    fprintf(ficgp,"\nset out \"pe%s%d.gif\" \nreplot\n\n",strtok(optionfile, "."),jk);  
   }    }
   fclose(ficgp);   
       fclose(ficgp);
 chdir(path);  
       chdir(path);
     free_matrix(agev,1,maxwav,1,imx);      free_matrix(agev,1,maxwav,1,imx);
     free_ivector(wav,1,imx);      free_ivector(wav,1,imx);
     free_imatrix(dh,1,lastpass-firstpass+1,1,imx);      free_imatrix(dh,1,lastpass-firstpass+1,1,imx);
Line 2225  chdir(path); Line 2227  chdir(path);
   }    }
   ungetc(c,ficpar);    ungetc(c,ficpar);
     
   
   fscanf(ficpar,"agemin=%lf agemax=%lf bage=%lf fage=%lf\n",&agemin,&agemax, &bage, &fage);    fscanf(ficpar,"agemin=%lf agemax=%lf bage=%lf fage=%lf\n",&agemin,&agemax, &bage, &fage);
   printf("agemin=%.0f agemax=%.0f bage=%.0f fage=%.0f\n",agemin,agemax, bage, fage);    printf("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 2273  interval) in state (%d): v%s%d%d.gif <br Line 2276  interval) in state (%d): v%s%d%d.gif <br
      }       }
      for(cpt=1; cpt<=nlstate;cpt++) {       for(cpt=1; cpt<=nlstate;cpt++) {
         fprintf(fichtm,"\n<br>- Health life expectancies by age and initial health state (%d): exp%s%d%d.gif <br>          fprintf(fichtm,"\n<br>- Health life expectancies by age and initial health state (%d): exp%s%d%d.gif <br>
 <img src=\"exp%s%d%d.gif\">",cpt,strtok(optionfile, "."),cpt,j1,strtok(optionfile, "."),cpt,j1);  <img src=\"ex%s%d%d.gif\">",cpt,strtok(optionfile, "."),cpt,j1,strtok(optionfile, "."),cpt,j1);
      }       }
      fprintf(fichtm,"\n<br>- Total life expectancy by age and       fprintf(fichtm,"\n<br>- Total life expectancy by age and
 health expectancies in states (1) and (2): e%s%d.gif<br>  health expectancies in states (1) and (2): e%s%d.gif<br>
Line 2461  fclose(fichtm); Line 2464  fclose(fichtm);
   fclose(ficrest);    fclose(ficrest);
   fclose(ficpar);    fclose(ficpar);
   free_vector(epj,1,nlstate+1);    free_vector(epj,1,nlstate+1);
   /*  scanf("%d ",i); */    /*scanf("%d ",i); */
   
   /*------- Variance limit prevalence------*/      /*------- Variance limit prevalence------*/  
   
Line 2518  strcpy(fileresvpl,"vpl"); Line 2521  strcpy(fileresvpl,"vpl");
 #ifdef windows  #ifdef windows
  chdir(pathcd);   chdir(pathcd);
 #endif  #endif
  system("wgnuplot ../gp37mgw/graph.plt");   system("wgnuplot graph.plt");
   
 #ifdef windows  #ifdef windows
   while (z[0] != 'q') {    while (z[0] != 'q') {

Removed from v.1.2  
changed lines
  Added in v.1.4


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