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

version 1.227, 2016/07/21 08:43:33 version 1.233, 2016/08/23 07:40:50
Line 1 Line 1
 /* $Id$  /* $Id$
   $State$    $State$
   $Log$    $Log$
   Revision 1.227  2016/07/21 08:43:33  brouard    Revision 1.233  2016/08/23 07:40:50  brouard
   Summary: 0.99 working (more or less) for Asian Workshop on multitate methods    Summary: not working
   
     Revision 1.232  2016/08/22 14:20:21  brouard
     Summary: not working
   
     Revision 1.231  2016/08/22 07:17:15  brouard
     Summary: not working
   
     Revision 1.230  2016/08/22 06:55:53  brouard
     Summary: Not working
   
     Revision 1.229  2016/07/23 09:45:53  brouard
     Summary: Completing for func too
   
     Revision 1.228  2016/07/22 17:45:30  brouard
     Summary: Fixing some arrays, still debugging
   
   Revision 1.226  2016/07/12 18:42:34  brouard    Revision 1.226  2016/07/12 18:42:34  brouard
   Summary: temp    Summary: temp
Line 902  int cptcovsnq=0; /**< cptcovsnq number o Line 917  int cptcovsnq=0; /**< cptcovsnq number o
 int cptcovage=0; /**< Number of covariates with age: V3*age only =1 */  int cptcovage=0; /**< Number of covariates with age: V3*age only =1 */
 int cptcovprodnoage=0; /**< Number of covariate products without age */     int cptcovprodnoage=0; /**< Number of covariate products without age */   
 int cptcoveff=0; /* Total number of covariates to vary for printing results */  int cptcoveff=0; /* Total number of covariates to vary for printing results */
 int ncoveff=0; /* Total number of effective covariates in the model */  int ncovf=0; /* Total number of effective fixed covariates (dummy 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 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 */
 int nqtveff=0; /**< ntqveff number of effective time varying quantitative variables */  int nqtveff=0; /**< ntqveff number of effective time varying quantitative variables */
Line 927  int **dh; /* dh[mi][i] is number of step Line 946  int **dh; /* dh[mi][i] is number of step
 int **bh; /* bh[mi][i] is the bias (+ or -) for this individual if the delay between  int **bh; /* bh[mi][i] is the bias (+ or -) for this individual if the delay between
            * wave mi and wave mi+1 is not an exact multiple of stepm. */             * wave mi and wave mi+1 is not an exact multiple of stepm. */
 int countcallfunc=0;  /* Count the number of calls to func */  int countcallfunc=0;  /* Count the number of calls to func */
   int selected(int kvar); /* Is covariate kvar selected for printing results */
   
 double jmean=1; /* Mean space between 2 waves */  double jmean=1; /* Mean space between 2 waves */
 double **matprod2(); /* test */  double **matprod2(); /* test */
 double **oldm, **newm, **savm; /* Working pointers to matrices */  double **oldm, **newm, **savm; /* Working pointers to matrices */
Line 1056  double ***cotvar; /* Time varying covari Line 1077  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 */
   int *TvarF; /**< TvarF[1]=Tvar[6]=2,  TvarF[2]=Tvar[7]=7, TvarF[3]=Tvar[9]=1  in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */
   int *TvarFind; /**< TvarFind[1]=6,  TvarFind[2]=7, Tvarind[3]=9  in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */
   int *TvarV; /**< TvarV[1]=Tvar[1]=5, TvarV[2]=Tvar[2]=4  in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */
   int *TvarVind; /**< TvarVind[1]=1, TvarVind[2]=2  in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */
   int *TvarA; /**< TvarA[1]=Tvar[5]=5, TvarA[2]=Tvar[8]=1  in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */
   int *TvarAind; /**< TvarindA[1]=5, TvarAind[2]=8  in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */
   int *TvarFD; /**< TvarFD[1]=V1 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */
   int *TvarFDind; /* TvarFDind[1]=9 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */
   int *TvarFQ; /* TvarFQ[1]=V2 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */ /* Only simple fixed quantitative variable */
   int *TvarFQind; /* TvarFQind[1]=6 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */ /* Only simple fixed quantitative variable */
   int *TvarVD; /* TvarVD[1]=V5 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */ /* Only simple fixed quantitative variable */
   int *TvarVDind; /* TvarVDind[1]=1 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */ /* Only simple fixed quantitative variable */
   int *TvarVQ; /* TvarVQ[1]=V5 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */ /* Only simple time varying quantitative variable */
   int *TvarVQind; /* TvarVQind[1]=1 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */ /* Only simple time varying quantitative variable */
   
   int *Tvarsel; /**< Selected covariates for output */
   double *Tvalsel; /**< Selected modality value of covariate for output */
 int *Typevar; /**< 0 for simple covariate (dummy, quantitative, fixed or varying), 1 for age product, 2 for  product */  int *Typevar; /**< 0 for simple covariate (dummy, quantitative, fixed or varying), 1 for age product, 2 for  product */
 int *Fixed; /** Fixed[k] 0=fixed, 1 varying, 2 fixed with age product, 3 varying with age product */   int *Fixed; /** Fixed[k] 0=fixed, 1 varying, 2 fixed with age product, 3 varying with age product */ 
 int *Dummy; /** Dummy[k] 0=dummy (0 1), 1 quantitative (single or product without age), 2 dummy with age product, 3 quant with age product */   int *Dummy; /** Dummy[k] 0=dummy (0 1), 1 quantitative (single or product without age), 2 dummy with age product, 3 quant with age product */ 
 int *Tage;  int *Tage;
 int anyvaryingduminmodel=0; /**< Any varying dummy in Model=1 yes, 0 no, to avoid a loop on waves in freq */   int anyvaryingduminmodel=0; /**< Any varying dummy in Model=1 yes, 0 no, to avoid a loop on waves in freq */ 
 int *Tmodelind; /** Tmodelind[Tvaraff[3]]=9,Tvaraff[1]@9={4, 3, 1, 0, 0, 0, 0, 0, 0}, model=V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1*/  int *Tmodelind; /** Tmodelind[Tvaraff[3]]=9 for V1 position,Tvaraff[1]@9={4, 3, 1, 0, 0, 0, 0, 0, 0}, model=V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1*/
   int *TmodelInvind; /** Tmodelind[Tvaraff[3]]=9 for V1 position,Tvaraff[1]@9={4, 3, 1, 0, 0, 0, 0, 0, 0}, model=V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1*/ 
   int *TmodelInvQind; /** Tmodelqind[1]=1 for V5(quantitative varying) position,Tvaraff[1]@9={4, 3, 1, 0, 0, 0, 0, 0, 0}, model=V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1  */
 int *Ndum; /** Freq of modality (tricode */  int *Ndum; /** Freq of modality (tricode */
 /* int **codtab;*/ /**< codtab=imatrix(1,100,1,10); */  /* int **codtab;*/ /**< codtab=imatrix(1,100,1,10); */
 int **Tvard;  int **Tvard;
Line 1074  int *Tposprod; /**< Gives the k1 product Line 1114  int *Tposprod; /**< Gives the k1 product
 int cptcovprod, *Tvaraff, *invalidvarcomb;  int cptcovprod, *Tvaraff, *invalidvarcomb;
 double *lsurv, *lpop, *tpop;  double *lsurv, *lpop, *tpop;
   
   #define FD 1; /* Fixed dummy covariate */
   #define FQ 2; /* Fixed quantitative covariate */
   #define FP 3; /* Fixed product covariate */
   #define FPDD 7; /* Fixed product dummy*dummy covariate */
   #define FPDQ 8; /* Fixed product dummy*quantitative covariate */
   #define FPQQ 9; /* Fixed product quantitative*quantitative covariate */
   #define VD 10; /* Varying dummy covariate */
   #define VQ 11; /* Varying quantitative covariate */
   #define VP 12; /* Varying product covariate */
   #define VPDD 13; /* Varying product dummy*dummy covariate */
   #define VPDQ 14; /* Varying product dummy*quantitative covariate */
   #define VPQQ 15; /* Varying product quantitative*quantitative covariate */
   #define APFD 16; /* Age product * fixed dummy covariate */
   #define APFQ 17; /* Age product * fixed quantitative covariate */
   #define APVD 18; /* Age product * varying dummy covariate */
   #define APVQ 19; /* Age product * varying quantitative covariate */
   
   #define FTYPE 1; /* Fixed covariate */
   #define VTYPE 2; /* Varying covariate (loop in wave) */
   #define ATYPE 2; /* Age product covariate (loop in dh within wave)*/
   
   struct kmodel{
           int maintype; /* main type */
           int subtype; /* subtype */
   };
   struct kmodel modell[NCOVMAX];
   
 double ftol=FTOL; /**< Tolerance for computing Max Likelihood */  double ftol=FTOL; /**< Tolerance for computing Max Likelihood */
 double ftolhess; /**< Tolerance for computing hessian */  double ftolhess; /**< Tolerance for computing hessian */
   
Line 2946  double func( double *x) Line 3013  double func( double *x)
   int ioffset=0;    int ioffset=0;
   double l, ll[NLSTATEMAX+1], cov[NCOVMAX+1];    double l, ll[NLSTATEMAX+1], cov[NCOVMAX+1];
   double **out;    double **out;
   double sw; /* Sum of weights */  
   double lli; /* Individual log likelihood */    double lli; /* Individual log likelihood */
   int s1, s2;    int s1, s2;
   int iv=0, iqv=0, itv=0, iqtv=0 ; /* Index of varying covariate, fixed quantitative cov, time varying covariate, quatitative time varying covariate */    int iv=0, iqv=0, itv=0, iqtv=0 ; /* Index of varying covariate, fixed quantitative cov, time varying covariate, quantitative time varying covariate */
   double bbh, survp;    double bbh, survp;
   long ipmx;    long ipmx;
   double agexact;    double agexact;
