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

version 1.234, 2016/08/23 16:51:20 version 1.235, 2016/08/25 06:59:23
Line 1 Line 1
 /* $Id$  /* $Id$
   $State$    $State$
   $Log$    $Log$
     Revision 1.235  2016/08/25 06:59:23  brouard
     *** empty log message ***
   
   Revision 1.234  2016/08/23 16:51:20  brouard    Revision 1.234  2016/08/23 16:51:20  brouard
   *** empty log message ***    *** empty log message ***
   
Line 1105  int *TvarsDind; Line 1108  int *TvarsDind;
 int *TvarsQ;  int *TvarsQ;
 int *TvarsQind;  int *TvarsQind;
   
   #define MAXRESULTLINES 10
   int nresult=0;
   int TKresult[MAXRESULTLINES];
   double Tresult[MAXRESULTLINES][NCOVMAX];/* For dummy variable , value (output) */
   int Tvresult[MAXRESULTLINES][NCOVMAX]; /* For dummy variable , variable # (output) */
   double Tqresult[MAXRESULTLINES][NCOVMAX]; /* For quantitative variable , value (output) */
   int Tvqresult[MAXRESULTLINES][NCOVMAX]; /* For quantitative variable , variable # (output) */
   
 /* int *TDvar; /\**< TDvar[1]=4,  TDvarF[2]=3, TDvar[3]=6  in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 *\/ */  /* int *TDvar; /\**< TDvar[1]=4,  TDvarF[2]=3, TDvar[3]=6  in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 *\/ */
 int *TvarF; /**< TvarF[1]=Tvar[6]=2,  TvarF[2]=Tvar[7]=7, TvarF[3]=Tvar[9]=1  in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */  int *TvarF; /**< TvarF[1]=Tvar[6]=2,  TvarF[2]=Tvar[7]=7, TvarF[3]=Tvar[9]=1  in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */
 int *TvarFind; /**< TvarFind[1]=6,  TvarFind[2]=7, Tvarind[3]=9  in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */  int *TvarFind; /**< TvarFind[1]=6,  TvarFind[2]=7, Tvarind[3]=9  in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */
