Diff for /imach/src/imach.c between versions 1.233 and 1.234

version 1.233, 2016/08/23 07:40:50 version 1.234, 2016/08/23 16:51:20
Line 1 Line 1
 /* $Id$  /* $Id$
   $State$    $State$
   $Log$    $Log$
     Revision 1.234  2016/08/23 16:51:20  brouard
     *** empty log message ***
   
   Revision 1.233  2016/08/23 07:40:50  brouard    Revision 1.233  2016/08/23 07:40:50  brouard
   Summary: not working    Summary: not working
   
Line 920  int cptcoveff=0; /* Total number of cova Line 923  int cptcoveff=0; /* Total number of cova
 int ncovf=0; /* Total number of effective fixed covariates (dummy or quantitative) in the model */  int ncovf=0; /* Total number of effective fixed covariates (dummy or quantitative) in the model */
 int ncovv=0; /* Total number of effective (wave) varying covariates (dummy or quantitative) in the model */  int ncovv=0; /* Total number of effective (wave) varying covariates (dummy or 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 ncova=0; /* Total number of effective (wave and stepm) varying with age covariates (dummy of quantitative) in the model */
   int nsd=0; /**< Total number of single dummy variables (output) */
   int nsq=0; /**< Total number of single quantitative variables (output) */
 int ncoveff=0; /* Total number of effective fixed dummy covariates 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 nqfveff=0; /**< nqfveff Number of Quantitative Fixed Variables Effective */
 int ntveff=0; /**< ntveff number of effective time varying variables */  int ntveff=0; /**< ntveff number of effective time varying variables */
Line 978  char fileresv[FILENAMELENGTH]; Line 982  char fileresv[FILENAMELENGTH];
 FILE  *ficresvpl;  FILE  *ficresvpl;
 char fileresvpl[FILENAMELENGTH];  char fileresvpl[FILENAMELENGTH];
 char title[MAXLINE];  char title[MAXLINE];
   char model[MAXLINE]; /**< The model line */
 char optionfile[FILENAMELENGTH], datafile[FILENAMELENGTH],  filerespl[FILENAMELENGTH],  fileresplb[FILENAMELENGTH];  char optionfile[FILENAMELENGTH], datafile[FILENAMELENGTH],  filerespl[FILENAMELENGTH],  fileresplb[FILENAMELENGTH];
 char plotcmd[FILENAMELENGTH], pplotcmd[FILENAMELENGTH];  char plotcmd[FILENAMELENGTH], pplotcmd[FILENAMELENGTH];
 char tmpout[FILENAMELENGTH],  tmpout2[FILENAMELENGTH];   char tmpout[FILENAMELENGTH],  tmpout2[FILENAMELENGTH]; 
Line 1077  double ***cotvar; /* Time varying covari Line 1082  double ***cotvar; /* Time varying covari
 double ***cotqvar; /* Time varying quantitative covariate itqv */  double ***cotqvar; /* Time varying quantitative covariate itqv */
 double  idx;   double  idx; 
 int **nbcode, *Tvar; /**< model=V2 => Tvar[1]= 2 */  int **nbcode, *Tvar; /**< model=V2 => Tvar[1]= 2 */
   /*           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 */
   /* Tndvar[k]    1   2   3               4          5 */
   /*TDvar         4   3   6               7          1 */ /* For outputs only; combination of dummies fixed or varying */
   /* Tns[k]    1  2   2              4               5 */ /* Number of single cova */
   /* TvarsD[k]    1   2                              3 */ /* Number of single dummy cova */
   /* TvarsDind    2   3                              9 */ /* position K of single dummy cova */
   /* TvarsQ[k] 1                     2                 */ /* Number of single quantitative cova */
   /* TvarsQind 1                     6                 */ /* position K of single quantitative cova */
   /* Tprod[i]=k           4               7            */
   /* Tage[i]=k                  5               8      */
   /* */
   /* Type                    */
   /* V         1  2  3  4  5 */
   /*           F  F  V  V  V */
   /*           D  Q  D  D  Q */
   /*                         */
   int *TvarsD;
   int *TvarsDind;
   int *TvarsQ;
   int *TvarsQind;
   
   /* 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 *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 *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 *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 */
Line 1336  int nbocc(char *s, char occ) Line 1365  int nbocc(char *s, char occ)
   i=0;    i=0;
   lg=strlen(s);    lg=strlen(s);
   for(i=0; i<= lg; i++) {    for(i=0; i<= lg; i++) {
   if  (s[i] == occ ) j++;      if  (s[i] == occ ) j++;
   }    }
   return j;    return j;
 }  }