Line 2974  double func( double *x) Line 3040  double func( double *x)
          to be observed in j being in i according to the model.           to be observed in j being in i according to the model.
       */        */
       ioffset=2+nagesqr+cptcovage;        ioffset=2+nagesqr+cptcovage;
       /* for (k=1; k<=cptcovn;k++){ /\* Simple and product covariates without age* products *\/ */     /* Fixed */
       for (k=1; k<=ncoveff;k++){ /* Simple and product covariates without age* products */                          for (k=1; k<=ncovf;k++){ /* Simple and product fixed covariates without age* products */
         cov[++ioffset]=covar[Tvar[k]][i];                                  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)*/
       }                          }
       for(iqv=1; iqv <= nqfveff; iqv++){ /* Quantitatives and Fixed covariates */  
         cov[++ioffset]=coqvar[iqv][i];  
       }  
   
       /* 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 2995  double func( double *x) Line 3057  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(itv=1; itv <= ntveff; itv++){ /* Varying dummy covariates */                                  for(k=1; k <= ncovv ; k++){ /* Varying  covariates (single and product but no age )*/
           cov[ioffset+itv]=cotvar[mw[mi][i]][itv][i];                                          cov[ioffset+TvarVind[k]]=cotvar[mw[mi][i]][Tvar[TvarVind[k]]][i];
         }                                  }
         for(iqtv=1; iqtv <= nqtveff; iqtv++){ /* Varying quantitatives covariates */                                  for (ii=1;ii<=nlstate+ndeath;ii++)
           if(cotqvar[mw[mi][i]][iqtv][i] == -1){                                          for (j=1;j<=nlstate+ndeath;j++){
             printf("i=%d, mi=%d, iqtv=%d, cotqvar[mw[mi][i]][iqtv][i]=%f",i,mi,iqtv,cotqvar[mw[mi][i]][iqtv][i]);                                                  oldm[ii][j]=(ii==j ? 1.0 : 0.0);
           }                                                  savm[ii][j]=(ii==j ? 1.0 : 0.0);
           cov[ioffset+ntveff+iqtv]=cotqvar[mw[mi][i]][iqtv][i];                                          }
         }                                  for(d=0; d<dh[mi][i]; d++){
         /* ioffset=2+nagesqr+cptcovn+nqv+ntv+nqtv; */                                          newm=savm;
         for (ii=1;ii<=nlstate+ndeath;ii++)                                          agexact=agev[mw[mi][i]][i]+d*stepm/YEARM;
           for (j=1;j<=nlstate+ndeath;j++){                                          cov[2]=agexact;
             oldm[ii][j]=(ii==j ? 1.0 : 0.0);                                          if(nagesqr==1)
             savm[ii][j]=(ii==j ? 1.0 : 0.0);                                                  cov[3]= agexact*agexact;  /* Should be changed here */
           }                                          for (kk=1; kk<=cptcovage;kk++) {
         for(d=0; d<dh[mi][i]; d++){                                                  cov[Tage[kk]+2+nagesqr]=covar[Tvar[Tage[kk]]][i]*agexact; /* Tage[kk] gives the data-covariate associated with age */
           newm=savm;                                          }
           agexact=agev[mw[mi][i]][i]+d*stepm/YEARM;                                          out=matprod2(newm,oldm,1,nlstate+ndeath,1,nlstate+ndeath,
           cov[2]=agexact;                                                                                           1,nlstate+ndeath,pmij(pmmij,cov,ncovmodel,x,nlstate));
           if(nagesqr==1)                                          savm=oldm;
             cov[3]= agexact*agexact;  /* Should be changed here */                                          oldm=newm;
           for (kk=1; kk<=cptcovage;kk++) {                                  } /* end mult */
             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,  
                        1,nlstate+ndeath,pmij(pmmij,cov,ncovmodel,x,nlstate));  
           savm=oldm;  
           oldm=newm;  
         } /* 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 3275  double func( double *x) Line 3330  double func( double *x)
 /*************** log-likelihood *************/  /*************** log-likelihood *************/
 double funcone( double *x)  double funcone( double *x)
 {  {
   /* Same as likeli but slower because of a lot of printf and if */    /* Same as func but slower because of a lot of printf and if */
   int i, ii, j, k, mi, d, kk;    int i, ii, j, k, mi, d, kk;
         int ioffset=0;    int ioffset=0;
   double l, ll[NLSTATEMAX+1], cov[NCOVMAX+1];    double l, ll[NLSTATEMAX+1], cov[NCOVMAX+1];
   double **out;    double **out;
   double lli; /* Individual log likelihood */    double lli; /* Individual log likelihood */
   double llt;    double llt;
   int s1, s2;    int s1, s2;
         int iv=0, iqv=0, itv=0, iqtv=0 ; /* Index of varying covariate, fixed quantitative cov, time varying covariate */    int iv=0, iqv=0, itv=0, iqtv=0 ; /* Index of varying covariate, fixed quantitative cov, time varying covariate, quantitative time varying covariate */
   
   double bbh, survp;    double bbh, survp;
   double agexact;    double agexact;
   double agebegin, ageend;    double agebegin, ageend;
Line 3299  double funcone( double *x) Line 3355  double funcone( double *x)
   ioffset=0;    ioffset=0;
   for (i=1,ipmx=0, sw=0.; i<=imx; i++){    for (i=1,ipmx=0, sw=0.; i<=imx; i++){
     ioffset=2+nagesqr+cptcovage;      ioffset=2+nagesqr+cptcovage;
       /* Fixed */
     /* for (k=1; k<=cptcovn;k++) cov[2+nagesqr+k]=covar[Tvar[k]][i]; */      /* for (k=1; k<=cptcovn;k++) cov[2+nagesqr+k]=covar[Tvar[k]][i]; */
     for (k=1; k<=ncoveff+nqfveff;k++){ /* Simple and product fixed covariates without age* products */      /* for (k=1; k<=ncoveff;k++){ /\* Simple and product fixed Dummy covariates without age* products *\/ */
       cov[++ioffset]=covar[Tvar[k]][i];      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)*/
     for(iqv=1; iqv <= nqfveff; iqv++){ /* Quantitative fixed covariates */  /*    cov[ioffset+TvarFind[1]]=covar[Tvar[TvarFind[1]]][i];  */
       cov[++ioffset]=coqvar[Tvar[iqv]][i];  /*    cov[2+6]=covar[Tvar[6]][i];  */
   /*    cov[2+6]=covar[2][i]; V2  */
   /*    cov[TvarFind[2]]=covar[Tvar[TvarFind[2]]][i];  */
   /*    cov[2+7]=covar[Tvar[7]][i];  */
   /*    cov[2+7]=covar[7][i]; V7=V1*V2  */
   /*    cov[TvarFind[3]]=covar[Tvar[TvarFind[3]]][i];  */
   /*    cov[2+9]=covar[Tvar[9]][i];  */
   /*    cov[2+9]=covar[1][i]; V1  */
     }      }
       /* for (k=1; k<=nqfveff;k++){ /\* Simple and product fixed Quantitative covariates without age* products *\/ */
       /*   cov[++ioffset]=coqvar[TvarFQ[k]][i];/\* V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1, only V2 and V1*V2 is fixed (k=6 and 7?)*\/ */
       /* } */
       /* for(iqv=1; iqv <= nqfveff; iqv++){ /\* Quantitative fixed covariates *\/ */
       /*   cov[++ioffset]=coqvar[Tvar[iqv]][i]; /\* Only V2 k=6 and V1*V2 7 *\/ */
       /* } */
           
   
     for(mi=1; mi<= wav[i]-1; mi++){  /* Varying with waves */      for(mi=1; mi<= wav[i]-1; mi++){  /* Varying with waves */
       for(itv=1; itv <= ntveff; itv++){ /* Varying dummy covariates */      /* Wave varying (but not age varying) */
         cov[ioffset+itv]=cotvar[mw[mi][i]][itv][i];        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];
       for(iqtv=1; iqtv <= nqtveff; iqtv++){ /* Varying quantitatives covariates */                          }
         cov[ioffset+ntveff+iqtv]=cotqvar[mw[mi][i]][iqtv][i];        /* for(itv=1; itv <= ntveff; itv++){ /\* Varying dummy covariates (single??)*\/ */
       }                                  /* iv= Tvar[Tmodelind[ioffset-2-nagesqr-cptcovage+itv]]-ncovcol-nqv; /\* Counting the # varying covariate from 1 to ntveff *\/ */
                                   /* cov[ioffset+iv]=cotvar[mw[mi][i]][iv][i]; */
                                   /* k=ioffset-2-nagesqr-cptcovage+itv; /\* position in simple model *\/ */
                                   /* cov[ioffset+itv]=cotvar[mw[mi][i]][TmodelInvind[itv]][i]; */
                                   /* printf(" i=%d,mi=%d,itv=%d,TmodelInvind[itv]=%d,cotvar[mw[mi][i]][TmodelInvind[itv]][i]=%f\n", i, mi, itv, TmodelInvind[itv],cotvar[mw[mi][i]][TmodelInvind[itv]][i]); */
         /* for(iqtv=1; iqtv <= nqtveff; iqtv++){ /\* Varying quantitatives covariates *\/ */
                           /*      iv=TmodelInvQind[iqtv]; /\* Counting the # varying covariate from 1 to ntveff *\/ */
                           /*      /\* printf(" i=%d,mi=%d,iqtv=%d,TmodelInvQind[iqtv]=%d,cotqvar[mw[mi][i]][TmodelInvQind[iqtv]][i]=%f\n", i, mi, iqtv, TmodelInvQind[iqtv],cotqvar[mw[mi][i]][TmodelInvQind[iqtv]][i]); *\/ */
                           /*      cov[ioffset+ntveff+iqtv]=cotqvar[mw[mi][i]][TmodelInvQind[iqtv]][i]; */
         /* } */
       for (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);
         }                                  }
               
       agebegin=agev[mw[mi][i]][i]; /* Age at beginning of effective wave */        agebegin=agev[mw[mi][i]][i]; /* Age at beginning of effective wave */
       ageend=agev[mw[mi][i]][i] + (dh[mi][i])*stepm/YEARM; /* Age at end of effective wave and at the end of transition */        ageend=agev[mw[mi][i]][i] + (dh[mi][i])*stepm/YEARM; /* Age at end of effective wave and at the end of transition */
       for(d=0; d<dh[mi][i]; d++){  /* Delay between two effective waves */        for(d=0; d<dh[mi][i]; d++){  /* Delay between two effective waves */
         /*dh[m][i] or dh[mw[mi][i]][i] is the delay between two effective waves m=mw[mi][i]                                  /*dh[m][i] or dh[mw[mi][i]][i] is the delay between two effective waves m=mw[mi][i]
           and mw[mi+1][i]. dh depends on stepm.*/                                          and mw[mi+1][i]. dh depends on stepm.*/
         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;                                          cov[3]= agexact*agexact;
         for (kk=1; kk<=cptcovage;kk++) {                                  for (kk=1; kk<=cptcovage;kk++) {
           cov[Tage[kk]+2+nagesqr]=covar[Tvar[Tage[kk]]][i]*agexact;                                          cov[Tage[kk]+2+nagesqr]=covar[Tvar[Tage[kk]]][i]*agexact;
         }                                  }
         /* printf("i=%d,mi=%d,d=%d,mw[mi][i]=%d\n",i, mi,d,mw[mi][i]); */                                  /* printf("i=%d,mi=%d,d=%d,mw[mi][i]=%d\n",i, mi,d,mw[mi][i]); */
         /* savm=pmij(pmmij,cov,ncovmodel,x,nlstate); */                                  /* savm=pmij(pmmij,cov,ncovmodel,x,nlstate); */
         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));
         /* 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 */
               
       s1=s[mw[mi][i]][i];        s1=s[mw[mi][i]][i];
Line 3354  double funcone( double *x) Line 3434  double funcone( double *x)
        * is higher than the multiple of stepm and negative otherwise.         * is higher than the multiple of stepm and negative otherwise.
        */         */
       if( s2 > nlstate && (mle <5) ){  /* Jackson */        if( s2 > nlstate && (mle <5) ){  /* Jackson */
         lli=log(out[s1][s2] - savm[s1][s2]);                                  lli=log(out[s1][s2] - savm[s1][s2]);
       } else if  ( s2==-1 ) { /* alive */        } else if  ( s2==-1 ) { /* alive */
         for (j=1,survp=0. ; j<=nlstate; j++)                                   for (j=1,survp=0. ; j<=nlstate; j++) 
           survp += (1.+bbh)*out[s1][j]- bbh*savm[s1][j];                                          survp += (1.+bbh)*out[s1][j]- bbh*savm[s1][j];
         lli= log(survp);                                  lli= log(survp);
       }else if (mle==1){        }else if (mle==1){
         lli= log((1.+bbh)*out[s1][s2]- bbh*savm[s1][s2]); /* linear interpolation */                                  lli= log((1.+bbh)*out[s1][s2]- bbh*savm[s1][s2]); /* linear interpolation */
       } else if(mle==2){        } else if(mle==2){
         lli= (savm[s1][s2]>(double)1.e-8 ?log((1.+bbh)*out[s1][s2]- bbh*savm[s1][s2]):log((1.+bbh)*out[s1][s2])); /* linear interpolation */                                  lli= (savm[s1][s2]>(double)1.e-8 ?log((1.+bbh)*out[s1][s2]- bbh*savm[s1][s2]):log((1.+bbh)*out[s1][s2])); /* linear interpolation */
       } else if(mle==3){  /* exponential inter-extrapolation */        } else if(mle==3){  /* exponential inter-extrapolation */
         lli= (savm[s1][s2]>(double)1.e-8 ?(1.+bbh)*log(out[s1][s2])- bbh*log(savm[s1][s2]):log((1.+bbh)*out[s1][s2])); /* exponential inter-extrapolation */                                  lli= (savm[s1][s2]>(double)1.e-8 ?(1.+bbh)*log(out[s1][s2])- bbh*log(savm[s1][s2]):log((1.+bbh)*out[s1][s2])); /* exponential inter-extrapolation */
       } else if (mle==4){  /* mle=4 no inter-extrapolation */        } else if (mle==4){  /* mle=4 no inter-extrapolation */
         lli=log(out[s1][s2]); /* Original formula */                                  lli=log(out[s1][s2]); /* Original formula */
       } else{  /* mle=0 back to 1 */        } else{  /* mle=0 back to 1 */
         lli= log((1.+bbh)*out[s1][s2]- bbh*savm[s1][s2]); /* linear interpolation */                                  lli= log((1.+bbh)*out[s1][s2]- bbh*savm[s1][s2]); /* linear interpolation */
         /*lli=log(out[s1][s2]); */ /* Original formula */                                  /*lli=log(out[s1][s2]); */ /* Original formula */
       } /* End of if */        } /* End of if */
       ipmx +=1;        ipmx +=1;
       sw += weight[i];        sw += weight[i];
       ll[s[mw[mi][i]][i]] += 2*weight[i]*lli;        ll[s[mw[mi][i]][i]] += 2*weight[i]*lli;
       /*printf("i=%6d s1=%1d s2=%1d mi=%1d mw=%1d dh=%3d prob=%10.6f w=%6.4f out=%10.6f sav=%10.6f\n",i,s1,s2,mi,mw[mi][i],dh[mi][i],exp(lli),weight[i],out[s1][s2],savm[s1][s2]); */        /*printf("i=%6d s1=%1d s2=%1d mi=%1d mw=%1d dh=%3d prob=%10.6f w=%6.4f out=%10.6f sav=%10.6f\n",i,s1,s2,mi,mw[mi][i],dh[mi][i],exp(lli),weight[i],out[s1][s2],savm[s1][s2]); */
       if(globpr){        if(globpr){
         fprintf(ficresilk,"%9ld %6.1f %6.1f %6d %2d %2d %2d %2d %3d %15.6f %8.4f %8.3f\                                  fprintf(ficresilk,"%9ld %6.1f %6.1f %6d %2d %2d %2d %2d %3d %15.6f %8.4f %8.3f\
  %11.6f %11.6f %11.6f ", \   %11.6f %11.6f %11.6f ", \
                 num[i], agebegin, ageend, i,s1,s2,mi,mw[mi][i],dh[mi][i],exp(lli),weight[i],weight[i]*gipmx/gsw,                                                                  num[i], agebegin, ageend, i,s1,s2,mi,mw[mi][i],dh[mi][i],exp(lli),weight[i],weight[i]*gipmx/gsw,
                 2*weight[i]*lli,out[s1][s2],savm[s1][s2]);                                                                  2*weight[i]*lli,out[s1][s2],savm[s1][s2]);
         for(k=1,llt=0.,l=0.; k<=nlstate; k++){                                  for(k=1,llt=0.,l=0.; k<=nlstate; k++){
           llt +=ll[k]*gipmx/gsw;                                          llt +=ll[k]*gipmx/gsw;
           fprintf(ficresilk," %10.6f",-ll[k]*gipmx/gsw);                                          fprintf(ficresilk," %10.6f",-ll[k]*gipmx/gsw);
         }                                  }
         fprintf(ficresilk," %10.6f\n", -llt);                                  fprintf(ficresilk," %10.6f\n", -llt);
       }        }
     } /* end of wave */          } /* end of wave */
   } /* end of individual */  } /* end of individual */
   for(k=1,l=0.; k<=nlstate; k++) l += ll[k];  for(k=1,l=0.; k<=nlstate; k++) l += ll[k];
   /* printf("l1=%f l2=%f ",ll[1],ll[2]); */  /* printf("l1=%f l2=%f ",ll[1],ll[2]); */
   l= l*ipmx/sw; /* To get the same order of magnitude as if weight=1 for every body */  l= l*ipmx/sw; /* To get the same order of magnitude as if weight=1 for every body */
   if(globpr==0){ /* First time we count the contributions and weights */  if(globpr==0){ /* First time we count the contributions and weights */
     gipmx=ipmx;          gipmx=ipmx;
     gsw=sw;          gsw=sw;
   }  }
   return -l;  return -l;
 }  }
   
   
