]> henry.ined.fr Git - .git/commitdiff
(Module): sump fixed, loop imx fixed, and simplifications.
authorAgnès Lièvre <agnes.lievre@education.gouv.fr>
Fri, 30 Sep 2005 16:11:43 +0000 (16:11 +0000)
committerAgnès Lièvre <agnes.lievre@education.gouv.fr>
Fri, 30 Sep 2005 16:11:43 +0000 (16:11 +0000)
(Module): If the status is missing at the last wave but we know
that the person is alive, then we can code his/her status as -2
(instead of missing=-1 in earlier versions) and his/her
contributions to the likelihood is 1 - Prob of dying from last
health status (= 1-p13= p11+p12 in the easiest case of somebody in
the healthy state at last known wave). Version is 0.98

src/imach.c

index 4051c0e912f8107eecc6099b58fe32cab0ec41c2..24f6196ce9d064fbc67f08daf2665b97ca90498a 100644 (file)
@@ -1,6 +1,9 @@
 /* $Id$
   $State$
   $Log$
+  Revision 1.103  2005/09/30 15:54:49  lievre
+  (Module): sump fixed, loop imx fixed, and simplifications.
+
   Revision 1.102  2004/09/15 17:31:30  brouard
   Add the possibility to read data file including tab characters.
 
 /* $Id$ */
 /* $State$ */
 
-char version[]="Imach version 0.97c, September 2004, INED-EUROREVES ";
+char version[]="Imach version 0.98, September 2005, INED-EUROREVES ";
 char fullversion[]="$Revision$ $Date$"; 
 int erreur, nberr=0, nbwarn=0; /* Error number, number of errors number of warnings  */
 int nvar;
@@ -1261,9 +1264,10 @@ double func( double *x)
         */
        /* 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){ 
-         /* 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 
-            step unit time, which is also equal to probability to die before dh 
+         /* 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  step unit time, 
+            which is also equal to probability to die before dh 
             minus probability to die before dh-stepm . 
             In version up to 0.92 likelihood was computed
        as if date of death was unknown. Death was treated as any other
@@ -1284,7 +1288,16 @@ double func( double *x)
        lower mortality.
          */
          lli=log(out[s1][s2] - savm[s1][s2]);
-       }else{
+
+
+       } else if  (s2==-2) {
+         for (j=1,survp=0. ; j<=nlstate; j++) 
+           survp += out[s1][j];
+         lli= survp;
+       }
+
+
+       else{
          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 */
        } 
@@ -1868,7 +1881,7 @@ void  freqsummary(char fileres[], int iagemin, int iagemax, int **s, double **ag
     fprintf(ficlog,"Problem with prevalence resultfile: %s\n", fileresp);
     exit(0);
   }
-  freq= ma3x(-1,nlstate+ndeath,-1,nlstate+ndeath,iagemin,iagemax+3);
+  freq= ma3x(-2,nlstate+ndeath,-2,nlstate+ndeath,iagemin,iagemax+3);
   j1=0;
   
   j=cptcoveff;
@@ -1881,8 +1894,8 @@ void  freqsummary(char fileres[], int iagemin, int iagemax, int **s, double **ag
       j1++;
       /*printf("cptcoveff=%d Tvaraff=%d", cptcoveff,Tvaraff[1]);
        scanf("%d", i);*/
-      for (i=-1; i<=nlstate+ndeath; i++)  
-       for (jk=-1; jk<=nlstate+ndeath; jk++)  
+      for (i=-2; i<=nlstate+ndeath; i++)  
+       for (jk=-2; jk<=nlstate+ndeath; jk++)  
          for(m=iagemin; m <= iagemax+3; m++)
            freq[i][jk][m]=0;
 
@@ -2007,7 +2020,7 @@ void  freqsummary(char fileres[], int iagemin, int iagemax, int **s, double **ag
   dateintmean=dateintsum/k2cpt; 
  
   fclose(ficresp);
-  free_ma3x(freq,-1,nlstate+ndeath,-1,nlstate+ndeath, iagemin, iagemax+3);
+  free_ma3x(freq,-2,nlstate+ndeath,-2,nlstate+ndeath, iagemin, iagemax+3);
   free_vector(pp,1,nlstate);
   free_matrix(prop,1,nlstate,iagemin, iagemax+3);
   /* End of Freq */
@@ -2116,7 +2129,7 @@ void  concatwav(int wav[], int **dh, int **bh,  int **mw, int **s, double *agedc
     mi=0;
     m=firstpass;
     while(s[m][i] <= nlstate){
-      if(s[m][i]>=1)
+      if(s[m][i]>=1 || s[m][i]==-2)
        mw[++mi][i]=m;
       if(m >=lastpass)
        break;
@@ -2170,7 +2183,8 @@ void  concatwav(int wav[], int **dh, int **bh,  int **mw, int **s, double *agedc
        }
        else{
          j= rint( (agev[mw[mi+1][i]][i]*12 - agev[mw[mi][i]][i]*12));
-         /*      printf("%d %d %d %d\n", s[mw[mi][i]][i] ,s[mw[mi+1][i]][i],j,i);*/
+/*       if (j<0) printf("%d %lf %lf %d %d %d\n", i,agev[mw[mi+1][i]][i], agev[mw[mi][i]][i],j,s[mw[mi][i]][i] ,s[mw[mi+1][i]][i]); */
+
          k=k+1;
          if (j >= jmax) jmax=j;
          else if (j <= jmin)jmin=j;
@@ -2263,7 +2277,7 @@ void tricode(int *Tvar, int **nbcode, int imx)
  for (k=0; k< maxncov; k++) Ndum[k]=0;
 
  for (i=1; i<=ncovmodel-2; i++) { 
-   /* Listing of all covariables in staement model to see if some covariates appear twice. For example, V1 appears twice in V1+V1*V2.*/
+   /* Listing of all covariables in statement model to see if some covariates appear twice. For example, V1 appears twice in V1+V1*V2.*/
    ij=Tvar[i];
    Ndum[ij]++;
  }
@@ -4566,7 +4580,7 @@ int main(int argc, char *argv[])
   for (i=1; i<=imx; i++)  {
     agedc[i]=(moisdc[i]/12.+andc[i])-(moisnais[i]/12.+annais[i]);
     for(m=firstpass; (m<= lastpass); m++){
-      if(s[m][i] >0){
+      if(s[m][i] >0 || s[m][i]==-2){
        if (s[m][i] >= nlstate+1) {
          if(agedc[i]>0)
            if((int)moisdc[i]!=99 && (int)andc[i]!=9999)