From 6fd336a790872faee334563ef323b35a000d2cc9 Mon Sep 17 00:00:00 2001 From: brouard Date: Tue, 27 Aug 2024 11:44:24 +0200 Subject: [PATCH] Version 0.99s8 Minor bug on firstpass fixed --- src/imach.c | 109 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 65 insertions(+), 44 deletions(-) diff --git a/src/imach.c b/src/imach.c index 5980146..f04ffd8 100644 --- a/src/imach.c +++ b/src/imach.c @@ -1430,7 +1430,7 @@ char copyright[]="April 2024,INED-EUROREVES-Institut de longevite-Japan Society char fullversion[]="$Revision$ $Date$"; char strstart[80]; char optionfilext[10], optionfilefiname[FILENAMELENGTH]; -int erreur=0, nberr=0, nbwarn=0; /* Error number, number of errors number of warnings */ +int erreur=0, nberr=0, nbwarn=0, nbinfo=0; /* Error number, number of errors, number of warnings, number of infos */ int debugILK=0; /* debugILK is set by a #d in a comment line */ int nagesqr=0, nforce=0; /* nagesqr=1 if model is including age*age, number of forces */ /* Number of covariates model (1)=V2+V1+ V3*age+V2*V4 */ @@ -5664,7 +5664,7 @@ double func( double *x) But if the variable is not in the model TTvar[iv] is the real variable effective in the model: meaning that decodemodel should be used cotvar[mw[mi+1][i]][TTvar[iv]][i] */ - for(mi=1; mi<= wav[i]-1; mi++){ /* Varying with waves */ + for(mi=firstpass; mi<= wav[i]-1; mi++){ /* mi=1 Varying with waves */ /* Wave varying (but not age varying) */ /* for(k=1; k <= ncovv ; k++){ /\* Varying covariates in the model (single and product but no age )"V5+V4+V3+V4*V3+V5*age+V1*age+V1" +TvarVind 1,2,3,4(V4*V3) Tvar[1]@7{5, 4, 3, 6, 5, 1, 1 ; 6 because the created covar is after V5 and is 6, minus 1+1, 3,2,1,4 positions in cotvar*\/ */ /* /\* cov[ioffset+TvarVind[k]]=cotvar[mw[mi][i]][Tvar[TvarVind[k]]][i]; but where is the crossproduct? *\/ */ @@ -5834,7 +5834,7 @@ double func( double *x) ioffset=2+nagesqr ; for (k=1; k<=ncovf;k++) cov[ioffset+TvarFind[k]]=covar[Tvar[TvarFind[k]]][i]; - for(mi=1; mi<= wav[i]-1; mi++){ + for(mi=firstpass; mi<= wav[i]-1; mi++){ /* mi=1 */ for(k=1; k <= ncovv ; k++){ cov[ioffset+TvarVind[k]]=cotvar[mw[mi][i]][Tvar[TvarVind[k]]][i]; /* because cotvar starts now at first ncovcol+nqv+ (1 to nqtv) */ } @@ -5870,7 +5870,7 @@ double func( double *x) } else if(mle==3){ /* exponential inter-extrapolation */ for (i=1,ipmx=0, sw=0.; i<=imx; i++){ for (k=1; k<=cptcovn;k++) cov[2+nagesqr+k]=covar[Tvar[k]][i]; - for(mi=1; mi<= wav[i]-1; mi++){ + for(mi=firstpass; mi<= wav[i]-1; mi++){ /* mi=1 */ for (ii=1;ii<=nlstate+ndeath;ii++) for (j=1;j<=nlstate+ndeath;j++){ oldm[ii][j]=(ii==j ? 1.0 : 0.0); @@ -5906,7 +5906,7 @@ double func( double *x) }else if (mle==4){ /* ml=4 no inter-extrapolation */ for (i=1,ipmx=0, sw=0.; i<=imx; i++){ for (k=1; k<=cptcovn;k++) cov[2+nagesqr+k]=covar[Tvar[k]][i]; - for(mi=1; mi<= wav[i]-1; mi++){ + for(mi=firstpass; mi<= wav[i]-1; mi++){ /* mi=1 */ for (ii=1;ii<=nlstate+ndeath;ii++) for (j=1;j<=nlstate+ndeath;j++){ oldm[ii][j]=(ii==j ? 1.0 : 0.0); @@ -5948,7 +5948,7 @@ double func( double *x) }else{ /* ml=5 no inter-extrapolation no jackson =0.8a */ for (i=1,ipmx=0, sw=0.; i<=imx; i++){ for (k=1; k<=cptcovn;k++) cov[2+nagesqr+k]=covar[Tvar[k]][i]; - for(mi=1; mi<= wav[i]-1; mi++){ + for(mi=firstpass; mi<= wav[i]-1; mi++){ for (ii=1;ii<=nlstate+ndeath;ii++) for (j=1;j<=nlstate+ndeath;j++){ oldm[ii][j]=(ii==j ? 1.0 : 0.0); @@ -6063,7 +6063,7 @@ double funcone( double *x) /* } */ - for(mi=1; mi<= wav[i]-1; mi++){ /* Varying with waves */ + for(mi=firstpass; mi<= wav[i]-1; mi++){ /* mi=1 Varying with waves */ /* Wave varying (but not age varying) *//* V1+V3+age*V1+age*V3+V1*V3 with V4 tv and V5 tvq k= 1 to 5 and extra at V(5+1)=6 for V1*V3 */ /* for(k=1; k <= ncovv ; k++){ /\* Varying covariates (single and product but no age )*\/ */ /* /\* cov[ioffset+TvarVind[k]]=cotvar[mw[mi][i]][Tvar[TvarVind[k]]][i]; *\/ */ @@ -7268,7 +7268,7 @@ Title=%s
Datafile=%s Firstpass=%d Lastpass=%d Stepm=%d Weight=%d Model=1+age }/* end j==0 */ if (bool==1){ /* We selected an individual iind satisfying combination j1 (V4=1 V3=0) or all fixed covariates */ /* for(m=firstpass; m<=lastpass; m++){ */ - for(mi=1; mi=1 && firsthree < 10){ 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 as 1-p_{%d%d} .\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, s[m][i], nlstate+ndeath); @@ -7954,6 +7954,10 @@ void concatwav(int wav[], int **dh, int **bh, int **mw, int **s, double *agedc /* if(mi==0) never been interviewed correctly before death */ /* Only death is a correct wave */ mw[mi][i]=m; + /* if(mi==firstpass) */ + /* mw[mi+1][i]=m; */ + /* s[mw[mi+1][i]][i]=s[m][i]; */ + /* if(mi==firstpass) never been interviewed correctly before death */ } /* else not in a death state */ #ifndef DISPATCHINGKNOWNDEATHAFTERLASTWAVE else if ((int) andc[i] != 9999) { /* Date of death is known */ @@ -7987,7 +7991,7 @@ void concatwav(int wav[], int **dh, int **bh, int **mw, int **s, double *agedc #endif wav[i]=mi; /* mi should be the last effective wave (or mli), */ /* wav[i]=mw[mi][i]; */ - if(mi==0){ + if(mi==firstpass-1){ /* was mi==0 */ nbwarn++; if(first==0){ printf("Warning! No valid information for individual %ld line=%d (skipped) and may be others, see log file\n",num[i],i); @@ -7996,7 +8000,7 @@ void concatwav(int wav[], int **dh, int **bh, int **mw, int **s, double *agedc if(first==1){ fprintf(ficlog,"Warning! No valid information for individual %ld line=%d (skipped)\n",num[i],i); } - } /* end mi==0 */ + } /* end mi==firstpass-1 was ==0 */ } /* End individuals */ /* wav and mw are no more changed */ @@ -8005,14 +8009,14 @@ void concatwav(int wav[], int **dh, int **bh, int **mw, int **s, double *agedc for(i=1; i<=imx; i++){ - for(mi=1; mi nlstate) { /* A death, but what if date is unknown? */ if (agedc[i] < 2*AGESUP) { j= rint(agedc[i]*12-agev[mw[mi][i]][i]*12); - if(j==0) j=1; /* Survives at least one month after exam */ + if(j==0) j=1; /* Survives at least one month after exam */ /* To be checked */ else if(j<0){ nberr++; printf("Error! Negative delay (%d to death) between waves %d and %d of individual %ld (around line %d) who is aged %.1f with statuses from %d to %d\n ",j,mw[mi][i],mw[mi+1][i],num[i], i,agev[mw[mi][i]][i],s[mw[mi][i]][i] ,s[mw[mi+1][i]][i]); @@ -12459,6 +12463,7 @@ int readdata(char datafile[], int firstobs, int lastobs, int *imax) int lstra; int linei, month, year,iout; int noffset=0; /* This is the offset if BOM data file */ + int firstone=0; char line[MAXLINE], linetmp[MAXLINE]; char stra[MAXLINE], strb[MAXLINE]; char *stratrunc; @@ -12628,7 +12633,7 @@ int readdata(char datafile[], int firstobs, int lastobs, int *imax) } } - s[j][i]=lval; + s[j][i]=lval; /* status of i at wave j */ /* Date of Interview */ strcpy(line,stra); @@ -12684,7 +12689,6 @@ int readdata(char datafile[], int firstobs, int lastobs, int *imax) printf("Error reading data around '%s' at line number %d for individual %d, '%s'\nShould be a date of birth (mm/yyyy) but at least the year of birth should be given. Exiting.\n",strb, linei,i,line); fprintf(ficlog,"Error reading data around '%s' at line number %d for individual %d, '%s'\nShould be a date of birth (mm/yyyy) but at least the year of birth should be given. Exiting.\n",strb, linei,i,line);fflush(ficlog); return 1; - } annais[i]=(double)(year); moisnais[i]=(double)(month); @@ -12782,7 +12786,20 @@ int readdata(char datafile[], int firstobs, int lastobs, int *imax) num[i]=atol(stra); /*if((s[2][i]==2) && (s[3][i]==-1)&&(s[4][i]==9)){ printf("%ld %.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])); ij=ij+1;}*/ - + /* Should break (individual is skipped) if state at firstpass interview + * is death, or dates of interviews between firstpass and lastpass + * are unknown */ + /* This can happen when the firstpass occurs after the death. */ + if( s[firstpass][i] > nlstate){ + nbinfo++; + /* *nberr = *nberr + 1; */ + if(firstone == 0){ + firstone=1; + printf("Information (#%d)! Date of death (month %2d and year %4d) of individual %ld on line %d with status %d at wave %d occurred before the firstpass (%d) that you selected: whole information on this individual is skipped.\nOther similar cases in log file\n", nbinfo, (int)moisdc[i],(int)andc[i],num[i],i,s[firstpass][i],firstpass,firstpass); + } + fprintf(ficlog,"Information (#%d)! Date of death (month %2d and year %4d) of individual %ld on line %d with status %d at wave %d occurred before the firstpass (%d) that you selected: whole information on this individual is skipped.\n", nbinfo, (int)moisdc[i],(int)andc[i],num[i],i,s[firstpass][i],firstpass,firstpass); + i--; + } i=i+1; } /* End loop reading data */ @@ -13967,7 +13984,7 @@ Dummy[k] 0=dummy (0 1), 1 quantitative (single or product without age), 2 dummy return (1); } -int calandcheckages(int imx, int maxwav, double *agemin, double *agemax, int *nberr, int *nbwarn ) +int calandcheckages(int imx, int maxwav, double *agemin, double *agemax)/*, int *nberr, int *nbwarn )*/ {/* Check ages at death */ int i, m; int firstone=0; @@ -13980,18 +13997,18 @@ int calandcheckages(int imx, int maxwav, double *agemin, double *agemax, int *nb s[m][i]=-1; } if((int)moisdc[i]==99 && (int)andc[i]==9999 && s[m][i]>nlstate){ - *nberr = *nberr + 1; + nberr = nberr + 1; if(firstone == 0){ firstone=1; - printf("Warning (#%d)! Date of death (month %2d and year %4d) of individual %ld on line %d was unknown but status is a death state %d at wave %d. If you don't know the vital status, please enter -2. If he/she is still alive but don't know the state, please code with '-1 or '.'. Here, we do not believe in a death, skipped.\nOther similar cases in log file\n", *nberr,(int)moisdc[i],(int)andc[i],num[i],i,s[m][i],m); + printf("Warning (#%d)! Date of death (month %2d and year %4d) of individual %ld on line %d was unknown but status is a death state %d at wave %d. If you don't know the vital status, please enter -2. If he/she is still alive but don't know the state, please code with '-1 or '.'. Here, we do not believe in a death, skipped.\nOther similar cases in log file\n", nberr,(int)moisdc[i],(int)andc[i],num[i],i,s[m][i],m); } - fprintf(ficlog,"Warning (#%d)! Date of death (month %2d and year %4d) of individual %ld on line %d was unknown but status is a death state %d at wave %d. If you don't know the vital status, please enter -2. If he/she is still alive but don't know the state, please code with '-1 or '.'. Here, we do not believe in a death, skipped.\n", *nberr,(int)moisdc[i],(int)andc[i],num[i],i,s[m][i],m); + fprintf(ficlog,"Warning (#%d)! Date of death (month %2d and year %4d) of individual %ld on line %d was unknown but status is a death state %d at wave %d. If you don't know the vital status, please enter -2. If he/she is still alive but don't know the state, please code with '-1 or '.'. Here, we do not believe in a death, skipped.\n", nberr,(int)moisdc[i],(int)andc[i],num[i],i,s[m][i],m); s[m][i]=-1; /* Droping the death status */ } if((int)moisdc[i]==99 && (int)andc[i]!=9999 && s[m][i]>nlstate){ - (*nberr)++; - printf("Error (#%d)! Month of death of individual %ld on line %d was unknown (%2d) (year of death is %4d) and status is a death state %d at wave %d. Please impute an arbitrary (or not) month and rerun. Currently this transition to death will be skipped (status is set to -2).\nOther similar cases in log file\n", *nberr, num[i],i,(int)moisdc[i],(int)andc[i],s[m][i],m); - fprintf(ficlog,"Error (#%d)! Month of death of individual %ld on line %d was unknown (%2d) (year of death is %4d) and status is a death state %d at wave %d. Please impute an arbitrary (or not) month and rerun. Currently this transition to death will be skipped (status is set to -2).\n", *nberr, num[i],i,(int)moisdc[i],(int)andc[i],s[m][i],m); + nberr++; + printf("Error (#%d)! Month of death of individual %ld on line %d was unknown (%2d) (year of death is %4d) and status is a death state %d at wave %d. Please impute an arbitrary (or not) month and rerun. Currently this transition to death will be skipped (status is set to -2).\nOther similar cases in log file\n", nberr, num[i],i,(int)moisdc[i],(int)andc[i],s[m][i],m); + fprintf(ficlog,"Error (#%d)! Month of death of individual %ld on line %d was unknown (%2d) (year of death is %4d) and status is a death state %d at wave %d. Please impute an arbitrary (or not) month and rerun. Currently this transition to death will be skipped (status is set to -2).\n", nberr, num[i],i,(int)moisdc[i],(int)andc[i],s[m][i],m); s[m][i]=-2; /* We prefer to skip it (and to skip it in version 0.8a1 too */ } } @@ -14051,9 +14068,9 @@ int calandcheckages(int imx, int maxwav, double *agemin, double *agemax, int *nb for (i=1; i<=imx; i++) { for(m=firstpass; (m<=lastpass); m++){ if (s[m][i] > (nlstate+ndeath)) { - (*nberr)++; - printf("Error: on wave %d of individual %d status %d > (nlstate+ndeath)=(%d+%d)=%d\n",m,i,s[m][i],nlstate, ndeath, nlstate+ndeath); - fprintf(ficlog,"Error: on wave %d of individual %d status %d > (nlstate+ndeath)=(%d+%d)=%d\n",m,i,s[m][i],nlstate, ndeath, nlstate+ndeath); + nberr++; + printf("Error (#%d): on wave %d of individual %d status %d > (nlstate+ndeath)=(%d+%d)=%d\n",nberr,m,i,s[m][i],nlstate, ndeath, nlstate+ndeath); + fprintf(ficlog,"Error (#%d): on wave %d of individual %d status %d > (nlstate+ndeath)=(%d+%d)=%d\n",nberr,m,i,s[m][i],nlstate, ndeath, nlstate+ndeath); return 1; } } @@ -14806,7 +14823,7 @@ int main(int argc, char *argv[]) */ nberr=0; /* Number of errors and warnings */ - nbwarn=0; + nbwarn=0;nbinfo=0; #ifdef WIN32 _getcwd(pathcd, size); #else @@ -15497,7 +15514,7 @@ Please run with mle=-1 to get a correct covariance matrix.\n",optionfile,numline /*-calculation of age at interview from date of interview and age at death -*/ agev=matrix(1,maxwav,1,imx); - if(calandcheckages(imx, maxwav, &agemin, &agemax, &nberr, &nbwarn) == 1) + if(calandcheckages(imx, maxwav, &agemin, &agemax)==1) /*, &nberr, &nbwarn) == 1)*/ goto end; @@ -15514,14 +15531,16 @@ Please run with mle=-1 to get a correct covariance matrix.\n",optionfile,numline /* dh=imatrix(1,lastpass-firstpass+1,1,imx); */ /* bh=imatrix(1,lastpass-firstpass+1,1,imx); */ /* mw=imatrix(1,lastpass-firstpass+1,1,imx); */ - dh=imatrix(1,lastpass-firstpass+2,1,imx); /* We are adding a wave if status is unknown at last wave but death occurs after last wave.*/ - bh=imatrix(1,lastpass-firstpass+2,1,imx); - mw=imatrix(1,lastpass-firstpass+2,1,imx); - + /*dh=imatrix(1,lastpass-firstpass+2,1,imx);*/ /* We are adding a wave if status is unknown at last wave but death occurs after last wave.*/ + dh=imatrix(firstpass,lastpass+1,1,imx); /* We are adding a wave if status is unknown at last wave but death occurs after last wave.*/ + /* bh=imatrix(1,lastpass-firstpass+2,1,imx); */ + /* mw=imatrix(1,lastpass-firstpass+2,1,imx); */ + bh=imatrix(firstpass,lastpass+1,1,imx); + mw=imatrix(firstpass,lastpass+1,1,imx); /* Concatenates waves */ /* Concatenates waves: wav[i] is the number of effective (useful waves) of individual i. Death is a valid wave (if date is known). - mw[mi][i] is the number of (mi=1 to wav[i]) effective wave out of mi of individual i + mw[mi][i] is the number of (mi=firstpass to wav[i]) effective wave out of mi of individual i dh[m][i] or dh[mw[mi][i]][i] is the delay between two effective waves m=mw[mi][i] and mw[mi+1][i]. dh depends on stepm. */ @@ -16683,10 +16702,12 @@ Please run with mle=-1 to get a correct covariance matrix.\n",ageminpar,agemaxpa /* ------ Other prevalence ratios------------ */ free_ivector(wav,1,imx); - free_imatrix(dh,1,lastpass-firstpass+2,1,imx); - free_imatrix(bh,1,lastpass-firstpass+2,1,imx); - free_imatrix(mw,1,lastpass-firstpass+2,1,imx); - + /* free_imatrix(dh,1,lastpass-firstpass+2,1,imx); */ + /* free_imatrix(bh,1,lastpass-firstpass+2,1,imx); */ + /* free_imatrix(mw,1,lastpass-firstpass+2,1,imx); */ + free_imatrix(dh,firstpass,lastpass+1,1,imx); + free_imatrix(bh,firstpass,lastpass+1,1,imx); + free_imatrix(mw,firstpass,lastpass+1,1,imx); /*---------- Health expectancies, no variances ------------*/ @@ -17075,9 +17096,9 @@ Please run with mle=-1 to get a correct covariance matrix.\n",ageminpar,agemaxpa fflush(ficgp); - if((nberr >0) || (nbwarn>0)){ - 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. Please look at the log file for details.\n",nberr,nbwarn); + if((nberr >0) || (nbwarn>0) || (nbinfo>0)){ + printf("End of Imach with %d errors and/or %d warnings and/or infos %d. Please look at the log file for details.\n",nberr,nbwarn,nbinfo); + fprintf(ficlog,"End of Imach with %d errors and/or %d warnings and/or infos %d. Please look at the log file for details.\n",nberr,nbwarn,nbinfo); }else{ printf("End of Imach\n"); fprintf(ficlog,"End of Imach\n"); -- 2.43.0