Diff for /imach/src/imach.c between versions 1.215 and 1.216

version 1.215, 2015/12/16 08:52:24 version 1.216, 2015/12/18 17:32:11
Line 1 Line 1
 /* $Id$  /* $Id$
   $State$    $State$
   $Log$    $Log$
     Revision 1.216  2015/12/18 17:32:11  brouard
     Summary: 0.98r4 Warning and status=-2
   
     Version 0.98r4 is now:
      - displaying an error when status is -1, date of interview unknown and date of death known;
      - permitting a status -2 when the vital status is unknown at a known date of right truncation.
     Older changes concerning s=-2, dating from 2005 have been supersed.
   
   Revision 1.215  2015/12/16 08:52:24  brouard    Revision 1.215  2015/12/16 08:52:24  brouard
   Summary: 0.98r4 working    Summary: 0.98r4 working
   
Line 2446  double func( double *x) Line 2454  double func( double *x)
 /*        else */  /*        else */
 /*          lli=log(out[s1][s2] - savm[s1][s2]); */  /*          lli=log(out[s1][s2] - savm[s1][s2]); */
 /* #endif */  /* #endif */
             lli=log(out[s1][s2] - savm[s1][s2]);            lli=log(out[s1][s2] - savm[s1][s2]);
             
         } else if  (s2==-2) {          } else if  ( s2==-1 ) { /* alive */
           for (j=1,survp=0. ; j<=nlstate; j++)             for (j=1,survp=0. ; j<=nlstate; j++) 
             survp += (1.+bbh)*out[s1][j]- bbh*savm[s1][j];              survp += (1.+bbh)*out[s1][j]- bbh*savm[s1][j];
           /*survp += out[s1][j]; */            /*survp += out[s1][j]; */
           lli= log(survp);            lli= log(survp);
         }          }
           
         else if  (s2==-4) {           else if  (s2==-4) { 
           for (j=3,survp=0. ; j<=nlstate; j++)              for (j=3,survp=0. ; j<=nlstate; j++)  
             survp += (1.+bbh)*out[s1][j]- bbh*savm[s1][j];              survp += (1.+bbh)*out[s1][j]- bbh*savm[s1][j];
           lli= log(survp);             lli= log(survp); 
         }           } 
   
         else if  (s2==-5) {           else if  (s2==-5) { 
           for (j=1,survp=0. ; j<=2; j++)              for (j=1,survp=0. ; j<=2; j++)  
             survp += (1.+bbh)*out[s1][j]- bbh*savm[s1][j];              survp += (1.+bbh)*out[s1][j]- bbh*savm[s1][j];
           lli= log(survp);             lli= log(survp); 
         }           } 
           
         else{          else{
           lli= log((1.+bbh)*out[s1][s2]- bbh*savm[s1][s2]); /* linear interpolation */            lli= log((1.+bbh)*out[s1][s2]- bbh*savm[s1][s2]); /* linear interpolation */
           /*  lli= (savm[s1][s2]>(double)1.e-8 ?log((1.+bbh)*out[s1][s2]- bbh*(savm[s1][s2])):log((1.+bbh)*out[s1][s2]));*/ /* linear interpolation */            /*  lli= (savm[s1][s2]>(double)1.e-8 ?log((1.+bbh)*out[s1][s2]- bbh*(savm[s1][s2])):log((1.+bbh)*out[s1][s2]));*/ /* linear interpolation */
Line 2578  double func( double *x) Line 2583  double func( double *x)
         s2=s[mw[mi+1][i]][i];          s2=s[mw[mi+1][i]][i];
         if( s2 > nlstate){           if( s2 > nlstate){ 
           lli=log(out[s1][s2] - savm[s1][s2]);            lli=log(out[s1][s2] - savm[s1][s2]);
           } else if  ( s2==-1 ) { /* alive */
             for (j=1,survp=0. ; j<=nlstate; j++) 
               survp += out[s1][j];
             lli= log(survp);
         }else{          }else{
           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 */
         }          }
Line 2685  double funcone( double *x) Line 2694  double funcone( 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];
         if(s2==-1){
           printf(" s1=%d, s2=%d i=%d \n", s1, s2, i);
           /* exit(1); */
         }
       bbh=(double)bh[mi][i]/(double)stepm;         bbh=(double)bh[mi][i]/(double)stepm; 
       /* bias is positive if real duration        /* bias 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.
        */         */
       if( s2 > nlstate && (mle <5) ){  /* Jackson */        if( s2 > nlstate && (mle <5) ){  /* Jackson */
         lli=log(out[s1][s2] - savm[s1][s2]);          lli=log(out[s1][s2] - savm[s1][s2]);
       } else if  (s2==-2) {        } else if  ( s2==-1 ) { /* alive */
         for (j=1,survp=0. ; j<=nlstate; j++)           for (j=1,survp=0. ; j<=nlstate; j++) 
           survp += (1.+bbh)*out[s1][j]- bbh*savm[s1][j];            survp += (1.+bbh)*out[s1][j]- bbh*savm[s1][j];
         lli= log(survp);          lli= log(survp);
Line 3613  void  concatwav(int wav[], int **dh, int Line 3626  void  concatwav(int wav[], int **dh, int
     mi=0;      mi=0;
     m=firstpass;      m=firstpass;
     while(s[m][i] <= nlstate){  /* a live state */      while(s[m][i] <= nlstate){  /* a live state */
       if(s[m][i]>=1 || s[m][i]==-2 || s[m][i]==-4 || s[m][i]==-5)        if(s[m][i]>=1 || s[m][i]==-4 || s[m][i]==-5){ /* Since 0.98r4 if status=-2 vital status is really unknown, wave should be skipped */
         mw[++mi][i]=m;          mw[++mi][i]=m;
       if(m >=lastpass)        }
         if(m >=lastpass){
           if(s[m][i]==-1 && (int) andc[i] == 9999 && (int)anint[m][i] != 9999){
             printf("Information! Unknown health status for individual %ld line=%d occurred at last wave %d at known date %d/%d. Please, check if your unknown date of death %d/%d means a live state %d at wave %d. This case(%d)/wave(%d) contributes to the likelihood.\nOthers in log file only\n",num[i],i,lastpass,(int)mint[m][i],(int)anint[m][i], (int) moisdc[i], (int) andc[i], s[m][i], m, i, m);
             fprintf(ficlog,"Information! Unknown status for individual %ld line=%d occurred at last wave %d at known date %d/%d. Please, check if your unknown date of death %d/%d means a live state %d at wave %d. This case(%d)/wave(%d) contributes to the likelihood.\nOthers in log file only\n",num[i],i,lastpass,(int)mint[m][i],(int)anint[m][i], (int) moisdc[i], (int) andc[i], s[m][i], m, i, m);
             mw[++mi][i]=m;
           }
           if(s[m][i]==-2){ /* Vital status is really unknown */
             nbwarn++;
             if((int)anint[m][i] == 9999){  /*  Has the vital status really been verified? */
               printf("Warning! Vital status for individual %ld (line=%d) at last wave %d interviewed at date %d/%d is unknown %d. Please, check if the vital status and the date of death %d/%d are really unknown. This case (%d)/wave (%d) is skipped, no contribution to likelihood.\nOthers in log file only\n",num[i],i,lastpass,(int)mint[m][i],(int)anint[m][i], s[m][i], (int) moisdc[i], (int) andc[i], i, m);
               fprintf(ficlog,"Warning! Vital status for individual %ld (line=%d) at last wave %d interviewed at date %d/%d is unknown %d. Please, check if the vital status and the date of death %d/%d are really unknown. This case (%d)/wave (%d) is skipped, no contribution to likelihood.\nOthers in log file only\n",num[i],i,lastpass,(int)mint[m][i],(int)anint[m][i], s[m][i], (int) moisdc[i], (int) andc[i], i, m);
             }
             break;
           }
         break;          break;
         }
       else        else
         m++;          m++;
     }/* end while */      }/* end while */
       
       /* After last pass */
     if (s[m][i] > nlstate){  /* In a death state */      if (s[m][i] > nlstate){  /* In a death state */
       mi++;     /* Death is another wave */        mi++;     /* Death is another wave */
       /* if(mi==0)  never been interviewed correctly before death */        /* if(mi==0)  never been interviewed correctly before death */
          /* Only death is a correct wave */           /* Only death is a correct wave */
       mw[mi][i]=m;        mw[mi][i]=m;
     }else if (andc[i] != 9999) { /* A death occured after lastpass */      }else if ((int) andc[i] != 9999) { /* Status is either death or negative. A death occured after lastpass, we can't take it into account because of potential bias */
       m++;        /* m++; */
       mi++;        /* mi++; */
       s[m][i]=nlstate+1;  /* We are setting the status to the last of non live state */        /* s[m][i]=nlstate+1;  /\* We are setting the status to the last of non live state *\/ */
       mw[mi][i]=m;        /* mw[mi][i]=m; */
       nbwarn++;        nberr++;
       if(firstwo==0){        if(firstwo==0){
         printf("Warning! Death for individual %ld line=%d  occurred after last wave %d. Since 0.98r4 we considered a status %d at wave %d\nOthers in log file only\n",num[i],i,lastpass,nlstate+1, m);          printf("Error! Death for individual %ld line=%d  occurred %d/%d after last wave %d interviewed at %d/%d. Potential bias if other individuals are still alive at this date but ignored. This case (%d)/wave (%d) is skipped, no contribution to likelihood.\nOthers in log file only\n",num[i],i,(int) moisdc[i], (int) andc[i], lastpass,(int)mint[m][i],(int)anint[m][i], i,m );
         fprintf(ficlog,"Warning! Death for individual %ld line=%d  occurred after last wave %d. Since 0.98r4 we considered a status %d at wave %d\n",num[i],i,lastpass,nlstate+1, m);          fprintf(ficlog,"Error! Death for individual %ld line=%d  occurred %d/%d after last wave %d interviewed at %d/%d. Potential bias if other individuals are still alive at this date but ignored. This case (%d)/wave (%d) is skipped, no contribution to likelihood.\nOthers in log file only\n",num[i],i,(int) moisdc[i], (int) andc[i], lastpass,(int)mint[m][i],(int)anint[m][i], i,m );
         firstwo=1;          firstwo=1;
       }        }else if(firstwo==1){
       if(firstwo==1){          fprintf(ficlog,"Error! Death for individual %ld line=%d  occurred %d/%d after last wave %d interviewed at %d/%d. Potential bias if other individuals are still alive at this date but ignored. This case (%d)/wave (%d) is skipped, no contribution to likelihood.\nOthers in log file only\n",num[i],i,(int) moisdc[i], (int) andc[i], lastpass,(int)mint[m][i],(int)anint[m][i], i,m );
         fprintf(ficlog,"Warning! Death for individual %ld line=%d  occurred after last wave %d. Since 0.98r4 we considered a status %d at wave %d\n",num[i],i,lastpass,nlstate+1, m);  
       }        }
     }      }
     wav[i]=mi;      wav[i]=mi;
Line 6625  int calandcheckages(int imx, int maxwav, Line 6654  int calandcheckages(int imx, int maxwav,
     for(m=2; (m<= maxwav); m++) {      for(m=2; (m<= maxwav); m++) {
       if (((int)mint[m][i]== 99) && (s[m][i] <= nlstate)){        if (((int)mint[m][i]== 99) && (s[m][i] <= nlstate)){
         anint[m][i]=9999;          anint[m][i]=9999;
         s[m][i]=-1;          if (s[m][i] != -2) /* Keeping initial status of unknown vital status */
             s[m][i]=-1;
       }        }
       if((int)moisdc[i]==99 && (int)andc[i]==9999 && s[m][i]>nlstate){        if((int)moisdc[i]==99 && (int)andc[i]==9999 && s[m][i]>nlstate){
         *nberr = *nberr + 1;          *nberr = *nberr + 1;
Line 8784  Please run with mle=-1 to get a correct Line 8814  Please run with mle=-1 to get a correct
       
   
   if((nberr >0) || (nbwarn>0)){    if((nberr >0) || (nbwarn>0)){
     printf("End of Imach with %d errors and/or %d warnings\n",nberr,nbwarn);      printf("End of Imach with %d errors and/or %d warnings. Please look at the log file for details.\n",nberr,nbwarn);
     fprintf(ficlog,"End of Imach with %d errors and/or warnings %d\n",nberr,nbwarn);      fprintf(ficlog,"End of Imach with %d errors and/or warnings %d. Please look at the log file for details.\n",nberr,nbwarn);
   }else{    }else{
     printf("End of Imach\n");      printf("End of Imach\n");
     fprintf(ficlog,"End of Imach\n");      fprintf(ficlog,"End of Imach\n");

Removed from v.1.215  
changed lines
  Added in v.1.216


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