--- imach/src/imach.c 2021/02/20 15:44:02 1.306 +++ imach/src/imach.c 2022/05/24 08:10:59 1.318 @@ -1,6 +1,55 @@ -/* $Id: imach.c,v 1.306 2021/02/20 15:44:02 brouard Exp $ +/* $Id: imach.c,v 1.318 2022/05/24 08:10:59 brouard Exp $ $State: Exp $ $Log: imach.c,v $ + Revision 1.318 2022/05/24 08:10:59 brouard + * imach.c (Module): Some attempts to find a bug of wrong estimates + of confidencce intervals with product in the equation modelC + + Revision 1.317 2022/05/15 15:06:23 brouard + * imach.c (Module): Some minor improvements + + Revision 1.316 2022/05/11 15:11:31 brouard + Summary: r27 + + Revision 1.315 2022/05/11 15:06:32 brouard + *** empty log message *** + + Revision 1.314 2022/04/13 17:43:09 brouard + * imach.c (Module): Adding link to text data files + + Revision 1.313 2022/04/11 15:57:42 brouard + * imach.c (Module): Error in rewriting the 'r' file with yearsfproj or yearsbproj fixed + + Revision 1.312 2022/04/05 21:24:39 brouard + *** empty log message *** + + Revision 1.311 2022/04/05 21:03:51 brouard + Summary: Fixed quantitative covariates + + Fixed covariates (dummy or quantitative) + with missing values have never been allowed but are ERRORS and + program quits. Standard deviations of fixed covariates were + wrongly computed. Mean and standard deviations of time varying + covariates are still not computed. + + Revision 1.310 2022/03/17 08:45:53 brouard + Summary: 99r25 + + Improving detection of errors: result lines should be compatible with + the model. + + Revision 1.309 2021/05/20 12:39:14 brouard + Summary: Version 0.99r24 + + Revision 1.308 2021/03/31 13:11:57 brouard + Summary: Version 0.99r23 + + + * imach.c (Module): Still bugs in the result loop. Thank to Holly Benett + + Revision 1.307 2021/03/08 18:11:32 brouard + Summary: 0.99r22 fixed bug on result: + Revision 1.306 2021/02/20 15:44:02 brouard Summary: Version 0.99r21 @@ -1117,7 +1166,7 @@ typedef struct { #define NINTERVMAX 8 #define NLSTATEMAX 8 /**< Maximum number of live states (for func) */ #define NDEATHMAX 8 /**< Maximum number of dead states (for func) */ -#define NCOVMAX 20 /**< Maximum number of covariates, including generated covariates V1*V2 */ +#define NCOVMAX 30 /**< Maximum number of covariates, including generated covariates V1*V2 */ #define codtabm(h,k) (1 & (h-1) >> (k-1))+1 /*#define decodtabm(h,k,cptcoveff)= (h <= (1<> (k-1)) & 1) +1 : -1)*/ #define decodtabm(h,k,cptcoveff) (((h-1) >> (k-1)) & 1) +1 @@ -1141,12 +1190,12 @@ typedef struct { #define ODIRSEPARATOR '\\' #endif -/* $Id: imach.c,v 1.306 2021/02/20 15:44:02 brouard Exp $ */ +/* $Id: imach.c,v 1.318 2022/05/24 08:10:59 brouard Exp $ */ /* $State: Exp $ */ #include "version.h" char version[]=__IMACH_VERSION__; -char copyright[]="Feb 2021,INED-EUROREVES-Institut de longevite-Japan Society for the Promotion of Science (Grant-in-Aid for Scientific Research 25293121), Intel Software 2015-2020, INED 2000-2021"; -char fullversion[]="$Revision: 1.306 $ $Date: 2021/02/20 15:44:02 $"; +char copyright[]="May 2022,INED-EUROREVES-Institut de longevite-Japan Society for the Promotion of Science (Grant-in-Aid for Scientific Research 25293121), Intel Software 2015-2020, Nihon University 2021-202, INED 2000-2022"; +char fullversion[]="$Revision: 1.318 $ $Date: 2022/05/24 08:10:59 $"; char strstart[80]; char optionfilext[10], optionfilefiname[FILENAMELENGTH]; int erreur=0, nberr=0, nbwarn=0; /* Error number, number of errors number of warnings */ @@ -1327,6 +1376,10 @@ double ***cotvar; /* Time varying covari double ***cotqvar; /* Time varying quantitative covariate itqv */ double idx; int **nbcode, *Tvar; /**< model=V2 => Tvar[1]= 2 */ +/* ncovcol=1(Males=0 Females=1) nqv=1(raedyrs) ntv=2(withoutiadl=0 withiadl=1, witoutadl=0 withoutadl=1) nqtv=1(bmi) nlstate=3 ndeath=1 + # States 1=Coresidence, 2 Living alone, 3 Institution + # V1=sex, V2=raedyrs Quant Fixed, State=livarnb4..livarnb11, V3=iadl4..iald11, V4=adlw4..adlw11, V5=r4bmi..r11bmi +*/ /* V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */ /*k 1 2 3 4 5 6 7 8 9 */ /*Tvar[k]= 5 4 3 6 5 2 7 1 1 */ @@ -1350,17 +1403,21 @@ int *TvarsDind; int *TvarsQ; int *TvarsQind; -#define MAXRESULTLINES 10 +#define MAXRESULTLINESPONE 10+1 int nresult=0; int parameterline=0; /* # of the parameter (type) line */ -int TKresult[MAXRESULTLINES]; -int Tresult[MAXRESULTLINES][NCOVMAX];/* For dummy variable , value (output) */ -int Tinvresult[MAXRESULTLINES][NCOVMAX];/* For dummy variable , value (output) */ -int Tvresult[MAXRESULTLINES][NCOVMAX]; /* For dummy variable , variable # (output) */ -double Tqresult[MAXRESULTLINES][NCOVMAX]; /* For quantitative variable , value (output) */ -double Tqinvresult[MAXRESULTLINES][NCOVMAX]; /* For quantitative variable , value (output) */ -int Tvqresult[MAXRESULTLINES][NCOVMAX]; /* For quantitative variable , variable # (output) */ - +int TKresult[MAXRESULTLINESPONE]; +int Tresult[MAXRESULTLINESPONE][NCOVMAX];/* For dummy variable , value (output) */ +int Tinvresult[MAXRESULTLINESPONE][NCOVMAX];/* For dummy variable , value (output) */ +int Tvresult[MAXRESULTLINESPONE][NCOVMAX]; /* For dummy variable , variable # (output) */ +double Tqresult[MAXRESULTLINESPONE][NCOVMAX]; /* For quantitative variable , value (output) */ +double Tqinvresult[MAXRESULTLINESPONE][NCOVMAX]; /* For quantitative variable , value (output) */ +int Tvqresult[MAXRESULTLINESPONE][NCOVMAX]; /* For quantitative variable , variable # (output) */ + +/* ncovcol=1(Males=0 Females=1) nqv=1(raedyrs) ntv=2(withoutiadl=0 withiadl=1, witoutadl=0 withoutadl=1) nqtv=1(bmi) nlstate=3 ndeath=1 + # States 1=Coresidence, 2 Living alone, 3 Institution + # V1=sex, V2=raedyrs Quant Fixed, State=livarnb4..livarnb11, V3=iadl4..iald11, V4=adlw4..adlw11, V5=r4bmi..r11bmi +*/ /* int *TDvar; /\**< TDvar[1]=4, TDvarF[2]=3, TDvar[3]=6 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 *\/ */ int *TvarF; /**< TvarF[1]=Tvar[6]=2, TvarF[2]=Tvar[7]=7, TvarF[3]=Tvar[9]=1 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */ int *TvarFind; /**< TvarFind[1]=6, TvarFind[2]=7, Tvarind[3]=9 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */ @@ -1562,7 +1619,7 @@ char *cutl(char *blocc, char *alocc, cha { /* cuts string in into blocc and alocc where blocc ends before FIRST occurence of char 'occ' and alocc starts after first occurence of char 'occ' : ex cutv(blocc,alocc,"abcdef2ghi2j",'2') - gives blocc="abcdef" and alocc="ghi2j". + gives alocc="abcdef" and blocc="ghi2j". If occ is not found blocc is null and alocc is equal to in. Returns blocc */ char *s, *t; @@ -1844,7 +1901,9 @@ char *subdirf(char fileres[]) /*************** function subdirf2 ***********/ char *subdirf2(char fileres[], char *preop) { - + /* Example subdirf2(optionfilefiname,"FB_") with optionfilefiname="texte", result="texte/FB_texte" + Errors in subdirf, 2, 3 while printing tmpout is + rewritten within the same printf. Workaround: many printfs */ /* Caution optionfilefiname is hidden */ strcpy(tmpout,optionfilefiname); strcat(tmpout,"/"); @@ -2215,10 +2274,10 @@ void linmin(double p[], double xi[], int #endif #ifdef LINMINORIGINAL #else - if(fb == fx){ /* Flat function in the direction */ - xmin=xx; + if(fb == fx){ /* Flat function in the direction */ + xmin=xx; *flat=1; - }else{ + }else{ *flat=0; #endif /*Flat mnbrak2 shift (*ax=0.000000000000, *fa=51626.272983130431), (*bx=-1.618034000000, *fb=51590.149499362531), (*cx=-4.236068025156, *fc=51590.149499362531) */ @@ -2276,10 +2335,10 @@ void linmin(double p[], double xi[], int /*************** powell ************************/ /* -Minimization of a function func of n variables. Input consists of an initial starting point -p[1..n] ; an initial matrix xi[1..n][1..n] , whose columns contain the initial set of di- -rections (usually the n unit vectors); and ftol , the fractional tolerance in the function value -such that failure to decrease by more than this amount on one iteration signals doneness. On +Minimization of a function func of n variables. Input consists in an initial starting point +p[1..n] ; an initial matrix xi[1..n][1..n] whose columns contain the initial set of di- +rections (usually the n unit vectors); and ftol, the fractional tolerance in the function value +such that failure to decrease by more than this amount in one iteration signals doneness. On output, p is set to the best point found, xi is the then-current direction set, fret is the returned function value at p , and iter is the number of iterations taken. The routine linmin is used. */ @@ -2760,8 +2819,16 @@ void powell(double p[], double **xi, int if(!first){ first=1; printf("Warning: the stable prevalence at age %d did not converge with the required precision (%g > ftolpl=%g) within %.d years and %d loops. Try to lower 'ftolpl'. Youngest age to start was %d=(%d-%d). Others in log file only...\n", (int)age, maxmax, ftolpl, *ncvyear, ncvloop, (int)(agefin+stepm/YEARM), (int)(age-stepm/YEARM), (int)delaymax); + fprintf(ficlog, "Warning: the stable prevalence at age %d did not converge with the required precision (%g > ftolpl=%g) within %.d years and %d loops. Try to lower 'ftolpl'. Youngest age to start was %d=(%d-%d).\n", (int)age, maxmax, ftolpl, *ncvyear, ncvloop, (int)(agefin+stepm/YEARM), (int)(age-stepm/YEARM), (int)delaymax); + }else if (first >=1 && first <10){ + fprintf(ficlog, "Warning: the stable prevalence at age %d did not converge with the required precision (%g > ftolpl=%g) within %.d years and %d loops. Try to lower 'ftolpl'. Youngest age to start was %d=(%d-%d).\n", (int)age, maxmax, ftolpl, *ncvyear, ncvloop, (int)(agefin+stepm/YEARM), (int)(age-stepm/YEARM), (int)delaymax); + first++; + }else if (first ==10){ + fprintf(ficlog, "Warning: the stable prevalence at age %d did not converge with the required precision (%g > ftolpl=%g) within %.d years and %d loops. Try to lower 'ftolpl'. Youngest age to start was %d=(%d-%d).\n", (int)age, maxmax, ftolpl, *ncvyear, ncvloop, (int)(agefin+stepm/YEARM), (int)(age-stepm/YEARM), (int)delaymax); + printf("Warning: the stable prevalence dit not converge. This warning came too often, IMaCh will stop notifying, even in its log file. Look at the graphs to appreciate the non convergence.\n"); + fprintf(ficlog,"Warning: the stable prevalence no convergence; too many cases, giving up noticing, even in log file\n"); + first++; } - fprintf(ficlog, "Warning: the stable prevalence at age %d did not converge with the required precision (%g > ftolpl=%g) within %.d years and %d loops. Try to lower 'ftolpl'. Youngest age to start was %d=(%d-%d).\n", (int)age, maxmax, ftolpl, *ncvyear, ncvloop, (int)(agefin+stepm/YEARM), (int)(age-stepm/YEARM), (int)delaymax); /* Try to lower 'ftol', for example from 1.e-8 to 6.e-9.\n", ftolpl, (int)age, (int)delaymax, (int)agefin, ncvloop, (int)age-(int)agefin); */ free_vector(min,1,nlstate); @@ -2930,7 +2997,7 @@ void powell(double p[], double **xi, int maxmax=0.; for(i=1; i<=nlstate; i++){ - meandiff[i]=(max[i]-min[i])/(max[i]+min[i])*2.; /* mean difference for each column */ + meandiff[i]=(max[i]-min[i])/(max[i]+min[i])*2.; /* mean difference for each column, could be nan! */ maxmax=FMAX(maxmax,meandiff[i]); /* printf("Back age= %d meandiff[%d]=%f, agefin=%d max[%d]=%f min[%d]=%f maxmax=%f\n", (int)age, i, meandiff[i],(int)agefin, i, max[i], i, min[i],maxmax); */ } /* i loop */ @@ -3064,7 +3131,9 @@ double **pmij(double **ps, double *cov, doldm=ddoldms; /* global pointers */ dnewm=ddnewms; dsavm=ddsavms; - + + /* Debug */ + /* printf("Bmij ij=%d, cov[2}=%f\n", ij, cov[2]); */ agefin=cov[2]; /* Bx = Diag(w_x) P_x Diag(Sum_i w^i_x p^ij_x */ /* bmij *//* age is cov[2], ij is included in cov, but we need for @@ -3388,6 +3457,8 @@ double ***hbxij(double ***po, int nhstep cov[1]=1.; agexact=age-( (h-1)*hstepm + (d) )*stepm/YEARM; /* age just before transition, d or d-1? */ /* agexact=age+((h-1)*hstepm + (d-1))*stepm/YEARM; /\* age just before transition *\/ */ + /* Debug */ + /* printf("hBxij age=%lf, agexact=%lf\n", age, agexact); */ cov[2]=agexact; if(nagesqr==1) cov[3]= agexact*agexact; @@ -3539,10 +3610,10 @@ double func( double *x) if(nagesqr==1) cov[3]= agexact*agexact; /* Should be changed here */ for (kk=1; kk<=cptcovage;kk++) { - if(!FixedV[Tvar[Tage[kk]]]) - cov[Tage[kk]+2+nagesqr]=covar[Tvar[Tage[kk]]][i]*agexact; /* Tage[kk] gives the data-covariate associated with age */ - else - cov[Tage[kk]+2+nagesqr]=cotvar[mw[mi][i]][Tvar[Tage[kk]]-ncovcol-nqv][i]*agexact; + if(!FixedV[Tvar[Tage[kk]]]) + cov[Tage[kk]+2+nagesqr]=covar[Tvar[Tage[kk]]][i]*agexact; /* Tage[kk] gives the data-covariate associated with age */ + else + cov[Tage[kk]+2+nagesqr]=cotvar[mw[mi][i]][Tvar[Tage[kk]]-ncovcol-nqv][i]*agexact; } out=matprod2(newm,oldm,1,nlstate+ndeath,1,nlstate+ndeath, 1,nlstate+ndeath,pmij(pmmij,cov,ncovmodel,x,nlstate)); @@ -3829,7 +3900,7 @@ double funcone( double *x) /* Fixed */ /* for (k=1; k<=cptcovn;k++) cov[2+nagesqr+k]=covar[Tvar[k]][i]; */ /* for (k=1; k<=ncoveff;k++){ /\* Simple and product fixed Dummy covariates without age* products *\/ */ - for (k=1; k<=ncovf;k++){ /* Simple and product fixed covariates without age* products */ + for (k=1; k<=ncovf;k++){ /* Simple and product fixed covariates without age* products *//* Missing values are set to -1 but should be dropped */ cov[ioffset+TvarFind[k]]=covar[Tvar[TvarFind[k]]][i];/* V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1, only V1 is fixed (k=6)*/ /* cov[ioffset+TvarFind[1]]=covar[Tvar[TvarFind[1]]][i]; */ /* cov[2+6]=covar[Tvar[6]][i]; */ @@ -4684,10 +4755,13 @@ Title=%s
Datafile=%s Firstpass=%d La if(s[m][iind]==-1) printf(" num=%ld m=%d, iind=%d s1=%d s2=%d agev at m=%d agebegin=%.2f ageend=%.2f, agemed=%d\n", num[iind], m, iind,s[m][iind],s[m+1][iind], (int)agev[m][iind],agebegin, ageend, (int)((agebegin+ageend)/2.)); freq[s[m][iind]][s[m+1][iind]][(int)agev[m][iind]] += weight[iind]; /* At age of beginning of transition, where status is known */ - for (z1=1; z1<= nqfveff; z1++) { /* Quantitative variables, calculating mean */ - idq[z1]=idq[z1]+weight[iind]; - meanq[z1]+=covar[ncovcol+z1][iind]*weight[iind]; /* Computes mean of quantitative with selected filter */ - stdq[z1]+=covar[ncovcol+z1][iind]*covar[ncovcol+z1][iind]*weight[iind]*weight[iind]; /* *weight[iind];*/ /* Computes mean of quantitative with selected filter */ + for (z1=1; z1<= nqfveff; z1++) { /* Quantitative variables, calculating mean on known values only */ + if(!isnan(covar[ncovcol+z1][iind])){ + idq[z1]=idq[z1]+weight[iind]; + meanq[z1]+=covar[ncovcol+z1][iind]*weight[iind]; /* Computes mean of quantitative with selected filter */ + /* stdq[z1]+=covar[ncovcol+z1][iind]*covar[ncovcol+z1][iind]*weight[iind]*weight[iind]; *//*error*/ + stdq[z1]+=covar[ncovcol+z1][iind]*covar[ncovcol+z1][iind]*weight[iind]; /* *weight[iind];*/ /* Computes mean of quantitative with selected filter */ + } } /* if((int)agev[m][iind] == 55) */ /* printf("j=%d, j1=%d Age %d, iind=%d, num=%09ld m=%d\n",j,j1,(int)agev[m][iind],iind, num[iind],m); */ @@ -4750,16 +4824,19 @@ Title=%s
Datafile=%s Firstpass=%d La Printing means of quantitative variables if any */ for (z1=1; z1<= nqfveff; z1++) { - fprintf(ficlog,"Mean of fixed quantitative variable V%d on %.0f individuals sum=%f", ncovcol+z1, idq[z1], meanq[z1]); + fprintf(ficlog,"Mean of fixed quantitative variable V%d on %.3g (weighted) individuals sum=%f", ncovcol+z1, idq[z1], meanq[z1]); fprintf(ficlog,", mean=%.3g\n",meanq[z1]/idq[z1]); if(weightopt==1){ printf(" Weighted mean and standard deviation of"); fprintf(ficlog," Weighted mean and standard deviation of"); fprintf(ficresphtmfr," Weighted mean and standard deviation of"); } - printf(" fixed quantitative variable V%d on %.0f representatives of the population : %6.3g (%6.3g)\n", ncovcol+z1, idq[z1],meanq[z1]/idq[z1], sqrt((stdq[z1]-meanq[z1]*meanq[z1]/idq[z1])/idq[z1])); - fprintf(ficlog," fixed quantitative variable V%d on %.0f representatives of the population : %6.3g (%6.3g)\n", ncovcol+z1, idq[z1],meanq[z1]/idq[z1], sqrt((stdq[z1]-meanq[z1]*meanq[z1]/idq[z1])/idq[z1])); - fprintf(ficresphtmfr," fixed quantitative variable V%d on %.0f representatives of the population : %6.3g (%6.3g)

\n", ncovcol+z1, idq[z1],meanq[z1]/idq[z1], sqrt((stdq[z1]-meanq[z1]*meanq[z1]/idq[z1])/idq[z1])); + /* mu = \frac{w x}{\sum w} + var = \frac{\sum w (x-mu)^2}{\sum w} = \frac{w x^2}{\sum w} - mu^2 + */ + printf(" fixed quantitative variable V%d on %.3g (weighted) representatives of the population : %8.5g (%8.5g)\n", ncovcol+z1, idq[z1],meanq[z1]/idq[z1], sqrt(stdq[z1]/idq[z1]-meanq[z1]*meanq[z1]/idq[z1]/idq[z1])); + fprintf(ficlog," fixed quantitative variable V%d on %.3g (weighted) representatives of the population : %8.5g (%8.5g)\n", ncovcol+z1, idq[z1],meanq[z1]/idq[z1], sqrt(stdq[z1]/idq[z1]-meanq[z1]*meanq[z1]/idq[z1]/idq[z1])); + fprintf(ficresphtmfr," fixed quantitative variable V%d on %.3g (weighted) representatives of the population : %8.5g (%8.5g)

\n", ncovcol+z1, idq[z1],meanq[z1]/idq[z1], sqrt(stdq[z1]/idq[z1]-meanq[z1]*meanq[z1]/idq[z1]/idq[z1])); } /* for (z1=1; z1<= nqtveff; z1++) { */ /* for(m=1;m<=lastpass;m++){ */ @@ -5262,33 +5339,41 @@ void concatwav(int wav[], int **dh, int for(i=1; i<=imx; i++){ /* For simple cases and if state is death */ mi=0; /* First valid wave */ mli=0; /* Last valid wave */ - m=firstpass; - while(s[m][i] <= nlstate){ /* a live state */ + m=firstpass; /* Loop on waves */ + while(s[m][i] <= nlstate){ /* a live state or unknown state */ if(m >firstpass && s[m][i]==s[m-1][i] && mint[m][i]==mint[m-1][i] && anint[m][i]==anint[m-1][i]){/* Two succesive identical information on wave m */ mli=m-1;/* mw[++mi][i]=m-1; */ }else 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; /* Valid wave: incrementing mi and updating mi; mw[mi] is the wave number of mi_th valid transition */ mli=m; } /* else might be a useless wave -1 and mi is not incremented and mw[mi] not updated */ if(m < lastpass){ /* m < lastpass, standard case */ m++; /* mi gives the "effective" current wave, m the current wave, go to next wave by incrementing m */ } - else{ /* m >= lastpass, eventual special issue with warning */ + else{ /* m = lastpass, eventual special issue with warning */ #ifdef UNKNOWNSTATUSNOTCONTRIBUTING break; #else - if(s[m][i]==-1 && (int) andc[i] == 9999 && (int)anint[m][i] != 9999){ + if(s[m][i]==-1 && (int) andc[i] == 9999 && (int)anint[m][i] != 9999){ /* no death date and known date of interview, case -2 (vital status unknown is warned later */ if(firsthree == 0){ printf("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} .\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, s[m][i], nlstate+ndeath); firsthree=1; + }else if(firsthree >=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); + firsthree++; + }else if(firsthree == 10){ + printf("Information, too many Information flags: no more reported to log either\n"); + fprintf(ficlog,"Information, too many Information flags: no more reported to log either\n"); + firsthree++; + }else{ + firsthree++; } - 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); - mw[++mi][i]=m; + mw[++mi][i]=m; /* Valid transition with unknown status */ mli=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? */ + if((int)anint[m][i] == 9999){ /* Has the vital status really been verified?not a transition */ 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.\n",num[i],i,lastpass,(int)mint[m][i],(int)anint[m][i], s[m][i], (int) moisdc[i], (int) andc[i], i, m); } @@ -5313,34 +5398,35 @@ void concatwav(int wav[], int **dh, int #ifndef DISPATCHINGKNOWNDEATHAFTERLASTWAVE else if ((int) andc[i] != 9999) { /* Date of death is known */ if ((int)anint[m][i]!= 9999) { /* date of last interview is known */ - if((andc[i]+moisdc[i]/12.) <=(anint[m][i]+mint[m][i]/12.)){ /* death occured before last wave and status should have been death instead of -1 */ + if((andc[i]+moisdc[i]/12.) <=(anint[m][i]+mint[m][i]/12.)){ /* month of death occured before last wave month and status should have been death instead of -1 */ nbwarn++; if(firstfiv==0){ - printf("Warning! Death for individual %ld line=%d occurred at %d/%d before last wave %d interviewed at %d/%d and should have been coded as death instead of '%d'. This case (%d)/wave (%d) is contributing 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], s[m][i], i,m ); + printf("Warning! Death for individual %ld line=%d occurred at %d/%d before last wave %d, interviewed on %d/%d and should have been coded as death instead of '%d'. This case (%d)/wave (%d) is contributing 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], s[m][i], i,m ); firstfiv=1; }else{ - fprintf(ficlog,"Warning! Death for individual %ld line=%d occurred at %d/%d before last wave %d interviewed at %d/%d and should have been coded as death instead of '%d'. This case (%d)/wave (%d) is contributing to likelihood.\n",num[i],i,(int) moisdc[i], (int) andc[i], lastpass,(int)mint[m][i],(int)anint[m][i], s[m][i], i,m ); + fprintf(ficlog,"Warning! Death for individual %ld line=%d occurred at %d/%d before last wave %d, interviewed on %d/%d and should have been coded as death instead of '%d'. This case (%d)/wave (%d) is contributing to likelihood.\n",num[i],i,(int) moisdc[i], (int) andc[i], lastpass,(int)mint[m][i],(int)anint[m][i], s[m][i], i,m ); } - }else{ /* Death occured afer last wave potential bias */ + s[m][i]=nlstate+1; /* Fixing the status as death. Be careful if multiple death states */ + }else{ /* Month of Death occured afer last wave month, potential bias */ nberr++; if(firstwo==0){ - printf("Error! Death for individual %ld line=%d occurred at %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. Please add a new fictive wave at the date of last vital status scan, with a dead status or alive but unknown state status (-1). See documentation\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 ); + printf("Error! Death for individual %ld line=%d occurred at %d/%d after last wave %d interviewed at %d/%d with status %d. Potential bias if other individuals are still alive on this date but ignored. This case (%d)/wave (%d) is skipped, no contribution to likelihood. Please add a new fictitious wave at the date of last vital status scan, with a dead status. See documentation\nOthers in log file only\n",num[i],i,(int) moisdc[i], (int) andc[i], lastpass,(int)mint[m][i],(int)anint[m][i], s[m][i], i,m ); firstwo=1; } - fprintf(ficlog,"Error! Death for individual %ld line=%d occurred at %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. Please add a new fictive wave at the date of last vital status scan, with a dead status or alive but unknown state status (-1). See documentation\n\n",num[i],i,(int) moisdc[i], (int) andc[i], lastpass,(int)mint[m][i],(int)anint[m][i], i,m ); + fprintf(ficlog,"Error! Death for individual %ld line=%d occurred at %d/%d after last wave %d interviewed at %d/%d with status %d. Potential bias if other individuals are still alive on this date but ignored. This case (%d)/wave (%d) is skipped, no contribution to likelihood. Please add a new fictitious wave at the date of last vital status scan, with a dead status. See documentation\n\n",num[i],i,(int) moisdc[i], (int) andc[i], lastpass,(int)mint[m][i],(int)anint[m][i], s[m][i], i,m ); } }else{ /* if date of interview is unknown */ /* death is known but not confirmed by death status at any wave */ if(firstfour==0){ - printf("Error! Death for individual %ld line=%d occurred %d/%d but not confirmed by any death status for any wave, including last wave %d at unknown date %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 ); + printf("Error! Death for individual %ld line=%d occurred %d/%d but not confirmed by any death status for any wave, including last wave %d at unknown date %d/%d with status %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], s[m][i], i,m ); firstfour=1; } - fprintf(ficlog,"Error! Death for individual %ld line=%d occurred %d/%d but not confirmed by any death status for any wave, including last wave %d at unknown date %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.\n",num[i],i,(int) moisdc[i], (int) andc[i], lastpass,(int)mint[m][i],(int)anint[m][i], i,m ); + fprintf(ficlog,"Error! Death for individual %ld line=%d occurred %d/%d but not confirmed by any death status for any wave, including last wave %d at unknown date %d/%d with status %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.\n",num[i],i,(int) moisdc[i], (int) andc[i], lastpass,(int)mint[m][i],(int)anint[m][i], s[m][i], i,m ); } } /* end if date of death is known */ #endif - wav[i]=mi; /* mi should be the last effective wave (or mli) */ - /* wav[i]=mw[mi][i]; */ + wav[i]=mi; /* mi should be the last effective wave (or mli), */ + /* wav[i]=mw[mi][i]; */ if(mi==0){ nbwarn++; if(first==0){ @@ -5354,7 +5440,10 @@ void concatwav(int wav[], int **dh, int } /* End individuals */ /* wav and mw are no more changed */ - + printf("Information, you have to check %d informations which haven't been logged!\n",firsthree); + fprintf(ficlog,"Information, you have to check %d informations which haven't been logged!\n",firsthree); + + for(i=1; i<=imx; i++){ for(mi=1; mi1 ){ - printf("Information, IMaCh doesn't treat covariate with missing values (-1), individual %d will be skipped.\n",i); - fprintf(ficlog,"Information, currently IMaCh doesn't treat covariate with missing values (-1), individual %d will be skipped.\n",i); + printf("ERROR, IMaCh doesn't treat covariate with missing values V%d=-1, individual %d will be skipped.\n",Tvar[k],i); + fprintf(ficlog,"ERROR, currently IMaCh doesn't treat covariate with missing values V%d=-1, individual %d will be skipped.\n",Tvar[k],i); + fflush(ficlog); + exit(1); } if ((ij < -1) || (ij > NCOVMAX)){ printf( "Error: minimal is less than -1 or maximal is bigger than %d. Exiting. \n", NCOVMAX ); @@ -5564,6 +5657,16 @@ void concatwav(int wav[], int **dh, int break; } /* end switch */ } /* end dummy test */ + if(Dummy[k]==1 && Typevar[k] !=1){ /* Dummy covariate and not age product */ + for (i=1; i<=imx; i++) { /* Loop on individuals: reads the data file to get the maximum value of the modality of this covariate Vj*/ + if(isnan(covar[Tvar[k]][i])){ + printf("ERROR, IMaCh doesn't treat fixed quantitative covariate with missing values V%d=., individual %d will be skipped.\n",Tvar[k],i); + fprintf(ficlog,"ERROR, currently IMaCh doesn't treat covariate with missing values V%d=., individual %d will be skipped.\n",Tvar[k],i); + fflush(ficlog); + exit(1); + } + } + } } /* end of loop on model-covariate k. nbcode[Tvark][1]=-1, nbcode[Tvark][1]=0 and nbcode[Tvark][2]=1 sets the value of covariate k*/ for (k=-1; k< maxncov; k++) Ndum[k]=0; @@ -6672,7 +6775,7 @@ To be simple, these graphs help to under /* nbcode[1][1]=0 nbcode[1][2]=1;*/ } /* for (k=1; k<=cptcovage;k++) cov[2+Tage[k]]=cov[2+Tage[k]]*cov[2]; */ - for (k=1; k<=cptcovage;k++) cov[2+Tage[k]]=nbcode[Tvar[Tage[k]]][codtabm(ij,k)]*cov[2]; + for (k=1; k<=cptcovage;k++) cov[2+Tage[k]+nagesqr]=nbcode[Tvar[Tage[k]]][codtabm(ij,k)]*cov[2]; for (k=1; k<=cptcovprod;k++) cov[2+nagesqr+Tprod[k]]=nbcode[Tvard[k][1]][codtabm(ij,k)]*nbcode[Tvard[k][2]][codtabm(ij,k)]; @@ -6921,7 +7024,7 @@ void printinghtml(char fileresu[], char m=pow(2,cptcoveff); if (cptcovn < 1) {m=1;ncodemax[1]=1;} - fprintf(fichtm," \n