Line 3976  Title=%s <br>Datafile=%s Firstpass=%d La Line 4056  Title=%s <br>Datafile=%s Firstpass=%d La
       scanf("%d", i);*/        scanf("%d", i);*/
     for (i=-5; i<=nlstate+ndeath; i++)        for (i=-5; i<=nlstate+ndeath; i++)  
       for (jk=-5; jk<=nlstate+ndeath; jk++)          for (jk=-5; jk<=nlstate+ndeath; jk++)  
         for(m=iagemin; m <= iagemax+3; m++)                                  for(m=iagemin; m <= iagemax+3; m++)
           freq[i][jk][m]=0;                                          freq[i][jk][m]=0;
                         
     for (i=1; i<=nlstate; i++)  {      for (i=1; i<=nlstate; i++)  {
       for(m=iagemin; m <= iagemax+3; m++)        for(m=iagemin; m <= iagemax+3; m++)
         prop[i][m]=0;                                  prop[i][m]=0;
       posprop[i]=0;        posprop[i]=0;
       pospropt[i]=0;        pospropt[i]=0;
     }      }
Line 3991  Title=%s <br>Datafile=%s Firstpass=%d La Line 4071  Title=%s <br>Datafile=%s Firstpass=%d La
     /*  meanqt[m][z1]=0.; */      /*  meanqt[m][z1]=0.; */
     /*   } */      /*   } */
     /* } */      /* } */
                         
     dateintsum=0;      dateintsum=0;
     k2cpt=0;      k2cpt=0;
     /* For that combination of covariate j1, we count and print the frequencies in one pass */      /* For that combination of covariate j1, we count and print the frequencies in one pass */
     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
        freq[s1][s2][age] at single age of beginning the transition, for a combination j1 */         freq[s1][s2][age] at single age of beginning the transition, for a combination j1 */
                   
                   
     /*      fprintf(ficresp, "#Count between %.lf/%.lf/%.lf and %.lf/%.lf/%.lf\n",jprev1, mprev1,anprev1,jprev2, mprev2,anprev2);*/      /*      fprintf(ficresp, "#Count between %.lf/%.lf/%.lf and %.lf/%.lf/%.lf\n",jprev1, mprev1,anprev1,jprev2, mprev2,anprev2);*/
     pstamp(ficresp);      pstamp(ficresp);
     /* if  (ncoveff>0) { */      /* if  (ncoveff>0) { */
Line 4080  Title=%s <br>Datafile=%s Firstpass=%d La Line 4160  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 4098  Title=%s <br>Datafile=%s Firstpass=%d La Line 4178  Title=%s <br>Datafile=%s Firstpass=%d La
     }      }
     fprintf(ficresp, "\n");      fprintf(ficresp, "\n");
     fprintf(ficresphtm, "\n");      fprintf(ficresphtm, "\n");
                         
     /* Header of frequency table by age */      /* Header of frequency table by age */
     fprintf(ficresphtmfr,"<table style=\"text-align:center; border: 1px solid\">");      fprintf(ficresphtmfr,"<table style=\"text-align:center; border: 1px solid\">");
     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");
                         
     /* For each age */      /* For each age */
     for(iage=iagemin; iage <= iagemax+3; iage++){      for(iage=iagemin; iage <= iagemax+3; iage++){
       fprintf(ficresphtm,"<tr>");        fprintf(ficresphtm,"<tr>");
       if(iage==iagemax+1){        if(iage==iagemax+1){
         fprintf(ficlog,"1");                                  fprintf(ficlog,"1");
         fprintf(ficresphtmfr,"<tr><th>0</th> ");                                  fprintf(ficresphtmfr,"<tr><th>0</th> ");
       }else if(iage==iagemax+2){        }else if(iage==iagemax+2){
         fprintf(ficlog,"0");                                  fprintf(ficlog,"0");
         fprintf(ficresphtmfr,"<tr><th>Unknown</th> ");                                  fprintf(ficresphtmfr,"<tr><th>Unknown</th> ");
       }else if(iage==iagemax+3){        }else if(iage==iagemax+3){
         fprintf(ficlog,"Total");                                  fprintf(ficlog,"Total");
         fprintf(ficresphtmfr,"<tr><th>Total</th> ");                                  fprintf(ficresphtmfr,"<tr><th>Total</th> ");
       }else{        }else{
         if(first==1){                                  if(first==1){
           first=0;                                          first=0;
           printf("See log file for details...\n");                                          printf("See log file for details...\n");
         }                                  }
         fprintf(ficresphtmfr,"<tr><th>%d</th> ",iage);                                  fprintf(ficresphtmfr,"<tr><th>%d</th> ",iage);
         fprintf(ficlog,"Age %d", iage);                                  fprintf(ficlog,"Age %d", iage);
       }        }
       for(jk=1; jk <=nlstate ; jk++){        for(jk=1; jk <=nlstate ; jk++){
         for(m=-1, pp[jk]=0; m <=nlstate+ndeath ; m++)                                  for(m=-1, pp[jk]=0; m <=nlstate+ndeath ; m++)
           pp[jk] += freq[jk][m][iage];                                           pp[jk] += freq[jk][m][iage]; 
       }        }
       for(jk=1; jk <=nlstate ; jk++){        for(jk=1; jk <=nlstate ; jk++){
         for(m=-1, pos=0; m <=0 ; m++)                                  for(m=-1, pos=0; m <=0 ; m++)
           pos += freq[jk][m][iage];                                          pos += freq[jk][m][iage];
         if(pp[jk]>=1.e-10){                                  if(pp[jk]>=1.e-10){
           if(first==1){                                          if(first==1){
             printf(" %d.=%.0f loss[%d]=%.1f%%",jk,pp[jk],jk,100*pos/pp[jk]);                                                  printf(" %d.=%.0f loss[%d]=%.1f%%",jk,pp[jk],jk,100*pos/pp[jk]);
           }                                          }
           fprintf(ficlog," %d.=%.0f loss[%d]=%.1f%%",jk,pp[jk],jk,100*pos/pp[jk]);                                          fprintf(ficlog," %d.=%.0f loss[%d]=%.1f%%",jk,pp[jk],jk,100*pos/pp[jk]);
         }else{                                  }else{
           if(first==1)                                          if(first==1)
             printf(" %d.=%.0f loss[%d]=NaNQ%%",jk,pp[jk],jk);                                                  printf(" %d.=%.0f loss[%d]=NaNQ%%",jk,pp[jk],jk);
           fprintf(ficlog," %d.=%.0f loss[%d]=NaNQ%%",jk,pp[jk],jk);                                          fprintf(ficlog," %d.=%.0f loss[%d]=NaNQ%%",jk,pp[jk],jk);
         }                                  }
       }        }
                           
       for(jk=1; jk <=nlstate ; jk++){         for(jk=1; jk <=nlstate ; jk++){ 
         /* posprop[jk]=0; */                                  /* posprop[jk]=0; */
         for(m=0, pp[jk]=0; m <=nlstate+ndeath; m++)/* Summing on all ages */                                  for(m=0, pp[jk]=0; m <=nlstate+ndeath; m++)/* Summing on all ages */
           pp[jk] += freq[jk][m][iage];                                          pp[jk] += freq[jk][m][iage];
       } /* pp[jk] is the total number of transitions starting from state jk and any ending status until this age */        } /* pp[jk] is the total number of transitions starting from state jk and any ending status until this age */
                           
       for(jk=1,pos=0, pospropta=0.; jk <=nlstate ; jk++){        for(jk=1,pos=0, pospropta=0.; jk <=nlstate ; jk++){
         pos += pp[jk]; /* pos is the total number of transitions until this age */                                  pos += pp[jk]; /* pos is the total number of transitions until this age */
         posprop[jk] += prop[jk][iage]; /* prop is the number of transitions from a live state                                  posprop[jk] += prop[jk][iage]; /* prop is the number of transitions from a live state
                                           from jk at age iage prop[s[m][iind]][(int)agev[m][iind]] += weight[iind] */                                                                                                                                                                          from jk at age iage prop[s[m][iind]][(int)agev[m][iind]] += weight[iind] */
         pospropta += prop[jk][iage]; /* prop is the number of transitions from a live state                                  pospropta += prop[jk][iage]; /* prop is the number of transitions from a live state
                                         from jk at age iage prop[s[m][iind]][(int)agev[m][iind]] += weight[iind] */                                                                                                                                                                  from jk at age iage prop[s[m][iind]][(int)agev[m][iind]] += weight[iind] */
       }        }
       for(jk=1; jk <=nlstate ; jk++){        for(jk=1; jk <=nlstate ; jk++){
         if(pos>=1.e-5){                                  if(pos>=1.e-5){
           if(first==1)                                          if(first==1)
             printf(" %d.=%.0f prev[%d]=%.1f%%",jk,pp[jk],jk,100*pp[jk]/pos);                                                  printf(" %d.=%.0f prev[%d]=%.1f%%",jk,pp[jk],jk,100*pp[jk]/pos);
           fprintf(ficlog," %d.=%.0f prev[%d]=%.1f%%",jk,pp[jk],jk,100*pp[jk]/pos);                                          fprintf(ficlog," %d.=%.0f prev[%d]=%.1f%%",jk,pp[jk],jk,100*pp[jk]/pos);
         }else{                                  }else{
           if(first==1)                                          if(first==1)
             printf(" %d.=%.0f prev[%d]=NaNQ%%",jk,pp[jk],jk);                                                  printf(" %d.=%.0f prev[%d]=NaNQ%%",jk,pp[jk],jk);
           fprintf(ficlog," %d.=%.0f prev[%d]=NaNQ%%",jk,pp[jk],jk);                                          fprintf(ficlog," %d.=%.0f prev[%d]=NaNQ%%",jk,pp[jk],jk);
         }                                  }
         if( iage <= iagemax){                                  if( iage <= iagemax){
           if(pos>=1.e-5){                                          if(pos>=1.e-5){
             fprintf(ficresp," %d %.5f %.0f %.0f",iage,prop[jk][iage]/pospropta, prop[jk][iage],pospropta);                                                  fprintf(ficresp," %d %.5f %.0f %.0f",iage,prop[jk][iage]/pospropta, prop[jk][iage],pospropta);
             fprintf(ficresphtm,"<th>%d</th><td>%.5f</td><td>%.0f</td><td>%.0f</td>",iage,prop[jk][iage]/pospropta, prop[jk][iage],pospropta);                                                  fprintf(ficresphtm,"<th>%d</th><td>%.5f</td><td>%.0f</td><td>%.0f</td>",iage,prop[jk][iage]/pospropta, prop[jk][iage],pospropta);
             /*probs[iage][jk][j1]= pp[jk]/pos;*/                                                  /*probs[iage][jk][j1]= pp[jk]/pos;*/
             /*printf("\niage=%d jk=%d j1=%d %.5f %.0f %.0f %f",iage,jk,j1,pp[jk]/pos, pp[jk],pos,probs[iage][jk][j1]);*/                                                  /*printf("\niage=%d jk=%d j1=%d %.5f %.0f %.0f %f",iage,jk,j1,pp[jk]/pos, pp[jk],pos,probs[iage][jk][j1]);*/
           }                                          }
           else{                                          else{
             fprintf(ficresp," %d NaNq %.0f %.0f",iage,prop[jk][iage],pospropta);                                                  fprintf(ficresp," %d NaNq %.0f %.0f",iage,prop[jk][iage],pospropta);
             fprintf(ficresphtm,"<th>%d</th><td>NaNq</td><td>%.0f</td><td>%.0f</td>",iage, prop[jk][iage],pospropta);                                                  fprintf(ficresphtm,"<th>%d</th><td>NaNq</td><td>%.0f</td><td>%.0f</td>",iage, prop[jk][iage],pospropta);
           }                                          }
         }                                  }
         pospropt[jk] +=posprop[jk];                                  pospropt[jk] +=posprop[jk];
       } /* end loop jk */        } /* end loop jk */
       /* pospropt=0.; */        /* pospropt=0.; */
       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(freq[jk][m][iage] !=0 ) { /* minimizing output */                                          if(freq[jk][m][iage] !=0 ) { /* minimizing output */
             if(first==1){                                                  if(first==1){
               printf(" %d%d=%.0f",jk,m,freq[jk][m][iage]);                                                          printf(" %d%d=%.0f",jk,m,freq[jk][m][iage]);
             }                                                  }
             fprintf(ficlog," %d%d=%.0f",jk,m,freq[jk][m][iage]);                                                  fprintf(ficlog," %d%d=%.0f",jk,m,freq[jk][m][iage]);
           }                                          }
           if(jk!=0 && m!=0)                                          if(jk!=0 && m!=0)
             fprintf(ficresphtmfr,"<td>%.0f</td> ",freq[jk][m][iage]);                                                  fprintf(ficresphtmfr,"<td>%.0f</td> ",freq[jk][m][iage]);
         }                                  }
       } /* end loop jk */        } /* end loop jk */
       posproptt=0.;         posproptt=0.; 
       for(jk=1; jk <=nlstate; jk++){        for(jk=1; jk <=nlstate; jk++){
         posproptt += pospropt[jk];                                  posproptt += pospropt[jk];
       }        }
       fprintf(ficresphtmfr,"</tr>\n ");        fprintf(ficresphtmfr,"</tr>\n ");
       if(iage <= iagemax){        if(iage <= iagemax){
         fprintf(ficresp,"\n");                                  fprintf(ficresp,"\n");
         fprintf(ficresphtm,"</tr>\n");                                  fprintf(ficresphtm,"</tr>\n");
       }        }
       if(first==1)        if(first==1)
         printf("Others in log...\n");                                  printf("Others in log...\n");
       fprintf(ficlog,"\n");        fprintf(ficlog,"\n");
     } /* end loop age iage */      } /* end loop age iage */
     fprintf(ficresphtm,"<tr><th>Tot</th>");      fprintf(ficresphtm,"<tr><th>Tot</th>");
     for(jk=1; jk <=nlstate ; jk++){      for(jk=1; jk <=nlstate ; jk++){
       if(posproptt < 1.e-5){        if(posproptt < 1.e-5){
         fprintf(ficresphtm,"<td>Nanq</td><td>%.0f</td><td>%.0f</td>",pospropt[jk],posproptt);                                     fprintf(ficresphtm,"<td>Nanq</td><td>%.0f</td><td>%.0f</td>",pospropt[jk],posproptt);   
       }else{        }else{
         fprintf(ficresphtm,"<td>%.5f</td><td>%.0f</td><td>%.0f</td>",pospropt[jk]/posproptt,pospropt[jk],posproptt);                                      fprintf(ficresphtm,"<td>%.5f</td><td>%.0f</td><td>%.0f</td>",pospropt[jk]/posproptt,pospropt[jk],posproptt);    
       }        }
     }      }
     fprintf(ficresphtm,"</tr>\n");      fprintf(ficresphtm,"</tr>\n");
