--- imach/src/imach.c 2005/09/30 15:54:49 1.103 +++ imach/src/imach.c 2005/09/30 16:11:43 1.104 @@ -1,6 +1,15 @@ -/* $Id: imach.c,v 1.103 2005/09/30 15:54:49 lievre Exp $ +/* $Id: imach.c,v 1.104 2005/09/30 16:11:43 lievre Exp $ $State: Exp $ $Log: imach.c,v $ + Revision 1.104 2005/09/30 16:11:43 lievre + (Module): sump fixed, loop imx fixed, and simplifications. + (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 + Revision 1.103 2005/09/30 15:54:49 lievre (Module): sump fixed, loop imx fixed, and simplifications. @@ -247,11 +256,11 @@ #define ODIRSEPARATOR '/' #endif -/* $Id: imach.c,v 1.103 2005/09/30 15:54:49 lievre Exp $ */ +/* $Id: imach.c,v 1.104 2005/09/30 16:11:43 lievre Exp $ */ /* $State: Exp $ */ -char version[]="Imach version 0.97c, September 2004, INED-EUROREVES "; -char fullversion[]="$Revision: 1.103 $ $Date: 2005/09/30 15:54:49 $"; +char version[]="Imach version 0.98, September 2005, INED-EUROREVES "; +char fullversion[]="$Revision: 1.104 $ $Date: 2005/09/30 16:11:43 $"; int erreur, nberr=0, nbwarn=0; /* Error number, number of errors number of warnings */ int nvar; int cptcovn=0, cptcovage=0, cptcoveff=0,cptcov; @@ -1264,9 +1273,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 @@ -1287,7 +1297,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 */ } @@ -1871,7 +1890,7 @@ void freqsummary(char fileres[], int ia 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; @@ -1884,8 +1903,8 @@ void freqsummary(char fileres[], int ia 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; @@ -2010,7 +2029,7 @@ void freqsummary(char fileres[], int ia 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 */ @@ -2119,7 +2138,7 @@ void concatwav(int wav[], int **dh, int 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; @@ -2173,7 +2192,8 @@ void concatwav(int wav[], int **dh, int } 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; @@ -2266,7 +2286,7 @@ void tricode(int *Tvar, int **nbcode, in 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]++; } @@ -4569,7 +4589,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)