/* $Id$
$State$
$Log$
+ 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
#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<<cptcoveff)?(((h-1) >> (k-1)) & 1) +1 : -1)*/
#define decodtabm(h,k,cptcoveff) (((h-1) >> (k-1)) & 1) +1
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 */
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 */
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 */
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
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;
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));
/* 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)];
return (0);
}
if( j != cptcovs ){ /* Be careful if a variable is in a product but not single */
- printf("ERROR: the number of variables in the resultline, %d, differs from the number of variables used in the model line, %d.\n",j, cptcovs);
+ printf("ERROR: the number of variables in this result line, %d, differs from the number of variables used in the model line, %d.\n",j, cptcovs);
fprintf(ficlog,"ERROR: the number of variables in the resultline, %d, differs from the number of variables used in the model line, %d.\n",j, cptcovs);
}
for(k=1; k<=j;k++){ /* Loop on any covariate of the result line */
if(nbocc(resultsav,'=') >1){
- cutl(stra,strb,resultsav,' '); /* keeps in strb after the first ' '
- resultsav= V4=1 V5=25.1 V3=0 stra= V5=25.1 V3=0 strb= V4=1 */
- cutl(strc,strd,strb,'='); /* strb:V4=1 strc=1 strd=V4 */
+ cutl(stra,strb,resultsav,' '); /* keeps in strb after the first ' ' (stra is the rest of the resultline to be analyzed in the next loop *//* resultsav= "V4=1 V5=25.1 V3=0" stra= "V5=25.1 V3=0" strb= "V4=1" */
+ cutl(strc,strd,strb,'='); /* strb:"V4=1" strc="1" strd="V4" */
}else
cutl(strc,strd,resultsav,'=');
- Tvalsel[k]=atof(strc); /* 1 */
+ Tvalsel[k]=atof(strc); /* 1 */ /* Tvalsel of k is the float value of the kth covariate appearing in this result line */
cutl(strc,stre,strd,'V'); /* strd='V4' strc=4 stre='V' */;
- Tvarsel[k]=atoi(strc);
+ Tvarsel[k]=atoi(strc); /* 4 */ /* Tvarsel is the id of the kth covariate in the result line Tvarsel[1] in "V4=1.." is 4.*/
/* Typevarsel[k]=1; /\* 1 for age product *\/ */
/* cptcovsel++; */
if (nbocc(stra,'=') >0)
strcpy(resultsav,stra); /* and analyzes it */
}
/* Checking for missing or useless values in comparison of current model needs */
- for(k1=1; k1<= cptcovt ;k1++){ /* model line V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */
- if(Typevar[k1]==0){ /* Single covariate in model */
+ for(k1=1; k1<= cptcovt ;k1++){ /* Loop on model. model line V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */
+ if(Typevar[k1]==0){ /* Single covariate in model *//*0 for simple covariate (dummy, quantitative, fixed or varying), 1 for age product, 2 for product */
match=0;
- for(k2=1; k2 <=j;k2++){/* result line V4=1 V5=24.1 V3=1 V2=8 V1=0 */
- if(Tvar[k1]==Tvarsel[k2]) {/* Tvar[1]=5 == Tvarsel[2]=5 */
+ for(k2=1; k2 <=j;k2++){/* Loop on resultline. In result line V4=1 V5=24.1 V3=1 V2=8 V1=0 */
+ if(Tvar[k1]==Tvarsel[k2]) {/* Tvar is coming from the model, Tvarsel from the result. Tvar[1]=5 == Tvarsel[2]=5 */
modelresult[k2]=k1;/* modelresult[2]=1 modelresult[1]=2 modelresult[3]=3 modelresult[6]=4 modelresult[9]=5 */
- match=1;
+ match=1; /* modelresult of k2 variable of resultline is identical to k1 variable of the model good */
break;
}
}
}
}
/* Checking for missing or useless values in comparison of current model needs */
- for(k2=1; k2 <=j;k2++){ /* result line V4=1 V5=24.1 V3=1 V2=8 V1=0 */
+ for(k2=1; k2 <=j;k2++){ /* Loop on resultline variables: result line V4=1 V5=24.1 V3=1 V2=8 V1=0 */
match=0;
- for(k1=1; k1<= cptcovt ;k1++){ /* model line V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */
+ for(k1=1; k1<= cptcovt ;k1++){ /* loop on model: model line V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */
if(Typevar[k1]==0){ /* Single */
if(Tvar[k1]==Tvarsel[k2]) { /* Tvar[2]=4 == Tvarsel[1]=4 */
- resultmodel[k1]=k2; /* resultmodel[2]=1 resultmodel[1]=2 resultmodel[3]=3 resultmodel[6]=4 resultmodel[9]=5 */
+ resultmodel[k1]=k2; /* k2th variable of the model corresponds to k1 variable of the model. resultmodel[2]=1 resultmodel[1]=2 resultmodel[3]=3 resultmodel[6]=4 resultmodel[9]=5 */
++match;
}
}
/* V(Tvqresult)=Tqresult V5=25.1 V2=8 Tqresult[nres=1][1]=25.1 */
/* V5*age V5 known which value for nres? */
/* Tqinvresult[2]=8 Tqinvresult[1]=25.1 */
- for(k1=1, k=0, k4=0, k4q=0; k1 <=cptcovt;k1++){ /* model line */
+ for(k1=1, k=0, k4=0, k4q=0; k1 <=cptcovt;k1++){ /* loop on model line */
if( Dummy[k1]==0 && Typevar[k1]==0 ){ /* Single dummy */
k3= resultmodel[k1]; /* resultmodel[2(V4)] = 1=k3 */
k2=(int)Tvarsel[k3]; /* Tvarsel[resultmodel[2]]= Tvarsel[1] = 4=k2 */
printf("Decoderesult Dummy k=%d, V(k2=V%d)= Tvalsel[%d]=%d, 2**(%d)\n",k, k2, k3, (int)Tvalsel[k3], k4);
k4++;;
} else if( Dummy[k1]==1 && Typevar[k1]==0 ){ /* Single quantitative */
- k3q= resultmodel[k1]; /* resultmodel[2] = 1=k3 */
- k2q=(int)Tvarsel[k3q]; /* Tvarsel[resultmodel[2]]= Tvarsel[1] = 4=k2 */
+ k3q= resultmodel[k1]; /* resultmodel[1(V5)] = 25.1=k3q */
+ k2q=(int)Tvarsel[k3q]; /* Tvarsel[resultmodel[1]]= Tvarsel[1] = 4=k2 */
Tqresult[nres][k4q+1]=Tvalsel[k3q]; /* Tqresult[nres][1]=25.1 */
Tvqresult[nres][k4q+1]=(int)Tvarsel[k3q]; /* Tvqresult[nres][1]=5 */
Tqinvresult[nres][(int)Tvarsel[k3q]]=Tvalsel[k3q]; /* Tqinvresult[nres][5]=25.1 */
/* If Tvar[k] >ncovcol it is a product */
/* Tvar[k] is the value n of Vn with n varying for 1 to nvcol, or p Vp=Vn*Vm for product */
/* Computing effective variables, ie used by the model, that is from the cptcovt variables */
- printf("Model=%s\n\
+ printf("Model=1+age+%s\n\
Typevar: 0 for simple covariate (dummy, quantitative, fixed or varying), 1 for age product, 2 for product \n\
Fixed[k] 0=fixed (product or simple), 1 varying, 2 fixed with age product, 3 varying with age product \n\
Dummy[k] 0=dummy (0 1), 1 quantitative (single or product without age), 2 dummy with age product, 3 quant with age product\n",model);
- fprintf(ficlog,"Model=%s\n\
+ fprintf(ficlog,"Model=1+age+%s\n\
Typevar: 0 for simple covariate (dummy, quantitative, fixed or varying), 1 for age product, 2 for product \n\
Fixed[k] 0=fixed (product or simple), 1 varying, 2 fixed with age product, 3 varying with age product \n\
Dummy[k] 0=dummy (0 1), 1 quantitative (single or product without age), 2 dummy with age product, 3 quant with age product\n",model);
num_filled=sscanf(line,"result:%[^\n]\n",resultline);
nresult++; /* Sum of resultlines */
printf("Result %d: result:%s\n",nresult, resultline);
- if(nresult > MAXRESULTLINES){
- printf("ERROR: Current version of IMaCh limits the number of resultlines to %d, you used %d\nYou can use the 'r' parameter file '%s' which uses option mle=0 to get other results. ",MAXRESULTLINES,nresult,rfileres);
- fprintf(ficlog,"ERROR: Current version of IMaCh limits the number of resultlines to %d, you used %d\nYou can use the 'r' parameter file '%s' which uses option mle=0 to get other results. ",MAXRESULTLINES,nresult,rfileres);
+ if(nresult > MAXRESULTLINESPONE-1){
+ printf("ERROR: Current version of IMaCh limits the number of resultlines to %d, you used %d\nYou can use the 'r' parameter file '%s' which uses option mle=0 to get other results. ",MAXRESULTLINESPONE-1,nresult,rfileres);
+ fprintf(ficlog,"ERROR: Current version of IMaCh limits the number of resultlines to %d, you used %d\nYou can use the 'r' parameter file '%s' which uses option mle=0 to get other results. ",MAXRESULTLINESPONE-1,nresult,rfileres);
goto end;
}
if(!decoderesult(resultline, nresult)){ /* Fills TKresult[nresult] combination and Tresult[nresult][k4+1] combination values */