Line 4235  Title=%s <br>Datafile=%s Firstpass=%d La Line 4315  Title=%s <br>Datafile=%s Firstpass=%d La
     fprintf(ficresphtmfr,"</table>\n");      fprintf(ficresphtmfr,"</table>\n");
   } /* end selected combination of covariate j1 */    } /* end selected combination of covariate j1 */
   dateintmean=dateintsum/k2cpt;     dateintmean=dateintsum/k2cpt; 
                            
   fclose(ficresp);    fclose(ficresp);
   fclose(ficresphtm);    fclose(ficresphtm);
   fclose(ficresphtmfr);    fclose(ficresphtmfr);
Line 4596  void  concatwav(int wav[], int **dh, int Line 4676  void  concatwav(int wav[], int **dh, int
     if(Dummy[k]==0 && Typevar[k] !=1){ /* Dummy covariate and not age product */       if(Dummy[k]==0 && Typevar[k] !=1){ /* Dummy covariate and not age product */ 
       switch(Fixed[k]) {        switch(Fixed[k]) {
       case 0: /* Testing on fixed dummy covariate, simple or product of fixed */        case 0: /* Testing on fixed dummy covariate, simple or product of fixed */
         for (i=1; i<=imx; i++) { /* Loop on individuals: reads the data file to get the maximum value of the  modality of this covariate Vj*/                                  for (i=1; i<=imx; i++) { /* Loop on individuals: reads the data file to get the maximum value of the  modality of this covariate Vj*/
           ij=(int)(covar[Tvar[k]][i]);                                          ij=(int)(covar[Tvar[k]][i]);
           /* ij=0 or 1 or -1. Value of the covariate Tvar[j] for individual i                                          /* ij=0 or 1 or -1. Value of the covariate Tvar[j] for individual i
            * If product of Vn*Vm, still boolean *:                                           * If product of Vn*Vm, still boolean *:
            * If it was coded 1, 2, 3, 4 should be splitted into 3 boolean variables                                           * If it was coded 1, 2, 3, 4 should be splitted into 3 boolean variables
            * 1 => 0 0 0, 2 => 0 0 1, 3 => 0 1 1, 4=1 0 0   */                                           * 1 => 0 0 0, 2 => 0 0 1, 3 => 0 1 1, 4=1 0 0   */
           /* Finds for covariate j, n=Tvar[j] of Vn . ij is the                                          /* Finds for covariate j, n=Tvar[j] of Vn . ij is the
              modality of the nth covariate of individual i. */                                                   modality of the nth covariate of individual i. */
           if (ij > modmaxcovj)                                          if (ij > modmaxcovj)
             modmaxcovj=ij;                                                   modmaxcovj=ij; 
           else if (ij < modmincovj)                                           else if (ij < modmincovj) 
             modmincovj=ij;                                                   modmincovj=ij; 
           if ((ij < -1) && (ij > NCOVMAX)){                                          if ((ij < -1) && (ij > NCOVMAX)){
             printf( "Error: minimal is less than -1 or maximal is bigger than %d. Exiting. \n", NCOVMAX );                                                  printf( "Error: minimal is less than -1 or maximal is bigger than %d. Exiting. \n", NCOVMAX );
             exit(1);                                                  exit(1);
           }else                                          }else
             Ndum[ij]++; /*counts and stores the occurence of this modality 0, 1, -1*/                                                  Ndum[ij]++; /*counts and stores the occurence of this modality 0, 1, -1*/
           /*  If coded 1, 2, 3 , counts the number of 1 Ndum[1], number of 2, Ndum[2], etc */                                          /*  If coded 1, 2, 3 , counts the number of 1 Ndum[1], number of 2, Ndum[2], etc */
           /*printf("i=%d ij=%d Ndum[ij]=%d imx=%d",i,ij,Ndum[ij],imx);*/                                          /*printf("i=%d ij=%d Ndum[ij]=%d imx=%d",i,ij,Ndum[ij],imx);*/
           /* getting the maximum value of the modality of the covariate                                          /* getting the maximum value of the modality of the covariate
              (should be 0 or 1 now) Tvar[j]. If V=sex and male is coded 0 and                                                   (should be 0 or 1 now) Tvar[j]. If V=sex and male is coded 0 and
              female ies 1, then modmaxcovj=1.                                                   female ies 1, then modmaxcovj=1.
           */                                          */
         } /* end for loop on individuals i */                                  } /* end for loop on individuals i */
         printf(" Minimal and maximal values of %d th covariate V%d: min=%d max=%d \n", k, Tvar[k], modmincovj, modmaxcovj);                                  printf(" Minimal and maximal values of %d th covariate V%d: min=%d max=%d \n", k, Tvar[k], modmincovj, modmaxcovj);
         fprintf(ficlog," Minimal and maximal values of %d th covariate V%d: min=%d max=%d \n", k, Tvar[k], modmincovj, modmaxcovj);                                  fprintf(ficlog," Minimal and maximal values of %d th covariate V%d: min=%d max=%d \n", k, Tvar[k], modmincovj, modmaxcovj);
         cptcode=modmaxcovj;                                  cptcode=modmaxcovj;
         /* Ndum[0] = frequency of 0 for model-covariate j, Ndum[1] frequency of 1 etc. */                                  /* Ndum[0] = frequency of 0 for model-covariate j, Ndum[1] frequency of 1 etc. */
         /*for (i=0; i<=cptcode; i++) {*/                                  /*for (i=0; i<=cptcode; i++) {*/
         for (j=modmincovj;  j<=modmaxcovj; j++) { /* j=-1 ? 0 and 1*//* For each value j of the modality of model-cov k */                                  for (j=modmincovj;  j<=modmaxcovj; j++) { /* j=-1 ? 0 and 1*//* For each value j of the modality of model-cov k */
           printf("Frequencies of covariates %d ie V%d with value %d: %d\n", k, Tvar[k], j, Ndum[j]);                                          printf("Frequencies of covariates %d ie V%d with value %d: %d\n", k, Tvar[k], j, Ndum[j]);
           fprintf(ficlog, "Frequencies of covariates %d ie V%d with value %d: %d\n", k, Tvar[k], j, Ndum[j]);                                          fprintf(ficlog, "Frequencies of covariates %d ie V%d with value %d: %d\n", k, Tvar[k], j, Ndum[j]);
           if( Ndum[j] != 0 ){ /* Counts if nobody answered modality j ie empty modality, we skip it and reorder */                                          if( Ndum[j] != 0 ){ /* Counts if nobody answered modality j ie empty modality, we skip it and reorder */
             if( j != -1){                                                  if( j != -1){
               ncodemax[k]++;  /* ncodemax[k]= Number of modalities of the k th                                                          ncodemax[k]++;  /* ncodemax[k]= Number of modalities of the k th
                                  covariate for which somebody answered excluding                                                                                                                                    covariate for which somebody answered excluding 
                                  undefined. Usually 2: 0 and 1. */                                                                                                                                   undefined. Usually 2: 0 and 1. */
             }                                                  }
             ncodemaxwundef[k]++; /* ncodemax[j]= Number of modalities of the k th                                                  ncodemaxwundef[k]++; /* ncodemax[j]= Number of modalities of the k th
                                     covariate for which somebody answered including                                                                                                                                                   covariate for which somebody answered including 
                                     undefined. Usually 3: -1, 0 and 1. */                                                                                                                                                  undefined. Usually 3: -1, 0 and 1. */
           }                                          }       /* In fact  ncodemax[k]=2 (dichotom. variables only) but it could be more for
           /* In fact  ncodemax[k]=2 (dichotom. variables only) but it could be more for                                                   * historical reasons: 3 if coded 1, 2, 3 and 4 and Ndum[2]=0 */
            * historical reasons: 3 if coded 1, 2, 3 and 4 and Ndum[2]=0 */                                  } /* Ndum[-1] number of undefined modalities */
         } /* Ndum[-1] number of undefined modalities */                          
                                           /* j is a covariate, n=Tvar[j] of Vn; Fills nbcode */
         /* j is a covariate, n=Tvar[j] of Vn; Fills nbcode */                                  /* For covariate j, modalities could be 1, 2, 3, 4, 5, 6, 7. */
         /* For covariate j, modalities could be 1, 2, 3, 4, 5, 6, 7.                                   /* If Ndum[1]=0, Ndum[2]=0, Ndum[3]= 635, Ndum[4]=0, Ndum[5]=0, Ndum[6]=27, Ndum[7]=125; */
            If Ndum[1]=0, Ndum[2]=0, Ndum[3]= 635, Ndum[4]=0, Ndum[5]=0, Ndum[6]=27, Ndum[7]=125;                                  /* modmincovj=3; modmaxcovj = 7; */
            modmincovj=3; modmaxcovj = 7;                                  /* There are only 3 modalities non empty 3, 6, 7 (or 2 if 27 is too few) : ncodemax[j]=3; */
            There are only 3 modalities non empty 3, 6, 7 (or 2 if 27 is too few) : ncodemax[j]=3;                                  /* which will be coded 0, 1, 2 which in binary on 2=3-1 digits are 0=00 1=01, 2=10; */
            which will be coded 0, 1, 2 which in binary on 2=3-1 digits are 0=00 1=01, 2=10;                            /*             defining two dummy variables: variables V1_1 and V1_2.*/
            defining two dummy variables: variables V1_1 and V1_2.                /* nbcode[Tvar[j]][ij]=k; */
            nbcode[Tvar[j]][ij]=k;                /* nbcode[Tvar[j]][1]=0; */
            nbcode[Tvar[j]][1]=0;                /* nbcode[Tvar[j]][2]=1; */
            nbcode[Tvar[j]][2]=1;                /* nbcode[Tvar[j]][3]=2; */
            nbcode[Tvar[j]][3]=2;                /* To be continued (not working yet). */
            To be continued (not working yet).                ij=0; /* ij is similar to i but can jump over null modalities */
         */                                  for (i=modmincovj; i<=modmaxcovj; i++) { /* i= 1 to 2 for dichotomous, or from 1 to 3 or from -1 or 0 to 1 currently*/
         ij=0; /* ij is similar to i but can jump over null modalities */            if (Ndum[i] == 0) { /* If nobody responded to this modality k */
         for (i=modmincovj; i<=modmaxcovj; i++) { /* i= 1 to 2 for dichotomous, or from 1 to 3 or from -1 or 0 to 1 currently*/                    break;
           if (Ndum[i] == 0) { /* If nobody responded to this modality k */                  }
             break;                                          ij++;
           }                                          nbcode[Tvar[k]][ij]=i;  /* stores the original value of modality i in an array nbcode, ij modality from 1 to last non-nul modality. nbcode[1][1]=0 nbcode[1][2]=1*/
           ij++;                                          cptcode = ij; /* New max modality for covar j */
           nbcode[Tvar[k]][ij]=i;  /* stores the original value of modality i in an array nbcode, ij modality from 1 to last non-nul modality. nbcode[1][1]=0 nbcode[1][2]=1*/                                  } /* end of loop on modality i=-1 to 1 or more */
           cptcode = ij; /* New max modality for covar j */                                  break;
         } /* end of loop on modality i=-1 to 1 or more */  
         break;  
       case 1: /* Testing on varying covariate, could be simple and        case 1: /* Testing on varying covariate, could be simple and
                * should look at waves or product of fixed *                 * should look at waves or product of fixed *
                * varying. No time to test -1, assuming 0 and 1 only */                 * varying. No time to test -1, assuming 0 and 1 only */
         ij=0;                                  ij=0;
         for(i=0; i<=1;i++){                                  for(i=0; i<=1;i++){
           nbcode[Tvar[k]][++ij]=i;                                          nbcode[Tvar[k]][++ij]=i;
         }                                  }
         break;                                  break;
       default:        default:
         break;                                  break;
       } /* end switch */        } /* end switch */
     } /* end dummy test */      } /* end dummy test */
           
Line 4710  void  concatwav(int wav[], int **dh, int Line 4788  void  concatwav(int wav[], int **dh, int
     if(Ndum[Tvar[k]]!=0 && Dummy[k] == 0 && Typevar[k]==0){  /* Only Dummy and non empty in the model */      if(Ndum[Tvar[k]]!=0 && Dummy[k] == 0 && Typevar[k]==0){  /* Only Dummy and non empty in the model */
       /* If product not in single variable we don't print results */        /* If product not in single variable we don't print results */
       /*printf("diff Ndum[%d]=%d\n",i, Ndum[i]);*/        /*printf("diff Ndum[%d]=%d\n",i, Ndum[i]);*/
       ++ij;        ++ij;/* V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1, */
       Tvaraff[ij]=Tvar[k]; /*For printing */        Tvaraff[ij]=Tvar[k]; /* For printing combination *//* V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1, Tvar {5, 4, 3, 6, 5, 2, 7, 1, 1} Tvaraff={4, 3, 1} V4, V3, V1*/
       Tmodelind[ij]=k;        Tmodelind[ij]=k; /* Tmodelind: index in model of dummies Tmodelind[1]=2 V4: pos=2; V3: pos=3, V1=9 {2, 3, 9, ?, ?,} */
         TmodelInvind[ij]=Tvar[k]- ncovcol-nqv; /* Inverse TmodelInvind[2=V4]=2 second dummy varying cov (V4)4-1-1 {0, 2, 1, } TmodelInvind[3]=1 */
       if(Fixed[k]!=0)        if(Fixed[k]!=0)
         anyvaryingduminmodel=1;          anyvaryingduminmodel=1;
     /* }else if((Ndum[i]!=0) && (i<=ncovcol+nqv)){ */                          /* }else if((Ndum[i]!=0) && (i<=ncovcol+nqv)){ */
     /*   Tvaraff[++ij]=-10; /\* Dont'n know how to treat quantitative variables yet *\/ */                          /*   Tvaraff[++ij]=-10; /\* Dont'n know how to treat quantitative variables yet *\/ */
     /* }else if((Ndum[i]!=0) && (i<=ncovcol+nqv+ntv)){ */                          /* }else if((Ndum[i]!=0) && (i<=ncovcol+nqv+ntv)){ */
     /*   Tvaraff[++ij]=i; /\*For printing (unclear) *\/ */                          /*   Tvaraff[++ij]=i; /\*For printing (unclear) *\/ */
     /* }else if((Ndum[i]!=0) && (i<=ncovcol+nqv+ntv+nqtv)){ */                          /* }else if((Ndum[i]!=0) && (i<=ncovcol+nqv+ntv+nqtv)){ */
     /*   Tvaraff[++ij]=-20; /\* Dont'n know how to treat quantitative variables yet *\/ */                          /*   Tvaraff[++ij]=-20; /\* Dont'n know how to treat quantitative variables yet *\/ */
     }       } 
   } /* Tvaraff[1]@5 {3, 4, -20, 0, 0} Very strange */    } /* Tvaraff[1]@5 {3, 4, -20, 0, 0} Very strange */
   /* ij--; */    /* ij--; */
   /* cptcoveff=ij; /\*Number of total covariates*\/ */    /* cptcoveff=ij; /\*Number of total covariates*\/ */
   *cptcov=ij; /*Number of total real effective covariates: effective    *cptcov=ij; /*Number of total real effective covariates: effective
                * because they can be excluded from the model and real                                                           * because they can be excluded from the model and real
                * if in the model but excluded because missing values, but how to get k from ij?*/                                                           * if in the model but excluded because missing values, but how to get k from ij?*/
   for(j=ij+1; j<= cptcovt; j++){    for(j=ij+1; j<= cptcovt; j++){
     Tvaraff[j]=0;      Tvaraff[j]=0;
     Tmodelind[j]=0;      Tmodelind[j]=0;
   }    }
     for(j=ntveff+1; j<= cptcovt; j++){
       TmodelInvind[j]=0;
     }
   /* To be sorted */    /* To be sorted */
   ;    ;
 }  }
