/* $Id$
$State$
$Log$
+ Revision 1.231 2016/08/22 07:17:15 brouard
+ Summary: not working
+
Revision 1.230 2016/08/22 06:55:53 brouard
Summary: Not working
int cptcovage=0; /**< Number of covariates with age: V3*age only =1 */
int cptcovprodnoage=0; /**< Number of covariate products without age */
int cptcoveff=0; /* Total number of covariates to vary for printing results */
-int ncoveff=0; /* Total number of effective covariates in the model */
+int ncovf=0; /* Total number of effective fixed covariates (dummy of quantitative) in the model */
+int ncovv=0; /* Total number of effective (wave) varying covariates (dummy of quantitative) in the model */
+int ncova=0; /* Total number of effective (wave and stepm) varying with age covariates (dummy of quantitative) in the model */
+
+int ncoveff=0; /* Total number of effective fixed dummy covariates in the model */
int nqfveff=0; /**< nqfveff Number of Quantitative Fixed Variables Effective */
int ntveff=0; /**< ntveff number of effective time varying variables */
int nqtveff=0; /**< ntqveff number of effective time varying quantitative variables */
double ***cotqvar; /* Time varying quantitative covariate itqv */
double idx;
int **nbcode, *Tvar; /**< model=V2 => Tvar[1]= 2 */
+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 */
+int *TvarV; /**< TvarV[1]=Tvar[1]=5, TvarV[2]=Tvar[2]=4 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */
+int *TvarVind; /**< TvarVind[1]=1, TvarVind[2]=2 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */
+int *TvarA; /**< TvarA[1]=Tvar[5]=5, TvarA[2]=Tvar[8]=1 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */
+int *TvarAind; /**< TvarindA[1]=5, TvarAind[2]=8 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */
int *TvarFD; /**< TvarFD[1]=V1 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */
int *TvarFDind; /* TvarFDind[1]=9 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */
int *TvarFQ; /* TvarFQ[1]=V2 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */ /* Only simple fixed quantitative variable */
ioffset=2+nagesqr+cptcovage;
/* for (k=1; k<=cptcovn;k++){ /\* Simple and product covariates without age* products *\/ */
for (k=1; k<=ncoveff;k++){ /* Simple and product covariates without age* products */
- cov[++ioffset]=covar[Tvar[k]][i];
+ cov[++ioffset]=covar[Tvar[k]][i];
}
for(iqv=1; iqv <= nqfveff; iqv++){ /* Quantitatives and Fixed covariates */
- cov[++ioffset]=coqvar[Tvar[iqv]][i];
+ cov[++ioffset]=coqvar[Tvar[iqv]][i];
}
/* In model V2+V1*V4+age*V3+V3*V2 Tvar[1] is V2, Tvar[2=V1*V4]
ioffset=0;
for (i=1,ipmx=0, sw=0.; i<=imx; i++){
ioffset=2+nagesqr+cptcovage;
+ /* 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 */
- cov[++ioffset]=covar[TvarFD[k]][i];/* V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1, only V1 is fixed (k=6)*/
- }
- for (k=1; k<=nqfveff;k++){ /* Simple and product fixed Quantitative covariates without age* products */
- cov[++ioffset]=coqvar[TvarFQ[k]][i];/* V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1, only V2 and V1*V2 is fixed (k=6 and 7?)*/
- }
+ /* 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 */
+ 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]; */
+/* cov[2+6]=covar[2][i]; V2 */
+/* cov[TvarFind[2]]=covar[Tvar[TvarFind[2]]][i]; */
+/* cov[2+7]=covar[Tvar[7]][i]; */
+/* cov[2+7]=covar[7][i]; V7=V1*V2 */
+/* cov[TvarFind[3]]=covar[Tvar[TvarFind[3]]][i]; */
+/* cov[2+9]=covar[Tvar[9]][i]; */
+/* cov[2+9]=covar[1][i]; V1 */
+ }
+ /* for (k=1; k<=nqfveff;k++){ /\* Simple and product fixed Quantitative covariates without age* products *\/ */
+ /* cov[++ioffset]=coqvar[TvarFQ[k]][i];/\* V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1, only V2 and V1*V2 is fixed (k=6 and 7?)*\/ */
+ /* } */
/* for(iqv=1; iqv <= nqfveff; iqv++){ /\* Quantitative fixed covariates *\/ */
/* cov[++ioffset]=coqvar[Tvar[iqv]][i]; /\* Only V2 k=6 and V1*V2 7 *\/ */
/* } */
+ /* Wave varying (but not age varying) */
for(mi=1; mi<= wav[i]-1; mi++){ /* Varying with waves */
- for(itv=1; itv <= ntveff; itv++){ /* Varying dummy covariates (single??)*/
+ for(k=1; k <= ncovv ; k++){ /* Varying covariates (single and product but no age )*/
+ cov[ioffset+TvarVind[k]]=cotvar[mw[mi][i]][Tvar[TvarFind[k]]][i];
+ }
+ /* for(itv=1; itv <= ntveff; itv++){ /\* Varying dummy covariates (single??)*\/ */
/* iv= Tvar[Tmodelind[ioffset-2-nagesqr-cptcovage+itv]]-ncovcol-nqv; /\* Counting the # varying covariate from 1 to ntveff *\/ */
/* cov[ioffset+iv]=cotvar[mw[mi][i]][iv][i]; */
- k=ioffset-2-nagesqr-cptcovage+itv; /* position in simple model */
- cov[ioffset+itv]=cotvar[mw[mi][i]][TmodelInvind[itv]][i];
+ /* k=ioffset-2-nagesqr-cptcovage+itv; /\* position in simple model *\/ */
+ /* cov[ioffset+itv]=cotvar[mw[mi][i]][TmodelInvind[itv]][i]; */
/* printf(" i=%d,mi=%d,itv=%d,TmodelInvind[itv]=%d,cotvar[mw[mi][i]][TmodelInvind[itv]][i]=%f\n", i, mi, itv, TmodelInvind[itv],cotvar[mw[mi][i]][TmodelInvind[itv]][i]); */
- }
- for(iqtv=1; iqtv <= nqtveff; iqtv++){ /* Varying quantitatives covariates */
- iv=TmodelInvQind[iqtv]; /* Counting the # varying covariate from 1 to ntveff */
- /* printf(" i=%d,mi=%d,iqtv=%d,TmodelInvQind[iqtv]=%d,cotqvar[mw[mi][i]][TmodelInvQind[iqtv]][i]=%f\n", i, mi, iqtv, TmodelInvQind[iqtv],cotqvar[mw[mi][i]][TmodelInvQind[iqtv]][i]); */
- cov[ioffset+ntveff+iqtv]=cotqvar[mw[mi][i]][TmodelInvQind[iqtv]][i];
- }
+ /* for(iqtv=1; iqtv <= nqtveff; iqtv++){ /\* Varying quantitatives covariates *\/ */
+ /* iv=TmodelInvQind[iqtv]; /\* Counting the # varying covariate from 1 to ntveff *\/ */
+ /* /\* printf(" i=%d,mi=%d,iqtv=%d,TmodelInvQind[iqtv]=%d,cotqvar[mw[mi][i]][TmodelInvQind[iqtv]][i]=%f\n", i, mi, iqtv, TmodelInvQind[iqtv],cotqvar[mw[mi][i]][TmodelInvQind[iqtv]][i]); *\/ */
+ /* cov[ioffset+ntveff+iqtv]=cotqvar[mw[mi][i]][TmodelInvQind[iqtv]][i]; */
+ /* } */
for (ii=1;ii<=nlstate+ndeath;ii++)
for (j=1;j<=nlstate+ndeath;j++){
oldm[ii][j]=(ii==j ? 1.0 : 0.0);
* is higher than the multiple of stepm and negative otherwise.
*/
if( s2 > nlstate && (mle <5) ){ /* Jackson */
- lli=log(out[s1][s2] - savm[s1][s2]);
+ lli=log(out[s1][s2] - savm[s1][s2]);
} else if ( s2==-1 ) { /* alive */
- for (j=1,survp=0. ; j<=nlstate; j++)
- survp += (1.+bbh)*out[s1][j]- bbh*savm[s1][j];
- lli= log(survp);
+ for (j=1,survp=0. ; j<=nlstate; j++)
+ survp += (1.+bbh)*out[s1][j]- bbh*savm[s1][j];
+ lli= log(survp);
}else if (mle==1){
- lli= log((1.+bbh)*out[s1][s2]- bbh*savm[s1][s2]); /* linear interpolation */
+ lli= log((1.+bbh)*out[s1][s2]- bbh*savm[s1][s2]); /* linear interpolation */
} else if(mle==2){
- 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 */
+ 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 */
} else if(mle==3){ /* exponential inter-extrapolation */
- lli= (savm[s1][s2]>(double)1.e-8 ?(1.+bbh)*log(out[s1][s2])- bbh*log(savm[s1][s2]):log((1.+bbh)*out[s1][s2])); /* exponential inter-extrapolation */
+ lli= (savm[s1][s2]>(double)1.e-8 ?(1.+bbh)*log(out[s1][s2])- bbh*log(savm[s1][s2]):log((1.+bbh)*out[s1][s2])); /* exponential inter-extrapolation */
} else if (mle==4){ /* mle=4 no inter-extrapolation */
- lli=log(out[s1][s2]); /* Original formula */
+ lli=log(out[s1][s2]); /* Original formula */
} else{ /* mle=0 back to 1 */
- lli= log((1.+bbh)*out[s1][s2]- bbh*savm[s1][s2]); /* linear interpolation */
- /*lli=log(out[s1][s2]); */ /* Original formula */
+ lli= log((1.+bbh)*out[s1][s2]- bbh*savm[s1][s2]); /* linear interpolation */
+ /*lli=log(out[s1][s2]); */ /* Original formula */
} /* End of if */
ipmx +=1;
sw += weight[i];
ll[s[mw[mi][i]][i]] += 2*weight[i]*lli;
/*printf("i=%6d s1=%1d s2=%1d mi=%1d mw=%1d dh=%3d prob=%10.6f w=%6.4f out=%10.6f sav=%10.6f\n",i,s1,s2,mi,mw[mi][i],dh[mi][i],exp(lli),weight[i],out[s1][s2],savm[s1][s2]); */
if(globpr){
- fprintf(ficresilk,"%9ld %6.1f %6.1f %6d %2d %2d %2d %2d %3d %15.6f %8.4f %8.3f\
+ fprintf(ficresilk,"%9ld %6.1f %6.1f %6d %2d %2d %2d %2d %3d %15.6f %8.4f %8.3f\
%11.6f %11.6f %11.6f ", \
- num[i], agebegin, ageend, i,s1,s2,mi,mw[mi][i],dh[mi][i],exp(lli),weight[i],weight[i]*gipmx/gsw,
- 2*weight[i]*lli,out[s1][s2],savm[s1][s2]);
- for(k=1,llt=0.,l=0.; k<=nlstate; k++){
- llt +=ll[k]*gipmx/gsw;
- fprintf(ficresilk," %10.6f",-ll[k]*gipmx/gsw);
- }
- fprintf(ficresilk," %10.6f\n", -llt);
+ num[i], agebegin, ageend, i,s1,s2,mi,mw[mi][i],dh[mi][i],exp(lli),weight[i],weight[i]*gipmx/gsw,
+ 2*weight[i]*lli,out[s1][s2],savm[s1][s2]);
+ for(k=1,llt=0.,l=0.; k<=nlstate; k++){
+ llt +=ll[k]*gipmx/gsw;
+ fprintf(ficresilk," %10.6f",-ll[k]*gipmx/gsw);
+ }
+ fprintf(ficresilk," %10.6f\n", -llt);
}
- } /* end of wave */
- } /* end of individual */
- for(k=1,l=0.; k<=nlstate; k++) l += ll[k];
- /* printf("l1=%f l2=%f ",ll[1],ll[2]); */
- l= l*ipmx/sw; /* To get the same order of magnitude as if weight=1 for every body */
- if(globpr==0){ /* First time we count the contributions and weights */
- gipmx=ipmx;
- gsw=sw;
- }
- return -l;
+ } /* end of wave */
+} /* end of individual */
+for(k=1,l=0.; k<=nlstate; k++) l += ll[k];
+/* printf("l1=%f l2=%f ",ll[1],ll[2]); */
+l= l*ipmx/sw; /* To get the same order of magnitude as if weight=1 for every body */
+if(globpr==0){ /* First time we count the contributions and weights */
+ gipmx=ipmx;
+ gsw=sw;
+}
+return -l;
}
/* Loops on waves */
for (j=maxwav;j>=1;j--){
for (iv=nqtv;iv>=1;iv--){ /* Loop on time varying quantitative variables */
- cutv(stra, strb, line, ' ');
- if(strb[0]=='.') { /* Missing value */
- lval=-1;
- cotqvar[j][iv][i]=-1; /* 0.0/0.0 */
- if(isalpha(strb[1])) { /* .m or .d Really Missing value */
- printf("Error reading data around '%s' at line number %d for individual %d, '%s'\nShould be the %d th quantitative value out of %d measured at wave %d. If missing, you should remove this individual or impute a value. Exiting.\n", strb, linei,i,line,iv, nqtv, j);
- fprintf(ficlog,"Error reading data around '%s' at line number %d for individual %d, '%s'\nShould be the %d th quantitative value out of %d measured at wave %d. If missing, you should remove this individual or impute a value. Exiting.\n", strb, linei,i,line,iv, nqtv, j);fflush(ficlog);
- return 1;
- }
- }else{
- errno=0;
- /* what_kind_of_number(strb); */
- dval=strtod(strb,&endptr);
- /* if( strb[0]=='\0' || (*endptr != '\0')){ */
- /* if(strb != endptr && *endptr == '\0') */
- /* dval=dlval; */
- /* 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 the %d th quantitative value out of %d measured at wave %d. Setting maxwav=%d might be wrong. Exiting.\n", strb, linei,i,line,iv, nqtv, j,maxwav);
- fprintf(ficlog,"Error reading data around '%s' at line number %d for individual %d, '%s'\nShould be the %d th quantitative value out of %d measured at wave %d. Setting maxwav=%d might be wrong. Exiting.\n", strb, linei,i,line, iv, nqtv, j,maxwav);fflush(ficlog);
- return 1;
- }
- cotqvar[j][iv][i]=dval;
- }
- strcpy(line,stra);
+ cutv(stra, strb, line, ' ');
+ if(strb[0]=='.') { /* Missing value */
+ lval=-1;
+ cotqvar[j][iv][i]=-1; /* 0.0/0.0 */
+ cotvar[j][ntv+iv][i]=-1; /* For performance reasons */
+ if(isalpha(strb[1])) { /* .m or .d Really Missing value */
+ printf("Error reading data around '%s' at line number %d for individual %d, '%s'\nShould be the %d th quantitative value out of %d measured at wave %d. If missing, you should remove this individual or impute a value. Exiting.\n", strb, linei,i,line,iv, nqtv, j);
+ fprintf(ficlog,"Error reading data around '%s' at line number %d for individual %d, '%s'\nShould be the %d th quantitative value out of %d measured at wave %d. If missing, you should remove this individual or impute a value. Exiting.\n", strb, linei,i,line,iv, nqtv, j);fflush(ficlog);
+ return 1;
+ }
+ }else{
+ errno=0;
+ /* what_kind_of_number(strb); */
+ dval=strtod(strb,&endptr);
+ /* if( strb[0]=='\0' || (*endptr != '\0')){ */
+ /* if(strb != endptr && *endptr == '\0') */
+ /* dval=dlval; */
+ /* 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 the %d th quantitative value out of %d measured at wave %d. Setting maxwav=%d might be wrong. Exiting.\n", strb, linei,i,line,iv, nqtv, j,maxwav);
+ fprintf(ficlog,"Error reading data around '%s' at line number %d for individual %d, '%s'\nShould be the %d th quantitative value out of %d measured at wave %d. Setting maxwav=%d might be wrong. Exiting.\n", strb, linei,i,line, iv, nqtv, j,maxwav);fflush(ficlog);
+ return 1;
+ }
+ cotqvar[j][iv][i]=dval;
+ cotvar[j][ntv+iv][i]=dval;
+ }
+ strcpy(line,stra);
}/* end loop ntqv */
for (iv=ntv;iv>=1;iv--){ /* Loop on time varying dummies */
- cutv(stra, strb, line, ' ');
- if(strb[0]=='.') { /* Missing value */
- lval=-1;
- }else{
- 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 the %d th dummy covariate out of %d measured at wave %d. Setting maxwav=%d might be wrong. Exiting.\n", strb, linei,i,line,iv, ntv, j,maxwav);
- fprintf(ficlog,"Error reading data around '%s' at line number %d for individual %d, '%s'\nShould be the %d dummy covariate out of %d measured wave %d. Setting maxwav=%d might be wrong. Exiting.\n", strb, linei,i,line,iv, ntv,j,maxwav);fflush(ficlog);
- return 1;
- }
- }
- if(lval <-1 || lval >1){
- printf("Error reading data around '%ld' at line number %d for individual %d, '%s'\n \
+ cutv(stra, strb, line, ' ');
+ if(strb[0]=='.') { /* Missing value */
+ lval=-1;
+ }else{
+ 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 the %d th dummy covariate out of %d measured at wave %d. Setting maxwav=%d might be wrong. Exiting.\n", strb, linei,i,line,iv, ntv, j,maxwav);
+ fprintf(ficlog,"Error reading data around '%s' at line number %d for individual %d, '%s'\nShould be the %d dummy covariate out of %d measured wave %d. Setting maxwav=%d might be wrong. Exiting.\n", strb, linei,i,line,iv, ntv,j,maxwav);fflush(ficlog);
+ return 1;
+ }
+ }
+ if(lval <-1 || lval >1){
+ printf("Error reading data around '%ld' at line number %d for individual %d, '%s'\n \
Should be a value of %d(nth) covariate (0 should be the value for the reference and 1\n \
for the alternative. IMaCh does not build design variables automatically, do it yourself.\n \
- For example, for multinomial values like 1, 2 and 3,\n \
- build V1=0 V2=0 for the reference value (1),\n \
- V1=1 V2=0 for (2) \n \
+ For example, for multinomial values like 1, 2 and 3,\n \
+ build V1=0 V2=0 for the reference value (1),\n \
+ V1=1 V2=0 for (2) \n \
and V1=0 V2=1 for (3). V1=1 V2=1 should not exist and the corresponding\n \
- output of IMaCh is often meaningless.\n \
+ output of IMaCh is often meaningless.\n \
Exiting.\n",lval,linei, i,line,j);
- fprintf(ficlog,"Error reading data around '%ld' at line number %d for individual %d, '%s'\n \
+ fprintf(ficlog,"Error reading data around '%ld' at line number %d for individual %d, '%s'\n \
Should be a value of %d(nth) covariate (0 should be the value for the reference and 1\n \
for the alternative. IMaCh does not build design variables automatically, do it yourself.\n \
- For example, for multinomial values like 1, 2 and 3,\n \
- build V1=0 V2=0 for the reference value (1),\n \
- V1=1 V2=0 for (2) \n \
+ For example, for multinomial values like 1, 2 and 3,\n \
+ build V1=0 V2=0 for the reference value (1),\n \
+ V1=1 V2=0 for (2) \n \
and V1=0 V2=1 for (3). V1=1 V2=1 should not exist and the corresponding\n \
- output of IMaCh is often meaningless.\n \
+ output of IMaCh is often meaningless.\n \
Exiting.\n",lval,linei, i,line,j);fflush(ficlog);
- return 1;
- }
- cotvar[j][iv][i]=(double)(lval);
- strcpy(line,stra);
+ return 1;
+ }
+ cotvar[j][iv][i]=(double)(lval);
+ strcpy(line,stra);
}/* end loop ntv */
/* Statuses at wave */
cutv(stra, strb, line, ' ');
if(strb[0]=='.') { /* Missing value */
- lval=-1;
+ lval=-1;
}else{
- 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);
- return 1;
- }
+ 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);
+ return 1;
+ }
}
s[j][i]=lval;
}
cptcovage=0;
for(k=1; k<=cptcovt;k++){ /* Loop on total covariates of the model */
- cutl(stra,strb,modelsav,'+'); /* keeps in strb after the first '+'
+ cutl(stra,strb,modelsav,'+'); /* keeps in strb after the first '+'
modelsav==V2+V1+V4+V3*age strb=V3*age stra=V2+V1+V4 */
- if (nbocc(modelsav,'+')==0) strcpy(strb,modelsav); /* and analyzes it */
- /* printf("i=%d a=%s b=%s sav=%s\n",i, stra,strb,modelsav);*/
- /*scanf("%d",i);*/
- if (strchr(strb,'*')) { /**< Model includes a product V2+V1+V4+V3*age strb=V3*age */
- cutl(strc,strd,strb,'*'); /**< strd*strc Vm*Vn: strb=V3*age(input) strc=age strd=V3 ; V3*V2 strc=V2, strd=V3 */
- if (strcmp(strc,"age")==0) { /**< Model includes age: Vn*age */
- /* covar is not filled and then is empty */
- cptcovprod--;
- cutl(stre,strb,strd,'V'); /* strd=V3(input): stre="3" */
- Tvar[k]=atoi(stre); /* V2+V1+V4+V3*age Tvar[4]=3 ; V1+V2*age Tvar[2]=2; V1+V1*age Tvar[2]=1 */
- Typevar[k]=1; /* 1 for age product */
- cptcovage++; /* Sums the number of covariates which include age as a product */
- Tage[cptcovage]=k; /* Tvar[4]=3, Tage[1] = 4 or V1+V1*age Tvar[2]=1, Tage[1]=2 */
- /*printf("stre=%s ", stre);*/
- } else if (strcmp(strd,"age")==0) { /* or age*Vn */
- cptcovprod--;
- cutl(stre,strb,strc,'V');
- Tvar[k]=atoi(stre);
- Typevar[k]=1; /* 1 for age product */
- cptcovage++;
- Tage[cptcovage]=k;
- } else { /* Age is not in the model product V2+V1+V1*V4+V3*age+V3*V2 strb=V3*V2*/
- /* loops on k1=1 (V3*V2) and k1=2 V4*V3 */
- cptcovn++;
- cptcovprodnoage++;k1++;
- cutl(stre,strb,strc,'V'); /* strc= Vn, stre is n; strb=V3*V2 stre=3 strc=*/
- Tvar[k]=ncovcol+nqv+ntv+nqtv+k1; /* For model-covariate k tells which data-covariate to use but
- because this model-covariate is a construction we invent a new column
- which is after existing variables ncovcol+nqv+ntv+nqtv + k1
- If already ncovcol=4 and model=V2+V1+V1*V4+age*V3+V3*V2
- Tvar[3=V1*V4]=4+1 Tvar[5=V3*V2]=4 + 2= 6, etc */
- Typevar[k]=2; /* 2 for double fixed dummy covariates */
- cutl(strc,strb,strd,'V'); /* strd was Vm, strc is m */
- Tprod[k1]=k; /* Tprod[1]=3(=V1*V4) for V2+V1+V1*V4+age*V3+V3*V2 */
- Tposprod[k]=k1; /* Tpsprod[3]=1, Tposprod[2]=5 */
- Tvard[k1][1] =atoi(strc); /* m 1 for V1*/
- Tvard[k1][2] =atoi(stre); /* n 4 for V4*/
- k2=k2+2; /* k2 is initialize to -1, We want to store the n and m in Vn*Vm at the end of Tvar */
- /* Tvar[cptcovt+k2]=Tvard[k1][1]; /\* Tvar[(cptcovt=4+k2=1)=5]= 1 (V1) *\/ */
- /* Tvar[cptcovt+k2+1]=Tvard[k1][2]; /\* Tvar[(cptcovt=4+(k2=1)+1)=6]= 4 (V4) *\/ */
+ if (nbocc(modelsav,'+')==0) strcpy(strb,modelsav); /* and analyzes it */
+ /* printf("i=%d a=%s b=%s sav=%s\n",i, stra,strb,modelsav);*/
+ /*scanf("%d",i);*/
+ if (strchr(strb,'*')) { /**< Model includes a product V2+V1+V4+V3*age strb=V3*age */
+ cutl(strc,strd,strb,'*'); /**< strd*strc Vm*Vn: strb=V3*age(input) strc=age strd=V3 ; V3*V2 strc=V2, strd=V3 */
+ if (strcmp(strc,"age")==0) { /**< Model includes age: Vn*age */
+ /* covar is not filled and then is empty */
+ cptcovprod--;
+ cutl(stre,strb,strd,'V'); /* strd=V3(input): stre="3" */
+ Tvar[k]=atoi(stre); /* V2+V1+V4+V3*age Tvar[4]=3 ; V1+V2*age Tvar[2]=2; V1+V1*age Tvar[2]=1 */
+ Typevar[k]=1; /* 1 for age product */
+ cptcovage++; /* Sums the number of covariates which include age as a product */
+ Tage[cptcovage]=k; /* Tvar[4]=3, Tage[1] = 4 or V1+V1*age Tvar[2]=1, Tage[1]=2 */
+ /*printf("stre=%s ", stre);*/
+ } else if (strcmp(strd,"age")==0) { /* or age*Vn */
+ cptcovprod--;
+ cutl(stre,strb,strc,'V');
+ Tvar[k]=atoi(stre);
+ Typevar[k]=1; /* 1 for age product */
+ cptcovage++;
+ Tage[cptcovage]=k;
+ } else { /* Age is not in the model product V2+V1+V1*V4+V3*age+V3*V2 strb=V3*V2*/
+ /* loops on k1=1 (V3*V2) and k1=2 V4*V3 */
+ cptcovn++;
+ cptcovprodnoage++;k1++;
+ cutl(stre,strb,strc,'V'); /* strc= Vn, stre is n; strb=V3*V2 stre=3 strc=*/
+ Tvar[k]=ncovcol+nqv+ntv+nqtv+k1; /* For model-covariate k tells which data-covariate to use but
+ because this model-covariate is a construction we invent a new column
+ which is after existing variables ncovcol+nqv+ntv+nqtv + k1
+ If already ncovcol=4 and model=V2+V1+V1*V4+age*V3+V3*V2
+ Tvar[3=V1*V4]=4+1 Tvar[5=V3*V2]=4 + 2= 6, etc */
+ Typevar[k]=2; /* 2 for double fixed dummy covariates */
+ cutl(strc,strb,strd,'V'); /* strd was Vm, strc is m */
+ Tprod[k1]=k; /* Tprod[1]=3(=V1*V4) for V2+V1+V1*V4+age*V3+V3*V2 */
+ Tposprod[k]=k1; /* Tpsprod[3]=1, Tposprod[2]=5 */
+ Tvard[k1][1] =atoi(strc); /* m 1 for V1*/
+ Tvard[k1][2] =atoi(stre); /* n 4 for V4*/
+ k2=k2+2; /* k2 is initialize to -1, We want to store the n and m in Vn*Vm at the end of Tvar */
+ /* Tvar[cptcovt+k2]=Tvard[k1][1]; /\* Tvar[(cptcovt=4+k2=1)=5]= 1 (V1) *\/ */
+ /* Tvar[cptcovt+k2+1]=Tvard[k1][2]; /\* Tvar[(cptcovt=4+(k2=1)+1)=6]= 4 (V4) *\/ */
/*ncovcol=4 and model=V2+V1+V1*V4+age*V3+V3*V2, Tvar[3]=5, Tvar[4]=6, cptcovt=5 */
- /* 1 2 3 4 5 | Tvar[5+1)=1, Tvar[7]=2 */
- for (i=1; i<=lastobs;i++){
- /* Computes the new covariate which is a product of
- covar[n][i]* covar[m][i] and stores it at ncovol+k1 May not be defined */
- covar[ncovcol+k1][i]=covar[atoi(stre)][i]*covar[atoi(strc)][i];
- }
- } /* End age is not in the model */
- } /* End if model includes a product */
- else { /* no more sum */
- /*printf("d=%s c=%s b=%s\n", strd,strc,strb);*/
- /* scanf("%d",i);*/
- cutl(strd,strc,strb,'V');
- ks++; /**< Number of simple covariates dummy or quantitative, fixe or varying */
- cptcovn++; /** V4+V3+V5: V4 and V3 timevarying dummy covariates, V5 timevarying quantitative */
- Tvar[k]=atoi(strd);
- Typevar[k]=0; /* 0 for simple covariates */
- }
- strcpy(modelsav,stra); /* modelsav=V2+V1+V4 stra=V2+V1+V4 */
+ /* 1 2 3 4 5 | Tvar[5+1)=1, Tvar[7]=2 */
+ for (i=1; i<=lastobs;i++){
+ /* Computes the new covariate which is a product of
+ covar[n][i]* covar[m][i] and stores it at ncovol+k1 May not be defined */
+ covar[ncovcol+k1][i]=covar[atoi(stre)][i]*covar[atoi(strc)][i];
+ }
+ } /* End age is not in the model */
+ } /* End if model includes a product */
+ else { /* no more sum */
+ /*printf("d=%s c=%s b=%s\n", strd,strc,strb);*/
+ /* scanf("%d",i);*/
+ cutl(strd,strc,strb,'V');
+ ks++; /**< Number of simple covariates dummy or quantitative, fixe or varying */
+ cptcovn++; /** V4+V3+V5: V4 and V3 timevarying dummy covariates, V5 timevarying quantitative */
+ Tvar[k]=atoi(strd);
+ Typevar[k]=0; /* 0 for simple covariates */
+ }
+ strcpy(modelsav,stra); /* modelsav=V2+V1+V4 stra=V2+V1+V4 */
/*printf("a=%s b=%s sav=%s\n", stra,strb,modelsav);
scanf("%d",i);*/
} /* end of loop + on total covariates */
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);
- for(k=1, ncoveff=0, nqfveff=0, ntveff=0, nqtveff=0;k<=cptcovt; k++){ /* or cptocvt */
+ for(k=1, ncovf=0, ncovv=0, ncova=0, ncoveff=0, nqfveff=0, ntveff=0, nqtveff=0;k<=cptcovt; k++){ /* or cptocvt */
if (Tvar[k] <=ncovcol && (Typevar[k]==0 || Typevar[k]==2)){ /* Simple or product fixed dummy (<=ncovcol) covariates */
Fixed[k]= 0;
Dummy[k]= 0;
ncoveff++;
+ ncovf++;
modell[k].maintype= FTYPE;
+ TvarF[ncovf]=Tvar[k];
+ TvarFind[ncovf]=k;
TvarFD[ncoveff]=Tvar[k]; /* TvarFD[1]=V1 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */
TvarFDind[ncoveff]=k; /* TvarFDind[1]=9 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */
}else if( Tvar[k] <=ncovcol+nqv && Typevar[k]==0){ /* Remind that product Vn*Vm are added in k*/ /* Only simple fixed quantitative variable */
nqfveff++;
modell[k].maintype= FTYPE;
modell[k].subtype= FQ;
+ ncovf++;
+ TvarF[ncovf]=Tvar[k];
+ TvarFind[ncovf]=k;
TvarFQ[nqfveff]=Tvar[k]-ncovcol; /* TvarFQ[1]=V2-1=1st in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */ /* Only simple fixed quantitative variable */
TvarFQind[nqfveff]=k; /* TvarFQind[1]=6 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */ /* Only simple fixed quantitative variable */
}else if( Tvar[k] <=ncovcol+nqv+ntv && Typevar[k]==0){
ntveff++; /* Only simple time varying dummy variable */
modell[k].maintype= VTYPE;
modell[k].subtype= VD;
+ ncovv++; /* Only simple time varying variables */
+ TvarV[ncovv]=Tvar[k];
+ TvarVind[ncovv]=k;
TvarVD[ntveff]=Tvar[k]; /* TvarVD[1]=V4 TvarVD[2]=V3 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */ /* Only simple time varying dummy variable */
TvarVDind[ntveff]=k; /* TvarVDind[1]=2 TvarVDind[2]=3 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */ /* Only simple time varying dummy variable */
printf("Quasi Tmodelind[%d]=%d,Tvar[Tmodelind[%d]]=V%d, ncovcol=%d, nqv=%d,Tvar[k]- ncovcol-nqv=%d\n",ntveff,k,ntveff,Tvar[k], ncovcol, nqv,Tvar[k]- ncovcol-nqv);
nqtveff++;
modell[k].maintype= VTYPE;
modell[k].subtype= VQ;
+ ncovv++; /* Only simple time varying variables */
+ TvarV[ncovv]=Tvar[k];
+ TvarVind[ncovv]=k;
TvarVQ[nqtveff]=Tvar[k]; /* TvarVQ[1]=V5 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */ /* Only simple time varying quantitative variable */
TvarVQind[nqtveff]=k; /* TvarVQind[1]=1 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */ /* Only simple time varying quantitative variable */
TmodelInvQind[nqtveff]=Tvar[k]- ncovcol-nqv-ntv;/* Only simple time varying quantitative variable */
printf("Quasi TmodelQind[%d]=%d,Tvar[TmodelQind[%d]]=V%d, ncovcol=%d, nqv=%d, ntv=%d,Tvar[k]- ncovcol-nqv-ntv=%d\n",nqtveff,k,nqtveff,Tvar[k], ncovcol, nqv, ntv, Tvar[k]- ncovcol-nqv-ntv);
printf("Quasi TmodelInvQind[%d]=%d\n",k,Tvar[k]- ncovcol-nqv-ntv);
}else if (Typevar[k] == 1) { /* product with age */
+ ncova++;
+ TvarA[ncova]=Tvar[k];
+ TvarAind[ncova]=k;
if (Tvar[k] <=ncovcol ){ /* Product age with fixed dummy covariatee */
Fixed[k]= 2;
Dummy[k]= 2;
}
}else if (Typevar[k] == 2) { /* product without age */
k1=Tposprod[k];
+ ncovv++; /* Only time varying variables */
+ TvarV[ncovv]=Tvar[k];
+ TvarVind[ncovv]=k;
if(Tvard[k1][1] <=ncovcol){
if(Tvard[k1][2] <=ncovcol){
Fixed[k]= 1;
}
printf("ncoveff=%d, nqfveff=%d, ntveff=%d, nqtveff=%d, cptcovn=%d\n",ncoveff,nqfveff,ntveff,nqtveff,cptcovn);
fprintf(ficlog,"ncoveff=%d, nqfveff=%d, ntveff=%d, nqtveff=%d, cptcovn=%d\n",ncoveff,nqfveff,ntveff,nqtveff,cptcovn);
+ printf("ncovf=%d, ncovv=%d, ncova=%d\n",ncovf,ncovv,ncova);
+ fprintf(ficlog,"ncovf=%d, ncovv=%d, ncova=%d\n",ncovf,ncovv,ncova);
return (0); /* with covar[new additional covariate if product] and Tage if age */
/*endread:*/
printf("Exiting decodemodel: ");
*/
Tvar=ivector(1,NCOVMAX); /* Was 15 changed to NCOVMAX. */
+ TvarF=ivector(1,NCOVMAX); /* */
+ TvarFind=ivector(1,NCOVMAX); /* */
+ TvarV=ivector(1,NCOVMAX); /* */
+ TvarVind=ivector(1,NCOVMAX); /* */
+ TvarA=ivector(1,NCOVMAX); /* */
+ TvarAind=ivector(1,NCOVMAX); /* */
TvarFD=ivector(1,NCOVMAX); /* */
TvarFDind=ivector(1,NCOVMAX); /* */
TvarFQ=ivector(1,NCOVMAX); /* */
free_ivector(Tvar,1,NCOVMAX);
free_ivector(TvarFD,1,NCOVMAX);
free_ivector(TvarFDind,1,NCOVMAX);
+ free_ivector(TvarF,1,NCOVMAX);
+ free_ivector(TvarFind,1,NCOVMAX);
+ free_ivector(TvarV,1,NCOVMAX);
+ free_ivector(TvarVind,1,NCOVMAX);
+ free_ivector(TvarA,1,NCOVMAX);
+ free_ivector(TvarAind,1,NCOVMAX);
free_ivector(TvarFQ,1,NCOVMAX);
free_ivector(TvarFQind,1,NCOVMAX);
free_ivector(TvarVD,1,NCOVMAX);