Line 2333  void powell(double p[], double **xi, int Line 2344  void powell(double p[], double **xi, int
       
 /**** Prevalence limit (stable or period prevalence)  ****************/  /**** Prevalence limit (stable or period prevalence)  ****************/
       
 double **prevalim(double **prlim, int nlstate, double x[], double age, double **oldm, double **savm, double ftolpl, int *ncvyear, int ij)    double **prevalim(double **prlim, int nlstate, double x[], double age, double **oldm, double **savm, double ftolpl, int *ncvyear, int ij, int nres)
   {    {
     /* Computes the prevalence limit in each live state at age x and for covariate combiation ij by left multiplying the unit      /* Computes the prevalence limit in each live state at age x and for covariate combination ij 
          (and selected quantitative values in nres)
          by left multiplying the unit
        matrix by transitions matrix until convergence is reached with precision ftolpl */         matrix by transitions matrix until convergence is reached with precision ftolpl */
   /* Wx= Wx-1 Px-1= Wx-2 Px-2 Px-1  = Wx-n Px-n ... Px-2 Px-1 I */    /* Wx= Wx-1 Px-1= Wx-2 Px-2 Px-1  = Wx-n Px-n ... Px-2 Px-1 I */
   /* Wx is row vector: population in state 1, population in state 2, population dead */    /* Wx is row vector: population in state 1, population in state 2, population dead */
Line 2387  double **prevalim(double **prlim, int nl Line 2400  double **prevalim(double **prlim, int nl
     for (k=1; k<=nsd;k++) { /* For single dummy covariates only */      for (k=1; k<=nsd;k++) { /* For single dummy covariates only */
                         /* Here comes the value of the covariate 'ij' after renumbering k with single dummy covariates */                          /* Here comes the value of the covariate 'ij' after renumbering k with single dummy covariates */
       cov[2+nagesqr+TvarsDind[k]]=nbcode[TvarsD[k]][codtabm(ij,k)];        cov[2+nagesqr+TvarsDind[k]]=nbcode[TvarsD[k]][codtabm(ij,k)];
       printf("prevalim ij=%d k=%d TvarsD[%d]=%d TvarsDind[%d]=%d nbcode=%d cov=%lf codtabm(%d,Tvar[%d])=%d \n",ij,k, k, TvarsD[k],k,TvarsDind[k],nbcode[TvarsD[k]][codtabm(ij,k)],cov[2+nagesqr+TvarsDind[k]], ij, k, codtabm(ij,k));        /* printf("prevalim Dummy combi=%d k=%d TvarsD[%d]=V%d TvarsDind[%d]=%d nbcode=%d cov=%lf codtabm(%d,Tvar[%d])=%d \n",ij,k, k, TvarsD[k],k,TvarsDind[k],nbcode[TvarsD[k]][codtabm(ij,k)],cov[2+nagesqr+TvarsDind[k]], ij, k, codtabm(ij,k)); */
     }      }
     for (k=1; k<=nsq;k++) { /* For single varying covariates only */      for (k=1; k<=nsq;k++) { /* For single varying covariates only */
                         /* Here comes the value of quantitative after renumbering k with single quantitative covariates */                          /* Here comes the value of quantitative after renumbering k with single quantitative covariates */
       /* cov[2+nagesqr+TvarsQind[k]]=qselvar[k]; */        cov[2+nagesqr+TvarsQind[k]]=Tqresult[nres][k]; 
       printf("prevalim ij=%d k=%d  TvarsQind[%d]=%d \n",ij,k,k,TvarsQind[k]);        /* printf("prevalim Quantitative k=%d  TvarsQind[%d]=%d, TvarsQ[%d]=V%d,Tqresult[%d][%d]=%f\n",k,k,TvarsQind[k],k,TvarsQ[k],nres,k,Tqresult[nres][k]); */
     }      }
     /*wrong? for (k=1; k<=cptcovage;k++) cov[2+Tage[k]]=cov[2+Tage[k]]*cov[2]; */  
     /* for (k=1; k<=cptcovage;k++) cov[2+nagesqr+Tage[k]]=nbcode[Tvar[k]][codtabm(ij,Tvar[k])]*cov[2]; */  
     for (k=1; k<=cptcovage;k++){      for (k=1; k<=cptcovage;k++){
       if(Dummy[Tvar[Tage[k]]]){        if(Dummy[Tvar[Tage[k]]]){
         cov[2+nagesqr+Tage[k]]=nbcode[Tvar[Tage[k]]][codtabm(ij,k)]*cov[2];          cov[2+nagesqr+Tage[k]]=nbcode[Tvar[Tage[k]]][codtabm(ij,k)]*cov[2];
       } else{        } else{
         ;          cov[2+nagesqr+Tage[k]]=Tqresult[nres][k]; 
         /* cov[2+nagesqr+Tage[k]]=qselvar[k]; */  
       }        }
       printf("prevalim Age ij=%d k=%d  Tage[%d]=%d \n",ij,k,k,Tage[k]);        /* printf("prevalim Age combi=%d k=%d  Tage[%d]=V%d Tqresult[%d][%d]=%f\n",ij,k,k,Tage[k],nres,k,Tqresult[nres][k]); */
     }      }
     for (k=1; k<=cptcovprod;k++){ /*  */      for (k=1; k<=cptcovprod;k++){ /*  */
       printf("prevalim Prod ij=%d k=%d  Tprod[%d]=%d Tvard[%d][1]=%d, Tvard[%d][2]=%d\n",ij,k,k,Tprod[k], k,Tvard[k][1], k,Tvard[k][2]);        /* printf("prevalim Prod ij=%d k=%d  Tprod[%d]=%d Tvard[%d][1]=V%d, Tvard[%d][2]=V%d\n",ij,k,k,Tprod[k], k,Tvard[k][1], k,Tvard[k][2]); */
       cov[2+nagesqr+Tprod[k]]=nbcode[Tvard[k][1]][codtabm(ij,k)] * nbcode[Tvard[k][2]][codtabm(ij,k)];        cov[2+nagesqr+Tprod[k]]=nbcode[Tvard[k][1]][codtabm(ij,k)] * nbcode[Tvard[k][2]][codtabm(ij,k)];
     }      }
     /*printf("ij=%d cptcovprod=%d tvar=%d ", ij, cptcovprod, Tvar[1]);*/      /*printf("ij=%d cptcovprod=%d tvar=%d ", ij, cptcovprod, Tvar[1]);*/
Line 2530  Earliest age to start was %d-%d=%d, ncvl Line 2540  Earliest age to start was %d-%d=%d, ncvl
       cov[2+nagesqr+k]=nbcode[Tvar[k]][codtabm(ij,k)];        cov[2+nagesqr+k]=nbcode[Tvar[k]][codtabm(ij,k)];
       /* printf("prevalim ij=%d k=%d Tvar[%d]=%d nbcode=%d cov=%lf codtabm(%d,Tvar[%d])=%d \n",ij,k, k, Tvar[k],nbcode[Tvar[k]][codtabm(ij,Tvar[k])],cov[2+k], ij, k, codtabm(ij,Tvar[k])]); */        /* printf("prevalim ij=%d k=%d Tvar[%d]=%d nbcode=%d cov=%lf codtabm(%d,Tvar[%d])=%d \n",ij,k, k, Tvar[k],nbcode[Tvar[k]][codtabm(ij,Tvar[k])],cov[2+k], ij, k, codtabm(ij,Tvar[k])]); */
     }      }
     /*wrong? for (k=1; k<=cptcovage;k++) cov[2+Tage[k]]=cov[2+Tage[k]]*cov[2]; */  
     /* for (k=1; k<=cptcovage;k++) cov[2+nagesqr+Tage[k]]=nbcode[Tvar[k]][codtabm(ij,Tvar[k])]*cov[2]; */  
     for (k=1; k<=cptcovage;k++) cov[2+nagesqr+Tage[k]]=nbcode[Tvar[k]][codtabm(ij,k)]*cov[2];      for (k=1; k<=cptcovage;k++) cov[2+nagesqr+Tage[k]]=nbcode[Tvar[k]][codtabm(ij,k)]*cov[2];
     for (k=1; k<=cptcovprod;k++) /* Useless */      for (k=1; k<=cptcovprod;k++) /* Useless */
       /* cov[2+nagesqr+Tprod[k]]=nbcode[Tvard[k][1]][codtabm(ij,Tvard[k][1])] * nbcode[Tvard[k][2]][codtabm(ij,Tvard[k][2])]; */        /* cov[2+nagesqr+Tprod[k]]=nbcode[Tvard[k][1]][codtabm(ij,Tvard[k][1])] * nbcode[Tvard[k][2]][codtabm(ij,Tvard[k][2])]; */
Line 2856  double **matprod2(double **out, double * Line 2864  double **matprod2(double **out, double *
   
 /************* Higher Matrix Product ***************/  /************* Higher Matrix Product ***************/
   
 double ***hpxij(double ***po, int nhstepm, double age, int hstepm, double *x, int nlstate, int stepm, double **oldm, double **savm, int ij )  double ***hpxij(double ***po, int nhstepm, double age, int hstepm, double *x, int nlstate, int stepm, double **oldm, double **savm, int ij, int nres )
 {  {
   /* Computes the transition matrix starting at age 'age' and combination of covariate values corresponding to ij over     /* Computes the transition matrix starting at age 'age' and combination of covariate values corresponding to ij over 
      'nhstepm*hstepm*stepm' months (i.e. until       'nhstepm*hstepm*stepm' months (i.e. until
Line 2892  double ***hpxij(double ***po, int nhstep Line 2900  double ***hpxij(double ***po, int nhstep
       cov[2]=agexact;        cov[2]=agexact;
       if(nagesqr==1)        if(nagesqr==1)
         cov[3]= agexact*agexact;          cov[3]= agexact*agexact;
       for (k=1; k<=cptcovn;k++)         for (k=1; k<=nsd;k++) { /* For single dummy covariates only */
         cov[2+nagesqr+k]=nbcode[Tvar[k]][codtabm(ij,k)];                          /* Here comes the value of the covariate 'ij' after renumbering k with single dummy covariates */
       /* cov[2+nagesqr+k]=nbcode[Tvar[k]][codtabm(ij,Tvar[k])]; */          cov[2+nagesqr+TvarsDind[k]]=nbcode[TvarsD[k]][codtabm(ij,k)];
       for (k=1; k<=cptcovage;k++) /* Should start at cptcovn+1 */          /* printf("hpxij Dummy combi=%d k=%d TvarsD[%d]=V%d TvarsDind[%d]=%d nbcode=%d cov=%lf codtabm(%d,Tvar[%d])=%d \n",ij,k, k, TvarsD[k],k,TvarsDind[k],nbcode[TvarsD[k]][codtabm(ij,k)],cov[2+nagesqr+TvarsDind[k]], ij, k, codtabm(ij,k)); */
         /* cov[2+Tage[k]]=cov[2+Tage[k]]*cov[2]; */        }
         cov[2+nagesqr+Tage[k]]=nbcode[Tvar[Tage[k]]][codtabm(ij,k)]*cov[2];        for (k=1; k<=nsq;k++) { /* For single varying covariates only */
       /* cov[2+nagesqr+Tage[k]]=nbcode[Tvar[Tage[k]]][codtabm(ij,Tvar[Tage[k]])]*cov[2]; */          /* Here comes the value of quantitative after renumbering k with single quantitative covariates */
       for (k=1; k<=cptcovprod;k++) /* Useless because included in cptcovn */          cov[2+nagesqr+TvarsQind[k]]=Tqresult[nres][k]; 
         cov[2+nagesqr+Tprod[k]]=nbcode[Tvard[k][1]][codtabm(ij,k)]*nbcode[Tvard[k][2]][codtabm(ij,k)];          /* printf("hPxij Quantitative k=%d  TvarsQind[%d]=%d, TvarsQ[%d]=V%d,Tqresult[%d][%d]=%f\n",k,k,TvarsQind[k],k,TvarsQ[k],nres,k,Tqresult[nres][k]); */
       /* cov[2+nagesqr+Tprod[k]]=nbcode[Tvard[k][1]][codtabm(ij,Tvard[k][1])]*nbcode[Tvard[k][2]][codtabm(ij,Tvard[k][2])]; */        }
         for (k=1; k<=cptcovage;k++){
           if(Dummy[Tvar[Tage[k]]]){
             cov[2+nagesqr+Tage[k]]=nbcode[Tvar[Tage[k]]][codtabm(ij,k)]*cov[2];
           } else{
             cov[2+nagesqr+Tage[k]]=Tqresult[nres][k]; 
           }
           /* printf("hPxij Age combi=%d k=%d  Tage[%d]=V%d Tqresult[%d][%d]=%f\n",ij,k,k,Tage[k],nres,k,Tqresult[nres][k]); */
         }
         for (k=1; k<=cptcovprod;k++){ /*  */
           /* printf("hPxij Prod ij=%d k=%d  Tprod[%d]=%d Tvard[%d][1]=V%d, Tvard[%d][2]=V%d\n",ij,k,k,Tprod[k], k,Tvard[k][1], k,Tvard[k][2]); */
           cov[2+nagesqr+Tprod[k]]=nbcode[Tvard[k][1]][codtabm(ij,k)] * nbcode[Tvard[k][2]][codtabm(ij,k)];
         }
         /* for (k=1; k<=cptcovn;k++)  */
         /*        cov[2+nagesqr+k]=nbcode[Tvar[k]][codtabm(ij,k)]; */
         /* for (k=1; k<=cptcovage;k++) /\* Should start at cptcovn+1 *\/ */
         /*        cov[2+nagesqr+Tage[k]]=nbcode[Tvar[Tage[k]]][codtabm(ij,k)]*cov[2]; */
         /* for (k=1; k<=cptcovprod;k++) /\* Useless because included in cptcovn *\/ */
         /*        cov[2+nagesqr+Tprod[k]]=nbcode[Tvard[k][1]][codtabm(ij,k)]*nbcode[Tvard[k][2]][codtabm(ij,k)]; */
               
               
       /*printf("hxi cptcov=%d cptcode=%d\n",cptcov,cptcode);*/        /*printf("hxi cptcov=%d cptcode=%d\n",cptcov,cptcode);*/
Line 4862  void  concatwav(int wav[], int **dh, int Line 4888  void  concatwav(int wav[], int **dh, int
   
 /*********** Health Expectancies ****************/  /*********** Health Expectancies ****************/
   
 void evsij(double ***eij, double x[], int nlstate, int stepm, int bage, int fage, double **oldm, double **savm, int cij, int estepm,char strstart[] )   void evsij(double ***eij, double x[], int nlstate, int stepm, int bage, int fage, double **oldm, double **savm, int cij, int estepm,char strstart[], int nres )
   
 {  {
   /* Health expectancies, no variances */    /* Health expectancies, no variances */
Line 4935  void evsij(double ***eij, double x[], in Line 4961  void evsij(double ***eij, double x[], in
     /* Computed by stepm unit matrices, product of hstepma matrices, stored      /* Computed by stepm unit matrices, product of hstepma matrices, stored
        in an array of nhstepma length: nhstepma=10, hstepm=4, stepm=6 months */         in an array of nhstepma length: nhstepma=10, hstepm=4, stepm=6 months */
           
     hpxij(p3mat,nhstepma,age,hstepm,x,nlstate,stepm,oldm, savm, cij);        hpxij(p3mat,nhstepma,age,hstepm,x,nlstate,stepm,oldm, savm, cij, nres);  
           
     hf=hstepm*stepm/YEARM;  /* Duration of hstepm expressed in year unit. */      hf=hstepm*stepm/YEARM;  /* Duration of hstepm expressed in year unit. */
           
Line 4970  void evsij(double ***eij, double x[], in Line 4996  void evsij(double ***eij, double x[], in
       
 }  }
   
 void cvevsij(double ***eij, double x[], int nlstate, int stepm, int bage, int fage, double **oldm, double **savm, int cij, int estepm,double delti[],double **matcov,char strstart[] )   void cvevsij(double ***eij, double x[], int nlstate, int stepm, int bage, int fage, double **oldm, double **savm, int cij, int estepm,double delti[],double **matcov,char strstart[], int nres )
   
 {  {
   /* Covariances of health expectancies eij and of total life expectancies according    /* Covariances of health expectancies eij and of total life expectancies according
Line 5083  void cvevsij(double ***eij, double x[], Line 5109  void cvevsij(double ***eij, double x[],
         xp[i] = x[i] + (i==theta ?delti[theta]:0);          xp[i] = x[i] + (i==theta ?delti[theta]:0);
         xm[i] = x[i] - (i==theta ?delti[theta]:0);          xm[i] = x[i] - (i==theta ?delti[theta]:0);
       }        }
       hpxij(p3matp,nhstepm,age,hstepm,xp,nlstate,stepm,oldm,savm, cij);          hpxij(p3matp,nhstepm,age,hstepm,xp,nlstate,stepm,oldm,savm, cij, nres);  
       hpxij(p3matm,nhstepm,age,hstepm,xm,nlstate,stepm,oldm,savm, cij);          hpxij(p3matm,nhstepm,age,hstepm,xm,nlstate,stepm,oldm,savm, cij, nres);  
                                                   
       for(j=1; j<= nlstate; j++){        for(j=1; j<= nlstate; j++){
         for(i=1; i<=nlstate; i++){          for(i=1; i<=nlstate; i++){
Line 5125  void cvevsij(double ***eij, double x[], Line 5151  void cvevsij(double ***eij, double x[],
     }      }
                                   
     /* Computing expectancies */      /* Computing expectancies */
     hpxij(p3matm,nhstepm,age,hstepm,x,nlstate,stepm,oldm, savm, cij);        hpxij(p3matm,nhstepm,age,hstepm,x,nlstate,stepm,oldm, savm, cij,nres);  
     for(i=1; i<=nlstate;i++)      for(i=1; i<=nlstate;i++)
       for(j=1; j<=nlstate;j++)        for(j=1; j<=nlstate;j++)
         for (h=0, eij[i][j][(int)age]=0; h<=nhstepm-1; h++){          for (h=0, eij[i][j][(int)age]=0; h<=nhstepm-1; h++){
Line 5180  void cvevsij(double ***eij, double x[], Line 5206  void cvevsij(double ***eij, double x[],
 }  }
     
 /************ Variance ******************/  /************ Variance ******************/
  void varevsij(char optionfilefiname[], double ***vareij, double **matcov, double x[], double delti[], int nlstate, int stepm, double bage, double fage, double **oldm, double **savm, double **prlim, double ftolpl, int *ncvyearp, int ij, int estepm, int cptcov, int cptcod, int popbased, int mobilav, char strstart[])   void varevsij(char optionfilefiname[], double ***vareij, double **matcov, double x[], double delti[], int nlstate, int stepm, double bage, double fage, double **oldm, double **savm, double **prlim, double ftolpl, int *ncvyearp, int ij, int estepm, int cptcov, int cptcod, int popbased, int mobilav, char strstart[], int nres)
  {   {
    /* Variance of health expectancies */     /* Variance of health expectancies */
    /*  double **prevalim(double **prlim, int nlstate, double *xp, double age, double **oldm, double ** savm,double ftolpl);*/     /*  double **prevalim(double **prlim, int nlstate, double *xp, double age, double **oldm, double ** savm,double ftolpl);*/
Line 5306  void cvevsij(double ***eij, double x[], Line 5332  void cvevsij(double ***eij, double x[],
          xp[i] = x[i] + (i==theta ?delti[theta]:0);           xp[i] = x[i] + (i==theta ?delti[theta]:0);
        }         }
                                                   
        prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyearp,ij);         prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyearp,ij, nresult);
                                                   
        if (popbased==1) {         if (popbased==1) {
          if(mobilav ==0){           if(mobilav ==0){
Line 5318  void cvevsij(double ***eij, double x[], Line 5344  void cvevsij(double ***eij, double x[],
          }           }
        }         }
                                                   
        hpxij(p3mat,nhstepm,age,hstepm,xp,nlstate,stepm,oldm,savm, ij);  /* Returns p3mat[i][j][h] for h=1 to nhstepm */         hpxij(p3mat,nhstepm,age,hstepm,xp,nlstate,stepm,oldm,savm, ij,nres);  /* Returns p3mat[i][j][h] for h=1 to nhstepm */
        for(j=1; j<= nlstate; j++){         for(j=1; j<= nlstate; j++){
          for(h=0; h<=nhstepm; h++){           for(h=0; h<=nhstepm; h++){
            for(i=1, gp[h][j]=0.;i<=nlstate;i++)             for(i=1, gp[h][j]=0.;i<=nlstate;i++)
Line 5338  void cvevsij(double ***eij, double x[], Line 5364  void cvevsij(double ***eij, double x[],
        for(i=1; i<=npar; i++) /* Computes gradient x - delta */         for(i=1; i<=npar; i++) /* Computes gradient x - delta */
          xp[i] = x[i] - (i==theta ?delti[theta]:0);           xp[i] = x[i] - (i==theta ?delti[theta]:0);
                                                   
        prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyearp, ij);         prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyearp, ij, nresult);
                                                   
        if (popbased==1) {         if (popbased==1) {
          if(mobilav ==0){           if(mobilav ==0){
Line 5350  void cvevsij(double ***eij, double x[], Line 5376  void cvevsij(double ***eij, double x[],
          }           }
        }         }
                                                   
        hpxij(p3mat,nhstepm,age,hstepm,xp,nlstate,stepm,oldm,savm, ij);           hpxij(p3mat,nhstepm,age,hstepm,xp,nlstate,stepm,oldm,savm, ij,nres);  
                                                   
        for(j=1; j<= nlstate; j++){  /* Sum of wi * eij = e.j */         for(j=1; j<= nlstate; j++){  /* Sum of wi * eij = e.j */
          for(h=0; h<=nhstepm; h++){           for(h=0; h<=nhstepm; h++){
Line 5415  void cvevsij(double ***eij, double x[], Line 5441  void cvevsij(double ***eij, double x[],
      /* end ppptj */       /* end ppptj */
      /*  x centered again */       /*  x centered again */
                                   
      prevalim(prlim,nlstate,x,age,oldm,savm,ftolpl,ncvyearp,ij);       prevalim(prlim,nlstate,x,age,oldm,savm,ftolpl,ncvyearp,ij, nresult);
                                   
      if (popbased==1) {       if (popbased==1) {
        if(mobilav ==0){         if(mobilav ==0){
Line 5431  void cvevsij(double ***eij, double x[], Line 5457  void cvevsij(double ***eij, double x[],
         computed over hstepm (estepm) matrices product = hstepm*stepm months)           computed over hstepm (estepm) matrices product = hstepm*stepm months) 
         as a weighted average of prlim.          as a weighted average of prlim.
      */       */
      hpxij(p3mat,nhstepm,age,hstepm,x,nlstate,stepm,oldm,savm, ij);         hpxij(p3mat,nhstepm,age,hstepm,x,nlstate,stepm,oldm,savm, ij, nres);  
      for(j=nlstate+1;j<=nlstate+ndeath;j++){       for(j=nlstate+1;j<=nlstate+ndeath;j++){
        for(i=1,gmp[j]=0.;i<= nlstate; i++)          for(i=1,gmp[j]=0.;i<= nlstate; i++) 
          gmp[j] += prlim[i][i]*p3mat[i][j][1];            gmp[j] += prlim[i][i]*p3mat[i][j][1]; 
Line 5494  void cvevsij(double ***eij, double x[], Line 5520  void cvevsij(double ***eij, double x[],
  }  /* end varevsij */   }  /* end varevsij */
   
 /************ Variance of prevlim ******************/  /************ Variance of prevlim ******************/
  void varprevlim(char fileres[], double **varpl, double **matcov, double x[], double delti[], int nlstate, int stepm, double bage, double fage, double **oldm, double **savm, double **prlim, double ftolpl, int *ncvyearp, int ij, char strstart[])   void varprevlim(char fileres[], double **varpl, double **matcov, double x[], double delti[], int nlstate, int stepm, double bage, double fage, double **oldm, double **savm, double **prlim, double ftolpl, int *ncvyearp, int ij, char strstart[], int nres)
 {  {
   /* Variance of prevalence limit  for each state ij using current parameters x[] and estimates of neighbourhood give by delti*/    /* Variance of prevalence limit  for each state ij using current parameters x[] and estimates of neighbourhood give by delti*/
   /*  double **prevalim(double **prlim, int nlstate, double *xp, double age, double **oldm, double **savm,double ftolpl);*/    /*  double **prevalim(double **prlim, int nlstate, double *xp, double age, double **oldm, double **savm,double ftolpl);*/
Line 5537  void cvevsij(double ***eij, double x[], Line 5563  void cvevsij(double ***eij, double x[],
         xp[i] = x[i] + (i==theta ?delti[theta]:0);          xp[i] = x[i] + (i==theta ?delti[theta]:0);
       }        }
       if((int)age==79 ||(int)age== 80 ||(int)age== 81 )        if((int)age==79 ||(int)age== 80 ||(int)age== 81 )
         prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyearp,ij);          prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyearp,ij,nres);
       else        else
         prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyearp,ij);          prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyearp,ij,nres);
       for(i=1;i<=nlstate;i++){        for(i=1;i<=nlstate;i++){
         gp[i] = prlim[i][i];          gp[i] = prlim[i][i];
         mgp[theta][i] = prlim[i][i];          mgp[theta][i] = prlim[i][i];
Line 5547  void cvevsij(double ***eij, double x[], Line 5573  void cvevsij(double ***eij, double x[],
       for(i=1; i<=npar; i++) /* Computes gradient */        for(i=1; i<=npar; i++) /* Computes gradient */
         xp[i] = x[i] - (i==theta ?delti[theta]:0);          xp[i] = x[i] - (i==theta ?delti[theta]:0);
       if((int)age==79 ||(int)age== 80 ||(int)age== 81 )        if((int)age==79 ||(int)age== 80 ||(int)age== 81 )
         prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyearp,ij);          prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyearp,ij,nres);
       else        else
         prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyearp,ij);          prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyearp,ij,nres);
       for(i=1;i<=nlstate;i++){        for(i=1;i<=nlstate;i++){
         gm[i] = prlim[i][i];          gm[i] = prlim[i][i];
         mgm[theta][i] = prlim[i][i];          mgm[theta][i] = prlim[i][i];
Line 6153  void printinggnuplot(char fileresu[], ch Line 6179  void printinggnuplot(char fileresu[], ch
   
   char dirfileres[132],optfileres[132];    char dirfileres[132],optfileres[132];
   char gplotcondition[132];    char gplotcondition[132];
   int cpt=0,k1=0,i=0,k=0,j=0,jk=0,k2=0,k3=0,ij=0,l=0;    int cpt=0,k1=0,i=0,k=0,j=0,jk=0,k2=0,k3=0,k4=0,ij=0,l=0;
   int lv=0, vlv=0, kl=0;    int lv=0, vlv=0, kl=0;
   int ng=0;    int ng=0;
   int vpopbased;    int vpopbased;
   int ioffset; /* variable offset for columns */    int ioffset; /* variable offset for columns */
     int nres=0; /* Index of resultline */
   
 /*   if((ficgp=fopen(optionfilegnuplot,"a"))==NULL) { */  /*   if((ficgp=fopen(optionfilegnuplot,"a"))==NULL) { */
 /*     printf("Problem with file %s",optionfilegnuplot); */  /*     printf("Problem with file %s",optionfilegnuplot); */
Line 6202  void printinggnuplot(char fileresu[], ch Line 6229  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 && selected(k1) ; k1 ++) { /* For each valid combination of covariate */      for(nres=1; nres <= nresult; nres++) /* For each resultline */
       /* plot [100000000000000000000:-100000000000000000000] "mysbiaspar/vplrmysbiaspar.txt to check */      for (k1=1; k1<= m ; k1 ++) { /* For each valid combination of covariate */
       fprintf(ficgp,"\n# 1st: Period (stable) prevalence with CI: 'VPL_' files ");      /* plot [100000000000000000000:-100000000000000000000] "mysbiaspar/vplrmysbiaspar.txt to check */
         if(TKresult[nres]!= k1)
           continue;
         /* We are interested in selected combination by the resultline */
         printf("\n# 1st: Period (stable) prevalence with CI: 'VPL_' files and live state =%d ", cpt);
         fprintf(ficgp,"\n# 1st: Period (stable) prevalence with CI: 'VPL_' files  and live state =%d ", cpt);
       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 */
         lv= decodtabm(k1,k,cptcoveff); /* Should be the value of the covariate corresponding to k1 combination */          lv= decodtabm(k1,k,cptcoveff); /* Should be the value of the covariate corresponding to k1 combination */
         /* decodtabm(1,1,4) = 1 because h=1  k= (1) 1  1  1 */          /* decodtabm(1,1,4) = 1 because h=1  k= (1) 1  1  1 */
Line 6212  void printinggnuplot(char fileresu[], ch Line 6244  void printinggnuplot(char fileresu[], ch
         /* decodtabm(13,3,4)= 2 because h=13 k=  1  1 (2) 2 */          /* decodtabm(13,3,4)= 2 because h=13 k=  1  1 (2) 2 */
         vlv= nbcode[Tvaraff[k]][lv]; /* vlv is the value of the covariate lv, 0 or 1 */          vlv= nbcode[Tvaraff[k]][lv]; /* vlv is the value of the covariate lv, 0 or 1 */
         /* For each combination of covariate k1 (V1=1, V3=0), we printed the current covariate k and its value vlv */          /* For each combination of covariate k1 (V1=1, V3=0), we printed the current covariate k and its value vlv */
           printf(" V%d=%d ",Tvaraff[k],vlv);
         fprintf(ficgp," V%d=%d ",Tvaraff[k],vlv);          fprintf(ficgp," V%d=%d ",Tvaraff[k],vlv);
       }        }
         for (k4=1; k4<= nsq; k4++){ /* For each selected (single) quantitative value */
           printf(" V%d=%f ",Tvqresult[nres][k4],Tqresult[nres][k4]);
           fprintf(ficgp," V%d=%f ",Tvqresult[nres][k4],Tqresult[nres][k4]);
         } 
         printf("\n#\n");
       fprintf(ficgp,"\n#\n");        fprintf(ficgp,"\n#\n");
       if(invalidvarcomb[k1]){        if(invalidvarcomb[k1]){
         fprintf(ficgp,"#Combination (%d) ignored because no cases \n",k1);           fprintf(ficgp,"#Combination (%d) ignored because no cases \n",k1); 
         continue;          continue;
       }        }
         
       fprintf(ficgp,"\nset out \"%s_%d-%d.svg\" \n",subdirf2(optionfilefiname,"V_"),cpt,k1);        fprintf(ficgp,"\nset out \"%s_%d-%d.svg\" \n",subdirf2(optionfilefiname,"V_"),cpt,k1);
       fprintf(ficgp,"\n#set out \"V_%s_%d-%d.svg\" \n",optionfilefiname,cpt,k1);        fprintf(ficgp,"\n#set out \"V_%s_%d-%d.svg\" \n",optionfilefiname,cpt,k1);
       fprintf(ficgp,"set xlabel \"Age\" \n\        fprintf(ficgp,"set xlabel \"Age\" \n\
 set ylabel \"Probability\" \n   \  set ylabel \"Probability\" \n             \
 set ter svg size 640, 480\n     \  set ter svg size 640, 480\n                                             \
 plot [%.f:%.f] \"%s\" every :::%d::%d u 1:2 \"%%lf",ageminpar,fage,subdirf2(fileresu,"VPL_"),k1-1,k1-1);  plot [%.f:%.f] \"%s\" every :::%d::%d u 1:2 \"%%lf",ageminpar,fage,subdirf2(fileresu,"VPL_"),k1-1,k1-1);
                                 
       for (i=1; i<= nlstate ; i ++) {        for (i=1; i<= nlstate ; i ++) {
         if (i==cpt) fprintf(ficgp," %%lf (%%lf)");          if (i==cpt) fprintf(ficgp," %%lf (%%lf)");
         else        fprintf(ficgp," %%*lf (%%*lf)");          else        fprintf(ficgp," %%*lf (%%*lf)");
Line 6273  plot [%.f:%.f] \"%s\" every :::%d::%d u Line 6311  plot [%.f:%.f] \"%s\" every :::%d::%d u
       fprintf(ficgp,"\nset out \n");        fprintf(ficgp,"\nset out \n");
     } /* k1 */      } /* k1 */
   } /* cpt */    } /* cpt */
   
     
   /*2 eme*/    /*2 eme*/
   for (k1=1; k1<= m ; k1 ++) {     for (k1=1; k1<= m ; k1 ++) { 
   
     fprintf(ficgp,"\n# 2nd: Total life expectancy with CI: 't' files ");      fprintf(ficgp,"\n# 2nd: Total life expectancy with CI: 't' files ");
       for(nres=1; nres <= nresult; nres++) /* For each resultline */
     for (k=1; k<=cptcoveff; k++){    /* For each covariate and each value */      for (k=1; k<=cptcoveff; k++){    /* For each covariate and each value */
         if(TKresult[nres]!= k)
           continue;
       lv= decodtabm(k1,k,cptcoveff); /* Should be the covariate number corresponding to k1 combination */        lv= decodtabm(k1,k,cptcoveff); /* Should be the covariate number corresponding to k1 combination */
       /* decodtabm(1,1,4) = 1 because h=1  k= (1) 1  1  1 */        /* decodtabm(1,1,4) = 1 because h=1  k= (1) 1  1  1 */
       /* decodtabm(1,2,4) = 1 because h=1  k=  1 (1) 1  1 */        /* decodtabm(1,2,4) = 1 because h=1  k=  1 (1) 1  1 */
       /* decodtabm(13,3,4)= 2 because h=13 k=  1  1 (2) 2 */        /* decodtabm(13,3,4)= 2 because h=13 k=  1  1 (2) 2 */
       vlv= nbcode[Tvaraff[k]][lv];        vlv= nbcode[Tvaraff[k]][lv];
       fprintf(ficgp," V%d=%d ",Tvaraff[k],vlv);        fprintf(ficgp," V%d=%d ",Tvaraff[k],vlv);
         for (k4=1; k4<= nsq; k4++){ /* For each selected (single) quantitative value */
           printf(" V%d=%f ",Tvqresult[nres][k4],Tqresult[nres][k4]);
           fprintf(ficgp," V%d=%f ",Tvqresult[nres][k4],Tqresult[nres][k4]);
         }
     }      }
     fprintf(ficgp,"\n#\n");      fprintf(ficgp,"\n#\n");
     if(invalidvarcomb[k1]){      if(invalidvarcomb[k1]){
Line 6322  plot [%.f:%.f] \"%s\" every :::%d::%d u Line 6368  plot [%.f:%.f] \"%s\" every :::%d::%d u
       } /* state */        } /* state */
     } /* vpopbased */      } /* vpopbased */
     fprintf(ficgp,"\nset out;set out \"%s_%d.svg\"; replot; set out; \n",subdirf2(optionfilefiname,"E_"),k1); /* Buggy gnuplot */      fprintf(ficgp,"\nset out;set out \"%s_%d.svg\"; replot; set out; \n",subdirf2(optionfilefiname,"E_"),k1); /* Buggy gnuplot */
   } /* k1 */    } /* k1 end 2 eme*/
                   
                   
   /*3eme*/    /*3eme*/
Line 6330  plot [%.f:%.f] \"%s\" every :::%d::%d u Line 6376  plot [%.f:%.f] \"%s\" every :::%d::%d u
   
     for (cpt=1; cpt<= nlstate ; cpt ++) {      for (cpt=1; cpt<= nlstate ; cpt ++) {
       fprintf(ficgp,"\n# 3d: Life expectancy with EXP_ files:  cov=%d state=%d",k1, cpt);        fprintf(ficgp,"\n# 3d: Life expectancy with EXP_ files:  cov=%d state=%d",k1, cpt);
         for(nres=1; nres <= nresult; nres++) /* For each resultline */
       for (k=1; k<=cptcoveff; k++){    /* For each covariate and each value */        for (k=1; k<=cptcoveff; k++){    /* For each covariate and each value */
           if(TKresult[nres]!= k)
             continue;
         lv= decodtabm(k1,k,cptcoveff); /* Should be the covariate number corresponding to k1 combination */          lv= decodtabm(k1,k,cptcoveff); /* Should be the covariate number corresponding to k1 combination */
         /* decodtabm(1,1,4) = 1 because h=1  k= (1) 1  1  1 */          /* decodtabm(1,1,4) = 1 because h=1  k= (1) 1  1  1 */
         /* decodtabm(1,2,4) = 1 because h=1  k=  1 (1) 1  1 */          /* decodtabm(1,2,4) = 1 because h=1  k=  1 (1) 1  1 */
         /* decodtabm(13,3,4)= 2 because h=13 k=  1  1 (2) 2 */          /* decodtabm(13,3,4)= 2 because h=13 k=  1  1 (2) 2 */
         vlv= nbcode[Tvaraff[k]][lv];          vlv= nbcode[Tvaraff[k]][lv];
         fprintf(ficgp," V%d=%d ",Tvaraff[k],vlv);          fprintf(ficgp," V%d=%d ",Tvaraff[k],vlv);
           for (k4=1; k4<= nsq; k4++){ /* For each selected (single) quantitative value */
             printf(" V%d=%f ",Tvqresult[nres][k4],Tqresult[nres][k4]);
             fprintf(ficgp," V%d=%f ",Tvqresult[nres][k4],Tqresult[nres][k4]);
           }       
       }        }
       fprintf(ficgp,"\n#\n");        fprintf(ficgp,"\n#\n");
       if(invalidvarcomb[k1]){        if(invalidvarcomb[k1]){
Line 6898  plot [%.f:%.f]  ", ageminpar, agemaxpar) Line 6951  plot [%.f:%.f]  ", ageminpar, agemaxpar)
      } /* end bad */       } /* end bad */
                                   
      for (age=bage; age<=fage; age++){       for (age=bage; age<=fage; age++){
        printf("%d %d ", cptcod, (int)age);         /* printf("%d %d ", cptcod, (int)age); */
        sumnewp[cptcod]=0.;         sumnewp[cptcod]=0.;
        sumnewm[cptcod]=0.;         sumnewm[cptcod]=0.;
        for (i=1; i<=nlstate;i++){         for (i=1; i<=nlstate;i++){
Line 6937  plot [%.f:%.f]  ", ageminpar, agemaxpar) Line 6990  plot [%.f:%.f]  ", ageminpar, agemaxpar)
     
   
 /************** Forecasting ******************/  /************** Forecasting ******************/
 void prevforecast(char fileres[], double anproj1, double mproj1, double jproj1, double ageminpar, double agemax, double dateprev1, double dateprev2, int mobilav, double bage, double fage, int firstpass, int lastpass, double anproj2, double p[], int cptcoveff){   void prevforecast(char fileres[], double anproj1, double mproj1, double jproj1, double ageminpar, double agemax, double dateprev1, double dateprev2, int mobilav, double bage, double fage, int firstpass, int lastpass, double anproj2, double p[], int cptcoveff){
   /* proj1, year, month, day of starting projection     /* proj1, year, month, day of starting projection 
      agemin, agemax range of age       agemin, agemax range of age
      dateprev1 dateprev2 range of dates during which prevalence is computed       dateprev1 dateprev2 range of dates during which prevalence is computed
      anproj2 year of en of projection (same day and month as proj1).       anproj2 year of en of projection (same day and month as proj1).
   */    */
   int yearp, stepsize, hstepm, nhstepm, j, k, cptcod, i, h, i1;     int yearp, stepsize, hstepm, nhstepm, j, k, cptcod, i, h, i1, k4, nres=0;
   double agec; /* generic age */    double agec; /* generic age */
   double agelim, ppij, yp,yp1,yp2,jprojmean,mprojmean,anprojmean;    double agelim, ppij, yp,yp1,yp2,jprojmean,mprojmean,anprojmean;
   double *popeffectif,*popcount;    double *popeffectif,*popcount;
Line 6965  void prevforecast(char fileres[], double Line 7018  void prevforecast(char fileres[], double
     printf("Problem with forecast resultfile: %s\n", fileresf);      printf("Problem with forecast resultfile: %s\n", fileresf);
     fprintf(ficlog,"Problem with forecast resultfile: %s\n", fileresf);      fprintf(ficlog,"Problem with forecast resultfile: %s\n", fileresf);
   }    }
   printf("Computing forecasting: result on file '%s', please wait... \n", fileresf);    printf("\nComputing forecasting: result on file '%s', please wait... \n", fileresf);
   fprintf(ficlog,"Computing forecasting: result on file '%s', please wait... \n", fileresf);    fprintf(ficlog,"\nComputing forecasting: result on file '%s', please wait... \n", fileresf);
   
   if (cptcoveff==0) ncodemax[cptcoveff]=1;    if (cptcoveff==0) ncodemax[cptcoveff]=1;
   
Line 6997  void prevforecast(char fileres[], double Line 7050  void prevforecast(char fileres[], double
   fprintf(ficresf,"#****** Routine prevforecast **\n");    fprintf(ficresf,"#****** Routine prevforecast **\n");
       
 /*            if (h==(int)(YEARM*yearp)){ */  /*            if (h==(int)(YEARM*yearp)){ */
   for(k=1;k<=i1;k++){    for(nres=1; nres <= nresult; nres++) /* For each resultline */
     for(k=1; k<=i1;k++){
       if(TKresult[nres]!= k)
         continue;
     if(invalidvarcomb[k]){      if(invalidvarcomb[k]){
       printf("\nCombination (%d) projection ignored because no cases \n",k);         printf("\nCombination (%d) projection ignored because no cases \n",k); 
       continue;        continue;
Line 7006  void prevforecast(char fileres[], double Line 7062  void prevforecast(char fileres[], double
     for(j=1;j<=cptcoveff;j++) {      for(j=1;j<=cptcoveff;j++) {
       fprintf(ficresf," V%d (=) %d",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);        fprintf(ficresf," V%d (=) %d",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
     }      }
       for (k4=1; k4<= nsq; k4++){ /* For each selected (single) quantitative value */
         printf(" V%d=%f ",Tvqresult[nres][k4],Tqresult[nres][k4]);
         fprintf(ficlog," V%d=%f ",Tvqresult[nres][k4],Tqresult[nres][k4]);
       }
     fprintf(ficresf," yearproj age");      fprintf(ficresf," yearproj age");
     for(j=1; j<=nlstate+ndeath;j++){       for(j=1; j<=nlstate+ndeath;j++){ 
       for(i=1; i<=nlstate;i++)                for(i=1; i<=nlstate;i++)        
Line 7020  void prevforecast(char fileres[], double Line 7080  void prevforecast(char fileres[], double
         nhstepm = nhstepm/hstepm;           nhstepm = nhstepm/hstepm; 
         p3mat=ma3x(1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);          p3mat=ma3x(1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);
         oldm=oldms;savm=savms;          oldm=oldms;savm=savms;
         hpxij(p3mat,nhstepm,agec,hstepm,p,nlstate,stepm,oldm,savm, k);          hpxij(p3mat,nhstepm,agec,hstepm,p,nlstate,stepm,oldm,savm, k,nres);
                   
         for (h=0; h<=nhstepm; h++){          for (h=0; h<=nhstepm; h++){
           if (h*hstepm/YEARM*stepm ==yearp) {            if (h*hstepm/YEARM*stepm ==yearp) {
Line 7890  int readdata(char datafile[], int firsto Line 7950  int readdata(char datafile[], int firsto
   
 void removefirstspace(char **stri){/*, char stro[]) {*/  void removefirstspace(char **stri){/*, char stro[]) {*/
   char *p1 = *stri, *p2 = *stri;    char *p1 = *stri, *p2 = *stri;
   if (*p2 == ' ')    while (*p2 == ' ')
     p2++;       p2++; 
   /* while ((*p1++ = *p2++) !=0) */    /* while ((*p1++ = *p2++) !=0) */
   /*   ; */    /*   ; */
Line 7901  void removefirstspace(char **stri){/*, c Line 7961  void removefirstspace(char **stri){/*, c
   *stri=p2;     *stri=p2; 
 }  }
   
 int decoderesult ( char resultline[])  int decoderesult ( char resultline[], int nres)
 /**< This routine decode one result line and returns the combination # of dummy covariates only **/  /**< This routine decode one result line and returns the combination # of dummy covariates only **/
 {  {
   int j=0, k=0, k1=0, k2=0, match=0;    int j=0, k=0, k1=0, k2=0, k3=0, k4=0, match=0, k2q=0, k3q=0, k4q=0;
   char resultsav[MAXLINE];    char resultsav[MAXLINE];
   int resultmodel[MAXLINE];    int resultmodel[MAXLINE];
   int modelresult[MAXLINE];    int modelresult[MAXLINE];
Line 7942  int decoderesult ( char resultline[]) Line 8002  int decoderesult ( char resultline[])
     if (nbocc(stra,'=') >0)      if (nbocc(stra,'=') >0)
       strcpy(resultsav,stra); /* and analyzes it */        strcpy(resultsav,stra); /* and analyzes it */
   }    }
   /* Checking if no missing or useless values in comparison of current model needs */    /* Checking for missing or useless values in comparison of current model needs */
   for(k1=1; k1<= cptcovt ;k1++){ /* model line */    for(k1=1; k1<= cptcovt ;k1++){ /* model line */
     if(Typevar[k1]==0){      if(Typevar[k1]==0){
       match=0;        match=0;
Line 7958  int decoderesult ( char resultline[]) Line 8018  int decoderesult ( char resultline[])
       }        }
     }      }
   }    }
       /* Checking for missing or useless values in comparison of current model needs */
   for(k2=1; k2 <=j;k2++){ /* result line */    for(k2=1; k2 <=j;k2++){ /* result line V4=1 V5=24.1 V3=1  V2=8 V1=0 */
     match=0;      match=0;
     for(k1=1; k1<= cptcovt ;k1++){ /* model line */      for(k1=1; k1<= cptcovt ;k1++){ /* model line V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */
       if(Typevar[k1]==0){        if(Typevar[k1]==0){ /* Single */
         if(Tvar[k1]==Tvarsel[k2]) {          if(Tvar[k1]==Tvarsel[k2]) { /* Tvar[2]=5 == Tvarsel[1]=4   */
           resultmodel[k1]=k2;            resultmodel[k1]=k2;  /* resultmodel[2]=1 resultmodel[1]=2  resultmodel[3]=3  resultmodel[6]=4 resultmodel[9]=5 */
           ++match;            ++match;
         }          }
       }        }
Line 7975  int decoderesult ( char resultline[]) Line 8035  int decoderesult ( char resultline[])
       printf("Error in result line: %d doubled; result: %s, model=%s\n",k2, resultline, model);        printf("Error in result line: %d doubled; result: %s, model=%s\n",k2, resultline, model);
     }      }
   }    }
           
   /* We need to deduce which combination number is chosen and save quantitative values */    /* We need to deduce which combination number is chosen and save quantitative values */
     /* model line V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */
     /* result line V4=1 V5=25.1 V3=0  V2=8 V1=1 */
     /* should give a combination of dummy V4=1, V3=0, V1=1 => V4*2**(0) + V3*2**(1) + V1*2**(2) = 5 + (1offset) = 6*/
     /* result line V4=1 V5=24.1 V3=1  V2=8 V1=0 */
     /* should give a combination of dummy V4=1, V3=1, V1=0 => V4*2**(0) + V3*2**(1) + V1*2**(2) = 3 + (1offset) = 4*/
     /*    1 0 0 0 */
     /*    2 1 0 0 */
     /*    3 0 1 0 */ 
     /*    4 1 1 0 */ /* V4=1, V3=1, V1=0 */
     /*    5 0 0 1 */
     /*    6 1 0 1 */ /* V4=1, V3=0, V1=1 */
     /*    7 0 1 1 */
     /*    8 1 1 1 */
     for(k1=1, k=0, k4=0, k4q=0; k1 <=cptcovt;k1++){ /* model line */
       if( Dummy[k1]==0 && Typevar[k1]==0 ){ /* Single dummy */
         k3= resultmodel[k1]; /* resultmodel[2] = 1=k3 */
         k2=(int)Tvarsel[k3]; /*  Tvarsel[resultmodel[2]]= Tvarsel[1] = 4=k2 */
         k+=Tvalsel[k3]*pow(2,k4);  /*  Tvalsel[1]=1  */
         Tresult[nres][k4+1]=Tvalsel[k3];
         Tvresult[nres][k4+1]=(int)Tvarsel[k3];
         printf("Decoderesult Dummy k=%d, V(k2=V%d)= Tvalsel[%d]=%d, 2**(%d)\n",k, k2, k3, (int)Tvalsel[k3], k4);
         k4++;;
       }  else if( Dummy[k1]==1 && Typevar[k1]==0 ){ /* Single quantitative */
         k3q= resultmodel[k1]; /* resultmodel[2] = 1=k3 */
         k2q=(int)Tvarsel[k3q]; /*  Tvarsel[resultmodel[2]]= Tvarsel[1] = 4=k2 */
         Tqresult[nres][k4q+1]=Tvalsel[k3q];
         Tvqresult[nres][k4q+1]=(int)Tvarsel[k3q];
         printf("Decoderesult Quantitative nres=%d, V(k2q=V%d)= Tvalsel[%d]=%d, Tvarsel[%d]=%f\n",nres, k2q, k3q, Tvarsel[k3q], k3q, Tvalsel[k3q]);
         k4q++;;
       }
     }
       
     TKresult[nres]=++k; /* Combination for the nresult and the model */
   return (0);    return (0);
 }  }
 int selected( int kvar){ /* Selected combination of covariates */  
   if(Tvarsel[kvar])  
     return (0);  
   else  
     return(1);  
 }  
 int decodemodel( char model[], int lastobs)  int decodemodel( char model[], int lastobs)
  /**< This routine decodes the model and returns:   /**< 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
Line 8795  void syscompilerinfo(int logged) Line 8882  void syscompilerinfo(int logged)
   
 int prevalence_limit(double *p, double **prlim, double ageminpar, double agemaxpar, double ftolpl, int *ncvyearp){  int prevalence_limit(double *p, double **prlim, double ageminpar, double agemaxpar, double ftolpl, int *ncvyearp){
   /*--------------- Prevalence limit  (period or stable prevalence) --------------*/    /*--------------- Prevalence limit  (period or stable prevalence) --------------*/
   int i, j, k, i1 ;    int i, j, k, i1, k4=0, nres=0 ;
   /* double ftolpl = 1.e-10; */    /* double ftolpl = 1.e-10; */
   double age, agebase, agelim;    double age, agebase, agelim;
   double tot;    double tot;
Line 8823  int prevalence_limit(double *p, double * Line 8910  int prevalence_limit(double *p, double *
   i1=pow(2,cptcoveff); /* Number of combination of dummy covariates */    i1=pow(2,cptcoveff); /* Number of combination of dummy covariates */
   if (cptcovn < 1){i1=1;}    if (cptcovn < 1){i1=1;}
   
     for(nres=1; nres <= nresult; nres++) /* For each resultline */
   for(k=1; k<=i1;k++){    for(k=1; k<=i1;k++){
       if(TKresult[nres]!= k)
         continue;
   
   /* for(cptcov=1,k=0;cptcov<=i1;cptcov++){ */    /* for(cptcov=1,k=0;cptcov<=i1;cptcov++){ */
     /* for(cptcov=1,k=0;cptcov<=1;cptcov++){ */      /* for(cptcov=1,k=0;cptcov<=1;cptcov++){ */
     //for(cptcod=1;cptcod<=ncodemax[cptcov];cptcod++){      //for(cptcod=1;cptcod<=ncodemax[cptcov];cptcod++){
Line 8838  int prevalence_limit(double *p, double * Line 8929  int prevalence_limit(double *p, double *
       printf(" V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);        printf(" V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
       fprintf(ficlog," V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);        fprintf(ficlog," V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
     }      }
       for (k4=1; k4<= nsq; k4++){ /* For each selected (single) quantitative value */
         printf(" V%d=%f ",Tvqresult[nres][k4],Tqresult[nres][k4]);
         fprintf(ficlog," V%d=%f ",Tvqresult[nres][k4],Tqresult[nres][k4]);
       }
     fprintf(ficrespl,"******\n");      fprintf(ficrespl,"******\n");
     printf("******\n");      printf("******\n");
     fprintf(ficlog,"******\n");      fprintf(ficlog,"******\n");
Line 8857  int prevalence_limit(double *p, double * Line 8952  int prevalence_limit(double *p, double *
           
     for (age=agebase; age<=agelim; age++){      for (age=agebase; age<=agelim; age++){
       /* for (age=agebase; age<=agebase; age++){ */        /* for (age=agebase; age<=agebase; age++){ */
       prevalim(prlim, nlstate, p, age, oldm, savm, ftolpl, ncvyearp, k);        prevalim(prlim, nlstate, p, age, oldm, savm, ftolpl, ncvyearp, k, nres);
       fprintf(ficrespl,"%.0f ",age );        fprintf(ficrespl,"%.0f ",age );
       for(j=1;j<=cptcoveff;j++)        for(j=1;j<=cptcoveff;j++)
         fprintf(ficrespl,"%d %d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);          fprintf(ficrespl,"%d %d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
Line 8879  int back_prevalence_limit(double *p, dou Line 8974  int back_prevalence_limit(double *p, dou
         /* Computes the back prevalence limit  for any combination      of covariate values           /* Computes the back prevalence limit  for any combination      of covariate values 
    * at any age between ageminpar and agemaxpar     * at any age between ageminpar and agemaxpar
          */           */
   int i, j, k, i1 ;    int i, j, k, i1, nres=0 ;
   /* double ftolpl = 1.e-10; */    /* double ftolpl = 1.e-10; */
   double age, agebase, agelim;    double age, agebase, agelim;
   double tot;    double tot;
Line 8910  int back_prevalence_limit(double *p, dou Line 9005  int back_prevalence_limit(double *p, dou
   i1=pow(2,cptcoveff);    i1=pow(2,cptcoveff);
   if (cptcovn < 1){i1=1;}    if (cptcovn < 1){i1=1;}
       
   for(k=1; k<=i1;k++){     for(nres=1; nres <= nresult; nres++) /* For each resultline */
     for(k=1; k<=i1;k++){ /* For any combination of dummy covariates, fixed and varying */
       if(TKresult[nres]!= k)
         continue;
     //printf("cptcov=%d cptcod=%d codtab=%d\n",cptcov, cptcod,codtabm(cptcod,cptcov));      //printf("cptcov=%d cptcod=%d codtab=%d\n",cptcov, cptcod,codtabm(cptcod,cptcov));
     fprintf(ficresplb,"#******");      fprintf(ficresplb,"#******");
     printf("#******");      printf("#******");
Line 8920  int back_prevalence_limit(double *p, dou Line 9018  int back_prevalence_limit(double *p, dou
       printf(" V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);        printf(" V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
       fprintf(ficlog," V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);        fprintf(ficlog," V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
     }      }
       for (j=1; j<= nsq; j++){ /* For each selected (single) quantitative value */
         printf(" V%d=%f ",Tvqresult[nres][j],Tqresult[nres][j]);
         fprintf(ficresplb," V%d=%f ",Tvqresult[nres][j],Tqresult[nres][j]);
         fprintf(ficlog," V%d=%f ",Tvqresult[nres][j],Tqresult[nres][j]);
       }
     fprintf(ficresplb,"******\n");      fprintf(ficresplb,"******\n");
     printf("******\n");      printf("******\n");
     fprintf(ficlog,"******\n");      fprintf(ficlog,"******\n");
Line 8978  int hPijx(double *p, int bage, int fage) Line 9081  int hPijx(double *p, int bage, int fage)
   int agelim;    int agelim;
   int hstepm;    int hstepm;
   int nhstepm;    int nhstepm;
   int h, i, i1, j, k;    int h, i, i1, j, k, k4, nres=0;
   
   double agedeb;    double agedeb;
   double ***p3mat;    double ***p3mat;
Line 9005  int hPijx(double *p, int bage, int fage) Line 9108  int hPijx(double *p, int bage, int fage)
                 /* for(cptcov=1,k=0;cptcov<=i1;cptcov++){ */                  /* for(cptcov=1,k=0;cptcov<=i1;cptcov++){ */
                 /*    /\*for(cptcod=1;cptcod<=ncodemax[cptcov];cptcod++){*\/ */                  /*    /\*for(cptcod=1;cptcod<=ncodemax[cptcov];cptcod++){*\/ */
                 /*      k=k+1;  */                  /*      k=k+1;  */
     for (k=1; k <= (int) pow(2,cptcoveff); k++){      for(nres=1; nres <= nresult; nres++) /* For each resultline */
       for(k=1; k<=i1;k++){
         if(TKresult[nres]!= k)
           continue;
       fprintf(ficrespij,"\n#****** ");        fprintf(ficrespij,"\n#****** ");
       for(j=1;j<=cptcoveff;j++)         for(j=1;j<=cptcoveff;j++) 
         fprintf(ficrespij,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);          fprintf(ficrespij,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
         for (k4=1; k4<= nsq; k4++){ /* For each selected (single) quantitative value */
           printf(" V%d=%f ",Tvqresult[nres][k4],Tqresult[nres][k4]);
           fprintf(ficrespij," V%d=%f ",Tvqresult[nres][k4],Tqresult[nres][k4]);
         }
       fprintf(ficrespij,"******\n");        fprintf(ficrespij,"******\n");
               
       for (agedeb=fage; agedeb>=bage; agedeb--){ /* If stepm=6 months */        for (agedeb=fage; agedeb>=bage; agedeb--){ /* If stepm=6 months */
Line 9019  int hPijx(double *p, int bage, int fage) Line 9129  int hPijx(double *p, int bage, int fage)
                   
         p3mat=ma3x(1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);          p3mat=ma3x(1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);
         oldm=oldms;savm=savms;          oldm=oldms;savm=savms;
         hpxij(p3mat,nhstepm,agedeb,hstepm,p,nlstate,stepm,oldm,savm, k);            hpxij(p3mat,nhstepm,agedeb,hstepm,p,nlstate,stepm,oldm,savm, k, nres);  
         fprintf(ficrespij,"# Cov Agex agex+h hpijx with i,j=");          fprintf(ficrespij,"# Cov Agex agex+h hpijx with i,j=");
         for(i=1; i<=nlstate;i++)          for(i=1; i<=nlstate;i++)
           for(j=1; j<=nlstate+ndeath;j++)            for(j=1; j<=nlstate+ndeath;j++)
Line 9145  int main(int argc, char *argv[]) Line 9255  int main(int argc, char *argv[])
   int itimes;    int itimes;
   int NDIM=2;    int NDIM=2;
   int vpopbased=0;    int vpopbased=0;
     int nres=0;
   
   char ca[32], cb[32];    char ca[32], cb[32];
   /*  FILE *fichtm; *//* Html File */    /*  FILE *fichtm; *//* Html File */
Line 10548  Please run with mle=-1 to get a correct Line 10659  Please run with mle=-1 to get a correct
     /* 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 */      /* Results */
       nresult=0;
     while(fgets(line, MAXLINE, ficpar)) {      while(fgets(line, MAXLINE, ficpar)) {
       /* If line starts with a # it is a comment */        /* If line starts with a # it is a comment */
       if (line[0] == '#') {        if (line[0] == '#') {
Line 10565  Please run with mle=-1 to get a correct Line 10677  Please run with mle=-1 to get a correct
       else if (num_filled != 1){        else if (num_filled != 1){
         printf("ERROR %d: result line should be at minimum 'result=' %s\n",num_filled, line);          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);        nresult++; /* Sum of resultlines */
       decoderesult(resultline);        printf("Result %d: result=%s\n",nresult, resultline);
         if(nresult > MAXRESULTLINES){
           printf("ERROR: Current version of IMaCh limits the number of resultlines to %d, you used %d\n",MAXRESULTLINES,nresult);
           fprintf(ficlog,"ERROR: Current version of IMaCh limits the number of resultlines to %d, you used %d\n",MAXRESULTLINES,nresult);
           goto end;
         }
         decoderesult(resultline, nresult); /* Fills TKresult[nresult] combination and Tresult[nresult][k4+1] combination values */
       while(fgets(line, MAXLINE, ficpar)) {        while(fgets(line, MAXLINE, ficpar)) {
         /* If line starts with a # it is a comment */          /* If line starts with a # it is a comment */
         if (line[0] == '#') {          if (line[0] == '#') {
Line 10653  Please run with mle=-1 to get a correct Line 10771  Please run with mle=-1 to get a correct
             mobaverages[i][j][k]=0.;              mobaverages[i][j][k]=0.;
       mobaverage=mobaverages;        mobaverage=mobaverages;
       if (mobilav!=0) {        if (mobilav!=0) {
           printf("Movingaveraging observed prevalence\n");
         if (movingaverage(probs, ageminpar, agemaxpar, mobaverage, mobilav)!=0){          if (movingaverage(probs, ageminpar, agemaxpar, mobaverage, mobilav)!=0){
           fprintf(ficlog," Error in movingaverage mobilav=%d\n",mobilav);            fprintf(ficlog," Error in movingaverage mobilav=%d\n",mobilav);
           printf(" Error in movingaverage mobilav=%d\n",mobilav);            printf(" Error in movingaverage mobilav=%d\n",mobilav);
Line 10661  Please run with mle=-1 to get a correct Line 10780  Please run with mle=-1 to get a correct
       /* /\* Prevalence for each covariates in probs[age][status][cov] *\/ */        /* /\* Prevalence for each covariates in probs[age][status][cov] *\/ */
       /* prevalence(probs, ageminpar, agemaxpar, s, agev, nlstate, imx, Tvar, nbcode, ncodemax, mint, anint, dateprev1, dateprev2, firstpass, lastpass); */        /* prevalence(probs, ageminpar, agemaxpar, s, agev, nlstate, imx, Tvar, nbcode, ncodemax, mint, anint, dateprev1, dateprev2, firstpass, lastpass); */
       else if (mobilavproj !=0) {        else if (mobilavproj !=0) {
           printf("Movingaveraging projected observed prevalence\n");
         if (movingaverage(probs, ageminpar, agemaxpar, mobaverage, mobilavproj)!=0){          if (movingaverage(probs, ageminpar, agemaxpar, mobaverage, mobilavproj)!=0){
           fprintf(ficlog," Error in movingaverage mobilavproj=%d\n",mobilavproj);            fprintf(ficlog," Error in movingaverage mobilavproj=%d\n",mobilavproj);
           printf(" Error in movingaverage mobilavproj=%d\n",mobilavproj);            printf(" Error in movingaverage mobilavproj=%d\n",mobilavproj);
Line 10716  Please run with mle=-1 to get a correct Line 10836  Please run with mle=-1 to get a correct
     printf("Computing Health Expectancies: result on file '%s' ...", filerese);fflush(stdout);      printf("Computing Health Expectancies: result on file '%s' ...", filerese);fflush(stdout);
     fprintf(ficlog,"Computing Health Expectancies: result on file '%s' ...", filerese);fflush(ficlog);      fprintf(ficlog,"Computing Health Expectancies: result on file '%s' ...", filerese);fflush(ficlog);
                                   
     for (k=1; k <= (int) pow(2,cptcoveff); k++){ /* For any combination of dummy covariates, fixed and varying */      i1=pow(2,cptcoveff); /* Number of combination of dummy covariates */
       if (cptcovn < 1){i1=1;}
       
       for(nres=1; nres <= nresult; nres++) /* For each resultline */
       for(k=1; k<=i1;k++){ /* For any combination of dummy covariates, fixed and varying */
         if(TKresult[nres]!= k)
           continue;
       fprintf(ficreseij,"\n#****** ");        fprintf(ficreseij,"\n#****** ");
         printf("\n#****** ");
       for(j=1;j<=cptcoveff;j++) {        for(j=1;j<=cptcoveff;j++) {
         fprintf(ficreseij,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);          fprintf(ficreseij,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
           printf("V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
         }
         for (j=1; j<= nsq; j++){ /* For each selected (single) quantitative value */
           printf(" V%d=%f ",Tvqresult[nres][j],Tqresult[nres][j]);
           fprintf(ficreseij," V%d=%f ",Tvqresult[nres][j],Tqresult[nres][j]);
       }        }
       fprintf(ficreseij,"******\n");        fprintf(ficreseij,"******\n");
         printf("******\n");
               
       eij=ma3x(1,nlstate,1,nlstate,(int) bage, (int) fage);        eij=ma3x(1,nlstate,1,nlstate,(int) bage, (int) fage);
       oldm=oldms;savm=savms;        oldm=oldms;savm=savms;
       evsij(eij, p, nlstate, stepm, (int) bage, (int)fage, oldm, savm, k, estepm, strstart);          evsij(eij, p, nlstate, stepm, (int) bage, (int)fage, oldm, savm, k, estepm, strstart, nres);  
               
       free_ma3x(eij,1,nlstate,1,nlstate,(int) bage, (int)fage);        free_ma3x(eij,1,nlstate,1,nlstate,(int) bage, (int)fage);
     }      }
Line 10776  Please run with mle=-1 to get a correct Line 10909  Please run with mle=-1 to get a correct
     /*for(cptcov=1,k=0;cptcov<=i1;cptcov++){      /*for(cptcov=1,k=0;cptcov<=i1;cptcov++){
       for(cptcod=1;cptcod<=ncodemax[cptcov];cptcod++){*/        for(cptcod=1;cptcod<=ncodemax[cptcov];cptcod++){*/
                       
     for (k=1; k <= (int) pow(2,cptcoveff); k++){      i1=pow(2,cptcoveff); /* Number of combination of dummy covariates */
       printf("\n#****** ");      if (cptcovn < 1){i1=1;}
       fprintf(ficrest,"\n#****** ");      
       fprintf(ficlog,"\n#****** ");      for(nres=1; nres <= nresult; nres++) /* For each resultline */
       for(k=1; k<=i1;k++){ /* For any combination of dummy covariates, fixed and varying */
         if(TKresult[nres]!= k)
           continue;
         printf("\n#****** Selected:");
         fprintf(ficrest,"\n#****** Selected:");
         fprintf(ficlog,"\n#****** Selected:");
       for(j=1;j<=cptcoveff;j++){         for(j=1;j<=cptcoveff;j++){ 
         printf("V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);          printf("V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
         fprintf(ficrest,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);          fprintf(ficrest,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
         fprintf(ficlog,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);          fprintf(ficlog,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
       }        }
         for (j=1; j<= nsq; j++){ /* For each selected (single) quantitative value */
           printf(" V%d=%f ",Tvqresult[nres][j],Tqresult[nres][j]);
           fprintf(ficrest," V%d=%f ",Tvqresult[nres][j],Tqresult[nres][j]);
           fprintf(ficlog," V%d=%f ",Tvqresult[nres][j],Tqresult[nres][j]);
         } 
       fprintf(ficrest,"******\n");        fprintf(ficrest,"******\n");
       fprintf(ficlog,"******\n");        fprintf(ficlog,"******\n");
       printf("******\n");        printf("******\n");
Line 10795  Please run with mle=-1 to get a correct Line 10939  Please run with mle=-1 to get a correct
         fprintf(ficresstdeij,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);          fprintf(ficresstdeij,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
         fprintf(ficrescveij,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);          fprintf(ficrescveij,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
       }        }
         for (j=1; j<= nsq; j++){ /* For each selected (single) quantitative value */
           fprintf(ficresstdeij," V%d=%f ",Tvqresult[nres][j],Tqresult[nres][j]);
           fprintf(ficrescveij," V%d=%f ",Tvqresult[nres][j],Tqresult[nres][j]);
         } 
       fprintf(ficresstdeij,"******\n");        fprintf(ficresstdeij,"******\n");
       fprintf(ficrescveij,"******\n");        fprintf(ficrescveij,"******\n");
               
       fprintf(ficresvij,"\n#****** ");        fprintf(ficresvij,"\n#****** ");
       for(j=1;j<=cptcoveff;j++)         for(j=1;j<=cptcoveff;j++) 
         fprintf(ficresvij,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);          fprintf(ficresvij,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
         for (j=1; j<= nsq; j++){ /* For each selected (single) quantitative value */
           fprintf(ficresvij," V%d=%f ",Tvqresult[nres][j],Tqresult[nres][j]);
         } 
       fprintf(ficresvij,"******\n");        fprintf(ficresvij,"******\n");
               
       eij=ma3x(1,nlstate,1,nlstate,(int) bage, (int) fage);        eij=ma3x(1,nlstate,1,nlstate,(int) bage, (int) fage);
       oldm=oldms;savm=savms;        oldm=oldms;savm=savms;
       printf(" cvevsij combination#=%d, ",k);        printf(" cvevsij ");
       fprintf(ficlog, " cvevsij combination#=%d, ",k);        fprintf(ficlog, " cvevsij ");
       cvevsij(eij, p, nlstate, stepm, (int) bage, (int)fage, oldm, savm, k, estepm, delti, matcov, strstart);        cvevsij(eij, p, nlstate, stepm, (int) bage, (int)fage, oldm, savm, k, estepm, delti, matcov, strstart, nres);
       printf(" end cvevsij \n ");        printf(" end cvevsij \n ");
       fprintf(ficlog, " end cvevsij \n ");        fprintf(ficlog, " end cvevsij \n ");
               
Line 10824  Please run with mle=-1 to get a correct Line 10975  Please run with mle=-1 to get a correct
         cptcod= 0; /* To be deleted */          cptcod= 0; /* To be deleted */
         printf("varevsij vpopbased=%d \n",vpopbased);          printf("varevsij vpopbased=%d \n",vpopbased);
         fprintf(ficlog, "varevsij vpopbased=%d \n",vpopbased);          fprintf(ficlog, "varevsij vpopbased=%d \n",vpopbased);
         varevsij(optionfilefiname, vareij, matcov, p, delti, nlstate, stepm, (int) bage, (int) fage, oldm, savm, prlim, ftolpl, &ncvyear, k, estepm, cptcov,cptcod,vpopbased,mobilav, strstart); /* cptcod not initialized Intel */          varevsij(optionfilefiname, vareij, matcov, p, delti, nlstate, stepm, (int) bage, (int) fage, oldm, savm, prlim, ftolpl, &ncvyear, k, estepm, cptcov,cptcod,vpopbased,mobilav, strstart, nres); /* cptcod not initialized Intel */
         fprintf(ficrest,"# Total life expectancy with std error and decomposition into time to be expected in each health state\n#  (weighted average of eij where weights are ");          fprintf(ficrest,"# Total life expectancy with std error and decomposition into time to be expected in each health state\n#  (weighted average of eij where weights are ");
         if(vpopbased==1)          if(vpopbased==1)
           fprintf(ficrest,"the age specific prevalence observed (cross-sectionally) in the population i.e cross-sectionally\n in each health state (popbased=1) (mobilav=%d)\n",mobilav);            fprintf(ficrest,"the age specific prevalence observed (cross-sectionally) in the population i.e cross-sectionally\n in each health state (popbased=1) (mobilav=%d)\n",mobilav);
Line 10838  Please run with mle=-1 to get a correct Line 10989  Please run with mle=-1 to get a correct
         printf("Computing age specific period (stable) prevalences in each health state \n");          printf("Computing age specific period (stable) prevalences in each health state \n");
         fprintf(ficlog,"Computing age specific period (stable) prevalences in each health state \n");          fprintf(ficlog,"Computing age specific period (stable) prevalences in each health state \n");
         for(age=bage; age <=fage ;age++){          for(age=bage; age <=fage ;age++){
           prevalim(prlim, nlstate, p, age, oldm, savm, ftolpl, &ncvyear, k); /*ZZ Is it the correct prevalim */            prevalim(prlim, nlstate, p, age, oldm, savm, ftolpl, &ncvyear, k, nres); /*ZZ Is it the correct prevalim */
           if (vpopbased==1) {            if (vpopbased==1) {
             if(mobilav ==0){              if(mobilav ==0){
               for(i=1; i<=nlstate;i++)                for(i=1; i<=nlstate;i++)
Line 10875  Please run with mle=-1 to get a correct Line 11026  Please run with mle=-1 to get a correct
       free_ma3x(eij,1,nlstate,1,nlstate,(int) bage, (int)fage);        free_ma3x(eij,1,nlstate,1,nlstate,(int) bage, (int)fage);
       free_ma3x(vareij,1,nlstate,1,nlstate,(int) bage, (int)fage);        free_ma3x(vareij,1,nlstate,1,nlstate,(int) bage, (int)fage);
       free_vector(epj,1,nlstate+1);        free_vector(epj,1,nlstate+1);
       printf("done \n");fflush(stdout);        printf("done selection\n");fflush(stdout);
       fprintf(ficlog,"done\n");fflush(ficlog);        fprintf(ficlog,"done selection\n");fflush(ficlog);
               
       /*}*/        /*}*/
     } /* End k */      } /* End k selection */
   
     printf("done State-specific expectancies\n");fflush(stdout);      printf("done State-specific expectancies\n");fflush(stdout);
     fprintf(ficlog,"done State-specific expectancies\n");fflush(ficlog);      fprintf(ficlog,"done State-specific expectancies\n");fflush(ficlog);
Line 10898  Please run with mle=-1 to get a correct Line 11049  Please run with mle=-1 to get a correct
     /*for(cptcov=1,k=0;cptcov<=i1;cptcov++){      /*for(cptcov=1,k=0;cptcov<=i1;cptcov++){
       for(cptcod=1;cptcod<=ncodemax[cptcov];cptcod++){*/        for(cptcod=1;cptcod<=ncodemax[cptcov];cptcod++){*/
           
     for (k=1; k <= (int) pow(2,cptcoveff); k++){      i1=pow(2,cptcoveff);
       if (cptcovn < 1){i1=1;}
   
       for(nres=1; nres <= nresult; nres++) /* For each resultline */
       for(k=1; k<=i1;k++){
         if(TKresult[nres]!= k)
           continue;
       fprintf(ficresvpl,"\n#****** ");        fprintf(ficresvpl,"\n#****** ");
       printf("\n#****** ");        printf("\n#****** ");
       fprintf(ficlog,"\n#****** ");        fprintf(ficlog,"\n#****** ");
Line 10907  Please run with mle=-1 to get a correct Line 11064  Please run with mle=-1 to get a correct
         fprintf(ficlog,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);          fprintf(ficlog,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
         printf("V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);          printf("V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
       }        }
         for (j=1; j<= nsq; j++){ /* For each selected (single) quantitative value */
           printf(" V%d=%f ",Tvqresult[nres][j],Tqresult[nres][j]);
           fprintf(ficresvpl," V%d=%f ",Tvqresult[nres][j],Tqresult[nres][j]);
           fprintf(ficlog," V%d=%f ",Tvqresult[nres][j],Tqresult[nres][j]);
         } 
       fprintf(ficresvpl,"******\n");        fprintf(ficresvpl,"******\n");
       printf("******\n");        printf("******\n");
       fprintf(ficlog,"******\n");        fprintf(ficlog,"******\n");
               
       varpl=matrix(1,nlstate,(int) bage, (int) fage);        varpl=matrix(1,nlstate,(int) bage, (int) fage);
       oldm=oldms;savm=savms;        oldm=oldms;savm=savms;
       varprevlim(fileres, varpl, matcov, p, delti, nlstate, stepm, (int) bage, (int) fage, oldm, savm, prlim, ftolpl, &ncvyear, k, strstart);        varprevlim(fileres, varpl, matcov, p, delti, nlstate, stepm, (int) bage, (int) fage, oldm, savm, prlim, ftolpl, &ncvyear, k, strstart, nres);
       free_matrix(varpl,1,nlstate,(int) bage, (int)fage);        free_matrix(varpl,1,nlstate,(int) bage, (int)fage);
       /*}*/        /*}*/
     }      }

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


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