Line 5883  void printinghtml(char fileresu[], char Line 5965  void printinghtml(char fileresu[], char
          fprintf(fichtm," V%d=%d ",Tvaraff[cpt],nbcode[Tvaraff[cpt]][codtabm(jj1,cpt)]);           fprintf(fichtm," V%d=%d ",Tvaraff[cpt],nbcode[Tvaraff[cpt]][codtabm(jj1,cpt)]);
          printf(" V%d=%d ",Tvaraff[cpt],nbcode[Tvaraff[cpt]][codtabm(jj1,cpt)]);fflush(stdout);           printf(" V%d=%d ",Tvaraff[cpt],nbcode[Tvaraff[cpt]][codtabm(jj1,cpt)]);fflush(stdout);
        }         }
          /* if(nqfveff+nqtveff 0) */ /* Test to be done */
        fprintf(fichtm," ************\n<hr size=\"2\" color=\"#EC5E5E\">");         fprintf(fichtm," ************\n<hr size=\"2\" color=\"#EC5E5E\">");
        if(invalidvarcomb[k1]){         if(invalidvarcomb[k1]){
          fprintf(fichtm,"\n<h3>Combination (%d) ignored because no cases </h3>\n",k1);            fprintf(fichtm,"\n<h3>Combination (%d) ignored because no cases </h3>\n",k1); 
Line 6078  void printinggnuplot(char fileresu[], ch Line 6161  void printinggnuplot(char fileresu[], ch
   strcpy(optfileres,"vpl");    strcpy(optfileres,"vpl");
   /* 1eme*/    /* 1eme*/
   for (cpt=1; cpt<= nlstate ; cpt ++) { /* For each live state */    for (cpt=1; cpt<= nlstate ; cpt ++) { /* For each live state */
     for (k1=1; k1<= m ; k1 ++) { /* For each valid combination of covariate */      for (k1=1; k1<= m && selected(k1) ; k1 ++) { /* For each valid combination of covariate */
       /* plot [100000000000000000000:-100000000000000000000] "mysbiaspar/vplrmysbiaspar.txt to check */        /* plot [100000000000000000000:-100000000000000000000] "mysbiaspar/vplrmysbiaspar.txt to check */
       fprintf(ficgp,"\n# 1st: Period (stable) prevalence with CI: 'VPL_' files ");        fprintf(ficgp,"\n# 1st: Period (stable) prevalence with CI: 'VPL_' files ");
       for (k=1; k<=cptcoveff; k++){    /* For each covariate k get corresponding value lv for combination k1 */        for (k=1; k<=cptcoveff; k++){    /* For each covariate k get corresponding value lv for combination k1 */
Line 7526  int readdata(char datafile[], int firsto Line 7609  int readdata(char datafile[], int firsto
     /* Loops on waves */      /* Loops on waves */
     for (j=maxwav;j>=1;j--){      for (j=maxwav;j>=1;j--){
       for (iv=nqtv;iv>=1;iv--){  /* Loop  on time varying quantitative variables */        for (iv=nqtv;iv>=1;iv--){  /* Loop  on time varying quantitative variables */
         cutv(stra, strb, line, ' ');                                   cutv(stra, strb, line, ' '); 
         if(strb[0]=='.') { /* Missing value */                                  if(strb[0]=='.') { /* Missing value */
           lval=-1;                                          lval=-1;
           cotqvar[j][iv][i]=-1; /* 0.0/0.0 */                                          cotqvar[j][iv][i]=-1; /* 0.0/0.0 */
           if(isalpha(strb[1])) { /* .m or .d Really Missing value */                                          cotvar[j][ntv+iv][i]=-1; /* For performance reasons */
             printf("Error reading data around '%s' at line number %d for individual %d, '%s'\nShould be the %d th quantitative value out of %d measured at wave %d. If missing, you should remove this individual or impute a value.  Exiting.\n", strb, linei,i,line,iv, nqtv, j);                                          if(isalpha(strb[1])) { /* .m or .d Really Missing value */
             fprintf(ficlog,"Error reading data around '%s' at line number %d for individual %d, '%s'\nShould be the %d th quantitative value out of %d measured at wave %d. If missing, you should remove this individual or impute a value.  Exiting.\n", strb, linei,i,line,iv, nqtv, j);fflush(ficlog);                                                  printf("Error reading data around '%s' at line number %d for individual %d, '%s'\nShould be the %d th quantitative value out of %d measured at wave %d. If missing, you should remove this individual or impute a value.  Exiting.\n", strb, linei,i,line,iv, nqtv, j);
             return 1;                                                  fprintf(ficlog,"Error reading data around '%s' at line number %d for individual %d, '%s'\nShould be the %d th quantitative value out of %d measured at wave %d. If missing, you should remove this individual or impute a value.  Exiting.\n", strb, linei,i,line,iv, nqtv, j);fflush(ficlog);
           }                                                  return 1;
         }else{                                          }
           errno=0;                                  }else{
           /* what_kind_of_number(strb); */                                          errno=0;
           dval=strtod(strb,&endptr);                                           /* what_kind_of_number(strb); */
           /* if( strb[0]=='\0' || (*endptr != '\0')){ */                                          dval=strtod(strb,&endptr); 
           /* if(strb != endptr && *endptr == '\0') */                                          /* if( strb[0]=='\0' || (*endptr != '\0')){ */
           /*    dval=dlval; */                                          /* if(strb != endptr && *endptr == '\0') */
           /* if (errno == ERANGE && (lval == LONG_MAX || lval == LONG_MIN)) */                                          /*    dval=dlval; */
           if( strb[0]=='\0' || (*endptr != '\0')){                                          /* if (errno == ERANGE && (lval == LONG_MAX || lval == LONG_MIN)) */
             printf("Error reading data around '%s' at line number %d for individual %d, '%s'\nShould be the %d th quantitative value out of %d measured at wave %d. Setting maxwav=%d might be wrong.  Exiting.\n", strb, linei,i,line,iv, nqtv, j,maxwav);                                          if( strb[0]=='\0' || (*endptr != '\0')){
             fprintf(ficlog,"Error reading data around '%s' at line number %d for individual %d, '%s'\nShould be the %d th quantitative value out of %d measured at wave %d. Setting maxwav=%d might be wrong.  Exiting.\n", strb, linei,i,line, iv, nqtv, j,maxwav);fflush(ficlog);                                                  printf("Error reading data around '%s' at line number %d for individual %d, '%s'\nShould be the %d th quantitative value out of %d measured at wave %d. Setting maxwav=%d might be wrong.  Exiting.\n", strb, linei,i,line,iv, nqtv, j,maxwav);
             return 1;                                                  fprintf(ficlog,"Error reading data around '%s' at line number %d for individual %d, '%s'\nShould be the %d th quantitative value out of %d measured at wave %d. Setting maxwav=%d might be wrong.  Exiting.\n", strb, linei,i,line, iv, nqtv, j,maxwav);fflush(ficlog);
           }                                                  return 1;
           cotqvar[j][iv][i]=dval;                                           }
         }                                          cotqvar[j][iv][i]=dval; 
         strcpy(line,stra);                                          cotvar[j][ntv+iv][i]=dval; 
                                   }
                                   strcpy(line,stra);
       }/* end loop ntqv */        }/* end loop ntqv */
               
       for (iv=ntv;iv>=1;iv--){  /* Loop  on time varying dummies */        for (iv=ntv;iv>=1;iv--){  /* Loop  on time varying dummies */
         cutv(stra, strb, line, ' ');                                   cutv(stra, strb, line, ' '); 
         if(strb[0]=='.') { /* Missing value */                                  if(strb[0]=='.') { /* Missing value */
           lval=-1;                                          lval=-1;
         }else{                                  }else{
           errno=0;                                          errno=0;
           lval=strtol(strb,&endptr,10);                                           lval=strtol(strb,&endptr,10); 
           /*    if (errno == ERANGE && (lval == LONG_MAX || lval == LONG_MIN))*/                                          /*      if (errno == ERANGE && (lval == LONG_MAX || lval == LONG_MIN))*/
           if( strb[0]=='\0' || (*endptr != '\0')){                                          if( strb[0]=='\0' || (*endptr != '\0')){
             printf("Error reading data around '%s' at line number %d for individual %d, '%s'\nShould be the %d th dummy covariate out of %d measured at wave %d. Setting maxwav=%d might be wrong.  Exiting.\n", strb, linei,i,line,iv, ntv, j,maxwav);                                                  printf("Error reading data around '%s' at line number %d for individual %d, '%s'\nShould be the %d th dummy covariate out of %d measured at wave %d. Setting maxwav=%d might be wrong.  Exiting.\n", strb, linei,i,line,iv, ntv, j,maxwav);
             fprintf(ficlog,"Error reading data around '%s' at line number %d for individual %d, '%s'\nShould be the %d dummy covariate out of %d measured wave %d. Setting maxwav=%d might be wrong.  Exiting.\n", strb, linei,i,line,iv, ntv,j,maxwav);fflush(ficlog);                                                  fprintf(ficlog,"Error reading data around '%s' at line number %d for individual %d, '%s'\nShould be the %d dummy covariate out of %d measured wave %d. Setting maxwav=%d might be wrong.  Exiting.\n", strb, linei,i,line,iv, ntv,j,maxwav);fflush(ficlog);
             return 1;                                                  return 1;
           }                                          }
         }                                  }
         if(lval <-1 || lval >1){                                  if(lval <-1 || lval >1){
           printf("Error reading data around '%ld' at line number %d for individual %d, '%s'\n \                                          printf("Error reading data around '%ld' at line number %d for individual %d, '%s'\n \
  Should be a value of %d(nth) covariate (0 should be the value for the reference and 1\n \   Should be a value of %d(nth) covariate (0 should be the value for the reference and 1\n \
  for the alternative. IMaCh does not build design variables automatically, do it yourself.\n \   for the alternative. IMaCh does not build design variables automatically, do it yourself.\n \
  For example, for multinomial values like 1, 2 and 3,\n                 \   For example, for multinomial values like 1, 2 and 3,\n                                                                 \
  build V1=0 V2=0 for the reference value (1),\n                         \   build V1=0 V2=0 for the reference value (1),\n                                                                                                 \
         V1=1 V2=0 for (2) \n                                            \          V1=1 V2=0 for (2) \n                                                                                                                                                                            \
  and V1=0 V2=1 for (3). V1=1 V2=1 should not exist and the corresponding\n \   and V1=0 V2=1 for (3). V1=1 V2=1 should not exist and the corresponding\n \
  output of IMaCh is often meaningless.\n                                \   output of IMaCh is often meaningless.\n                                                                                                                                \
  Exiting.\n",lval,linei, i,line,j);   Exiting.\n",lval,linei, i,line,j);
           fprintf(ficlog,"Error reading data around '%ld' at line number %d for individual %d, '%s'\n \                                          fprintf(ficlog,"Error reading data around '%ld' at line number %d for individual %d, '%s'\n \
  Should be a value of %d(nth) covariate (0 should be the value for the reference and 1\n \   Should be a value of %d(nth) covariate (0 should be the value for the reference and 1\n \
  for the alternative. IMaCh does not build design variables automatically, do it yourself.\n \   for the alternative. IMaCh does not build design variables automatically, do it yourself.\n \
  For example, for multinomial values like 1, 2 and 3,\n                 \   For example, for multinomial values like 1, 2 and 3,\n                                                                 \
  build V1=0 V2=0 for the reference value (1),\n                         \   build V1=0 V2=0 for the reference value (1),\n                                                                                                 \
         V1=1 V2=0 for (2) \n                                            \          V1=1 V2=0 for (2) \n                                                                                                                                                                            \
  and V1=0 V2=1 for (3). V1=1 V2=1 should not exist and the corresponding\n \   and V1=0 V2=1 for (3). V1=1 V2=1 should not exist and the corresponding\n \
  output of IMaCh is often meaningless.\n                                \   output of IMaCh is often meaningless.\n                                                                                                                                \
  Exiting.\n",lval,linei, i,line,j);fflush(ficlog);   Exiting.\n",lval,linei, i,line,j);fflush(ficlog);
           return 1;                                          return 1;
         }                                  }
         cotvar[j][iv][i]=(double)(lval);                                  cotvar[j][iv][i]=(double)(lval);
         strcpy(line,stra);                                  strcpy(line,stra);
       }/* end loop ntv */        }/* end loop ntv */
               
       /* Statuses  at wave */        /* Statuses  at wave */
       cutv(stra, strb, line, ' ');         cutv(stra, strb, line, ' '); 
       if(strb[0]=='.') { /* Missing value */        if(strb[0]=='.') { /* Missing value */
         lval=-1;                                  lval=-1;
       }else{        }else{
         errno=0;                                  errno=0;
         lval=strtol(strb,&endptr,10);                                   lval=strtol(strb,&endptr,10); 
         /*      if (errno == ERANGE && (lval == LONG_MAX || lval == LONG_MIN))*/                                  /*      if (errno == ERANGE && (lval == LONG_MAX || lval == LONG_MIN))*/
         if( strb[0]=='\0' || (*endptr != '\0')){                                  if( strb[0]=='\0' || (*endptr != '\0')){
           printf("Error reading data around '%s' at line number %d for individual %d, '%s'\nShould be a status of wave %d. Setting maxwav=%d might be wrong.  Exiting.\n", strb, linei,i,line,j,maxwav);                                          printf("Error reading data around '%s' at line number %d for individual %d, '%s'\nShould be a status of wave %d. Setting maxwav=%d might be wrong.  Exiting.\n", strb, linei,i,line,j,maxwav);
           fprintf(ficlog,"Error reading data around '%s' at line number %d for individual %d, '%s'\nShould be a status of wave %d. Setting maxwav=%d might be wrong.  Exiting.\n", strb, linei,i,line,j,maxwav);fflush(ficlog);                                          fprintf(ficlog,"Error reading data around '%s' at line number %d for individual %d, '%s'\nShould be a status of wave %d. Setting maxwav=%d might be wrong.  Exiting.\n", strb, linei,i,line,j,maxwav);fflush(ficlog);
           return 1;                                          return 1;
         }                                  }
       }        }
               
       s[j][i]=lval;        s[j][i]=lval;
Line 7762  int readdata(char datafile[], int firsto Line 7847  int readdata(char datafile[], int firsto
   return (1);    return (1);
 }  }
   
 void removespace(char *str) {  void removespace(char **stri){/*, char stro[]) {*/
   char *p1 = str, *p2 = str;    char *p1 = *stri, *p2 = *stri;
   do    do
     while (*p2 == ' ')      while (*p2 == ' ')
       p2++;        p2++;
   while (*p1++ == *p2++);    while (*p1++ == *p2++);
     *stri=p1; 
 }  }
   
 int decodemodel ( char model[], int lastobs)  int decoderesult ( char resultline[])
  /**< This routine decode the model and returns:  /**< This routine decode one result line and returns the combination # of dummy covariates only **/
   {
     int j=0, k=0;
     char resultsav[MAXLINE];
     char stra[80], strb[80], strc[80], strd[80],stre[80];
   
     removespace(&resultline);
     printf("decoderesult:%s\n",resultline);
   
     if (strstr(resultline,"v") !=0){
       printf("Error. 'v' must be in upper case 'V' result: %s ",resultline);
       fprintf(ficlog,"Error. 'v' must be in upper case result: %s ",resultline);fflush(ficlog);
       return 1;
     }
     trimbb(resultsav, resultline);
     if (strlen(resultsav) >1){
       j=nbocc(resultsav,'='); /**< j=Number of covariate values'=' */
     }
   
     for(k=1; k<=j;k++){ /* Loop on total covariates of the model */
       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 */
       Tvalsel[k]=atof(strc); /* 1 */
   
       cutl(strc,stre,strd,'V'); /* strd='V4' strc=4 stre='V' */;
       Tvarsel[k]=atoi(strc);
       /* Typevarsel[k]=1;  /\* 1 for age product *\/ */
       /* cptcovsel++;     */
       if (nbocc(stra,'=') >0)
         strcpy(resultsav,stra); /* and analyzes it */
     }
     return (0);
   }
   int selected( int kvar){ /* Selected combination of covariates */
     if(Tvarsel[kvar])
       return (0);
     else
       return(1);
   }
   int decodemodel( char model[], int lastobs)
    /**< This routine decodes the model and returns:
         * Model  V1+V2+V3+V8+V7*V8+V5*V6+V8*age+V3*age+age*age          * Model  V1+V2+V3+V8+V7*V8+V5*V6+V8*age+V3*age+age*age
         * - nagesqr = 1 if age*age in the model, otherwise 0.          * - nagesqr = 1 if age*age in the model, otherwise 0.
         * - cptcovt total number of covariates of the model nbocc(+)+1 = 8 excepting constant and age and age*age          * - cptcovt total number of covariates of the model nbocc(+)+1 = 8 excepting constant and age and age*age
Line 7809  int decodemodel ( char model[], int last Line 7936  int decodemodel ( char model[], int last
     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 7893  int decodemodel ( char model[], int last Line 8020  int decodemodel ( char model[], int last
       }        }
       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 7969  int decodemodel ( char model[], int last Line 8096  int decodemodel ( char model[], int last
      scanf("%d ",i);*/       scanf("%d ",i);*/
   
   
 /* Decodemodel knows only the grammar (simple, product, age*) of the model but not what kind  /* Until here, decodemodel knows only the grammar (simple, product, age*) of the model but not what kind
    of variable (dummy vs quantitative, fixed vs time varying) is behind */     of variable (dummy vs quantitative, fixed vs time varying) is behind. But we know the # of each. */
 /* ncovcol= 1, nqv=1 | ntv=2, nqtv= 1  = 5 possible variables data: 2 fixed 3, varying  /* ncovcol= 1, nqv=1 | ntv=2, nqtv= 1  = 5 possible variables data: 2 fixed 3, varying
    model=        V5 + V4 +V3 + V4*V3 + V5*age + V2 + V1*V2 + V1*age + V5*age, V1 is not used saving its place     model=        V5 + V4 +V3 + V4*V3 + V5*age + V2 + V1*V2 + V1*age + V5*age, V1 is not used saving its place
    k =           1    2   3     4       5       6      7      8        9     k =           1    2   3     4       5       6      7      8        9
Line 7993  Typevar: 0 for simple covariate (dummy, Line 8120  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, ncoveff=0, nqfveff=0, ntveff=0, nqtveff=0;k<=cptcovt; k++){ /* or cptocvt */    for(k=1, ncovf=0, ncovv=0, ncova=0, ncoveff=0, nqfveff=0, ntveff=0, nqtveff=0;k<=cptcovt; k++){ /* or cptocvt */
     if (Tvar[k] <=ncovcol && (Typevar[k]==0 || Typevar[k]==2)){ /* Simple or product fixed dummy covariatee */      if (Tvar[k] <=ncovcol && (Typevar[k]==0 || Typevar[k]==2)){ /* Simple or product fixed dummy (<=ncovcol) covariates */
       Fixed[k]= 0;        Fixed[k]= 0;
       Dummy[k]= 0;        Dummy[k]= 0;
       ncoveff++;        ncoveff++;
     }else if( Tvar[k] <=ncovcol+nqv && Typevar[k]==0){ /* Remind that product Vn*Vm are added in k*/        ncovf++;
                           modell[k].maintype= FTYPE;
                           TvarF[ncovf]=Tvar[k];
                           TvarFind[ncovf]=k;
         TvarFD[ncoveff]=Tvar[k]; /* TvarFD[1]=V1 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */
         TvarFDind[ncoveff]=k; /* TvarFDind[1]=9 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */
       }else if( Tvar[k] <=ncovcol+nqv && Typevar[k]==0){ /* Remind that product Vn*Vm are added in k*/ /* Only simple fixed quantitative variable */
       Fixed[k]= 0;        Fixed[k]= 0;
       Dummy[k]= 1;        Dummy[k]= 1;
       nqfveff++;  /* Only simple fixed quantitative variable */        nqfveff++;
                           modell[k].maintype= FTYPE;
                           modell[k].subtype= FQ;
         ncovf++;
                           TvarF[ncovf]=Tvar[k];
                           TvarFind[ncovf]=k;
         TvarFQ[nqfveff]=Tvar[k]-ncovcol; /* TvarFQ[1]=V2-1=1st in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */ /* Only simple fixed quantitative variable */
         TvarFQind[nqfveff]=k; /* TvarFQind[1]=6 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */ /* Only simple fixed quantitative variable */
     }else if( Tvar[k] <=ncovcol+nqv+ntv && Typevar[k]==0){      }else if( Tvar[k] <=ncovcol+nqv+ntv && Typevar[k]==0){
       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 */
     }else if( Tvar[k] <=ncovcol+nqv+ntv+nqtv  && Typevar[k]==0){                          modell[k].maintype= VTYPE;
         Fixed[k]= 1;                          modell[k].subtype= VD;
         Dummy[k]= 1;                          ncovv++; /* Only simple time varying variables */
         nqtveff++;/* Only simple time varying quantitative variable */                          TvarV[ncovv]=Tvar[k];
                           TvarVind[ncovv]=k;
         TvarVD[ntveff]=Tvar[k]; /* TvarVD[1]=V4  TvarVD[2]=V3 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */ /* Only simple time varying dummy variable */
         TvarVDind[ntveff]=k; /* TvarVDind[1]=2 TvarVDind[2]=3 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */ /* Only simple time varying dummy variable */
         printf("Quasi Tmodelind[%d]=%d,Tvar[Tmodelind[%d]]=V%d, ncovcol=%d, nqv=%d,Tvar[k]- ncovcol-nqv=%d\n",ntveff,k,ntveff,Tvar[k], ncovcol, nqv,Tvar[k]- ncovcol-nqv);
         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*/
                           Fixed[k]= 1;
                           Dummy[k]= 1;
                           nqtveff++;
                           modell[k].maintype= VTYPE;
                           modell[k].subtype= VQ;
                           ncovv++; /* Only simple time varying variables */
                           TvarV[ncovv]=Tvar[k];
                           TvarVind[ncovv]=k;
         TvarVQ[nqtveff]=Tvar[k]; /* TvarVQ[1]=V5 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */ /* Only simple time varying quantitative variable */
         TvarVQind[nqtveff]=k; /* TvarVQind[1]=1 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */ /* Only simple time varying quantitative variable */
                           TmodelInvQind[nqtveff]=Tvar[k]- ncovcol-nqv-ntv;/* Only simple time varying quantitative variable */
                           /* 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 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 */
       if (Tvar[k] <=ncovcol ){ /* Simple or product fixed dummy covariatee */                          ncova++;
         Fixed[k]= 2;                          TvarA[ncova]=Tvar[k];
         Dummy[k]= 2;                          TvarAind[ncova]=k;
         /* ncoveff++; */        if (Tvar[k] <=ncovcol ){ /* Product age with fixed dummy covariatee */
                                   Fixed[k]= 2;
                                   Dummy[k]= 2;
                                   modell[k].maintype= ATYPE;
                                   modell[k].subtype= APFD;
                                   /* 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;
         /* nqfveff++;  /\* Only simple fixed quantitative variable *\/ */                                  modell[k].maintype= ATYPE;
                                   modell[k].subtype= APFQ;                /*      Product age * fixed quantitative */
                                   /* 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;
         /* ntveff++; /\* Only simple time varying dummy variable *\/ */                                  modell[k].maintype= ATYPE;
                                   modell[k].subtype= APVD;                /*      Product age * varying dummy */
                                   /* 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;
         /* nqtveff++;/\* Only simple time varying quantitative variable *\/ */                                  modell[k].maintype= ATYPE;
                                   modell[k].subtype= APVQ;                /*      Product age * varying quantitative */
                                   /* 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;
         }else if(Tvard[k1][2] <=ncovcol+nqv){                                          modell[k].maintype= FTYPE;
           Fixed[k]= 0;  /* or 2 ?*/                                          modell[k].subtype= FPDD;                /*      Product fixed dummy * fixed dummy */
           Dummy[k]= 1;                                          ncovf++; /* Fixed variables without age */
         }else if(Tvard[k1][2] <=ncovcol+nqv+ntv){                                          TvarF[ncovf]=Tvar[k];
           Fixed[k]= 1;                                          TvarFind[ncovf]=k;
           Dummy[k]= 0;                                  }else if(Tvard[k1][2] <=ncovcol+nqv){
         }else if(Tvard[k1][2] <=ncovcol+nqv+ntv+nqtv){                                          Fixed[k]= 0;  /* or 2 ?*/
           Fixed[k]= 1;                                          Dummy[k]= 1;
           Dummy[k]= 1;                                          modell[k].maintype= FTYPE;
         }                                           modell[k].subtype= FPDQ;                /*      Product fixed dummy * fixed quantitative */
                                           ncovf++; /* Varying variables without age */
                                           TvarF[ncovf]=Tvar[k];
                                           TvarFind[ncovf]=k;
                                   }else if(Tvard[k1][2] <=ncovcol+nqv+ntv){
                                           Fixed[k]= 1;
                                           Dummy[k]= 0;
                                           modell[k].maintype= VTYPE;
                                           modell[k].subtype= VPDD;                /*      Product fixed dummy * varying dummy */
                                           ncovv++; /* Varying variables without age */
                                           TvarV[ncovv]=Tvar[k];
                                           TvarVind[ncovv]=k;
                                   }else if(Tvard[k1][2] <=ncovcol+nqv+ntv+nqtv){
                                           Fixed[k]= 1;
                                           Dummy[k]= 1;
                                           modell[k].maintype= VTYPE;
                                           modell[k].subtype= VPDQ;                /*      Product fixed dummy * varying quantitative */
                                           ncovv++; /* Varying variables without age */
                                           TvarV[ncovv]=Tvar[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;
         }else if(Tvard[k1][2] <=ncovcol+nqv){                                          modell[k].maintype= FTYPE;
           Fixed[k]= 0; /* or 2 ?*/                                          modell[k].subtype= FPDQ;                /*      Product fixed quantitative * fixed dummy */
           Dummy[k]= 1;                                          ncovf++; /* Fixed variables without age */
         }else if(Tvard[k1][2] <=ncovcol+nqv+ntv){                                          TvarF[ncovf]=Tvar[k];
           Fixed[k]= 1;                                          TvarFind[ncovf]=k;
           Dummy[k]= 1;                                  }else if(Tvard[k1][2] <=ncovcol+nqv+ntv){
         }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].subtype= VPDQ;                /*      Product fixed quantitative * varying dummy */
                                           ncovv++; /* Varying variables without age */
                                           TvarV[ncovv]=Tvar[k];
                                           TvarVind[ncovv]=k;
                                   }else if(Tvard[k1][2] <=ncovcol+nqv+ntv+nqtv){
                                           Fixed[k]= 1;
                                           Dummy[k]= 1;
                                           modell[k].maintype= VTYPE;
                                           modell[k].subtype= VPQQ;                /*      Product fixed quantitative * varying quantitative */
                                           ncovv++; /* Varying variables without age */
                                           TvarV[ncovv]=Tvar[k];
                                           TvarVind[ncovv]=k;
                                           ncovv++; /* Varying variables without age */
                                           TvarV[ncovv]=Tvar[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;
         }else if(Tvard[k1][2] <=ncovcol+nqv){                                          modell[k].maintype= VTYPE;
           Fixed[k]= 1;                                          modell[k].subtype= VPDD;                /*      Product time varying dummy * fixed dummy */
           Dummy[k]= 1;                                          ncovv++; /* Varying variables without age */
         }else if(Tvard[k1][2] <=ncovcol+nqv+ntv){                                          TvarV[ncovv]=Tvar[k];
           Fixed[k]= 1;                                          TvarVind[ncovv]=k;
           Dummy[k]= 0;                                  }else if(Tvard[k1][2] <=ncovcol+nqv){
         }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].subtype= VPDQ;                /*      Product time varying dummy * fixed quantitative */
                                           ncovv++; /* Varying variables without age */
                                           TvarV[ncovv]=Tvar[k];
                                           TvarVind[ncovv]=k;
                                   }else if(Tvard[k1][2] <=ncovcol+nqv+ntv){
                                           Fixed[k]= 1;
                                           Dummy[k]= 0;
                                           modell[k].maintype= VTYPE;
                                           modell[k].subtype= VPDD;                /*      Product time varying dummy * time varying dummy */
                                           ncovv++; /* Varying variables without age */
                                           TvarV[ncovv]=Tvar[k];
                                           TvarVind[ncovv]=k;
                                   }else if(Tvard[k1][2] <=ncovcol+nqv+ntv+nqtv){
                                           Fixed[k]= 1;
                                           Dummy[k]= 1;
                                           modell[k].maintype= VTYPE;
                                           modell[k].subtype= VPDQ;                /*      Product time varying dummy * time varying quantitative */
                                           ncovv++; /* Varying variables without age */
                                           TvarV[ncovv]=Tvar[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;
         }else if(Tvard[k1][2] <=ncovcol+nqv){                                          modell[k].maintype= VTYPE;
           Fixed[k]= 1;                                          modell[k].subtype= VPDQ;                /*      Product time varying quantitative * fixed dummy */
           Dummy[k]= 1;                                          ncovv++; /* Varying variables without age */
         }else if(Tvard[k1][2] <=ncovcol+nqv+ntv){                                          TvarV[ncovv]=Tvar[k];
           Fixed[k]= 1;                                          TvarVind[ncovv]=k;
           Dummy[k]= 1;                                  }else if(Tvard[k1][2] <=ncovcol+nqv){
         }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].subtype= VPQQ;                /*      Product time varying quantitative * fixed quantitative */
                                           ncovv++; /* Varying variables without age */
                                           TvarV[ncovv]=Tvar[k];
                                           TvarVind[ncovv]=k;
                                   }else if(Tvard[k1][2] <=ncovcol+nqv+ntv){
                                           Fixed[k]= 1;
                                           Dummy[k]= 1;
                                           modell[k].maintype= VTYPE;
                                           modell[k].subtype= VPDQ;                /*      Product time varying quantitative * time varying dummy */
                                           ncovv++; /* Varying variables without age */
                                           TvarV[ncovv]=Tvar[k];
                                           TvarVind[ncovv]=k;
                                   }else if(Tvard[k1][2] <=ncovcol+nqv+ntv+nqtv){
                                           Fixed[k]= 1;
                                           Dummy[k]= 1;
                                           modell[k].maintype= VTYPE;
                                           modell[k].subtype= VPQQ;                /*      Product time varying quantitative * time varying quantitative */
                                           ncovv++; /* Varying variables without age */
                                           TvarV[ncovv]=Tvar[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]);
       fprintf(ficlog,"Error, current version can't treat for performance reasons, Tvar[%d]=%d, Typevar[%d]=%d\n", k, Tvar[k], k, Typevar[k]);        fprintf(ficlog,"Error, current version can't treat for performance reasons, Tvar[%d]=%d, Typevar[%d]=%d\n", k, Tvar[k], k, Typevar[k]);
     }      }
     printf("Decodemodel, k=%d, Tvar[%d]=V%d,Typevar=%d, Fixed=%d, Dummy=%d\n",k, k,Tvar[k],Typevar[k],Fixed[k],Dummy[k]);      printf("Decodemodel, k=%d, Tvar[%d]=V%d,Typevar=%d, Fixed=%d, Dummy=%d\n",k, k,Tvar[k],Typevar[k],Fixed[k],Dummy[k]);
       printf("           modell[%d].maintype=%d, modell[%d].subtype=%d\n",k,modell[k].maintype,k,modell[k].subtype);
     fprintf(ficlog,"Decodemodel, k=%d, Tvar[%d]=V%d,Typevar=%d, Fixed=%d, Dummy=%d\n",k, k,Tvar[k],Typevar[k],Fixed[k],Dummy[k]);      fprintf(ficlog,"Decodemodel, k=%d, Tvar[%d]=V%d,Typevar=%d, Fixed=%d, Dummy=%d\n",k, k,Tvar[k],Typevar[k],Fixed[k],Dummy[k]);
   }    }
   /* Searching for doublons in the model */    /* Searching for doublons in the model */
   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);
     fprintf(ficlog,"ncovf=%d, ncovv=%d, ncova=%d\n",ncovf,ncovv,ncova);
   return (0); /* with covar[new additional covariate if product] and Tage if age */     return (0); /* with covar[new additional covariate if product] and Tage if age */ 
   /*endread:*/    /*endread:*/
   printf("Exiting decodemodel: ");    printf("Exiting decodemodel: ");
Line 8804  int main(int argc, char *argv[]) Line 9053  int main(int argc, char *argv[])
   char path[MAXLINE],pathc[MAXLINE],pathcd[MAXLINE],pathtot[MAXLINE];    char path[MAXLINE],pathc[MAXLINE],pathcd[MAXLINE],pathtot[MAXLINE];
   
   char model[MAXLINE], modeltemp[MAXLINE];    char model[MAXLINE], modeltemp[MAXLINE];
     char resultline[MAXLINE];
     
   char pathr[MAXLINE], pathimach[MAXLINE];     char pathr[MAXLINE], pathimach[MAXLINE]; 
   char *tok, *val; /* pathtot */    char *tok, *val; /* pathtot */
   int firstobs=1, lastobs=10;    int firstobs=1, lastobs=10;
Line 9115  int main(int argc, char *argv[]) Line 9366  int main(int argc, char *argv[])
         
   covar=matrix(0,NCOVMAX,1,n);  /**< used in readdata */    covar=matrix(0,NCOVMAX,1,n);  /**< used in readdata */
   coqvar=matrix(1,nqv,1,n);  /**< Fixed quantitative covariate */    coqvar=matrix(1,nqv,1,n);  /**< Fixed quantitative covariate */
   cotvar=ma3x(1,maxwav,1,ntv,1,n);  /**< Time varying covariate */    cotvar=ma3x(1,maxwav,1,ntv+nqtv,1,n);  /**< Time varying covariate (dummy and quantitative)*/
   cotqvar=ma3x(1,maxwav,1,nqtv,1,n);  /**< Time varying quantitative covariate */    cotqvar=ma3x(1,maxwav,1,nqtv,1,n);  /**< Time varying quantitative covariate */
   cptcovn=0; /*Number of covariates, i.e. number of '+' in model statement plus one, indepently of n in Vn*/    cptcovn=0; /*Number of covariates, i.e. number of '+' in model statement plus one, indepently of n in Vn*/
   /* v1+v2+v3+v2*v4+v5*age makes cptcovn = 5    /* v1+v2+v3+v2*v4+v5*age makes cptcovn = 5
Line 9358  Please run with mle=-1 to get a correct Line 9609  Please run with mle=-1 to get a correct
         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. */
     TvarF=ivector(1,NCOVMAX); /*  */
     TvarFind=ivector(1,NCOVMAX); /*  */
     TvarV=ivector(1,NCOVMAX); /*  */
     TvarVind=ivector(1,NCOVMAX); /*  */
     TvarA=ivector(1,NCOVMAX); /*  */
     TvarAind=ivector(1,NCOVMAX); /*  */
     TvarFD=ivector(1,NCOVMAX); /*  */
     TvarFDind=ivector(1,NCOVMAX); /*  */
     TvarFQ=ivector(1,NCOVMAX); /*  */
     TvarFQind=ivector(1,NCOVMAX); /*  */
     TvarVD=ivector(1,NCOVMAX); /*  */
     TvarVDind=ivector(1,NCOVMAX); /*  */
     TvarVQ=ivector(1,NCOVMAX); /*  */
     TvarVQind=ivector(1,NCOVMAX); /*  */
   
     Tvalsel=vector(1,NCOVMAX); /*  */
     Tvarsel=ivector(1,NCOVMAX); /*  */
   Typevar=ivector(-1,NCOVMAX); /* -1 to 2 */    Typevar=ivector(-1,NCOVMAX); /* -1 to 2 */
   Fixed=ivector(-1,NCOVMAX); /* -1 to 3 */    Fixed=ivector(-1,NCOVMAX); /* -1 to 3 */
   Dummy=ivector(-1,NCOVMAX); /* -1 to 3 */    Dummy=ivector(-1,NCOVMAX); /* -1 to 3 */
Line 9385  Please run with mle=-1 to get a correct Line 9654  Please run with mle=-1 to get a correct
                          4 covariates (3 plus signs)                           4 covariates (3 plus signs)
                          Tage[1=V3*age]= 4; Tage[2=age*V4] = 3                           Tage[1=V3*age]= 4; Tage[2=age*V4] = 3
                       */                          */  
   Tmodelind=ivector(1,NCOVMAX);/** five the k model position of an    Tmodelind=ivector(1,NCOVMAX);/** gives the k model position of an
                                 * individual dummy, fixed or varying:                                  * individual dummy, fixed or varying:
                                 * Tmodelind[Tvaraff[3]]=9,Tvaraff[1]@9={4,                                  * Tmodelind[Tvaraff[3]]=9,Tvaraff[1]@9={4,
                                 * 3, 1, 0, 0, 0, 0, 0, 0},                                  * 3, 1, 0, 0, 0, 0, 0, 0},
                                   * model=V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 , 
                                   * V1 df, V2 qf, V3 & V4 dv, V5 qv
                                   * Tmodelind[1]@9={9,0,3,2,}*/
     TmodelInvind=ivector(1,NCOVMAX); /* TmodelInvind=Tvar[k]- ncovcol-nqv={5-2-1=2,*/
     TmodelInvQind=ivector(1,NCOVMAX);/** gives the k model position of an
                                   * individual quantitative, fixed or varying:
                                   * Tmodelqind[1]=1,Tvaraff[1]@9={4,
                                   * 3, 1, 0, 0, 0, 0, 0, 0},
                                 * model=V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1*/                                  * model=V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1*/
 /* Main decodemodel */  /* Main decodemodel */
   
Line 10155  Please run with mle=-1 to get a correct Line 10432  Please run with mle=-1 to get a correct
     fprintf(ficres,"backcast=%d starting-back-date=%.lf/%.lf/%.lf final-back-date=%.lf/%.lf/%.lf mobil_average=%d\n",backcast,jback1,mback1,anback1,jback2,mback2,anback2,mobilavproj);      fprintf(ficres,"backcast=%d starting-back-date=%.lf/%.lf/%.lf final-back-date=%.lf/%.lf/%.lf mobil_average=%d\n",backcast,jback1,mback1,anback1,jback2,mback2,anback2,mobilavproj);
     /* day and month of proj2 are not used but only year anproj2.*/      /* day and month of proj2 are not used but only year anproj2.*/
           
       /* Results */
       while(fgets(line, MAXLINE, ficpar)) {
         /* If line starts with a # it is a comment */
         if (line[0] == '#') {
           numlinepar++;
           fputs(line,stdout);
           fputs(line,ficparo);
           fputs(line,ficlog);
           continue;
         }else
           break;
       }
       while((num_filled=sscanf(line,"result:%[^\n]\n",resultline)) !=EOF){
         if (num_filled == 0)
           resultline[0]='\0';
         else if (num_filled != 1){
           printf("ERROR %d: result line should be at minimum 'result=' %s\n",num_filled, line);
         }
         printf("Result %d: result line should be at minimum 'line=' %s, result=%s\n",num_filled, line, resultline);
         decoderesult(resultline);
         while(fgets(line, MAXLINE, ficpar)) {
           /* If line starts with a # it is a comment */
           if (line[0] == '#') {
             numlinepar++;
             fputs(line,stdout);
             fputs(line,ficparo);
             fputs(line,ficlog);
             continue;
           }else
             break;
         }
         if (feof(ficpar))
           break;
         else{ /* Processess output results for this combination of covariate values */
         }                            
       }
   
   
           
                 /* freqsummary(fileres, agemin, agemax, s, agev, nlstate, imx,Tvaraff,nbcode, ncodemax,mint,anint); */      /* freqsummary(fileres, agemin, agemax, s, agev, nlstate, imx,Tvaraff,nbcode, ncodemax,mint,anint); */
     /* ,dateprev1,dateprev2,jprev1, mprev1,anprev1,jprev2, mprev2,anprev2); */      /* ,dateprev1,dateprev2,jprev1, mprev1,anprev1,jprev2, mprev2,anprev2); */
           
     replace_back_to_slash(pathc,pathcd); /* Even gnuplot wants a / */      replace_back_to_slash(pathc,pathcd); /* Even gnuplot wants a / */
     if(ageminpar == AGEOVERFLOW ||agemaxpar == -AGEOVERFLOW){      if(ageminpar == AGEOVERFLOW ||agemaxpar == -AGEOVERFLOW){
                         printf("Warning! Error in gnuplot file with ageminpar %f or agemaxpar %f overflow\n\        printf("Warning! Error in gnuplot file with ageminpar %f or agemaxpar %f overflow\n\
 This is probably because your parameter file doesn't \n  contain the exact number of lines (or columns) corresponding to your model line.\n\  This is probably because your parameter file doesn't \n  contain the exact number of lines (or columns) corresponding to your model line.\n\
 Please run with mle=-1 to get a correct covariance matrix.\n",ageminpar,agemaxpar);  Please run with mle=-1 to get a correct covariance matrix.\n",ageminpar,agemaxpar);
                         fprintf(ficlog,"Warning! Error in gnuplot file with ageminpar %f or agemaxpar %f overflow\n\        fprintf(ficlog,"Warning! Error in gnuplot file with ageminpar %f or agemaxpar %f overflow\n\
 This is probably because your parameter file doesn't \n  contain the exact number of lines (or columns) corresponding to your model line.\n\  This is probably because your parameter file doesn't \n  contain the exact number of lines (or columns) corresponding to your model line.\n\
 Please run with mle=-1 to get a correct covariance matrix.\n",ageminpar,agemaxpar);  Please run with mle=-1 to get a correct covariance matrix.\n",ageminpar,agemaxpar);
     }else{      }else{
Line 10518  Please run with mle=-1 to get a correct Line 10833  Please run with mle=-1 to get a correct
   free_matrix(newms, 1,nlstate+ndeath,1,nlstate+ndeath);    free_matrix(newms, 1,nlstate+ndeath,1,nlstate+ndeath);
   free_matrix(savms, 1,nlstate+ndeath,1,nlstate+ndeath);    free_matrix(savms, 1,nlstate+ndeath,1,nlstate+ndeath);
   free_ma3x(cotqvar,1,maxwav,1,nqtv,1,n);    free_ma3x(cotqvar,1,maxwav,1,nqtv,1,n);
   free_ma3x(cotvar,1,maxwav,1,ntv,1,n);    free_ma3x(cotvar,1,maxwav,1,ntv+nqtv,1,n);
   free_matrix(coqvar,1,maxwav,1,n);    free_matrix(coqvar,1,maxwav,1,n);
   free_matrix(covar,0,NCOVMAX,1,n);    free_matrix(covar,0,NCOVMAX,1,n);
   free_matrix(matcov,1,npar,1,npar);    free_matrix(matcov,1,npar,1,npar);
Line 10534  Please run with mle=-1 to get a correct Line 10849  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(TvarFD,1,NCOVMAX);
     free_ivector(TvarFDind,1,NCOVMAX);
     free_ivector(TvarF,1,NCOVMAX);
     free_ivector(TvarFind,1,NCOVMAX);
     free_ivector(TvarV,1,NCOVMAX);
     free_ivector(TvarVind,1,NCOVMAX);
     free_ivector(TvarA,1,NCOVMAX);
     free_ivector(TvarAind,1,NCOVMAX);
     free_ivector(TvarFQ,1,NCOVMAX);
     free_ivector(TvarFQind,1,NCOVMAX);
     free_ivector(TvarVD,1,NCOVMAX);
     free_ivector(TvarVDind,1,NCOVMAX);
     free_ivector(TvarVQ,1,NCOVMAX);
     free_ivector(TvarVQind,1,NCOVMAX);
     free_ivector(Tvarsel,1,NCOVMAX);
     free_vector(Tvalsel,1,NCOVMAX);
   free_ivector(Tposprod,1,NCOVMAX);    free_ivector(Tposprod,1,NCOVMAX);
   free_ivector(Tprod,1,NCOVMAX);    free_ivector(Tprod,1,NCOVMAX);
   free_ivector(Tvaraff,1,NCOVMAX);    free_ivector(Tvaraff,1,NCOVMAX);
   free_ivector(invalidvarcomb,1,ncovcombmax);    free_ivector(invalidvarcomb,1,ncovcombmax);
   free_ivector(Tage,1,NCOVMAX);    free_ivector(Tage,1,NCOVMAX);
   free_ivector(Tmodelind,1,NCOVMAX);    free_ivector(Tmodelind,1,NCOVMAX);
     free_ivector(TmodelInvind,1,NCOVMAX);
     free_ivector(TmodelInvQind,1,NCOVMAX);
       
   free_imatrix(nbcode,0,NCOVMAX,0,NCOVMAX);    free_imatrix(nbcode,0,NCOVMAX,0,NCOVMAX);
   /* free_imatrix(codtab,1,100,1,10); */    /* free_imatrix(codtab,1,100,1,10); */

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


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