"); jj1=0; @@ -7035,8 +7138,10 @@ divided by h: hPij if(prevfcast==1){ /* Projection of prevalence up to period (forward stable) prevalence in each health state */ for(cpt=1; cpt<=nlstate;cpt++){ - fprintf(fichtm,"
\n- Projection of cross-sectional prevalence (estimated with cases observed from %.1f to %.1f and mobil_average=%d), from year %.1f up to year %.1f tending to period (stable) forward prevalence in state %d. Or probability to be in state %d being in an observed weighted state (from 1 to %d). %s_%d-%d-%d.svg
\ -", dateprev1, dateprev2, mobilavproj, dateprojd, dateprojf, cpt, cpt, nlstate, subdirf2(optionfilefiname,"PROJ_"),cpt,k1,nres,subdirf2(optionfilefiname,"PROJ_"),cpt,k1,nres,subdirf2(optionfilefiname,"PROJ_"),cpt,k1,nres); + fprintf(fichtm,"
\n- Projection of cross-sectional prevalence (estimated with cases observed from %.1f to %.1f and mobil_average=%d), from year %.1f up to year %.1f tending to period (stable) forward prevalence in state %d. Or probability to be in state %d being in an observed weighted state (from 1 to %d). %s_%d-%d-%d.svg", dateprev1, dateprev2, mobilavproj, dateprojd, dateprojf, cpt, cpt, nlstate, subdirf2(optionfilefiname,"PROJ_"),cpt,k1,nres,subdirf2(optionfilefiname,"PROJ_"),cpt,k1,nres); + fprintf(fichtm," (data from text file %s.txt)\n
",subdirf2(optionfilefiname,"F_"),subdirf2(optionfilefiname,"F_")); + fprintf(fichtm,"", + subdirf2(optionfilefiname,"PROJ_"),cpt,k1,nres); } } if(prevbcast==1){ @@ -7045,14 +7150,16 @@ divided by h: hPij fprintf(fichtm,"
\n- Back projection of cross-sectional prevalence (estimated with cases observed from %.1f to %.1f and mobil_average=%d), \ from year %.1f up to year %.1f (probably close to stable [mixed] back prevalence in state %d (randomness in cross-sectional prevalence is not taken into \ account but can visually be appreciated). Or probability to have been in an state %d, knowing that the person was in either state (1 or %d) \ -with weights corresponding to observed prevalence at different ages. %s_%d-%d-%d.svg
\ - ", dateprev1, dateprev2, mobilavproj, dateback1, dateback2, cpt, cpt, nlstate, subdirf2(optionfilefiname,"PROJB_"),cpt,k1,nres,subdirf2(optionfilefiname,"PROJB_"),cpt,k1,nres,subdirf2(optionfilefiname,"PROJB_"),cpt,k1,nres); +with weights corresponding to observed prevalence at different ages. %s_%d-%d-%d.svg", dateprev1, dateprev2, mobilavproj, dateback1, dateback2, cpt, cpt, nlstate, subdirf2(optionfilefiname,"PROJB_"),cpt,k1,nres,subdirf2(optionfilefiname,"PROJB_"),cpt,k1,nres); + fprintf(fichtm," (data from text file %s.txt)\n
",subdirf2(optionfilefiname,"FB_"),subdirf2(optionfilefiname,"FB_")); + fprintf(fichtm," ", subdirf2(optionfilefiname,"PROJB_"),cpt,k1,nres); } } for(cpt=1; cpt<=nlstate;cpt++) { - fprintf(fichtm,"\n
- Life expectancy by health state (%d) at initial age and its decomposition into health expectancies in each alive state (1 to %d) (or area under each survival functions): %s_%d-%d-%d.svg
\ -",cpt,nlstate,subdirf2(optionfilefiname,"EXP_"),cpt,k1,nres,subdirf2(optionfilefiname,"EXP_"),cpt,k1,nres,subdirf2(optionfilefiname,"EXP_"),cpt,k1,nres); + fprintf(fichtm,"\n
- Life expectancy by health state (%d) at initial age and its decomposition into health expectancies in each alive state (1 to %d) (or area under each survival functions): %s_%d-%d-%d.svg",cpt,nlstate,subdirf2(optionfilefiname,"EXP_"),cpt,k1,nres,subdirf2(optionfilefiname,"EXP_"),cpt,k1,nres); + fprintf(fichtm," (data from text file %s.txt)\n
",subdirf2(optionfilefiname,"E_"),subdirf2(optionfilefiname,"E_")); + fprintf(fichtm,"", subdirf2(optionfilefiname,"EXP_"),cpt,k1,nres ); } /* } /\* end i1 *\/ */ }/* End k1 */ @@ -7104,11 +7211,47 @@ See page 'Matrix of variance-covariance /* else */ /* fprintf(fichtm,"\n No population forecast: popforecast = %d (instead of 1) or stepm = %d (instead of 1) or model=%s (instead of .)

\n",popforecast, stepm, model); */ fflush(fichtm); - fprintf(fichtm,"