--- imach/src/imach.c 2022/09/14 14:22:16 1.343 +++ imach/src/imach.c 2022/09/18 14:36:44 1.347 @@ -1,6 +1,22 @@ -/* $Id: imach.c,v 1.343 2022/09/14 14:22:16 brouard Exp $ +/* $Id: imach.c,v 1.347 2022/09/18 14:36:44 brouard Exp $ $State: Exp $ $Log: imach.c,v $ + Revision 1.347 2022/09/18 14:36:44 brouard + Summary: version 0.99r42 + + Revision 1.346 2022/09/16 13:52:36 brouard + * src/imach.c (Module): 0.99r41 Was an error when product of timevarying and fixed. Using FixedV[of name] now. Thank you Feinuo + + Revision 1.345 2022/09/16 13:40:11 brouard + Summary: Version 0.99r41 + + * imach.c (Module): 0.99r41 Was an error when product of timevarying and fixed. Using FixedV[of name] now. Thank you Feinuo + + Revision 1.344 2022/09/14 19:33:30 brouard + Summary: version 0.99r40 + + * imach.c (Module): Fixing names of variables in T_ (thanks to Feinuo) + Revision 1.343 2022/09/14 14:22:16 brouard Summary: version 0.99r39 @@ -1339,12 +1355,12 @@ double gnuplotversion=GNUPLOTVERSION; #define ODIRSEPARATOR '\\' #endif -/* $Id: imach.c,v 1.343 2022/09/14 14:22:16 brouard Exp $ */ +/* $Id: imach.c,v 1.347 2022/09/18 14:36:44 brouard Exp $ */ /* $State: Exp $ */ #include "version.h" char version[]=__IMACH_VERSION__; char copyright[]="September 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.343 $ $Date: 2022/09/14 14:22:16 $"; +char fullversion[]="$Revision: 1.347 $ $Date: 2022/09/18 14:36:44 $"; char strstart[80]; char optionfilext[10], optionfilefiname[FILENAMELENGTH]; int erreur=0, nberr=0, nbwarn=0; /* Error number, number of errors number of warnings */ @@ -3944,7 +3960,7 @@ double func( double *x) */ ioffset=2+nagesqr ; /* Fixed */ - for (kf=1; kf<=ncovf;kf++){ /* For each fixed covariate dummu or quant or prod */ + for (kf=1; kf<=ncovf;kf++){ /* For each fixed covariate dummy or quant or prod */ /* # 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 */ /* TvarF[1]=Tvar[6]=2, TvarF[2]=Tvar[7]=7, TvarF[3]=Tvar[9]=1 ID of fixed covariates or product V2, V1*V2, V1 */ @@ -3973,10 +3989,10 @@ double func( double *x) for(ncovv=1, iposold=0; ncovv <= ncovvt ; ncovv++){ /* Varying covariates (single and product but no age )*/ itv=TvarVV[ncovv]; /* TvarVV={3, 1, 3} gives the name of each varying covariate */ ipos=TvarVVind[ncovv]; /* TvarVVind={2, 5, 5] gives the position in the model of the ncovv th varying covariate*/ - if(TvarFind[itv]==0){ /* Not a fixed covariate */ + if(FixedV[itv]!=0){ /* Not a fixed covariate */ cotvarv=cotvar[mw[mi][i]][TvarVV[ncovv]][i]; /* cotvar[wav][ncovcol+nqv+iv][i] */ }else{ /* fixed covariate */ - cotvarv=covar[Tvar[TvarFind[itv]]][i]; + cotvarv=covar[itv][i]; /* Error: TvarFind gives the name, that is the true column of fixed covariates, but Tvar of the model */ } if(ipos!=iposold){ /* Not a product or first of a product */ cotvarvold=cotvarv; @@ -4379,13 +4395,36 @@ double funcone( double *x) * TvarVVind 2 3 7 7 8 8 9 9 * TvarFind[k] 1 0 0 0 0 0 0 0 0 */ + /* Other model ncovcol=5 nqv=0 ntv=3 nqtv=0 nlstate=3 + * V2 V3 V4 are fixed V6 V7 are timevarying so V8 and V5 are not in the model and product column will start at 9 Tvar[4]=6 + * FixedV[ncovcol+qv+ntv+nqtv] V5 + * V1 V2 V3 V4 V5 V6 V7 V8 + * 0 0 0 0 0 1 1 1 + * model= V2 + V3 + V4 + V6 + V7 + V6*V2 + V7*V2 + V6*V3 + V7*V3 + V6*V4 + V7*V4 + * kmodel 1 2 3 4 5 6 7 8 9 10 11 + * ncovf 1 2 3 + * ncovvt=14 1 2 3 4 5 6 7 8 9 10 11 12 13 14 + * TvarVV[1]@14 = itv {6, 7, 6, 2, 7, 2, 6, 3, 7, 3, 6, 4, 7, 4} + * TvarVVind[1]@14= {4, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11} + * TvarFind[1]@14= {1, 2, 3, 0 } + * Tvar[1]@20= {2, 3, 4, 6, 7, 9, 10, 11, 12, 13, 14} + * TvarFind[itv] 0 0 0 + * FixedV[itv] 1 1 1 0 1 0 1 0 1 0 0 + * Tvar[TvarFind[ncovf]]=[1]=2 [2]=3 [4]=4 + * Tvar[TvarFind[itv]] [0]=? ?ncovv 1 à ncovvt] + * Not a fixed cotvar[mw][itv][i] 6 7 6 2 7, 2, 6, 3, 7, 3, 6, 4, 7, 4} + * fixed covar[itv] [6] [7] [6][2] + */ + for(ncovv=1, iposold=0; ncovv <= ncovvt ; ncovv++){ /* Varying covariates (single and product but no age) including individual from products */ - itv=TvarVV[ncovv]; /* TvarVV={3, 1, 3} gives the name of each varying covariate */ + itv=TvarVV[ncovv]; /* TvarVV={3, 1, 3} gives the name of each varying covariate, exploding product */ ipos=TvarVVind[ncovv]; /* TvarVVind={2, 5, 5] gives the position in the model of the ncovv th varying covariate*/ - if(TvarFind[itv]==0){ /* Not a fixed covariate */ - cotvarv=cotvar[mw[mi][i]][TvarVV[ncovv]][i]; /* because cotvar starts now at first ncovcol+nqv+ (1 to nqtv) */ + /* if(TvarFind[itv]==0){ /\* Not a fixed covariate? Could be a fixed covariate of a product with a higher than ncovcol+nqv, itv *\/ */ + if(FixedV[itv]!=0){ /* Not a fixed covariate? Could be a fixed covariate of a product with a higher than ncovcol+nqv, itv */ + cotvarv=cotvar[mw[mi][i]][TvarVV[ncovv]][i]; /* because cotvar starts now at first ncovcol+nqv+ntv+nqtv (1 to nqtv) */ }else{ /* fixed covariate */ - cotvarv=covar[Tvar[TvarFind[itv]]][i]; + /* cotvarv=covar[Tvar[TvarFind[itv]]][i]; /\* Error: TvarFind gives the name, that is the true column of fixed covariates, but Tvar of the model *\/ */ + cotvarv=covar[itv][i]; /* Error: TvarFind gives the name, that is the true column of fixed covariates, but Tvar of the model */ } if(ipos!=iposold){ /* Not a product or first of a product */ cotvarvold=cotvarv; @@ -6811,6 +6850,7 @@ void concatwav(int wav[], int **dh, int /* fprintf(ficresprobmorprev," V%d=%f ",Tvqresult[nres][j],Tqresult[nres][resultmodel[nres][j]]); */ /* } */ for (j=1; j<= cptcovs; j++){ /* For each selected (single) quantitative value */ /* To be done*/ + /* fprintf(ficresprobmorprev," V%d=%lg ",Tvresult[nres][j],TinvDoQresult[nres][Tvresult[nres][j]]); */ fprintf(ficresprobmorprev," V%d=%lg ",Tvresult[nres][j],TinvDoQresult[nres][Tvresult[nres][j]]); } /* for(j=1;j<=cptcoveff;j++) */ @@ -8187,8 +8227,9 @@ void printinggnuplot(char fileresu[], ch fprintf(ficgp,"\nset ter pngcairo size 640, 480"); /* if(debugILK==1){ */ for(kf=1; kf <= ncovf; kf++){ /* For each simple dummy covariate of the model */ - kvar=Tvar[TvarFind[kf]]; /* variable */ - k=18+Tvar[TvarFind[kf]];/*offset because there are 18 columns in the ILK_ file */ + kvar=Tvar[TvarFind[kf]]; /* variable name */ + /* k=18+Tvar[TvarFind[kf]];/\*offset because there are 18 columns in the ILK_ file but could be placed else where *\/ */ + k=18+kf;/*offset because there are 18 columns in the ILK_ file */ for (i=1; i<= nlstate ; i ++) { fprintf(ficgp,"\nset out \"%s-p%dj-%d.png\";set ylabel \"Probability for each individual/wave\";",subdirf2(optionfilefiname,"ILK_"),i,kvar); fprintf(ficgp,"unset log;\n# For each simple dummy covariate of the model \n plot \"%s\"",subdirf(fileresilk)); @@ -10613,9 +10654,13 @@ int readdata(char datafile[], int firsto errno=0; lval=strtol(strb,&endptr,10); /* if (errno == ERANGE && (lval == LONG_MAX || lval == LONG_MIN))*/ - if( strb[0]=='\0' || (*endptr != '\0')){ - printf("Error reading data around '%s' at line number %d for individual %d, '%s'\nShould be a status of wave %d. Setting maxwav=%d might be wrong. Exiting.\n", strb, linei,i,line,j,maxwav); - fprintf(ficlog,"Error reading data around '%s' at line number %d for individual %d, '%s'\nShould be a status of wave %d. Setting maxwav=%d might be wrong. Exiting.\n", strb, linei,i,line,j,maxwav);fflush(ficlog); + if( strb[0]=='\0' || (*endptr != '\0' )){ + printf("Error reading data around '%s' at line number %d for individual %d, '%s'\nShould be a status of wave %d. Setting maxwav=%d might be wrong. Exiting.\n", strb, linei,i,line,j,maxwav); + fprintf(ficlog,"Error reading data around '%s' at line number %d for individual %d, '%s'\nShould be a status of wave %d. Setting maxwav=%d might be wrong. Exiting.\n", strb, linei,i,line,j,maxwav);fflush(ficlog); + return 1; + }else if( lval==0 || lval > nlstate+ndeath){ + printf("Error in data around '%s' at line number %d for individual %d, '%s'\n Should be a state at wave %d. A state should be 1 to %d and not %d.\n Fix your data file '%s'! Exiting.\n", strb, linei,i,line,j,nlstate+ndeath, lval, datafile);fflush(stdout); + fprintf(ficlog,"Error in data around '%s' at line number %d for individual %d, '%s'\n Should be a state at wave %d. A state should be 1 to %d and not %d.\n Fix your data file '%s'! Exiting.\n", strb, linei,i,line,j,nlstate+ndeath, lval, datafile); fflush(ficlog); return 1; } } @@ -10964,7 +11009,7 @@ int decoderesult( char resultline[], int /* k counting number of combination of single dummies in the equation model */ /* k4 counting single dummies in the equation model */ /* k4q counting single quantitatives in the equation model */ - if( Dummy[k1]==0 && Typevar[k1]==0 ){ /* Dummy and Single, k1 is sorting according to MODEL, but k3 to resultline */ + if( Dummy[k1]==0 && Typevar[k1]==0 ){ /* Dummy and Single, fixed or timevarying, k1 is sorting according to MODEL, but k3 to resultline */ /* k4+1= (not always if quant in model) position in the resultline V(Tvarsel)=Tvalsel=Tresult[nres][pos](value); V(Tvresult[nres][pos] (variable): V(variable)=value) */ /* modelresult[k3]=k1: k3th position in the result line corresponds to the k1 position in the model line (doesn't work with products)*/ /* Value in the (current nres) resultline of the variable at the k1th position in the model equation resultmodel[nres][k1]= k3 */ @@ -11114,23 +11159,23 @@ int decodemodel( char model[], int lasto * Model V2 + V1 + V3*age + V3 + V5*V6 + V7*V8 + V8*age + V8 * k= 1 2 3 4 5 6 7 8 * cptcovn number of covariates (not including constant and age ) = # of + plus 1 = 7+1=8 - * covar[k,i], value of kth covariate if not including age for individual i: + * covar[k,i], are for fixed covariates, value of kth covariate if not including age for individual i: * covar[1][i]= (V1), covar[4][i]=(V4), covar[8][i]=(V8) * Tvar[k] # of the kth covariate: Tvar[1]=2 Tvar[2]=1 Tvar[4]=3 Tvar[8]=8 * if multiplied by age: V3*age Tvar[3=V3*age]=3 (V3) Tvar[7]=8 and * Tage[++cptcovage]=k - * if products, new covar are created after ncovcol with k1 + * if products, new covar are created after ncovcol + nqv (quanti fixed) with k1 * Tvar[k]=ncovcol+k1; # of the kth covariate product: Tvar[5]=ncovcol+1=10 Tvar[6]=ncovcol+1=11 * Tprod[k1]=k; Tprod[1]=5 Tprod[2]= 6; gives the position of the k1th product * Tvard[k1][1]=m Tvard[k1][2]=m; Tvard[1][1]=5 (V5) Tvard[1][2]=6 Tvard[2][1]=7 (V7) Tvard[2][2]=8 * Tvar[cptcovn+k2]=Tvard[k1][1];Tvar[cptcovn+k2+1]=Tvard[k1][2]; * Tvar[8+1]=5;Tvar[8+2]=6;Tvar[8+3]=7;Tvar[8+4]=8 inverted * V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 - * < ncovcol=8 > + * < ncovcol=8 8 fixed covariate. Additional starts at 9 (V5*V6) and 10(V7*V8) > * Model V2 + V1 + V3*age + V3 + V5*V6 + V7*V8 + V8*age + V8 d1 d1 d2 d2 * k= 1 2 3 4 5 6 7 8 9 10 11 12 - * Tvar[k]= 2 1 3 3 10 11 8 8 5 6 7 8 - * p Tvar[1]@12={2, 1, 3, 3, 11, 10, 8, 8, 7, 8, 5, 6} + * Tvard[k]= 2 1 3 3 10 11 8 8 5 6 7 8 + * p Tvar[1]@12={2, 1, 3, 3, 9, 10, 8, 8} * p Tprod[1]@2={ 6, 5} *p Tvard[1][1]@4= {7, 8, 5, 6} * covar[k][i]= V2 V1 ? V3 V5*V6? V7*V8? ? V8 @@ -14352,9 +14397,10 @@ Please run with mle=-1 to get a correct /* printf("\n j=%d In computing T_ Dummy[modelresult[%d][%d]]=%d, modelresult[%d][%d]=%d cptcovs=%d, cptcoveff=%d Fixed[modelresult[nres][j]]=%d\n", j, nres, j, Dummy[modelresult[nres][j]],nres,j,modelresult[nres][j],cptcovs, cptcoveff,Fixed[modelresult[nres][j]]); /\* end if dummy or quanti *\/ */ if(Dummy[modelresult[nres][j]]==0){/* Dummy variable of the variable in position modelresult in the model corresponding to j in resultline */ - printf("V%d=%lg ",Tvresult[nres][j],TinvDoQresult[nres][j]); /* Output of each value for the combination TKresult[nres], ordere by the covariate values in the resultline */ - fprintf(ficlog,"V%d=%lg ",Tvresult[nres][j],TinvDoQresult[nres][j]); /* Output of each value for the combination TKresult[nres], ordere by the covariate values in the resultline */ - fprintf(ficrest,"V%d=%lg ",Tvresult[nres][j],TinvDoQresult[nres][j]); /* Output of each value for the combination TKresult[nres], ordere by the covariate values in the resultline */ + /* printf("V%d=%lg ",Tvresult[nres][j],TinvDoQresult[nres][j]); /\* Output of each value for the combination TKresult[nres], ordere by the covariate values in the resultline *\/ */ /* TinvDoQresult[nres][Name of the variable] */ + printf("V%d=%lg ",Tvresult[nres][j],TinvDoQresult[nres][Tvresult[nres][j]]); /* Output of each value for the combination TKresult[nres], ordered by the covariate values in the resultline */ + fprintf(ficlog,"V%d=%lg ",Tvresult[nres][j],TinvDoQresult[nres][Tvresult[nres][j]]); /* Output of each value for the combination TKresult[nres], ordere by the covariate values in the resultline */ + fprintf(ficrest,"V%d=%lg ",Tvresult[nres][j],TinvDoQresult[nres][Tvresult[nres][j]]); /* Output of each value for the combination TKresult[nres], ordere by the covariate values in the resultline */ if(Fixed[modelresult[nres][j]]==0){ /* Fixed */ printf("fixed ");fprintf(ficlog,"fixed ");fprintf(ficrest,"fixed "); }else{