Line 2227  void powell(double p[], double **xi, int Line 2256  void powell(double p[], double **xi, int
       if (directest < 0.0) { /* Then we use it for new direction */        if (directest < 0.0) { /* Then we use it for new direction */
 #endif  #endif
 #ifdef DEBUGLINMIN  #ifdef DEBUGLINMIN
                                 printf("Before linmin in direction P%d-P0\n",n);          printf("Before linmin in direction P%d-P0\n",n);
                                 for (j=1;j<=n;j++) {          for (j=1;j<=n;j++) {
                                         printf(" Before xit[%d]= %12.7f p[%d]= %12.7f",j,xit[j],j,p[j]);            printf(" Before xit[%d]= %12.7f p[%d]= %12.7f",j,xit[j],j,p[j]);
                                         fprintf(ficlog," Before xit[%d]= %12.7f p[%d]= %12.7f",j,xit[j],j,p[j]);            fprintf(ficlog," Before xit[%d]= %12.7f p[%d]= %12.7f",j,xit[j],j,p[j]);
                                         if(j % ncovmodel == 0){            if(j % ncovmodel == 0){
                                                 printf("\n");              printf("\n");
                                                 fprintf(ficlog,"\n");              fprintf(ficlog,"\n");
                                         }            }
                                 }          }
 #endif  #endif
 #ifdef LINMINORIGINAL  #ifdef LINMINORIGINAL
                                 linmin(p,xit,n,fret,func); /* computes minimum on the extrapolated direction: changes p and rescales xit.*/          linmin(p,xit,n,fret,func); /* computes minimum on the extrapolated direction: changes p and rescales xit.*/
 #else  #else
                                 linmin(p,xit,n,fret,func,&flat); /* computes minimum on the extrapolated direction: changes p and rescales xit.*/          linmin(p,xit,n,fret,func,&flat); /* computes minimum on the extrapolated direction: changes p and rescales xit.*/
                                 flatdir[i]=flat; /* Function is vanishing in that direction i */          flatdir[i]=flat; /* Function is vanishing in that direction i */
 #endif  #endif
           
 #ifdef DEBUGLINMIN  #ifdef DEBUGLINMIN
                                 for (j=1;j<=n;j++) {           for (j=1;j<=n;j++) { 
                                         printf("After xit[%d]= %12.7f p[%d]= %12.7f",j,xit[j],j,p[j]);            printf("After xit[%d]= %12.7f p[%d]= %12.7f",j,xit[j],j,p[j]);
                                         fprintf(ficlog,"After xit[%d]= %12.7f p[%d]= %12.7f",j,xit[j],j,p[j]);            fprintf(ficlog,"After xit[%d]= %12.7f p[%d]= %12.7f",j,xit[j],j,p[j]);
                                         if(j % ncovmodel == 0){            if(j % ncovmodel == 0){
                                                 printf("\n");              printf("\n");
                                                 fprintf(ficlog,"\n");              fprintf(ficlog,"\n");
                                         }            }
                                 }          }
 #endif  #endif
                                 for (j=1;j<=n;j++) {           for (j=1;j<=n;j++) { 
                                         xi[j][ibig]=xi[j][n]; /* Replace direction with biggest decrease by last direction n */            xi[j][ibig]=xi[j][n]; /* Replace direction with biggest decrease by last direction n */
                                         xi[j][n]=xit[j];      /* and this nth direction by the by the average p_0 p_n */            xi[j][n]=xit[j];      /* and this nth direction by the by the average p_0 p_n */
                                 }          }
 #ifdef LINMINORIGINAL  #ifdef LINMINORIGINAL
 #else  #else
                                 for (j=1, flatd=0;j<=n;j++) {          for (j=1, flatd=0;j<=n;j++) {
                                         if(flatdir[j]>0)            if(flatdir[j]>0)
                                                 flatd++;              flatd++;
                                 }          }
                                 if(flatd >0){          if(flatd >0){
                                         printf("%d flat directions\n",flatd);            printf("%d flat directions\n",flatd);
                                         fprintf(ficlog,"%d flat directions\n",flatd);            fprintf(ficlog,"%d flat directions\n",flatd);
                                         for (j=1;j<=n;j++) {             for (j=1;j<=n;j++) { 
                                                 if(flatdir[j]>0){              if(flatdir[j]>0){
                                                         printf("%d ",j);                printf("%d ",j);
                                                         fprintf(ficlog,"%d ",j);                fprintf(ficlog,"%d ",j);
                                                 }              }
                                         }            }
                                         printf("\n");            printf("\n");
                                         fprintf(ficlog,"\n");            fprintf(ficlog,"\n");
                                 }          }
 #endif  #endif
                                 printf("Gaining to use new average direction of P0 P%d instead of biggest increase direction %d :\n",n,ibig);          printf("Gaining to use new average direction of P0 P%d instead of biggest increase direction %d :\n",n,ibig);
                                 fprintf(ficlog,"Gaining to use new average direction of P0 P%d instead of biggest increase direction %d :\n",n,ibig);          fprintf(ficlog,"Gaining to use new average direction of P0 P%d instead of biggest increase direction %d :\n",n,ibig);
                                           
 #ifdef DEBUG  #ifdef DEBUG
                                 printf("Direction changed  last moved %d in place of ibig=%d, new last is the average:\n",n,ibig);          printf("Direction changed  last moved %d in place of ibig=%d, new last is the average:\n",n,ibig);
                                 fprintf(ficlog,"Direction changed  last moved %d in place of ibig=%d, new last is the average:\n",n,ibig);          fprintf(ficlog,"Direction changed  last moved %d in place of ibig=%d, new last is the average:\n",n,ibig);
                                 for(j=1;j<=n;j++){          for(j=1;j<=n;j++){
                                         printf(" %lf",xit[j]);            printf(" %lf",xit[j]);
                                         fprintf(ficlog," %lf",xit[j]);            fprintf(ficlog," %lf",xit[j]);
                                 }          }
                                 printf("\n");          printf("\n");
                                 fprintf(ficlog,"\n");          fprintf(ficlog,"\n");
 #endif  #endif
       } /* end of t or directest negative */        } /* end of t or directest negative */
 #ifdef POWELLNOF3INFF1TEST  #ifdef POWELLNOF3INFF1TEST
 #else  #else
     } /* end if (fptt < fp)  */        } /* end if (fptt < fp)  */
 #endif  #endif
 #ifdef NODIRECTIONCHANGEDUNTILNITER  /* No change in drections until some iterations are done */  #ifdef NODIRECTIONCHANGEDUNTILNITER  /* No change in drections until some iterations are done */
                 } /*NODIRECTIONCHANGEDUNTILNITER  No change in drections until some iterations are done */      } /*NODIRECTIONCHANGEDUNTILNITER  No change in drections until some iterations are done */
 #else  #else
 #endif  #endif
   } /* loop iteration */                   } /* loop iteration */ 
 }   } 
     
 /**** Prevalence limit (stable or period prevalence)  ****************/  /**** Prevalence limit (stable or period prevalence)  ****************/
     
 double **prevalim(double **prlim, int nlstate, double x[], double age, double **oldm, double **savm, double ftolpl, int *ncvyear, int ij)  double **prevalim(double **prlim, int nlstate, double x[], double age, double **oldm, double **savm, double ftolpl, int *ncvyear, int ij)
 {    {
   /* Computes the prevalence limit in each live state at age x and for covariate ij by left multiplying the unit      /* Computes the prevalence limit in each live state at age x and for covariate combiation ij by left multiplying the unit
      matrix by transitions matrix until convergence is reached with precision ftolpl */         matrix by transitions matrix until convergence is reached with precision ftolpl */
   /* Wx= Wx-1 Px-1= Wx-2 Px-2 Px-1  = Wx-n Px-n ... Px-2 Px-1 I */    /* Wx= Wx-1 Px-1= Wx-2 Px-2 Px-1  = Wx-n Px-n ... Px-2 Px-1 I */
   /* Wx is row vector: population in state 1, population in state 2, population dead */    /* Wx is row vector: population in state 1, population in state 2, population dead */
   /* or prevalence in state 1, prevalence in state 2, 0 */    /* or prevalence in state 1, prevalence in state 2, 0 */
Line 2325  double **prevalim(double **prlim, int nl Line 2354  double **prevalim(double **prlim, int nl
   /* {0.51571254859325999, 0.4842874514067399, */    /* {0.51571254859325999, 0.4842874514067399, */
   /*  0.51326036147820708, 0.48673963852179264} */    /*  0.51326036147820708, 0.48673963852179264} */
   /* If we start from prlim again, prlim tends to a constant matrix */    /* If we start from prlim again, prlim tends to a constant matrix */
       
   int i, ii,j,k;    int i, ii,j,k;
   double *min, *max, *meandiff, maxmax,sumnew=0.;    double *min, *max, *meandiff, maxmax,sumnew=0.;
   /* double **matprod2(); */ /* test */    /* double **matprod2(); */ /* test */
Line 2355  double **prevalim(double **prlim, int nl Line 2384  double **prevalim(double **prlim, int nl
     cov[2]=agefin;      cov[2]=agefin;
     if(nagesqr==1)      if(nagesqr==1)
       cov[3]= agefin*agefin;;        cov[3]= agefin*agefin;;
     for (k=1; k<=cptcovn;k++) {      for (k=1; k<=nsd;k++) { /* For single dummy covariates only */
       /* cov[2+nagesqr+k]=nbcode[Tvar[k]][codtabm(ij,Tvar[k])]; */                          /* Here comes the value of the covariate 'ij' after renumbering k with single dummy covariates */
                         /* Here comes the value of the covariate 'ij' */        cov[2+nagesqr+TvarsDind[k]]=nbcode[TvarsD[k]][codtabm(ij,k)];
       cov[2+nagesqr+k]=nbcode[Tvar[k]][codtabm(ij,k)];        printf("prevalim ij=%d k=%d TvarsD[%d]=%d TvarsDind[%d]=%d nbcode=%d cov=%lf codtabm(%d,Tvar[%d])=%d \n",ij,k, k, TvarsD[k],k,TvarsDind[k],nbcode[TvarsD[k]][codtabm(ij,k)],cov[2+nagesqr+TvarsDind[k]], ij, k, codtabm(ij,k));
       /* printf("prevalim ij=%d k=%d Tvar[%d]=%d nbcode=%d cov=%lf codtabm(%d,Tvar[%d])=%d \n",ij,k, k, Tvar[k],nbcode[Tvar[k]][codtabm(ij,Tvar[k])],cov[2+k], ij, k, codtabm(ij,Tvar[k])]); */      }
       for (k=1; k<=nsq;k++) { /* For single varying covariates only */
                           /* Here comes the value of quantitative after renumbering k with single quantitative covariates */
         /* cov[2+nagesqr+TvarsQind[k]]=qselvar[k]; */
         printf("prevalim ij=%d k=%d  TvarsQind[%d]=%d \n",ij,k,k,TvarsQind[k]);
     }      }
     /*wrong? for (k=1; k<=cptcovage;k++) cov[2+Tage[k]]=cov[2+Tage[k]]*cov[2]; */      /*wrong? for (k=1; k<=cptcovage;k++) cov[2+Tage[k]]=cov[2+Tage[k]]*cov[2]; */
     /* for (k=1; k<=cptcovage;k++) cov[2+nagesqr+Tage[k]]=nbcode[Tvar[k]][codtabm(ij,Tvar[k])]*cov[2]; */      /* for (k=1; k<=cptcovage;k++) cov[2+nagesqr+Tage[k]]=nbcode[Tvar[k]][codtabm(ij,Tvar[k])]*cov[2]; */
     for (k=1; k<=cptcovage;k++) cov[2+nagesqr+Tage[k]]=nbcode[Tvar[k]][codtabm(ij,k)]*cov[2];      for (k=1; k<=cptcovage;k++){
     for (k=1; k<=cptcovprod;k++) /* Useless */        if(Dummy[Tvar[Tage[k]]]){
       /* cov[2+nagesqr+Tprod[k]]=nbcode[Tvard[k][1]][codtabm(ij,Tvard[k][1])] * nbcode[Tvard[k][2]][codtabm(ij,Tvard[k][2])]; */          cov[2+nagesqr+Tage[k]]=nbcode[Tvar[Tage[k]]][codtabm(ij,k)]*cov[2];
         } else{
           ;
           /* cov[2+nagesqr+Tage[k]]=qselvar[k]; */
         }
         printf("prevalim Age ij=%d k=%d  Tage[%d]=%d \n",ij,k,k,Tage[k]);
       }
       for (k=1; k<=cptcovprod;k++){ /*  */
         printf("prevalim Prod ij=%d k=%d  Tprod[%d]=%d Tvard[%d][1]=%d, Tvard[%d][2]=%d\n",ij,k,k,Tprod[k], k,Tvard[k][1], k,Tvard[k][2]);
       cov[2+nagesqr+Tprod[k]]=nbcode[Tvard[k][1]][codtabm(ij,k)] * nbcode[Tvard[k][2]][codtabm(ij,k)];        cov[2+nagesqr+Tprod[k]]=nbcode[Tvard[k][1]][codtabm(ij,k)] * nbcode[Tvard[k][2]][codtabm(ij,k)];
           }
     /*printf("ij=%d cptcovprod=%d tvar=%d ", ij, cptcovprod, Tvar[1]);*/      /*printf("ij=%d cptcovprod=%d tvar=%d ", ij, cptcovprod, Tvar[1]);*/
     /*printf("ij=%d cov[3]=%lf cov[4]=%lf \n",ij, cov[3],cov[4]);*/      /*printf("ij=%d cov[3]=%lf cov[4]=%lf \n",ij, cov[3],cov[4]);*/
     /*printf("ij=%d cov[3]=%lf \n",ij, cov[3]);*/      /*printf("ij=%d cov[3]=%lf \n",ij, cov[3]);*/
Line 2517  Earliest age to start was %d-%d=%d, ncvl Line 2558  Earliest age to start was %d-%d=%d, ncvl
     }      }
     for(j=1; j<=nlstate; j++){       for(j=1; j<=nlstate; j++){ 
       for(i=1;i<=nlstate;i++){        for(i=1;i<=nlstate;i++){
                                 /* bprlim[i][j]= newm[i][j]/(1-sumnew); */          /* bprlim[i][j]= newm[i][j]/(1-sumnew); */
                                 bprlim[i][j]= newm[i][j];          bprlim[i][j]= newm[i][j];
                                 max[i]=FMAX(max[i],bprlim[i][j]); /* Max in line */          max[i]=FMAX(max[i],bprlim[i][j]); /* Max in line */
                                 min[i]=FMIN(min[i],bprlim[i][j]);          min[i]=FMIN(min[i],bprlim[i][j]);
       }        }
     }      }
                                   
Line 2715  double **bpmij(double **ps, double *cov, Line 2756  double **bpmij(double **ps, double *cov,
   /*double t34;*/    /*double t34;*/
   int i,j, nc, ii, jj;    int i,j, nc, ii, jj;
   
         for(i=1; i<= nlstate; i++){    for(i=1; i<= nlstate; i++){
                 for(j=1; j<i;j++){      for(j=1; j<i;j++){
                         for (nc=1, lnpijopii=0.;nc <=ncovmodel; nc++){        for (nc=1, lnpijopii=0.;nc <=ncovmodel; nc++){
                                 /*lnpijopii += param[i][j][nc]*cov[nc];*/          /*lnpijopii += param[i][j][nc]*cov[nc];*/
                                 lnpijopii += x[nc+((i-1)*(nlstate+ndeath-1)+j-1)*ncovmodel]*cov[nc];          lnpijopii += x[nc+((i-1)*(nlstate+ndeath-1)+j-1)*ncovmodel]*cov[nc];
                                 /*       printf("Int j<i s1=%.17e, lnpijopii=%.17e\n",s1,lnpijopii); */          /*       printf("Int j<i s1=%.17e, lnpijopii=%.17e\n",s1,lnpijopii); */
                         }        }
                         ps[i][j]=lnpijopii; /* In fact ln(pij/pii) */        ps[i][j]=lnpijopii; /* In fact ln(pij/pii) */
                         /*      printf("s1=%.17e, lnpijopii=%.17e\n",s1,lnpijopii); */        /*        printf("s1=%.17e, lnpijopii=%.17e\n",s1,lnpijopii); */
                 }      }
                 for(j=i+1; j<=nlstate+ndeath;j++){      for(j=i+1; j<=nlstate+ndeath;j++){
                         for (nc=1, lnpijopii=0.;nc <=ncovmodel; nc++){        for (nc=1, lnpijopii=0.;nc <=ncovmodel; nc++){
                                 /*lnpijopii += x[(i-1)*nlstate*ncovmodel+(j-2)*ncovmodel+nc+(i-1)*(ndeath-1)*ncovmodel]*cov[nc];*/          /*lnpijopii += x[(i-1)*nlstate*ncovmodel+(j-2)*ncovmodel+nc+(i-1)*(ndeath-1)*ncovmodel]*cov[nc];*/
                                 lnpijopii += x[nc + ((i-1)*(nlstate+ndeath-1)+(j-2))*ncovmodel]*cov[nc];          lnpijopii += x[nc + ((i-1)*(nlstate+ndeath-1)+(j-2))*ncovmodel]*cov[nc];
                                 /*        printf("Int j>i s1=%.17e, lnpijopii=%.17e %lx %lx\n",s1,lnpijopii,s1,lnpijopii); */          /*        printf("Int j>i s1=%.17e, lnpijopii=%.17e %lx %lx\n",s1,lnpijopii,s1,lnpijopii); */
                         }        }
                         ps[i][j]=lnpijopii; /* In fact ln(pij/pii) */        ps[i][j]=lnpijopii; /* In fact ln(pij/pii) */
                 }      }
         }    }
             
         for(i=1; i<= nlstate; i++){    for(i=1; i<= nlstate; i++){
                 s1=0;      s1=0;
                 for(j=1; j<i; j++){      for(j=1; j<i; j++){
                         s1+=exp(ps[i][j]); /* In fact sums pij/pii */        s1+=exp(ps[i][j]); /* In fact sums pij/pii */
                         /*printf("debug1 %d %d ps=%lf exp(ps)=%lf s1+=%lf\n",i,j,ps[i][j],exp(ps[i][j]),s1); */        /*printf("debug1 %d %d ps=%lf exp(ps)=%lf s1+=%lf\n",i,j,ps[i][j],exp(ps[i][j]),s1); */
                 }      }
                 for(j=i+1; j<=nlstate+ndeath; j++){      for(j=i+1; j<=nlstate+ndeath; j++){
                         s1+=exp(ps[i][j]); /* In fact sums pij/pii */        s1+=exp(ps[i][j]); /* In fact sums pij/pii */
                         /*printf("debug2 %d %d ps=%lf exp(ps)=%lf s1+=%lf\n",i,j,ps[i][j],exp(ps[i][j]),s1); */        /*printf("debug2 %d %d ps=%lf exp(ps)=%lf s1+=%lf\n",i,j,ps[i][j],exp(ps[i][j]),s1); */
                 }      }
                 /* s1= sum_{j<>i} pij/pii=(1-pii)/pii and thus pii is known from s1 */      /* s1= sum_{j<>i} pij/pii=(1-pii)/pii and thus pii is known from s1 */
                 ps[i][i]=1./(s1+1.);      ps[i][i]=1./(s1+1.);
                 /* Computing other pijs */      /* Computing other pijs */
                 for(j=1; j<i; j++)      for(j=1; j<i; j++)
                         ps[i][j]= exp(ps[i][j])*ps[i][i];        ps[i][j]= exp(ps[i][j])*ps[i][i];
                 for(j=i+1; j<=nlstate+ndeath; j++)      for(j=i+1; j<=nlstate+ndeath; j++)
                         ps[i][j]= exp(ps[i][j])*ps[i][i];        ps[i][j]= exp(ps[i][j])*ps[i][i];
                 /* ps[i][nlstate+1]=1.-s1- ps[i][i];*/ /* Sum should be 1 */      /* ps[i][nlstate+1]=1.-s1- ps[i][i];*/ /* Sum should be 1 */
         } /* end i */    } /* end i */
             
         for(ii=nlstate+1; ii<= nlstate+ndeath; ii++){    for(ii=nlstate+1; ii<= nlstate+ndeath; ii++){
                 for(jj=1; jj<= nlstate+ndeath; jj++){      for(jj=1; jj<= nlstate+ndeath; jj++){
                         ps[ii][jj]=0;        ps[ii][jj]=0;
                         ps[ii][ii]=1;        ps[ii][ii]=1;
                 }      }
         }    }
         /* Added for backcast */ /* Transposed matrix too */    /* Added for backcast */ /* Transposed matrix too */
         for(jj=1; jj<= nlstate+ndeath; jj++){    for(jj=1; jj<= nlstate+ndeath; jj++){
                 s1=0.;      s1=0.;
                 for(ii=1; ii<= nlstate+ndeath; ii++){      for(ii=1; ii<= nlstate+ndeath; ii++){
                         s1+=ps[ii][jj];        s1+=ps[ii][jj];
                 }      }
                 for(ii=1; ii<= nlstate; ii++){      for(ii=1; ii<= nlstate; ii++){
                         ps[ii][jj]=ps[ii][jj]/s1;        ps[ii][jj]=ps[ii][jj]/s1;
                 }      }
         }    }
         /* Transposition */    /* Transposition */
         for(jj=1; jj<= nlstate+ndeath; jj++){    for(jj=1; jj<= nlstate+ndeath; jj++){
                 for(ii=jj; ii<= nlstate+ndeath; ii++){      for(ii=jj; ii<= nlstate+ndeath; ii++){
                         s1=ps[ii][jj];        s1=ps[ii][jj];
                         ps[ii][jj]=ps[jj][ii];        ps[ii][jj]=ps[jj][ii];
                         ps[jj][ii]=s1;        ps[jj][ii]=s1;
                 }      }
         }    }
         /* for(ii=1; ii<= nlstate+ndeath; ii++){ */    /* for(ii=1; ii<= nlstate+ndeath; ii++){ */
         /*   for(jj=1; jj<= nlstate+ndeath; jj++){ */    /*   for(jj=1; jj<= nlstate+ndeath; jj++){ */
         /*      printf(" pmij  ps[%d][%d]=%lf ",ii,jj,ps[ii][jj]); */    /*    printf(" pmij  ps[%d][%d]=%lf ",ii,jj,ps[ii][jj]); */
         /*   } */    /*   } */
         /*   printf("\n "); */    /*   printf("\n "); */
         /* } */    /* } */
         /* printf("\n ");printf("%lf ",cov[2]);*/    /* printf("\n ");printf("%lf ",cov[2]);*/
         /*    /*
                 for(i=1; i<= npar; i++) printf("%f ",x[i]);      for(i=1; i<= npar; i++) printf("%f ",x[i]);
                 goto end;*/      goto end;*/
         return ps;    return ps;
 }  }
   
   
Line 3041  double func( double *x) Line 3082  double func( double *x)
       */        */
       ioffset=2+nagesqr+cptcovage;        ioffset=2+nagesqr+cptcovage;
    /* Fixed */     /* Fixed */
                         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 */
                                 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[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)*/
                         }        }
       /* In model V2+V1*V4+age*V3+V3*V2 Tvar[1] is V2, Tvar[2=V1*V4]         /* In model V2+V1*V4+age*V3+V3*V2 Tvar[1] is V2, Tvar[2=V1*V4] 
          is 6, Tvar[3=age*V3] should not be computed because of age Tvar[4=V3*V2]            is 6, Tvar[3=age*V3] should not be computed because of age Tvar[4=V3*V2] 
          has been calculated etc */           has been calculated etc */
Line 3057  double func( double *x) Line 3098  double func( double *x)
          meaning that decodemodel should be used cotvar[mw[mi+1][i]][TTvar[iv]][i]           meaning that decodemodel should be used cotvar[mw[mi+1][i]][TTvar[iv]][i]
       */        */
       for(mi=1; mi<= wav[i]-1; mi++){        for(mi=1; mi<= wav[i]-1; mi++){
                                 for(k=1; k <= ncovv ; k++){ /* Varying  covariates (single and product but no age )*/          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];            cov[ioffset+TvarVind[k]]=cotvar[mw[mi][i]][Tvar[TvarVind[k]]][i];
                                 }          }
                                 for (ii=1;ii<=nlstate+ndeath;ii++)          for (ii=1;ii<=nlstate+ndeath;ii++)
                                         for (j=1;j<=nlstate+ndeath;j++){            for (j=1;j<=nlstate+ndeath;j++){
                                                 oldm[ii][j]=(ii==j ? 1.0 : 0.0);              oldm[ii][j]=(ii==j ? 1.0 : 0.0);
                                                 savm[ii][j]=(ii==j ? 1.0 : 0.0);              savm[ii][j]=(ii==j ? 1.0 : 0.0);
                                         }            }
                                 for(d=0; d<dh[mi][i]; d++){          for(d=0; d<dh[mi][i]; d++){
                                         newm=savm;            newm=savm;
                                         agexact=agev[mw[mi][i]][i]+d*stepm/YEARM;            agexact=agev[mw[mi][i]][i]+d*stepm/YEARM;
                                         cov[2]=agexact;            cov[2]=agexact;
                                         if(nagesqr==1)            if(nagesqr==1)
                                                 cov[3]= agexact*agexact;  /* Should be changed here */              cov[3]= agexact*agexact;  /* Should be changed here */
                                         for (kk=1; kk<=cptcovage;kk++) {            for (kk=1; kk<=cptcovage;kk++) {
                                                 cov[Tage[kk]+2+nagesqr]=covar[Tvar[Tage[kk]]][i]*agexact; /* Tage[kk] gives the data-covariate associated with age */              cov[Tage[kk]+2+nagesqr]=covar[Tvar[Tage[kk]]][i]*agexact; /* Tage[kk] gives the data-covariate associated with age */
                                         }            }
                                         out=matprod2(newm,oldm,1,nlstate+ndeath,1,nlstate+ndeath,            out=matprod2(newm,oldm,1,nlstate+ndeath,1,nlstate+ndeath,
                                                                                          1,nlstate+ndeath,pmij(pmmij,cov,ncovmodel,x,nlstate));                         1,nlstate+ndeath,pmij(pmmij,cov,ncovmodel,x,nlstate));
                                         savm=oldm;            savm=oldm;
                                         oldm=newm;            oldm=newm;
                                 } /* end mult */          } /* end mult */
                                           
                                 /*lli=log(out[s[mw[mi][i]][i]][s[mw[mi+1][i]][i]]);*/ /* Original formula */          /*lli=log(out[s[mw[mi][i]][i]][s[mw[mi+1][i]][i]]);*/ /* Original formula */
                                 /* But now since version 0.9 we anticipate for bias at large stepm.          /* But now since version 0.9 we anticipate for bias at large stepm.
                                  * If stepm is larger than one month (smallest stepm) and if the exact delay            * If stepm is larger than one month (smallest stepm) and if the exact delay 
                                  * (in months) between two waves is not a multiple of stepm, we rounded to            * (in months) between two waves is not a multiple of stepm, we rounded to 
                                  * the nearest (and in case of equal distance, to the lowest) interval but now           * the nearest (and in case of equal distance, to the lowest) interval but now
                                  * we keep into memory the bias bh[mi][i] and also the previous matrix product           * we keep into memory the bias bh[mi][i] and also the previous matrix product
                                  * (i.e to dh[mi][i]-1) saved in 'savm'. Then we inter(extra)polate the           * (i.e to dh[mi][i]-1) saved in 'savm'. Then we inter(extra)polate the
                                  * probability in order to take into account the bias as a fraction of the way           * probability in order to take into account the bias as a fraction of the way
                                  * from savm to out if bh is negative or even beyond if bh is positive. bh varies                                   * from savm to out if bh is negative or even beyond if bh is positive. bh varies
                                  * -stepm/2 to stepm/2 .                                   * -stepm/2 to stepm/2 .
                                  * For stepm=1 the results are the same as for previous versions of Imach.                                   * For stepm=1 the results are the same as for previous versions of Imach.
                                  * For stepm > 1 the results are less biased than in previous versions.                                    * For stepm > 1 the results are less biased than in previous versions. 
                                  */                                   */
                                 s1=s[mw[mi][i]][i];          s1=s[mw[mi][i]][i];
                                 s2=s[mw[mi+1][i]][i];          s2=s[mw[mi+1][i]][i];
                                 bbh=(double)bh[mi][i]/(double)stepm;           bbh=(double)bh[mi][i]/(double)stepm; 
                                 /* bias bh is positive if real duration          /* bias bh is positive if real duration
                                  * is higher than the multiple of stepm and negative otherwise.           * is higher than the multiple of stepm and negative otherwise.
                                  */           */
                                 /* lli= (savm[s1][s2]>1.e-8 ?(1.+bbh)*log(out[s1][s2])- bbh*log(savm[s1][s2]):log((1.+bbh)*out[s1][s2]));*/          /* lli= (savm[s1][s2]>1.e-8 ?(1.+bbh)*log(out[s1][s2])- bbh*log(savm[s1][s2]):log((1.+bbh)*out[s1][s2]));*/
                                 if( s2 > nlstate){           if( s2 > nlstate){ 
                                         /* i.e. if s2 is a death state and if the date of death is known             /* i.e. if s2 is a death state and if the date of death is known 
                                                  then the contribution to the likelihood is the probability to                then the contribution to the likelihood is the probability to 
                                                  die between last step unit time and current  step unit time,                die between last step unit time and current  step unit time, 
                                                  which is also equal to probability to die before dh                which is also equal to probability to die before dh 
                                                  minus probability to die before dh-stepm .                minus probability to die before dh-stepm . 
                                                  In version up to 0.92 likelihood was computed               In version up to 0.92 likelihood was computed
                                                  as if date of death was unknown. Death was treated as any other               as if date of death was unknown. Death was treated as any other
                                                  health state: the date of the interview describes the actual state               health state: the date of the interview describes the actual state
                                                  and not the date of a change in health state. The former idea was               and not the date of a change in health state. The former idea was
                                                  to consider that at each interview the state was recorded               to consider that at each interview the state was recorded
                                                  (healthy, disable or death) and IMaCh was corrected; but when we               (healthy, disable or death) and IMaCh was corrected; but when we
                                                  introduced the exact date of death then we should have modified               introduced the exact date of death then we should have modified
                                                  the contribution of an exact death to the likelihood. This new               the contribution of an exact death to the likelihood. This new
                                                  contribution is smaller and very dependent of the step unit               contribution is smaller and very dependent of the step unit
                                                  stepm. It is no more the probability to die between last interview               stepm. It is no more the probability to die between last interview
                                                  and month of death but the probability to survive from last               and month of death but the probability to survive from last
                                                  interview up to one month before death multiplied by the               interview up to one month before death multiplied by the
                                                  probability to die within a month. Thanks to Chris               probability to die within a month. Thanks to Chris
                                                  Jackson for correcting this bug.  Former versions increased               Jackson for correcting this bug.  Former versions increased
                                                  mortality artificially. The bad side is that we add another loop               mortality artificially. The bad side is that we add another loop
                                                  which slows down the processing. The difference can be up to 10%               which slows down the processing. The difference can be up to 10%
                                                  lower mortality.               lower mortality.
                                         */            */
                                         /* If, at the beginning of the maximization mostly, the            /* If, at the beginning of the maximization mostly, the
                                                  cumulative probability or probability to be dead is               cumulative probability or probability to be dead is
                                                  constant (ie = 1) over time d, the difference is equal to               constant (ie = 1) over time d, the difference is equal to
                                                  0.  out[s1][3] = savm[s1][3]: probability, being at state               0.  out[s1][3] = savm[s1][3]: probability, being at state
                                                  s1 at precedent wave, to be dead a month before current               s1 at precedent wave, to be dead a month before current
                                                  wave is equal to probability, being at state s1 at               wave is equal to probability, being at state s1 at
                                                  precedent wave, to be dead at mont of the current               precedent wave, to be dead at mont of the current
                                                  wave. Then the observed probability (that this person died)               wave. Then the observed probability (that this person died)
                                                  is null according to current estimated parameter. In fact,               is null according to current estimated parameter. In fact,
                                                  it should be very low but not zero otherwise the log go to               it should be very low but not zero otherwise the log go to
                                                  infinity.               infinity.
                                         */            */
 /* #ifdef INFINITYORIGINAL */  /* #ifdef INFINITYORIGINAL */
 /*          lli=log(out[s1][s2] - savm[s1][s2]); */  /*          lli=log(out[s1][s2] - savm[s1][s2]); */
 /* #else */  /* #else */
Line 4078  Title=%s <br>Datafile=%s Firstpass=%d La Line 4119  Title=%s <br>Datafile=%s Firstpass=%d La
     for (iind=1; iind<=imx; iind++) { /* For each individual iind */      for (iind=1; iind<=imx; iind++) { /* For each individual iind */
       bool=1;        bool=1;
       if(anyvaryingduminmodel==0){ /* If All fixed covariates */        if(anyvaryingduminmodel==0){ /* If All fixed covariates */
                                 if (cptcoveff >0) { /* Filter is here: Must be looked at for model=V1+V2+V3+V4 */          if (cptcoveff >0) { /* Filter is here: Must be looked at for model=V1+V2+V3+V4 */
           /* for (z1=1; z1<= nqfveff; z1++) {   */            /* for (z1=1; z1<= nqfveff; z1++) {   */
           /*   meanq[z1]+=coqvar[Tvar[z1]][iind];  /\* Computes mean of quantitative with selected filter *\/ */            /*   meanq[z1]+=coqvar[Tvar[z1]][iind];  /\* Computes mean of quantitative with selected filter *\/ */
           /* } */            /* } */
                                         for (z1=1; z1<=cptcoveff; z1++) {              for (z1=1; z1<=cptcoveff; z1++) {  
                                                 /* if(Tvaraff[z1] ==-20){ */              /* if(Tvaraff[z1] ==-20){ */
                                                 /*       /\* sumnew+=cotvar[mw[mi][iind]][z1][iind]; *\/ */              /*   /\* sumnew+=cotvar[mw[mi][iind]][z1][iind]; *\/ */
                                                 /* }else  if(Tvaraff[z1] ==-10){ */              /* }else  if(Tvaraff[z1] ==-10){ */
                                                 /*       /\* sumnew+=coqvar[z1][iind]; *\/ */              /*   /\* sumnew+=coqvar[z1][iind]; *\/ */
                                                 /* }else  */              /* }else  */
                                                 if (covar[Tvaraff[z1]][iind]!= nbcode[Tvaraff[z1]][codtabm(j1,z1)]){              if (covar[Tvaraff[z1]][iind]!= nbcode[Tvaraff[z1]][codtabm(j1,z1)]){
                                                         /* Tests if this individual iind responded to j1 (V4=1 V3=0) */                /* Tests if this individual iind responded to j1 (V4=1 V3=0) */
                                                         bool=0;                bool=0;
                                                         /* printf("bool=%d i=%d, z1=%d, Tvaraff[%d]=%d, covar[Tvarff][%d]=%2f, codtabm(%d,%d)=%d, nbcode[Tvaraff][codtabm(%d,%d)=%d, j1=%d\n",                 /* printf("bool=%d i=%d, z1=%d, Tvaraff[%d]=%d, covar[Tvarff][%d]=%2f, codtabm(%d,%d)=%d, nbcode[Tvaraff][codtabm(%d,%d)=%d, j1=%d\n", 
                                                                  bool,i,z1, z1, Tvaraff[z1],i,covar[Tvaraff[z1]][i],j1,z1,codtabm(j1,z1),                   bool,i,z1, z1, Tvaraff[z1],i,covar[Tvaraff[z1]][i],j1,z1,codtabm(j1,z1),
                                                                  j1,z1,nbcode[Tvaraff[z1]][codtabm(j1,z1)],j1);*/                   j1,z1,nbcode[Tvaraff[z1]][codtabm(j1,z1)],j1);*/
                                                         /* For j1=7 in V1+V2+V3+V4 = 0 1 1 0 and codtabm(7,3)=1 and nbcde[3][?]=1*/                /* For j1=7 in V1+V2+V3+V4 = 0 1 1 0 and codtabm(7,3)=1 and nbcde[3][?]=1*/
                                                 } /* Onlyf fixed */              } /* Onlyf fixed */
                                         } /* end z1 */            } /* end z1 */
                                 } /* cptcovn > 0 */          } /* cptcovn > 0 */
       } /* end any */        } /* end any */
       if (bool==1){ /* We selected an individual iind satisfying combination j1 or all fixed */        if (bool==1){ /* We selected an individual iind satisfying combination j1 or all fixed */
                                 /* for(m=firstpass; m<=lastpass; m++){ */          /* for(m=firstpass; m<=lastpass; m++){ */
                                 for(mi=1; mi<wav[iind];mi++){ /* For that wave */          for(mi=1; mi<wav[iind];mi++){ /* For that wave */
                                         m=mw[mi][iind];            m=mw[mi][iind];
                                         if(anyvaryingduminmodel==1){ /* Some are varying covariates */            if(anyvaryingduminmodel==1){ /* Some are varying covariates */
                                                 for (z1=1; z1<=cptcoveff; z1++) {              for (z1=1; z1<=cptcoveff; z1++) {
                                                         if( Fixed[Tmodelind[z1]]==1){                if( Fixed[Tmodelind[z1]]==1){
                                                                 iv= Tvar[Tmodelind[z1]]-ncovcol-nqv;                  iv= Tvar[Tmodelind[z1]]-ncovcol-nqv;
                                                                 if (cotvar[m][iv][iind]!= nbcode[Tvaraff[z1]][codtabm(j1,z1)]) /* iv=1 to ntv, right modality */                  if (cotvar[m][iv][iind]!= nbcode[Tvaraff[z1]][codtabm(j1,z1)]) /* iv=1 to ntv, right modality */
                                                                         bool=0;                    bool=0;
                                                         }else if( Fixed[Tmodelind[z1]]== 0) { /* fixed */                }else if( Fixed[Tmodelind[z1]]== 0) { /* fixed */
                                                                 if (covar[Tvaraff[z1]][iind]!= nbcode[Tvaraff[z1]][codtabm(j1,z1)]) {                  if (covar[Tvaraff[z1]][iind]!= nbcode[Tvaraff[z1]][codtabm(j1,z1)]) {
                                                                         bool=0;                    bool=0;
                                                                 }                  }
                                                         }                }
                                                 }              }
                                         }/* Some are varying covariates, we tried to speed up if all fixed covariates in the model, avoiding waves loop  */            }/* Some are varying covariates, we tried to speed up if all fixed covariates in the model, avoiding waves loop  */
                                         /* bool =0 we keep that guy which corresponds to the combination of dummy values */            /* bool =0 we keep that guy which corresponds to the combination of dummy values */
                                         if(bool==1){            if(bool==1){
                                                 /* dh[m][iind] or dh[mw[mi][iind]][iind] is the delay between two effective (mi) waves m=mw[mi][iind]              /* dh[m][iind] or dh[mw[mi][iind]][iind] is the delay between two effective (mi) waves m=mw[mi][iind]
                                                          and mw[mi+1][iind]. dh depends on stepm. */                 and mw[mi+1][iind]. dh depends on stepm. */
                                                 agebegin=agev[m][iind]; /* Age at beginning of wave before transition*/              agebegin=agev[m][iind]; /* Age at beginning of wave before transition*/
                                                 ageend=agev[m][iind]+(dh[m][iind])*stepm/YEARM; /* Age at end of wave and transition */              ageend=agev[m][iind]+(dh[m][iind])*stepm/YEARM; /* Age at end of wave and transition */
                                                 if(m >=firstpass && m <=lastpass){              if(m >=firstpass && m <=lastpass){
                                                         k2=anint[m][iind]+(mint[m][iind]/12.);                k2=anint[m][iind]+(mint[m][iind]/12.);
                                                         /*if ((k2>=dateprev1) && (k2<=dateprev2)) {*/                /*if ((k2>=dateprev1) && (k2<=dateprev2)) {*/
                                                         if(agev[m][iind]==0) agev[m][iind]=iagemax+1;  /* All ages equal to 0 are in iagemax+1 */                if(agev[m][iind]==0) agev[m][iind]=iagemax+1;  /* All ages equal to 0 are in iagemax+1 */
                                                         if(agev[m][iind]==1) agev[m][iind]=iagemax+2;  /* All ages equal to 1 are in iagemax+2 */                if(agev[m][iind]==1) agev[m][iind]=iagemax+2;  /* All ages equal to 1 are in iagemax+2 */
                                                         if (s[m][iind]>0 && s[m][iind]<=nlstate)  /* If status at wave m is known and a live state */                if (s[m][iind]>0 && s[m][iind]<=nlstate)  /* If status at wave m is known and a live state */
                                                                 prop[s[m][iind]][(int)agev[m][iind]] += weight[iind];  /* At age of beginning of transition, where status is known */                  prop[s[m][iind]][(int)agev[m][iind]] += weight[iind];  /* At age of beginning of transition, where status is known */
                                                         if (m<lastpass) {                if (m<lastpass) {
                                                                 /* if(s[m][iind]==4 && s[m+1][iind]==4) */                  /* if(s[m][iind]==4 && s[m+1][iind]==4) */
                                                                 /*   printf(" num=%ld m=%d, iind=%d s1=%d s2=%d agev at m=%d\n", num[iind], m, iind,s[m][iind],s[m+1][iind], (int)agev[m][iind]); */                  /*   printf(" num=%ld m=%d, iind=%d s1=%d s2=%d agev at m=%d\n", num[iind], m, iind,s[m][iind],s[m+1][iind], (int)agev[m][iind]); */
                                                                 if(s[m][iind]==-1)                  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.));                    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 */                  freq[s[m][iind]][s[m+1][iind]][(int)agev[m][iind]] += weight[iind]; /* At age of beginning of transition, where status is known */
                                                                 /* freq[s[m][iind]][s[m+1][iind]][(int)((agebegin+ageend)/2.)] += weight[iind]; */                  /* freq[s[m][iind]][s[m+1][iind]][(int)((agebegin+ageend)/2.)] += weight[iind]; */
                                                                 freq[s[m][iind]][s[m+1][iind]][iagemax+3] += weight[iind]; /* Total is in iagemax+3 *//* At age of beginning of transition, where status is known */                  freq[s[m][iind]][s[m+1][iind]][iagemax+3] += weight[iind]; /* Total is in iagemax+3 *//* At age of beginning of transition, where status is known */
                                                         }                }
                                                 } /* end if between passes */                } /* end if between passes */  
                                                 if ((agev[m][iind]>1) && (agev[m][iind]< (iagemax+3)) && (anint[m][iind]!=9999) && (mint[m][iind]!=99)) {              if ((agev[m][iind]>1) && (agev[m][iind]< (iagemax+3)) && (anint[m][iind]!=9999) && (mint[m][iind]!=99)) {
                                                         dateintsum=dateintsum+k2;                dateintsum=dateintsum+k2;
                                                         k2cpt++;                k2cpt++;
                                                         /* printf("iind=%ld dateintmean = %lf dateintsum=%lf k2cpt=%lf k2=%lf\n",iind, dateintsum/k2cpt, dateintsum,k2cpt, k2); */                /* printf("iind=%ld dateintmean = %lf dateintsum=%lf k2cpt=%lf k2=%lf\n",iind, dateintsum/k2cpt, dateintsum,k2cpt, k2); */
                                                 }              }
                                         } /* end bool 2 */            } /* end bool 2 */
                                 } /* end m */          } /* end m */
       } /* end bool */        } /* end bool */
     } /* end iind = 1 to imx */      } /* end iind = 1 to imx */
     /* prop[s][age] is feeded for any initial and valid live state as well as      /* prop[s][age] is feeded for any initial and valid live state as well as
Line 4160  Title=%s <br>Datafile=%s Firstpass=%d La Line 4201  Title=%s <br>Datafile=%s Firstpass=%d La
       fprintf(ficresphtm, "\n<br/><br/><h3>********** Variable ");         fprintf(ficresphtm, "\n<br/><br/><h3>********** Variable "); 
       fprintf(ficresphtmfr, "\n<br/><br/><h3>********** Variable ");         fprintf(ficresphtmfr, "\n<br/><br/><h3>********** Variable "); 
       for (z1=1; z1<=cptcoveff; z1++){        for (z1=1; z1<=cptcoveff; z1++){
                                 fprintf(ficresp, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtabm(j1,z1)]);          fprintf(ficresp, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtabm(j1,z1)]);
                                 fprintf(ficresphtm, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtabm(j1,z1)]);          fprintf(ficresphtm, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtabm(j1,z1)]);
                                 fprintf(ficresphtmfr, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtabm(j1,z1)]);          fprintf(ficresphtmfr, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtabm(j1,z1)]);
       }        }
       fprintf(ficresp, "**********\n#");        fprintf(ficresp, "**********\n#");
       fprintf(ficresphtm, "**********</h3>\n");        fprintf(ficresphtm, "**********</h3>\n");
Line 4184  Title=%s <br>Datafile=%s Firstpass=%d La Line 4225  Title=%s <br>Datafile=%s Firstpass=%d La
     fprintf(ficresphtmfr,"<th>Age</th> ");      fprintf(ficresphtmfr,"<th>Age</th> ");
     for(jk=-1; jk <=nlstate+ndeath; jk++){      for(jk=-1; jk <=nlstate+ndeath; jk++){
       for(m=-1; m <=nlstate+ndeath; m++){        for(m=-1; m <=nlstate+ndeath; m++){
                                 if(jk!=0 && m!=0)          if(jk!=0 && m!=0)
                                         fprintf(ficresphtmfr,"<th>%d%d</th> ",jk,m);            fprintf(ficresphtmfr,"<th>%d%d</th> ",jk,m);
       }        }
     }      }
     fprintf(ficresphtmfr, "\n");      fprintf(ficresphtmfr, "\n");
Line 7847  int readdata(char datafile[], int firsto Line 7888  int readdata(char datafile[], int firsto
   return (1);    return (1);
 }  }
   
 void removespace(char **stri){/*, char stro[]) {*/  void removefirstspace(char **stri){/*, char stro[]) {*/
   char *p1 = *stri, *p2 = *stri;    char *p1 = *stri, *p2 = *stri;
   do    if (*p2 == ' ')
     while (*p2 == ' ')      p2++; 
       p2++;    /* while ((*p1++ = *p2++) !=0) */
   while (*p1++ == *p2++);    /*   ; */
   *stri=p1;     /* do */
     /*   while (*p2 == ' ') */
     /*     p2++; */
     /* while (*p1++ == *p2++); */
     *stri=p2; 
 }  }
   
 int decoderesult ( char resultline[])  int decoderesult ( char resultline[])
 /**< This routine decode one result line and returns the combination # of dummy covariates only **/  /**< This routine decode one result line and returns the combination # of dummy covariates only **/
 {  {
   int j=0, k=0;    int j=0, k=0, k1=0, k2=0, match=0;
   char resultsav[MAXLINE];    char resultsav[MAXLINE];
     int resultmodel[MAXLINE];
     int modelresult[MAXLINE];
   char stra[80], strb[80], strc[80], strd[80],stre[80];    char stra[80], strb[80], strc[80], strd[80],stre[80];
   
   removespace(&resultline);    removefirstspace(&resultline);
   printf("decoderesult:%s\n",resultline);    printf("decoderesult:%s\n",resultline);
   
   if (strstr(resultline,"v") !=0){    if (strstr(resultline,"v") !=0){
Line 7875  int decoderesult ( char resultline[]) Line 7922  int decoderesult ( char resultline[])
   if (strlen(resultsav) >1){    if (strlen(resultsav) >1){
     j=nbocc(resultsav,'='); /**< j=Number of covariate values'=' */      j=nbocc(resultsav,'='); /**< j=Number of covariate values'=' */
   }    }
     if( j != cptcovs ){ /* Be careful if a variable is in a product but not single */
   for(k=1; k<=j;k++){ /* Loop on total covariates of the model */      printf("ERROR: the number of variable in the resultline, %d, differs from the number of variable used in the model line, %d.\n",j, cptcovs);
     cutl(stra,strb,resultsav,' '); /* keeps in strb after the first ' '       fprintf(ficlog,"ERROR: the number of variable in the resultline, %d, differs from the number of variable used in the model line, %d.\n",j, cptcovs);
                                      resultsav= V4=1 V5=25.1 V3=0 strb=V3=0 stra= V4=1 V5=25.1 */    }
     cutl(strc,strd,strb,'=');  /* strb:V4=1 strc=1 strd=V4 */    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 strb=V3=0 stra= V4=1 V5=25.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 */
       
     cutl(strc,stre,strd,'V'); /* strd='V4' strc=4 stre='V' */;      cutl(strc,stre,strd,'V'); /* strd='V4' strc=4 stre='V' */;
     Tvarsel[k]=atoi(strc);      Tvarsel[k]=atoi(strc);
     /* Typevarsel[k]=1;  /\* 1 for age product *\/ */      /* Typevarsel[k]=1;  /\* 1 for age product *\/ */
Line 7889  int decoderesult ( char resultline[]) Line 7942  int decoderesult ( char resultline[])
     if (nbocc(stra,'=') >0)      if (nbocc(stra,'=') >0)
       strcpy(resultsav,stra); /* and analyzes it */        strcpy(resultsav,stra); /* and analyzes it */
   }    }
     /* Checking if no missing or useless values in comparison of current model needs */
     for(k1=1; k1<= cptcovt ;k1++){ /* model line */
       if(Typevar[k1]==0){
         match=0;
         for(k2=1; k2 <=j;k2++){
           if(Tvar[k1]==Tvarsel[k2]) {
             modelresult[k2]=k1;
             match=1;
             break;
           }
         }
         if(match == 0){
           printf("Error in result line: %d value missing; result: %s, model=%s\n",k1, resultline, model);
         }
       }
     }
     
     for(k2=1; k2 <=j;k2++){ /* result line */
       match=0;
       for(k1=1; k1<= cptcovt ;k1++){ /* model line */
         if(Typevar[k1]==0){
           if(Tvar[k1]==Tvarsel[k2]) {
             resultmodel[k1]=k2;
             ++match;
           }
         }
       }
       if(match == 0){
         printf("Error in result line: %d value missing; result: %s, model=%s\n",k1, resultline, model);
       }else if(match > 1){
         printf("Error in result line: %d doubled; result: %s, model=%s\n",k2, resultline, model);
       }
     }
     
     /* We need to deduce which combination number is chosen and save quantitative values */
     
   return (0);    return (0);
 }  }
 int selected( int kvar){ /* Selected combination of covariates */  int selected( int kvar){ /* Selected combination of covariates */
Line 7936  int decodemodel( char model[], int lasto Line 8025  int decodemodel( char model[], int lasto
     if ((strpt=strstr(model,"age*age")) !=0){      if ((strpt=strstr(model,"age*age")) !=0){
       printf(" strpt=%s, model=%s\n",strpt, model);        printf(" strpt=%s, model=%s\n",strpt, model);
       if(strpt != model){        if(strpt != model){
                                 printf("Error in model: 'model=%s'; 'age*age' should in first place before other covariates\n \          printf("Error in model: 'model=%s'; 'age*age' should in first place before other covariates\n \
  'model=1+age+age*age+V1.' or 'model=1+age+age*age+V1+V1*age.', please swap as well as \n \   'model=1+age+age*age+V1.' or 'model=1+age+age*age+V1+V1*age.', please swap as well as \n \
  corresponding column of parameters.\n",model);   corresponding column of parameters.\n",model);
                                 fprintf(ficlog,"Error in model: 'model=%s'; 'age*age' should in first place before other covariates\n \          fprintf(ficlog,"Error in model: 'model=%s'; 'age*age' should in first place before other covariates\n \
  'model=1+age+age*age+V1.' or 'model=1+age+age*age+V1+V1*age.', please swap as well as \n \   'model=1+age+age*age+V1.' or 'model=1+age+age*age+V1+V1*age.', please swap as well as \n \
  corresponding column of parameters.\n",model); fflush(ficlog);   corresponding column of parameters.\n",model); fflush(ficlog);
                                 return 1;          return 1;
       }        }
       nagesqr=1;        nagesqr=1;
       if (strstr(model,"+age*age") !=0)        if (strstr(model,"+age*age") !=0)
                                 substrchaine(modelsav, model, "+age*age");          substrchaine(modelsav, model, "+age*age");
       else if (strstr(model,"age*age+") !=0)        else if (strstr(model,"age*age+") !=0)
                                 substrchaine(modelsav, model, "age*age+");          substrchaine(modelsav, model, "age*age+");
       else         else 
                                 substrchaine(modelsav, model, "age*age");          substrchaine(modelsav, model, "age*age");
     }else      }else
       nagesqr=0;        nagesqr=0;
     if (strlen(modelsav) >1){      if (strlen(modelsav) >1){
Line 8020  int decodemodel( char model[], int lasto Line 8109  int decodemodel( char model[], int lasto
       }        }
       cptcovage=0;        cptcovage=0;
       for(k=1; k<=cptcovt;k++){ /* Loop on total covariates of the model */        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 */                                            modelsav==V2+V1+V4+V3*age strb=V3*age stra=V2+V1+V4 */ 
                                 if (nbocc(modelsav,'+')==0) strcpy(strb,modelsav); /* and analyzes it */          if (nbocc(modelsav,'+')==0) strcpy(strb,modelsav); /* and analyzes it */
                                 /*      printf("i=%d a=%s b=%s sav=%s\n",i, stra,strb,modelsav);*/          /*      printf("i=%d a=%s b=%s sav=%s\n",i, stra,strb,modelsav);*/
                                 /*scanf("%d",i);*/          /*scanf("%d",i);*/
                                 if (strchr(strb,'*')) {  /**< Model includes a product V2+V1+V4+V3*age strb=V3*age */          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 */            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 */            if (strcmp(strc,"age")==0) { /**< Model includes age: Vn*age */
                                                 /* covar is not filled and then is empty */              /* covar is not filled and then is empty */
                                                 cptcovprod--;              cptcovprod--;
                                                 cutl(stre,strb,strd,'V'); /* strd=V3(input): stre="3" */              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 */              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 */              Typevar[k]=1;  /* 1 for age product */
                                                 cptcovage++; /* Sums the number of covariates which include age as a 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 */              Tage[cptcovage]=k;  /* Tvar[4]=3, Tage[1] = 4 or V1+V1*age Tvar[2]=1, Tage[1]=2 */
                                                 /*printf("stre=%s ", stre);*/              /*printf("stre=%s ", stre);*/
                                         } else if (strcmp(strd,"age")==0) { /* or age*Vn */            } else if (strcmp(strd,"age")==0) { /* or age*Vn */
                                                 cptcovprod--;              cptcovprod--;
                                                 cutl(stre,strb,strc,'V');              cutl(stre,strb,strc,'V');
                                                 Tvar[k]=atoi(stre);              Tvar[k]=atoi(stre);
                                                 Typevar[k]=1;  /* 1 for age product */              Typevar[k]=1;  /* 1 for age product */
                                                 cptcovage++;              cptcovage++;
                                                 Tage[cptcovage]=k;              Tage[cptcovage]=k;
                                         } else {  /* Age is not in the model product V2+V1+V1*V4+V3*age+V3*V2  strb=V3*V2*/            } 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 */              /* loops on k1=1 (V3*V2) and k1=2 V4*V3 */
                                                 cptcovn++;              cptcovn++;
                                                 cptcovprodnoage++;k1++;              cptcovprodnoage++;k1++;
                                                 cutl(stre,strb,strc,'V'); /* strc= Vn, stre is n; strb=V3*V2 stre=3 strc=*/              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              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                                                  because this model-covariate is a construction we invent a new column
                                                                                                                                                                                                 which is after existing variables ncovcol+nqv+ntv+nqtv + k1                                                  which is after existing variables ncovcol+nqv+ntv+nqtv + k1
                                                                                                                                                                                                 If already ncovcol=4 and model=V2+V1+V1*V4+age*V3+V3*V2                                                  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 */                                                  Tvar[3=V1*V4]=4+1 Tvar[5=V3*V2]=4 + 2= 6, etc */
                                                 Typevar[k]=2;  /* 2 for double fixed dummy covariates */              Typevar[k]=2;  /* 2 for double fixed dummy covariates */
                                                 cutl(strc,strb,strd,'V'); /* strd was Vm, strc is m */              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  */              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 */              Tposprod[k]=k1; /* Tpsprod[3]=1, Tposprod[2]=5 */
                                                 Tvard[k1][1] =atoi(strc); /* m 1 for V1*/              Tvard[k1][1] =atoi(strc); /* m 1 for V1*/
                                                 Tvard[k1][2] =atoi(stre); /* n 4 for V4*/              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 */              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]=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) *\/ */              /* 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 */              /*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   */              /*                     1  2   3      4     5 | Tvar[5+1)=1, Tvar[7]=2   */
                                                 for (i=1; i<=lastobs;i++){              for (i=1; i<=lastobs;i++){
                                                         /* Computes the new covariate which is a product of                /* 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[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];                covar[ncovcol+k1][i]=covar[atoi(stre)][i]*covar[atoi(strc)][i];
                                                 }              }
                                         } /* End age is not in the model */            } /* End age is not in the model */
                                 } /* End if model includes a product */          } /* End if model includes a product */
                                 else { /* no more sum */          else { /* no more sum */
                                         /*printf("d=%s c=%s b=%s\n", strd,strc,strb);*/            /*printf("d=%s c=%s b=%s\n", strd,strc,strb);*/
                                         /*  scanf("%d",i);*/            /*  scanf("%d",i);*/
                                         cutl(strd,strc,strb,'V');            cutl(strd,strc,strb,'V');
                                         ks++; /**< Number of simple covariates dummy or quantitative, fixe or varying */            ks++; /**< Number of simple covariates dummy or quantitative, fixe or varying */
                                         cptcovn++; /** V4+V3+V5: V4 and V3 timevarying dummy covariates, V5 timevarying quantitative */            cptcovn++; /** V4+V3+V5: V4 and V3 timevarying dummy covariates, V5 timevarying quantitative */
                                         Tvar[k]=atoi(strd);            Tvar[k]=atoi(strd);
                                         Typevar[k]=0;  /* 0 for simple covariates */            Typevar[k]=0;  /* 0 for simple covariates */
                                 }          }
                                 strcpy(modelsav,stra);  /* modelsav=V2+V1+V4 stra=V2+V1+V4 */           strcpy(modelsav,stra);  /* modelsav=V2+V1+V4 stra=V2+V1+V4 */ 
                                 /*printf("a=%s b=%s sav=%s\n", stra,strb,modelsav);                                  /*printf("a=%s b=%s sav=%s\n", stra,strb,modelsav);
                                   scanf("%d",i);*/                                    scanf("%d",i);*/
       } /* end of loop + on total covariates */        } /* end of loop + on total covariates */
Line 8120  Typevar: 0 for simple covariate (dummy, Line 8209  Typevar: 0 for simple covariate (dummy,
 Fixed[k] 0=fixed (product or simple), 1 varying, 2 fixed with age product, 3 varying with age 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);  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, ncovf=0, ncovv=0, ncova=0, ncoveff=0, nqfveff=0, ntveff=0, nqtveff=0;k<=cptcovt; k++){ /* or cptocvt */    for(k=1, ncovf=0, nsd=0, nsq=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 */      if (Tvar[k] <=ncovcol && Typevar[k]==0 ){ /* Simple fixed dummy (<=ncovcol) covariates */
       Fixed[k]= 0;        Fixed[k]= 0;
       Dummy[k]= 0;        Dummy[k]= 0;
       ncoveff++;        ncoveff++;
       ncovf++;        ncovf++;
                         modell[k].maintype= FTYPE;        nsd++;
                         TvarF[ncovf]=Tvar[k];        modell[k].maintype= FTYPE;
                         TvarFind[ncovf]=k;        TvarsD[nsd]=Tvar[k];
         TvarsDind[nsd]=k;
         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 &&  Typevar[k]==2){ /* Product of 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 */        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 */        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 */      }else if( Tvar[k] <=ncovcol+nqv && Typevar[k]==0){ /* Remind that product Vn*Vm are added in k*/ /* Only simple fixed quantitative variable */
       Fixed[k]= 0;        Fixed[k]= 0;
       Dummy[k]= 1;        Dummy[k]= 1;
       nqfveff++;        nqfveff++;
                         modell[k].maintype= FTYPE;        modell[k].maintype= FTYPE;
                         modell[k].subtype= FQ;        modell[k].subtype= FQ;
         nsq++;
         TvarsQ[nsq]=Tvar[k];
         TvarsQind[nsq]=k;
       ncovf++;        ncovf++;
                         TvarF[ncovf]=Tvar[k];        TvarF[ncovf]=Tvar[k];
                         TvarFind[ncovf]=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 */        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 */        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){      }else if( Tvar[k] <=ncovcol+nqv+ntv && Typevar[k]==0){/* Only simple time varying variables */
       Fixed[k]= 1;        Fixed[k]= 1;
       Dummy[k]= 0;        Dummy[k]= 0;
       ntveff++; /* Only simple time varying dummy variable */        ntveff++; /* Only simple time varying dummy variable */
                         modell[k].maintype= VTYPE;        modell[k].maintype= VTYPE;
                         modell[k].subtype= VD;        modell[k].subtype= VD;
                         ncovv++; /* Only simple time varying variables */        nsd++;
                         TvarV[ncovv]=Tvar[k];        TvarsD[nsd]=Tvar[k];
                         TvarVind[ncovv]=k;        TvarsDind[nsd]=k;
         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 */        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 */        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);        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);
       printf("Quasi TmodelInvind[%d]=%d\n",k,Tvar[k]- ncovcol-nqv);        printf("Quasi TmodelInvind[%d]=%d\n",k,Tvar[k]- ncovcol-nqv);
     }else if( Tvar[k] <=ncovcol+nqv+ntv+nqtv  && Typevar[k]==0){ /* Only simple time varying quantitative variable V5*/      }else if( Tvar[k] <=ncovcol+nqv+ntv+nqtv  && Typevar[k]==0){ /* Only simple time varying quantitative variable V5*/
                         Fixed[k]= 1;        Fixed[k]= 1;
                         Dummy[k]= 1;        Dummy[k]= 1;
                         nqtveff++;        nqtveff++;
                         modell[k].maintype= VTYPE;        modell[k].maintype= VTYPE;
                         modell[k].subtype= VQ;        modell[k].subtype= VQ;
                         ncovv++; /* Only simple time varying variables */        ncovv++; /* Only simple time varying variables */
                         TvarV[ncovv]=Tvar[k];        nsq++;
                         TvarVind[ncovv]=k;        TvarsQ[nsq]=Tvar[k];
         TvarsQind[nsq]=k;
         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 */        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 */        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 */        TmodelInvQind[nqtveff]=Tvar[k]- ncovcol-nqv-ntv;/* Only simple time varying quantitative variable */
                         /* Tmodeliqind[k]=nqtveff;/\* Only simple time varying quantitative variable *\/ */        /* Tmodeliqind[k]=nqtveff;/\* 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 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);        printf("Quasi TmodelInvQind[%d]=%d\n",k,Tvar[k]- ncovcol-nqv-ntv);
     }else if (Typevar[k] == 1) {  /* product with age */      }else if (Typevar[k] == 1) {  /* product with age */
                         ncova++;        ncova++;
                         TvarA[ncova]=Tvar[k];        TvarA[ncova]=Tvar[k];
                         TvarAind[ncova]=k;        TvarAind[ncova]=k;
       if (Tvar[k] <=ncovcol ){ /* Product age with fixed dummy covariatee */        if (Tvar[k] <=ncovcol ){ /* Product age with fixed dummy covariatee */
                                 Fixed[k]= 2;          Fixed[k]= 2;
                                 Dummy[k]= 2;          Dummy[k]= 2;
                                 modell[k].maintype= ATYPE;          modell[k].maintype= ATYPE;
                                 modell[k].subtype= APFD;          modell[k].subtype= APFD;
                                 /* ncoveff++; */          /* ncoveff++; */
       }else if( Tvar[k] <=ncovcol+nqv) { /* Remind that product Vn*Vm are added in k*/        }else if( Tvar[k] <=ncovcol+nqv) { /* Remind that product Vn*Vm are added in k*/
                                 Fixed[k]= 2;          Fixed[k]= 2;
                                 Dummy[k]= 3;          Dummy[k]= 3;
                                 modell[k].maintype= ATYPE;          modell[k].maintype= ATYPE;
                                 modell[k].subtype= APFQ;                /*      Product age * fixed quantitative */          modell[k].subtype= APFQ;                /*      Product age * fixed quantitative */
                                 /* nqfveff++;  /\* Only simple fixed quantitative variable *\/ */          /* nqfveff++;  /\* Only simple fixed quantitative variable *\/ */
       }else if( Tvar[k] <=ncovcol+nqv+ntv ){        }else if( Tvar[k] <=ncovcol+nqv+ntv ){
                                 Fixed[k]= 3;          Fixed[k]= 3;
                                 Dummy[k]= 2;          Dummy[k]= 2;
                                 modell[k].maintype= ATYPE;          modell[k].maintype= ATYPE;
                                 modell[k].subtype= APVD;                /*      Product age * varying dummy */          modell[k].subtype= APVD;                /*      Product age * varying dummy */
                                 /* ntveff++; /\* Only simple time varying dummy variable *\/ */          /* ntveff++; /\* Only simple time varying dummy variable *\/ */
       }else if( Tvar[k] <=ncovcol+nqv+ntv+nqtv){        }else if( Tvar[k] <=ncovcol+nqv+ntv+nqtv){
                                 Fixed[k]= 3;          Fixed[k]= 3;
                                 Dummy[k]= 3;          Dummy[k]= 3;
                                 modell[k].maintype= ATYPE;          modell[k].maintype= ATYPE;
                                 modell[k].subtype= APVQ;                /*      Product age * varying quantitative */          modell[k].subtype= APVQ;                /*      Product age * varying quantitative */
                                 /* nqtveff++;/\* Only simple time varying quantitative variable *\/ */          /* nqtveff++;/\* Only simple time varying quantitative variable *\/ */
       }        }
     }else if (Typevar[k] == 2) {  /* product without age */      }else if (Typevar[k] == 2) {  /* product without age */
       k1=Tposprod[k];        k1=Tposprod[k];
       if(Tvard[k1][1] <=ncovcol){        if(Tvard[k1][1] <=ncovcol){
                                 if(Tvard[k1][2] <=ncovcol){          if(Tvard[k1][2] <=ncovcol){
                                         Fixed[k]= 1;            Fixed[k]= 1;
                                         Dummy[k]= 0;            Dummy[k]= 0;
                                         modell[k].maintype= FTYPE;            modell[k].maintype= FTYPE;
                                         modell[k].subtype= FPDD;                /*      Product fixed dummy * fixed dummy */            modell[k].subtype= FPDD;              /*      Product fixed dummy * fixed dummy */
                                         ncovf++; /* Fixed variables without age */            ncovf++; /* Fixed variables without age */
                                         TvarF[ncovf]=Tvar[k];            TvarF[ncovf]=Tvar[k];
                                         TvarFind[ncovf]=k;            TvarFind[ncovf]=k;
                                 }else if(Tvard[k1][2] <=ncovcol+nqv){          }else if(Tvard[k1][2] <=ncovcol+nqv){
                                         Fixed[k]= 0;  /* or 2 ?*/            Fixed[k]= 0;  /* or 2 ?*/
                                         Dummy[k]= 1;            Dummy[k]= 1;
                                         modell[k].maintype= FTYPE;            modell[k].maintype= FTYPE;
                                         modell[k].subtype= FPDQ;                /*      Product fixed dummy * fixed quantitative */            modell[k].subtype= FPDQ;              /*      Product fixed dummy * fixed quantitative */
                                         ncovf++; /* Varying variables without age */            ncovf++; /* Varying variables without age */
                                         TvarF[ncovf]=Tvar[k];            TvarF[ncovf]=Tvar[k];
                                         TvarFind[ncovf]=k;            TvarFind[ncovf]=k;
                                 }else if(Tvard[k1][2] <=ncovcol+nqv+ntv){          }else if(Tvard[k1][2] <=ncovcol+nqv+ntv){
                                         Fixed[k]= 1;            Fixed[k]= 1;
                                         Dummy[k]= 0;            Dummy[k]= 0;
                                         modell[k].maintype= VTYPE;            modell[k].maintype= VTYPE;
                                         modell[k].subtype= VPDD;                /*      Product fixed dummy * varying dummy */            modell[k].subtype= VPDD;              /*      Product fixed dummy * varying dummy */
                                         ncovv++; /* Varying variables without age */            ncovv++; /* Varying variables without age */
                                         TvarV[ncovv]=Tvar[k];            TvarV[ncovv]=Tvar[k];
                                         TvarVind[ncovv]=k;            TvarVind[ncovv]=k;
                                 }else if(Tvard[k1][2] <=ncovcol+nqv+ntv+nqtv){          }else if(Tvard[k1][2] <=ncovcol+nqv+ntv+nqtv){
                                         Fixed[k]= 1;            Fixed[k]= 1;
                                         Dummy[k]= 1;            Dummy[k]= 1;
                                         modell[k].maintype= VTYPE;            modell[k].maintype= VTYPE;
                                         modell[k].subtype= VPDQ;                /*      Product fixed dummy * varying quantitative */            modell[k].subtype= VPDQ;              /*      Product fixed dummy * varying quantitative */
                                         ncovv++; /* Varying variables without age */            ncovv++; /* Varying variables without age */
                                         TvarV[ncovv]=Tvar[k];            TvarV[ncovv]=Tvar[k];
                                         TvarVind[ncovv]=k;            TvarVind[ncovv]=k;
                                 }           } 
       }else if(Tvard[k1][1] <=ncovcol+nqv){        }else if(Tvard[k1][1] <=ncovcol+nqv){
                                 if(Tvard[k1][2] <=ncovcol){          if(Tvard[k1][2] <=ncovcol){
                                         Fixed[k]= 0;  /* or 2 ?*/            Fixed[k]= 0;  /* or 2 ?*/
                                         Dummy[k]= 1;            Dummy[k]= 1;
                                         modell[k].maintype= FTYPE;            modell[k].maintype= FTYPE;
                                         modell[k].subtype= FPDQ;                /*      Product fixed quantitative * fixed dummy */            modell[k].subtype= FPDQ;              /*      Product fixed quantitative * fixed dummy */
                                         ncovf++; /* Fixed variables without age */            ncovf++; /* Fixed variables without age */
                                         TvarF[ncovf]=Tvar[k];            TvarF[ncovf]=Tvar[k];
                                         TvarFind[ncovf]=k;            TvarFind[ncovf]=k;
                                 }else if(Tvard[k1][2] <=ncovcol+nqv+ntv){          }else if(Tvard[k1][2] <=ncovcol+nqv+ntv){
                                         Fixed[k]= 1;            Fixed[k]= 1;
                                         Dummy[k]= 1;            Dummy[k]= 1;
                                         modell[k].maintype= VTYPE;            modell[k].maintype= VTYPE;
                                         modell[k].subtype= VPDQ;                /*      Product fixed quantitative * varying dummy */            modell[k].subtype= VPDQ;              /*      Product fixed quantitative * varying dummy */
                                         ncovv++; /* Varying variables without age */            ncovv++; /* Varying variables without age */
                                         TvarV[ncovv]=Tvar[k];            TvarV[ncovv]=Tvar[k];
                                         TvarVind[ncovv]=k;            TvarVind[ncovv]=k;
                                 }else if(Tvard[k1][2] <=ncovcol+nqv+ntv+nqtv){          }else if(Tvard[k1][2] <=ncovcol+nqv+ntv+nqtv){
                                         Fixed[k]= 1;            Fixed[k]= 1;
                                         Dummy[k]= 1;            Dummy[k]= 1;
                                         modell[k].maintype= VTYPE;            modell[k].maintype= VTYPE;
                                         modell[k].subtype= VPQQ;                /*      Product fixed quantitative * varying quantitative */            modell[k].subtype= VPQQ;              /*      Product fixed quantitative * varying quantitative */
                                         ncovv++; /* Varying variables without age */            ncovv++; /* Varying variables without age */
                                         TvarV[ncovv]=Tvar[k];            TvarV[ncovv]=Tvar[k];
                                         TvarVind[ncovv]=k;            TvarVind[ncovv]=k;
                                         ncovv++; /* Varying variables without age */            ncovv++; /* Varying variables without age */
                                         TvarV[ncovv]=Tvar[k];            TvarV[ncovv]=Tvar[k];
                                         TvarVind[ncovv]=k;            TvarVind[ncovv]=k;
                                 }           } 
       }else if(Tvard[k1][1] <=ncovcol+nqv+ntv){        }else if(Tvard[k1][1] <=ncovcol+nqv+ntv){
                                 if(Tvard[k1][2] <=ncovcol){          if(Tvard[k1][2] <=ncovcol){
                                         Fixed[k]= 1;            Fixed[k]= 1;
                                         Dummy[k]= 1;            Dummy[k]= 1;
                                         modell[k].maintype= VTYPE;            modell[k].maintype= VTYPE;
                                         modell[k].subtype= VPDD;                /*      Product time varying dummy * fixed dummy */            modell[k].subtype= VPDD;              /*      Product time varying dummy * fixed dummy */
                                         ncovv++; /* Varying variables without age */            ncovv++; /* Varying variables without age */
                                         TvarV[ncovv]=Tvar[k];            TvarV[ncovv]=Tvar[k];
                                         TvarVind[ncovv]=k;            TvarVind[ncovv]=k;
                                 }else if(Tvard[k1][2] <=ncovcol+nqv){          }else if(Tvard[k1][2] <=ncovcol+nqv){
                                         Fixed[k]= 1;            Fixed[k]= 1;
                                         Dummy[k]= 1;            Dummy[k]= 1;
                                         modell[k].maintype= VTYPE;            modell[k].maintype= VTYPE;
                                         modell[k].subtype= VPDQ;                /*      Product time varying dummy * fixed quantitative */            modell[k].subtype= VPDQ;              /*      Product time varying dummy * fixed quantitative */
                                         ncovv++; /* Varying variables without age */            ncovv++; /* Varying variables without age */
                                         TvarV[ncovv]=Tvar[k];            TvarV[ncovv]=Tvar[k];
                                         TvarVind[ncovv]=k;            TvarVind[ncovv]=k;
                                 }else if(Tvard[k1][2] <=ncovcol+nqv+ntv){          }else if(Tvard[k1][2] <=ncovcol+nqv+ntv){
                                         Fixed[k]= 1;            Fixed[k]= 1;
                                         Dummy[k]= 0;            Dummy[k]= 0;
                                         modell[k].maintype= VTYPE;            modell[k].maintype= VTYPE;
                                         modell[k].subtype= VPDD;                /*      Product time varying dummy * time varying dummy */            modell[k].subtype= VPDD;              /*      Product time varying dummy * time varying dummy */
                                         ncovv++; /* Varying variables without age */            ncovv++; /* Varying variables without age */
                                         TvarV[ncovv]=Tvar[k];            TvarV[ncovv]=Tvar[k];
                                         TvarVind[ncovv]=k;            TvarVind[ncovv]=k;
                                 }else if(Tvard[k1][2] <=ncovcol+nqv+ntv+nqtv){          }else if(Tvard[k1][2] <=ncovcol+nqv+ntv+nqtv){
                                         Fixed[k]= 1;            Fixed[k]= 1;
                                         Dummy[k]= 1;            Dummy[k]= 1;
                                         modell[k].maintype= VTYPE;            modell[k].maintype= VTYPE;
                                         modell[k].subtype= VPDQ;                /*      Product time varying dummy * time varying quantitative */            modell[k].subtype= VPDQ;              /*      Product time varying dummy * time varying quantitative */
                                         ncovv++; /* Varying variables without age */            ncovv++; /* Varying variables without age */
                                         TvarV[ncovv]=Tvar[k];            TvarV[ncovv]=Tvar[k];
                                         TvarVind[ncovv]=k;            TvarVind[ncovv]=k;
                                 }           } 
       }else if(Tvard[k1][1] <=ncovcol+nqv+ntv+nqtv){        }else if(Tvard[k1][1] <=ncovcol+nqv+ntv+nqtv){
                                 if(Tvard[k1][2] <=ncovcol){          if(Tvard[k1][2] <=ncovcol){
                                         Fixed[k]= 1;            Fixed[k]= 1;
                                         Dummy[k]= 1;            Dummy[k]= 1;
                                         modell[k].maintype= VTYPE;            modell[k].maintype= VTYPE;
                                         modell[k].subtype= VPDQ;                /*      Product time varying quantitative * fixed dummy */            modell[k].subtype= VPDQ;              /*      Product time varying quantitative * fixed dummy */
                                         ncovv++; /* Varying variables without age */            ncovv++; /* Varying variables without age */
                                         TvarV[ncovv]=Tvar[k];            TvarV[ncovv]=Tvar[k];
                                         TvarVind[ncovv]=k;            TvarVind[ncovv]=k;
                                 }else if(Tvard[k1][2] <=ncovcol+nqv){          }else if(Tvard[k1][2] <=ncovcol+nqv){
                                         Fixed[k]= 1;            Fixed[k]= 1;
                                         Dummy[k]= 1;            Dummy[k]= 1;
                                         modell[k].maintype= VTYPE;            modell[k].maintype= VTYPE;
                                         modell[k].subtype= VPQQ;                /*      Product time varying quantitative * fixed quantitative */            modell[k].subtype= VPQQ;              /*      Product time varying quantitative * fixed quantitative */
                                         ncovv++; /* Varying variables without age */            ncovv++; /* Varying variables without age */
                                         TvarV[ncovv]=Tvar[k];            TvarV[ncovv]=Tvar[k];
                                         TvarVind[ncovv]=k;            TvarVind[ncovv]=k;
                                 }else if(Tvard[k1][2] <=ncovcol+nqv+ntv){          }else if(Tvard[k1][2] <=ncovcol+nqv+ntv){
                                         Fixed[k]= 1;            Fixed[k]= 1;
                                         Dummy[k]= 1;            Dummy[k]= 1;
                                         modell[k].maintype= VTYPE;            modell[k].maintype= VTYPE;
                                         modell[k].subtype= VPDQ;                /*      Product time varying quantitative * time varying dummy */            modell[k].subtype= VPDQ;              /*      Product time varying quantitative * time varying dummy */
                                         ncovv++; /* Varying variables without age */            ncovv++; /* Varying variables without age */
                                         TvarV[ncovv]=Tvar[k];            TvarV[ncovv]=Tvar[k];
                                         TvarVind[ncovv]=k;            TvarVind[ncovv]=k;
                                 }else if(Tvard[k1][2] <=ncovcol+nqv+ntv+nqtv){          }else if(Tvard[k1][2] <=ncovcol+nqv+ntv+nqtv){
                                         Fixed[k]= 1;            Fixed[k]= 1;
                                         Dummy[k]= 1;            Dummy[k]= 1;
                                         modell[k].maintype= VTYPE;            modell[k].maintype= VTYPE;
                                         modell[k].subtype= VPQQ;                /*      Product time varying quantitative * time varying quantitative */            modell[k].subtype= VPQQ;              /*      Product time varying quantitative * time varying quantitative */
                                         ncovv++; /* Varying variables without age */            ncovv++; /* Varying variables without age */
                                         TvarV[ncovv]=Tvar[k];            TvarV[ncovv]=Tvar[k];
                                         TvarVind[ncovv]=k;            TvarVind[ncovv]=k;
                                 }           } 
       }else{        }else{
                                 printf("Error unknown type of covariate: Tvard[%d][1]=%d,Tvard[%d][2]=%d\n",k1,Tvard[k1][1],k1,Tvard[k1][2]);          printf("Error unknown type of covariate: Tvard[%d][1]=%d,Tvard[%d][2]=%d\n",k1,Tvard[k1][1],k1,Tvard[k1][2]);
                                 fprintf(ficlog,"Error unknown type of covariate: Tvard[%d][1]=%d,Tvard[%d][2]=%d\n",k1,Tvard[k1][1],k1,Tvard[k1][2]);          fprintf(ficlog,"Error unknown type of covariate: Tvard[%d][1]=%d,Tvard[%d][2]=%d\n",k1,Tvard[k1][1],k1,Tvard[k1][2]);
       } /* end k1 */        } /* end k1 */
     }else{      }else{
       printf("Error, current version can't treat for performance reasons, Tvar[%d]=%d, Typevar[%d]=%d\n", k, Tvar[k], k, Typevar[k]);        printf("Error, current version can't treat for performance reasons, Tvar[%d]=%d, Typevar[%d]=%d\n", k, Tvar[k], k, Typevar[k]);
Line 8348  Dummy[k] 0=dummy (0 1), 1 quantitative ( Line 8459  Dummy[k] 0=dummy (0 1), 1 quantitative (
   for(k1=1; k1<= cptcovt;k1++){    for(k1=1; k1<= cptcovt;k1++){
     for(k2=1; k2 <k1;k2++){      for(k2=1; k2 <k1;k2++){
       if((Typevar[k1]==Typevar[k2]) && (Fixed[Tvar[k1]]==Fixed[Tvar[k2]]) && (Dummy[Tvar[k1]]==Dummy[Tvar[k2]] )){        if((Typevar[k1]==Typevar[k2]) && (Fixed[Tvar[k1]]==Fixed[Tvar[k2]]) && (Dummy[Tvar[k1]]==Dummy[Tvar[k2]] )){
                                 if((Typevar[k1] == 0 || Typevar[k1] == 1)){ /* Simple or age product */          if((Typevar[k1] == 0 || Typevar[k1] == 1)){ /* Simple or age product */
                                         if(Tvar[k1]==Tvar[k2]){            if(Tvar[k1]==Tvar[k2]){
                                                 printf("Error duplication in the model=%s at positions (+) %d and %d, Tvar[%d]=V%d, Tvar[%d]=V%d, Typevar=%d, Fixed=%d, Dummy=%d\n", model, k1,k2, k1, Tvar[k1], k2, Tvar[k2],Typevar[k1],Fixed[Tvar[k1]],Dummy[Tvar[k1]]);              printf("Error duplication in the model=%s at positions (+) %d and %d, Tvar[%d]=V%d, Tvar[%d]=V%d, Typevar=%d, Fixed=%d, Dummy=%d\n", model, k1,k2, k1, Tvar[k1], k2, Tvar[k2],Typevar[k1],Fixed[Tvar[k1]],Dummy[Tvar[k1]]);
                                                 fprintf(ficlog,"Error duplication in the model=%s at positions (+) %d and %d, Tvar[%d]=V%d, Tvar[%d]=V%d, Typevar=%d, Fixed=%d, Dummy=%d\n", model, k1,k2, k1, Tvar[k1], k2, Tvar[k2],Typevar[k1],Fixed[Tvar[k1]],Dummy[Tvar[k1]]); fflush(ficlog);              fprintf(ficlog,"Error duplication in the model=%s at positions (+) %d and %d, Tvar[%d]=V%d, Tvar[%d]=V%d, Typevar=%d, Fixed=%d, Dummy=%d\n", model, k1,k2, k1, Tvar[k1], k2, Tvar[k2],Typevar[k1],Fixed[Tvar[k1]],Dummy[Tvar[k1]]); fflush(ficlog);
                                                 return(1);              return(1);
                                         }            }
                                 }else if (Typevar[k1] ==2){          }else if (Typevar[k1] ==2){
                                         k3=Tposprod[k1];            k3=Tposprod[k1];
                                         k4=Tposprod[k2];            k4=Tposprod[k2];
                                         if( ((Tvard[k3][1]== Tvard[k4][1])&&(Tvard[k3][2]== Tvard[k4][2])) || ((Tvard[k3][1]== Tvard[k4][2])&&(Tvard[k3][2]== Tvard[k4][1])) ){            if( ((Tvard[k3][1]== Tvard[k4][1])&&(Tvard[k3][2]== Tvard[k4][2])) || ((Tvard[k3][1]== Tvard[k4][2])&&(Tvard[k3][2]== Tvard[k4][1])) ){
                                                 printf("Error duplication in the model=%s at positions (+) %d and %d, V%d*V%d, Typevar=%d, Fixed=%d, Dummy=%d\n",model, k1,k2, Tvard[k3][1], Tvard[k3][2],Typevar[k1],Fixed[Tvar[k1]],Dummy[Tvar[k1]]);              printf("Error duplication in the model=%s at positions (+) %d and %d, V%d*V%d, Typevar=%d, Fixed=%d, Dummy=%d\n",model, k1,k2, Tvard[k3][1], Tvard[k3][2],Typevar[k1],Fixed[Tvar[k1]],Dummy[Tvar[k1]]);
                                                 fprintf(ficlog,"Error duplication in the model=%s at positions (+) %d and %d, V%d*V%d, Typevar=%d, Fixed=%d, Dummy=%d\n",model, k1,k2, Tvard[k3][1], Tvard[k3][2],Typevar[k1],Fixed[Tvar[k1]],Dummy[Tvar[k1]]); fflush(ficlog);              fprintf(ficlog,"Error duplication in the model=%s at positions (+) %d and %d, V%d*V%d, Typevar=%d, Fixed=%d, Dummy=%d\n",model, k1,k2, Tvard[k3][1], Tvard[k3][2],Typevar[k1],Fixed[Tvar[k1]],Dummy[Tvar[k1]]); fflush(ficlog);
                                                 return(1);              return(1);
                                         }            }
                                 }          }
       }        }
     }      }
   }    }
   printf("ncoveff=%d, nqfveff=%d, ntveff=%d, nqtveff=%d, cptcovn=%d\n",ncoveff,nqfveff,ntveff,nqtveff,cptcovn);    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);    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);    printf("ncovf=%d, ncovv=%d, ncova=%d, nsd=%d, nsq=%d\n",ncovf,ncovv,ncova,nsd,nsq);
   fprintf(ficlog,"ncovf=%d, ncovv=%d, ncova=%d\n",ncovf,ncovv,ncova);    fprintf(ficlog,"ncovf=%d, ncovv=%d, ncova=%d, nsd=%d, nsq=%d\n",ncovf,ncovv,ncova,nsd, nsq);
   return (0); /* with covar[new additional covariate if product] and Tage if age */     return (0); /* with covar[new additional covariate if product] and Tage if age */ 
   /*endread:*/    /*endread:*/
   printf("Exiting decodemodel: ");    printf("Exiting decodemodel: ");
Line 8709  int prevalence_limit(double *p, double * Line 8820  int prevalence_limit(double *p, double *
   agelim=agemaxpar;    agelim=agemaxpar;
   
   /* i1=pow(2,ncoveff); */    /* i1=pow(2,ncoveff); */
   i1=pow(2,cptcoveff); /* Number of dummy covariates */    i1=pow(2,cptcoveff); /* Number of combination of dummy covariates */
   if (cptcovn < 1){i1=1;}    if (cptcovn < 1){i1=1;}
   
   for(k=1; k<=i1;k++){    for(k=1; k<=i1;k++){
Line 9052  int main(int argc, char *argv[]) Line 9163  int main(int argc, char *argv[])
   char line[MAXLINE];    char line[MAXLINE];
   char path[MAXLINE],pathc[MAXLINE],pathcd[MAXLINE],pathtot[MAXLINE];    char path[MAXLINE],pathc[MAXLINE],pathcd[MAXLINE],pathtot[MAXLINE];
   
   char model[MAXLINE], modeltemp[MAXLINE];    char  modeltemp[MAXLINE];
   char resultline[MAXLINE];    char resultline[MAXLINE];
       
   char pathr[MAXLINE], pathimach[MAXLINE];     char pathr[MAXLINE], pathimach[MAXLINE]; 
Line 9419  int main(int argc, char *argv[]) Line 9530  int main(int argc, char *argv[])
           
     param= ma3x(1,nlstate,1,nlstate+ndeath-1,1,ncovmodel);      param= ma3x(1,nlstate,1,nlstate+ndeath-1,1,ncovmodel);
     for(i=1; i <=nlstate; i++){      for(i=1; i <=nlstate; i++){
                         j=0;        j=0;
       for(jj=1; jj <=nlstate+ndeath; jj++){        for(jj=1; jj <=nlstate+ndeath; jj++){
                                 if(jj==i) continue;          if(jj==i) continue;
                                 j++;          j++;
                                 fscanf(ficpar,"%1d%1d",&i1,&j1);          fscanf(ficpar,"%1d%1d",&i1,&j1);
                                 if ((i1 != i) || (j1 != jj)){          if ((i1 != i) || (j1 != jj)){
                                         printf("Error in line parameters number %d, %1d%1d instead of %1d%1d \n \            printf("Error in line parameters number %d, %1d%1d instead of %1d%1d \n \
 It might be a problem of design; if ncovcol and the model are correct\n \  It might be a problem of design; if ncovcol and the model are correct\n \
 run imach with mle=-1 to get a correct template of the parameter file.\n",numlinepar, i,j, i1, j1);  run imach with mle=-1 to get a correct template of the parameter file.\n",numlinepar, i,j, i1, j1);
                                         exit(1);            exit(1);
                                 }          }
                                 fprintf(ficparo,"%1d%1d",i1,j1);          fprintf(ficparo,"%1d%1d",i1,j1);
                                 if(mle==1)          if(mle==1)
                                         printf("%1d%1d",i,jj);            printf("%1d%1d",i,jj);
                                 fprintf(ficlog,"%1d%1d",i,jj);          fprintf(ficlog,"%1d%1d",i,jj);
                                 for(k=1; k<=ncovmodel;k++){          for(k=1; k<=ncovmodel;k++){
                                         fscanf(ficpar," %lf",&param[i][j][k]);            fscanf(ficpar," %lf",&param[i][j][k]);
                                         if(mle==1){            if(mle==1){
                                                 printf(" %lf",param[i][j][k]);              printf(" %lf",param[i][j][k]);
                                                 fprintf(ficlog," %lf",param[i][j][k]);              fprintf(ficlog," %lf",param[i][j][k]);
                                         }            }
                                         else            else
                                                 fprintf(ficlog," %lf",param[i][j][k]);              fprintf(ficlog," %lf",param[i][j][k]);
                                         fprintf(ficparo," %lf",param[i][j][k]);            fprintf(ficparo," %lf",param[i][j][k]);
                                 }          }
                                 fscanf(ficpar,"\n");          fscanf(ficpar,"\n");
                                 numlinepar++;          numlinepar++;
                                 if(mle==1)          if(mle==1)
                                         printf("\n");            printf("\n");
                                 fprintf(ficlog,"\n");          fprintf(ficlog,"\n");
                                 fprintf(ficparo,"\n");          fprintf(ficparo,"\n");
       }        }
     }        }  
     fflush(ficlog);      fflush(ficlog);
       
     /* Reads scales values */      /* Reads scales values */
     p=param[1][1];      p=param[1][1];
           
Line 9470  run imach with mle=-1 to get a correct t Line 9581  run imach with mle=-1 to get a correct t
   
     for(i=1; i <=nlstate; i++){      for(i=1; i <=nlstate; i++){
       for(j=1; j <=nlstate+ndeath-1; j++){        for(j=1; j <=nlstate+ndeath-1; j++){
                                 fscanf(ficpar,"%1d%1d",&i1,&j1);          fscanf(ficpar,"%1d%1d",&i1,&j1);
                                 if ( (i1-i) * (j1-j) != 0){          if ( (i1-i) * (j1-j) != 0){
                                         printf("Error in line parameters number %d, %1d%1d instead of %1d%1d \n",numlinepar, i,j, i1, j1);            printf("Error in line parameters number %d, %1d%1d instead of %1d%1d \n",numlinepar, i,j, i1, j1);
                                         exit(1);            exit(1);
                                 }          }
                                 printf("%1d%1d",i,j);          printf("%1d%1d",i,j);
                                 fprintf(ficparo,"%1d%1d",i1,j1);          fprintf(ficparo,"%1d%1d",i1,j1);
                                 fprintf(ficlog,"%1d%1d",i1,j1);          fprintf(ficlog,"%1d%1d",i1,j1);
                                 for(k=1; k<=ncovmodel;k++){          for(k=1; k<=ncovmodel;k++){
                                         fscanf(ficpar,"%le",&delti3[i][j][k]);            fscanf(ficpar,"%le",&delti3[i][j][k]);
                                         printf(" %le",delti3[i][j][k]);            printf(" %le",delti3[i][j][k]);
                                         fprintf(ficparo," %le",delti3[i][j][k]);            fprintf(ficparo," %le",delti3[i][j][k]);
                                         fprintf(ficlog," %le",delti3[i][j][k]);            fprintf(ficlog," %le",delti3[i][j][k]);
                                 }          }
                                 fscanf(ficpar,"\n");          fscanf(ficpar,"\n");
                                 numlinepar++;          numlinepar++;
                                 printf("\n");          printf("\n");
                                 fprintf(ficparo,"\n");          fprintf(ficparo,"\n");
                                 fprintf(ficlog,"\n");          fprintf(ficlog,"\n");
       }        }
     }      }
     fflush(ficlog);      fflush(ficlog);
                       
     /* Reads covariance matrix */      /* Reads covariance matrix */
     delti=delti3[1][1];      delti=delti3[1][1];
                                   
Line 9582  Please run with mle=-1 to get a correct Line 9693  Please run with mle=-1 to get a correct
   agedc=vector(1,n);    agedc=vector(1,n);
   cod=ivector(1,n);    cod=ivector(1,n);
   for(i=1;i<=n;i++){    for(i=1;i<=n;i++){
                 num[i]=0;      num[i]=0;
                 moisnais[i]=0;      moisnais[i]=0;
                 annais[i]=0;      annais[i]=0;
                 moisdc[i]=0;      moisdc[i]=0;
                 andc[i]=0;      andc[i]=0;
                 agedc[i]=0;      agedc[i]=0;
                 cod[i]=0;      cod[i]=0;
                 weight[i]=1.0; /* Equal weights, 1 by default */      weight[i]=1.0; /* Equal weights, 1 by default */
         }    }
   mint=matrix(1,maxwav,1,n);    mint=matrix(1,maxwav,1,n);
   anint=matrix(1,maxwav,1,n);    anint=matrix(1,maxwav,1,n);
   s=imatrix(1,maxwav+1,1,n); /* s[i][j] health state for wave i and individual j */     s=imatrix(1,maxwav+1,1,n); /* s[i][j] health state for wave i and individual j */ 
Line 9603  Please run with mle=-1 to get a correct Line 9714  Please run with mle=-1 to get a correct
     goto end;      goto end;
   
   /* Calculation of the number of parameters from char model */    /* Calculation of the number of parameters from char model */
     /*    modelsav=V2+V1+V4+age*V3 strb=age*V3 stra=V2+V1+V4     /*    modelsav=V2+V1+V4+age*V3 strb=age*V3 stra=V2+V1+V4 
         k=4 (age*V3) Tvar[k=4]= 3 (from V3) Tag[cptcovage=1]=4          k=4 (age*V3) Tvar[k=4]= 3 (from V3) Tag[cptcovage=1]=4
         k=3 V4 Tvar[k=3]= 4 (from V4)          k=3 V4 Tvar[k=3]= 4 (from V4)
         k=2 V1 Tvar[k=2]= 1 (from V1)          k=2 V1 Tvar[k=2]= 1 (from V1)
         k=1 Tvar[1]=2 (from V2)          k=1 Tvar[1]=2 (from V2)
     */    */
     
         Tvar=ivector(1,NCOVMAX); /* Was 15 changed to NCOVMAX. */    Tvar=ivector(1,NCOVMAX); /* Was 15 changed to NCOVMAX. */
     TvarsDind=ivector(1,NCOVMAX); /*  */
     TvarsD=ivector(1,NCOVMAX); /*  */
     TvarsQind=ivector(1,NCOVMAX); /*  */
     TvarsQ=ivector(1,NCOVMAX); /*  */
   TvarF=ivector(1,NCOVMAX); /*  */    TvarF=ivector(1,NCOVMAX); /*  */
   TvarFind=ivector(1,NCOVMAX); /*  */    TvarFind=ivector(1,NCOVMAX); /*  */
   TvarV=ivector(1,NCOVMAX); /*  */    TvarV=ivector(1,NCOVMAX); /*  */
Line 10849  Please run with mle=-1 to get a correct Line 10964  Please run with mle=-1 to get a correct
   free_ivector(Fixed,-1,NCOVMAX);    free_ivector(Fixed,-1,NCOVMAX);
   free_ivector(Typevar,-1,NCOVMAX);    free_ivector(Typevar,-1,NCOVMAX);
   free_ivector(Tvar,1,NCOVMAX);    free_ivector(Tvar,1,NCOVMAX);
     free_ivector(TvarsQ,1,NCOVMAX);
     free_ivector(TvarsQind,1,NCOVMAX);
     free_ivector(TvarsD,1,NCOVMAX);
     free_ivector(TvarsDind,1,NCOVMAX);
   free_ivector(TvarFD,1,NCOVMAX);    free_ivector(TvarFD,1,NCOVMAX);
   free_ivector(TvarFDind,1,NCOVMAX);    free_ivector(TvarFDind,1,NCOVMAX);
   free_ivector(TvarF,1,NCOVMAX);    free_ivector(TvarF,1,NCOVMAX);

Removed from v.1.233  
changed lines
  Added in v.1.234


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>