Diff for /imach/src/imach.c between versions 1.278 and 1.291

version 1.278, 2017/07/19 14:09:02 version 1.291, 2019/05/09 13:44:18
Line 1 Line 1
 /* $Id$  /* $Id$
   $State$    $State$
   $Log$    $Log$
     Revision 1.291  2019/05/09 13:44:18  brouard
     Summary: Before ncovmax
   
     Revision 1.290  2019/05/09 13:39:37  brouard
     Summary: 0.99r18 unlimited number of individuals
   
     The number n which was limited to 20,000 cases is now unlimited, from firstobs to lastobs. If the number is too for the virtual memory, probably an error will occur.
   
     Revision 1.289  2018/12/13 09:16:26  brouard
     Summary: Bug for young ages (<-30) will be in r17
   
     Revision 1.288  2018/05/02 20:58:27  brouard
     Summary: Some bugs fixed
   
     Revision 1.287  2018/05/01 17:57:25  brouard
     Summary: Bug fixed by providing frequencies only for non missing covariates
   
     Revision 1.286  2018/04/27 14:27:04  brouard
     Summary: some minor bugs
   
     Revision 1.285  2018/04/21 21:02:16  brouard
     Summary: Some bugs fixed, valgrind tested
   
     Revision 1.284  2018/04/20 05:22:13  brouard
     Summary: Computing mean and stdeviation of fixed quantitative variables
   
     Revision 1.283  2018/04/19 14:49:16  brouard
     Summary: Some minor bugs fixed
   
     Revision 1.282  2018/02/27 22:50:02  brouard
     *** empty log message ***
   
     Revision 1.281  2018/02/27 19:25:23  brouard
     Summary: Adding second argument for quitting
   
     Revision 1.280  2018/02/21 07:58:13  brouard
     Summary: 0.99r15
   
     New Makefile with recent VirtualBox 5.26. Bug in sqrt negatve in imach.c
   
     Revision 1.279  2017/07/20 13:35:01  brouard
     Summary: temporary working
   
   Revision 1.278  2017/07/19 14:09:02  brouard    Revision 1.278  2017/07/19 14:09:02  brouard
   Summary: Bug for mobil_average=0 and prevforecast fixed(?)    Summary: Bug for mobil_average=0 and prevforecast fixed(?)
   
Line 1014  typedef struct { Line 1057  typedef struct {
 #define NINTERVMAX 8  #define NINTERVMAX 8
 #define NLSTATEMAX 8 /**< Maximum number of live states (for func) */  #define NLSTATEMAX 8 /**< Maximum number of live states (for func) */
 #define NDEATHMAX 8 /**< Maximum number of dead states (for func) */  #define NDEATHMAX 8 /**< Maximum number of dead states (for func) */
 #define NCOVMAX 20 /**< Maximum number of covariates, including generated covariates V1*V2 */  #define NCOVMAX 20  /**< Maximum number of covariates, including generated covariates V1*V2 */
 #define codtabm(h,k)  (1 & (h-1) >> (k-1))+1  #define codtabm(h,k)  (1 & (h-1) >> (k-1))+1
 /*#define decodtabm(h,k,cptcoveff)= (h <= (1<<cptcoveff)?(((h-1) >> (k-1)) & 1) +1 : -1)*/  /*#define decodtabm(h,k,cptcoveff)= (h <= (1<<cptcoveff)?(((h-1) >> (k-1)) & 1) +1 : -1)*/
 #define decodtabm(h,k,cptcoveff) (((h-1) >> (k-1)) & 1) +1   #define decodtabm(h,k,cptcoveff) (((h-1) >> (k-1)) & 1) +1 
 #define MAXN 20000  /*#define MAXN 20000 */ /* Should by replaced by nobs, real number of observations and unlimited */
 #define YEARM 12. /**< Number of months per year */  #define YEARM 12. /**< Number of months per year */
 /* #define AGESUP 130 */  /* #define AGESUP 130 */
 #define AGESUP 150  /* #define AGESUP 150 */
   #define AGESUP 200
 #define AGEINF 0  #define AGEINF 0
 #define AGEMARGE 25 /* Marge for agemin and agemax for(iage=agemin-AGEMARGE; iage <= agemax+3+AGEMARGE; iage++) */  #define AGEMARGE 25 /* Marge for agemin and agemax for(iage=agemin-AGEMARGE; iage <= agemax+3+AGEMARGE; iage++) */
 #define AGEBASE 40  #define AGEBASE 40
Line 1041  typedef struct { Line 1085  typedef struct {
 /* $State$ */  /* $State$ */
 #include "version.h"  #include "version.h"
 char version[]=__IMACH_VERSION__;  char version[]=__IMACH_VERSION__;
 char copyright[]="February 2016,INED-EUROREVES-Institut de longevite-Japan Society for the Promotion of Science (Grant-in-Aid for Scientific Research 25293121), Intel Software 2015-2018";  char copyright[]="April 2018,INED-EUROREVES-Institut de longevite-Japan Society for the Promotion of Science (Grant-in-Aid for Scientific Research 25293121), Intel Software 2015-2018";
 char fullversion[]="$Revision$ $Date$";   char fullversion[]="$Revision$ $Date$"; 
 char strstart[80];  char strstart[80];
 char optionfilext[10], optionfilefiname[FILENAMELENGTH];  char optionfilext[10], optionfilefiname[FILENAMELENGTH];
Line 1065  int nqfveff=0; /**< nqfveff Number of Qu Line 1109  int nqfveff=0; /**< nqfveff Number of Qu
 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 */
 int cptcov=0; /* Working variable */  int cptcov=0; /* Working variable */
   int nobs=10;  /* Number of observations in the data lastobs-firstobs */
 int ncovcombmax=NCOVMAX; /* Maximum calculated number of covariate combination = pow(2, cptcoveff) */  int ncovcombmax=NCOVMAX; /* Maximum calculated number of covariate combination = pow(2, cptcoveff) */
 int npar=NPARMAX;  int npar=NPARMAX;
 int nlstate=2; /* Number of live states */  int nlstate=2; /* Number of live states */
Line 2516  void powell(double p[], double **xi, int Line 2561  void powell(double p[], double **xi, int
       
   double **prevalim(double **prlim, int nlstate, double x[], double age, double **oldm, double **savm, double ftolpl, int *ncvyear, int ij, int nres)    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 combination ij       /**< Computes the prevalence limit in each live state at age x and for covariate combination ij 
        (and selected quantitative values in nres)       *   (and selected quantitative values in nres)
        by left multiplying the unit       *  by left multiplying the unit
        matrix by transitions matrix until convergence is reached with precision ftolpl */       *  matrix by transitions matrix until convergence is reached with precision ftolpl 
   /* Wx= Wx-1 Px-1= Wx-2 Px-2 Px-1  = Wx-n Px-n ... Px-2 Px-1 I */       * Wx= Wx-1 Px-1= Wx-2 Px-2 Px-1  = Wx-n Px-n ... Px-2 Px-1 I
   /* Wx is row vector: population in state 1, population in state 2, population dead */       * Wx is row vector: population in state 1, population in state 2, population dead
   /* or prevalence in state 1, prevalence in state 2, 0 */       * or prevalence in state 1, prevalence in state 2, 0
   /* newm is the matrix after multiplications, its rows are identical at a factor */       * newm is the matrix after multiplications, its rows are identical at a factor.
   /* Initial matrix pimij */       * Inputs are the parameter, age, a tolerance for the prevalence limit ftolpl.
        * Output is prlim.
        * Initial matrix pimij 
        */
   /* {0.85204250825084937, 0.13044499163996345, 0.017512500109187184, */    /* {0.85204250825084937, 0.13044499163996345, 0.017512500109187184, */
   /* 0.090851990222114765, 0.88271245433047185, 0.026435555447413338, */    /* 0.090851990222114765, 0.88271245433047185, 0.026435555447413338, */
   /*  0,                   0                  , 1} */    /*  0,                   0                  , 1} */
Line 2545  void powell(double p[], double **xi, int Line 2593  void powell(double p[], double **xi, int
   double **newm;    double **newm;
   double agefin, delaymax=200. ; /* 100 Max number of years to converge */    double agefin, delaymax=200. ; /* 100 Max number of years to converge */
   int ncvloop=0;    int ncvloop=0;
     int first=0;
       
   min=vector(1,nlstate);    min=vector(1,nlstate);
   max=vector(1,nlstate);    max=vector(1,nlstate);
Line 2641  void powell(double p[], double **xi, int Line 2690  void powell(double p[], double **xi, int
       free_vector(meandiff,1,nlstate);        free_vector(meandiff,1,nlstate);
       return prlim;        return prlim;
     }      }
   } /* age loop */    } /* agefin loop */
     /* After some age loop it doesn't converge */      /* After some age loop it doesn't converge */
   printf("Warning: the stable prevalence at age %d did not converge with the required precision (%g > ftolpl=%g) within %.0f years. Try to lower 'ftolpl'. \n\    if(!first){
 Earliest age to start was %d-%d=%d, ncvloop=%d, ncvyear=%d\n", (int)age, maxmax, ftolpl, delaymax, (int)age, (int)delaymax, (int)agefin, ncvloop, *ncvyear);      first=1;
       printf("Warning: the stable prevalence at age %d did not converge with the required precision (%g > ftolpl=%g) within %.d years and %d loops. Try to lower 'ftolpl'. Youngest age to start was %d=(%d-%d). Others in log file only...\n", (int)age, maxmax, ftolpl, *ncvyear, ncvloop, (int)(agefin+stepm/YEARM),  (int)(age-stepm/YEARM), (int)delaymax);
     }
     fprintf(ficlog, "Warning: the stable prevalence at age %d did not converge with the required precision (%g > ftolpl=%g) within %.d years and %d loops. Try to lower 'ftolpl'. Youngest age to start was %d=(%d-%d).\n", (int)age, maxmax, ftolpl, *ncvyear, ncvloop, (int)(agefin+stepm/YEARM),  (int)(age-stepm/YEARM), (int)delaymax);
   
   /* Try to lower 'ftol', for example from 1.e-8 to 6.e-9.\n", ftolpl, (int)age, (int)delaymax, (int)agefin, ncvloop, (int)age-(int)agefin); */    /* Try to lower 'ftol', for example from 1.e-8 to 6.e-9.\n", ftolpl, (int)age, (int)delaymax, (int)agefin, ncvloop, (int)age-(int)agefin); */
   free_vector(min,1,nlstate);    free_vector(min,1,nlstate);
   free_vector(max,1,nlstate);    free_vector(max,1,nlstate);
Line 2710  Earliest age to start was %d-%d=%d, ncvl Line 2763  Earliest age to start was %d-%d=%d, ncvl
   /* Even if hstepm = 1, at least one multiplication by the unit matrix */    /* Even if hstepm = 1, at least one multiplication by the unit matrix */
   /* Start at agefin= age, computes the matrix of passage and loops decreasing agefin until convergence is reached */    /* Start at agefin= age, computes the matrix of passage and loops decreasing agefin until convergence is reached */
   /* for(agefin=age+stepm/YEARM; agefin<=age+delaymax; agefin=agefin+stepm/YEARM){ /\* A changer en age *\/ */    /* for(agefin=age+stepm/YEARM; agefin<=age+delaymax; agefin=agefin+stepm/YEARM){ /\* A changer en age *\/ */
   for(agefin=age; agefin<AGESUP; agefin=agefin+stepm/YEARM){ /* A changer en age */    /* for(agefin=age; agefin<AGESUP; agefin=agefin+stepm/YEARM){ /\* A changer en age *\/ */
     for(agefin=age; agefin<FMIN(AGESUP,age+delaymax); agefin=agefin+stepm/YEARM){ /* A changer en age */
     ncvloop++;      ncvloop++;
     newm=savm; /* oldm should be kept from previous iteration or unity at start */      newm=savm; /* oldm should be kept from previous iteration or unity at start */
                 /* newm points to the allocated table savm passed by the function it can be written, savm could be reallocated */                  /* newm points to the allocated table savm passed by the function it can be written, savm could be reallocated */
Line 2824  Earliest age to start was %d-%d=%d, ncvl Line 2878  Earliest age to start was %d-%d=%d, ncvl
       free_vector(meandiff,1,nlstate);        free_vector(meandiff,1,nlstate);
       return bprlim;        return bprlim;
     }      }
   } /* age loop */    } /* agefin loop */
     /* After some age loop it doesn't converge */      /* After some age loop it doesn't converge */
   if(first){    if(!first){
     first=1;      first=1;
     printf("Warning: the back stable prevalence at age %d did not converge with the required precision (%g > ftolpl=%g) within %.0f years. Try to lower 'ftolpl'. Others in log file only...\n\      printf("Warning: the back stable prevalence at age %d did not converge with the required precision (%g > ftolpl=%g) within %.0f years. Try to lower 'ftolpl'. Others in log file only...\n\
 Oldest age to start was %d-%d=%d, ncvloop=%d, ncvyear=%d\n", (int)age, maxmax, ftolpl, delaymax, (int)age, (int)delaymax, (int)agefin, ncvloop, *ncvyear);  Oldest age to start was %d-%d=%d, ncvloop=%d, ncvyear=%d\n", (int)age, maxmax, ftolpl, delaymax, (int)age, (int)delaymax, (int)agefin, ncvloop, *ncvyear);
Line 4351  void  freqsummary(char fileres[], double Line 4405  void  freqsummary(char fileres[], double
   double ***freq; /* Frequencies */    double ***freq; /* Frequencies */
   double *x, *y, a=0.,b=0.,r=1., sa=0., sb=0.; /* for regression, y=b+m*x and r is the correlation coefficient */    double *x, *y, a=0.,b=0.,r=1., sa=0., sb=0.; /* for regression, y=b+m*x and r is the correlation coefficient */
   int no=0, linreg(int ifi, int ila, int *no, const double x[], const double y[], double* a, double* b, double* r, double* sa, double * sb);    int no=0, linreg(int ifi, int ila, int *no, const double x[], const double y[], double* a, double* b, double* r, double* sa, double * sb);
   double *meanq;    double *meanq, *stdq, *idq;
   double **meanqt;    double **meanqt;
   double *pp, **prop, *posprop, *pospropt;    double *pp, **prop, *posprop, *pospropt;
   double pos=0., posproptt=0., pospropta=0., k2, dateintsum=0,k2cpt=0;    double pos=0., posproptt=0., pospropta=0., k2, dateintsum=0,k2cpt=0;
Line 4364  void  freqsummary(char fileres[], double Line 4418  void  freqsummary(char fileres[], double
   pospropt=vector(1,nlstate); /* Counting the number of transition starting from a live state */     pospropt=vector(1,nlstate); /* Counting the number of transition starting from a live state */ 
   /* prop=matrix(1,nlstate,iagemin,iagemax+3); */    /* prop=matrix(1,nlstate,iagemin,iagemax+3); */
   meanq=vector(1,nqfveff); /* Number of Quantitative Fixed Variables Effective */    meanq=vector(1,nqfveff); /* Number of Quantitative Fixed Variables Effective */
     stdq=vector(1,nqfveff); /* Number of Quantitative Fixed Variables Effective */
     idq=vector(1,nqfveff); /* Number of Quantitative Fixed Variables Effective */
   meanqt=matrix(1,lastpass,1,nqtveff);    meanqt=matrix(1,lastpass,1,nqtveff);
   strcpy(fileresp,"P_");    strcpy(fileresp,"P_");
   strcat(fileresp,fileresu);    strcat(fileresp,fileresu);
Line 4472  Title=%s <br>Datafile=%s Firstpass=%d La Line 4528  Title=%s <br>Datafile=%s Firstpass=%d La
         posprop[i]=0;          posprop[i]=0;
         pospropt[i]=0;          pospropt[i]=0;
       }        }
       /* for (z1=1; z1<= nqfveff; z1++) {   */        for (z1=1; z1<= nqfveff; z1++) { /* zeroing for each combination j1 as well as for the total */
       /*   meanq[z1]+=0.; */          idq[z1]=0.;
           meanq[z1]=0.;
           stdq[z1]=0.;
         }
         /* for (z1=1; z1<= nqtveff; z1++) { */
       /*   for(m=1;m<=lastpass;m++){ */        /*   for(m=1;m<=lastpass;m++){ */
       /*        meanqt[m][z1]=0.; */        /*          meanqt[m][z1]=0.; */
       /*   } */        /*        } */
       /* } */        /* }       */
         
       /* dateintsum=0; */        /* dateintsum=0; */
       /* k2cpt=0; */        /* k2cpt=0; */
               
Line 4488  Title=%s <br>Datafile=%s Firstpass=%d La Line 4547  Title=%s <br>Datafile=%s Firstpass=%d La
         if(j !=0){          if(j !=0){
           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++) {   */  
               /*   meanq[z1]+=coqvar[Tvar[z1]][iind];  /\* Computes mean of quantitative with selected filter *\/ */  
               /* } */  
               for (z1=1; z1<=cptcoveff; z1++) { /* loops on covariates in the model */                for (z1=1; z1<=cptcoveff; z1++) { /* loops on covariates in the model */
                 /* if(Tvaraff[z1] ==-20){ */                  /* if(Tvaraff[z1] ==-20){ */
                 /*       /\* sumnew+=cotvar[mw[mi][iind]][z1][iind]; *\/ */                  /*       /\* sumnew+=cotvar[mw[mi][iind]][z1][iind]; *\/ */
Line 4511  Title=%s <br>Datafile=%s Firstpass=%d La Line 4567  Title=%s <br>Datafile=%s Firstpass=%d La
         }/* end j==0 */          }/* end j==0 */
         if (bool==1){ /* We selected an individual iind satisfying combination j1 (V4=1 V3=0) or all fixed covariates */          if (bool==1){ /* We selected an individual iind satisfying combination j1 (V4=1 V3=0) or all fixed covariates */
           /* 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 each wave */
             m=mw[mi][iind];              m=mw[mi][iind];
             if(j!=0){              if(j!=0){
               if(anyvaryingduminmodel==1){ /* Some are varying covariates */                if(anyvaryingduminmodel==1){ /* Some are varying covariates */
Line 4531  Title=%s <br>Datafile=%s Firstpass=%d La Line 4587  Title=%s <br>Datafile=%s Firstpass=%d La
               }/* 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  */
             } /* end j==0 */              } /* end j==0 */
             /* 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){ /*Selected */
               /* 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*/
Line 4549  Title=%s <br>Datafile=%s Firstpass=%d La Line 4605  Title=%s <br>Datafile=%s Firstpass=%d La
                   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 */
                     for (z1=1; z1<= nqfveff; z1++) { /* Quantitative variables, calculating mean */
                       idq[z1]=idq[z1]+weight[iind];
                       meanq[z1]+=covar[ncovcol+z1][iind]*weight[iind];  /* Computes mean of quantitative with selected filter */
                       stdq[z1]+=covar[ncovcol+z1][iind]*covar[ncovcol+z1][iind]*weight[iind]*weight[iind]; /* *weight[iind];*/  /* Computes mean of quantitative with selected filter */
                     }
                   /* if((int)agev[m][iind] == 55) */                    /* if((int)agev[m][iind] == 55) */
                   /*   printf("j=%d, j1=%d Age %d, iind=%d, num=%09ld m=%d\n",j,j1,(int)agev[m][iind],iind, num[iind],m); */                    /*   printf("j=%d, j1=%d Age %d, iind=%d, num=%09ld m=%d\n",j,j1,(int)agev[m][iind],iind, num[iind],m); */
                   /* 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]; */
Line 4564  Title=%s <br>Datafile=%s Firstpass=%d La Line 4625  Title=%s <br>Datafile=%s Firstpass=%d La
               bool=1;                bool=1;
             }/* end bool 2 */              }/* end bool 2 */
           } /* end m */            } /* end m */
             /* for (z1=1; z1<= nqfveff; z1++) { /\* Quantitative variables, calculating mean *\/ */
             /*   idq[z1]=idq[z1]+weight[iind]; */
             /*   meanq[z1]+=covar[ncovcol+z1][iind]*weight[iind];  /\* Computes mean of quantitative with selected filter *\/ */
             /*   stdq[z1]+=covar[ncovcol+z1][iind]*covar[ncovcol+z1][iind]*weight[iind]*weight[iind]; /\* *weight[iind];*\/  /\* Computes mean of quantitative with selected filter *\/ */
             /* } */
         } /* end bool */          } /* end bool */
       } /* end iind = 1 to imx */        } /* end iind = 1 to imx */
       /* prop[s][age] is feeded for any initial and valid live state as well as        /* prop[s][age] is feeded for any initial and valid live state as well as
Line 4601  Title=%s <br>Datafile=%s Firstpass=%d La Line 4667  Title=%s <br>Datafile=%s Firstpass=%d La
         fprintf(ficresphtmfr, "**********</h3>\n");          fprintf(ficresphtmfr, "**********</h3>\n");
         fprintf(ficlog, "**********\n");          fprintf(ficlog, "**********\n");
       }        }
         /*
           Printing means of quantitative variables if any
         */
         for (z1=1; z1<= nqfveff; z1++) {
           fprintf(ficlog,"Mean of fixed quantitative variable V%d on %.0f individuals sum=%f", ncovcol+z1, idq[z1], meanq[z1]);
           fprintf(ficlog,", mean=%.3g\n",meanq[z1]/idq[z1]);
           if(weightopt==1){
             printf(" Weighted mean and standard deviation of");
             fprintf(ficlog," Weighted mean and standard deviation of");
             fprintf(ficresphtmfr," Weighted mean and standard deviation of");
           }
           printf(" fixed quantitative variable V%d on %.0f representatives of the population : %6.3g (%6.3g)\n", ncovcol+z1, idq[z1],meanq[z1]/idq[z1], sqrt((stdq[z1]-meanq[z1]*meanq[z1]/idq[z1])/idq[z1]));
           fprintf(ficlog," fixed quantitative variable V%d on %.0f representatives of the population : %6.3g (%6.3g)\n", ncovcol+z1, idq[z1],meanq[z1]/idq[z1], sqrt((stdq[z1]-meanq[z1]*meanq[z1]/idq[z1])/idq[z1]));
           fprintf(ficresphtmfr," fixed quantitative variable V%d on %.0f representatives of the population : %6.3g (%6.3g)<p>\n", ncovcol+z1, idq[z1],meanq[z1]/idq[z1], sqrt((stdq[z1]-meanq[z1]*meanq[z1]/idq[z1])/idq[z1]));
         }
         /* for (z1=1; z1<= nqtveff; z1++) { */
         /*        for(m=1;m<=lastpass;m++){ */
         /*          fprintf(ficresphtmfr,"V quantitative id %d, pass id=%d, mean=%f<p>\n", z1, m, meanqt[m][z1]); */
         /*   } */
         /* } */
   
       fprintf(ficresphtm,"<table style=\"text-align:center; border: 1px solid\">");        fprintf(ficresphtm,"<table style=\"text-align:center; border: 1px solid\">");
       if((cptcoveff==0 && nj==1)|| nj==2 ) /* no covariate and first pass */        if((cptcoveff==0 && nj==1)|| nj==2 ) /* no covariate and first pass */
         fprintf(ficresp, " Age");          fprintf(ficresp, " Age");
Line 4835  Title=%s <br>Datafile=%s Firstpass=%d La Line 4922  Title=%s <br>Datafile=%s Firstpass=%d La
             fprintf(ficlog,"\n");              fprintf(ficlog,"\n");
           }            }
         }          }
       }        } /* end of state i */
       printf("#Freqsummary\n");        printf("#Freqsummary\n");
       fprintf(ficlog,"\n");        fprintf(ficlog,"\n");
       for(s1=-1; s1 <=nlstate+ndeath; s1++){        for(s1=-1; s1 <=nlstate+ndeath; s1++){
Line 4881  Title=%s <br>Datafile=%s Firstpass=%d La Line 4968  Title=%s <br>Datafile=%s Firstpass=%d La
   fclose(ficresp);    fclose(ficresp);
   fclose(ficresphtm);    fclose(ficresphtm);
   fclose(ficresphtmfr);    fclose(ficresphtmfr);
     free_vector(idq,1,nqfveff);
   free_vector(meanq,1,nqfveff);    free_vector(meanq,1,nqfveff);
     free_vector(stdq,1,nqfveff);
   free_matrix(meanqt,1,lastpass,1,nqtveff);    free_matrix(meanqt,1,lastpass,1,nqtveff);
   free_vector(x, iagemin-AGEMARGE, iagemax+4+AGEMARGE);    free_vector(x, iagemin-AGEMARGE, iagemax+4+AGEMARGE);
   free_vector(y, iagemin-AGEMARGE, iagemax+4+AGEMARGE);    free_vector(y, iagemin-AGEMARGE, iagemax+4+AGEMARGE);
Line 4988  void prevalence(double ***probs, double Line 5077  void prevalence(double ***probs, double
   /*j=cptcoveff;*/    /*j=cptcoveff;*/
   if (cptcovn<1) {j=1;ncodemax[1]=1;}    if (cptcovn<1) {j=1;ncodemax[1]=1;}
       
   first=1;    first=0;
   for(j1=1; j1<= (int) pow(2,cptcoveff);j1++){ /* For each combination of covariate */    for(j1=1; j1<= (int) pow(2,cptcoveff);j1++){ /* For each combination of covariate */
     for (i=1; i<=nlstate; i++)        for (i=1; i<=nlstate; i++)  
       for(iage=iagemin-AGEMARGE; iage <= iagemax+4+AGEMARGE; iage++)        for(iage=iagemin-AGEMARGE; iage <= iagemax+4+AGEMARGE; iage++)
Line 5046  void prevalence(double ***probs, double Line 5135  void prevalence(double ***probs, double
           if(posprop>=1.e-5){             if(posprop>=1.e-5){ 
             probs[i][jk][j1]= prop[jk][i]/posprop;              probs[i][jk][j1]= prop[jk][i]/posprop;
           } else{            } else{
             if(first==1){              if(!first){
               first=0;                first=1;
               printf("Warning Observed prevalence doesn't sum to 1 for state %d: probs[%d][%d][%d]=%lf because of lack of cases\nSee others in log file...\n",jk,i,jk, j1,probs[i][jk][j1]);                printf("Warning Observed prevalence doesn't sum to 1 for state %d: probs[%d][%d][%d]=%lf because of lack of cases\nSee others in log file...\n",jk,i,jk, j1,probs[i][jk][j1]);
               fprintf(ficlog,"Warning Observed prevalence doesn't sum to 1 for state %d: probs[%d][%d][%d]=%lf because of lack of cases\nSee others in log file...\n",jk,i,jk, j1,probs[i][jk][j1]);  
             }else{              }else{
               fprintf(ficlog,"Warning Observed prevalence doesn't sum to 1 for state %d: probs[%d][%d][%d]=%lf because of lack of cases\nSee others in log file...\n",jk,i,jk, j1,probs[i][jk][j1]);                fprintf(ficlog,"Warning Observed prevalence doesn't sum to 1 for state %d: probs[%d][%d][%d]=%lf because of lack of cases.\n",jk,i,jk, j1,probs[i][jk][j1]);
             }              }
           }            }
         }           } 
Line 5297  void  concatwav(int wav[], int **dh, int Line 5385  void  concatwav(int wav[], int **dh, int
    /* *cptcov=0; */     /* *cptcov=0; */
     
    for (k=1; k <= maxncov; k++) ncodemax[k]=0; /* Horrible constant again replaced by NCOVMAX */     for (k=1; k <= maxncov; k++) ncodemax[k]=0; /* Horrible constant again replaced by NCOVMAX */
      for (k=1; k <= maxncov; k++)
        for(j=1; j<=2; j++)
          nbcode[k][j]=0; /* Valgrind */
   
    /* Loop on covariates without age and products and no quantitative variable */     /* Loop on covariates without age and products and no quantitative variable */
    /* for (j=1; j<=(cptcovs); j++) { /\* From model V1 + V2*age+ V3 + V3*V4 keeps V1 + V3 = 2 only *\/ */  
    for (k=1; k<=cptcovt; k++) { /* From model V1 + V2*age + V3 + V3*V4 keeps V1 + V3 = 2 only */     for (k=1; k<=cptcovt; k++) { /* From model V1 + V2*age + V3 + V3*V4 keeps V1 + V3 = 2 only */
      for (j=-1; (j < maxncov); j++) Ndum[j]=0;       for (j=-1; (j < maxncov); j++) Ndum[j]=0;
      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 */ 
Line 5317  void  concatwav(int wav[], int **dh, int Line 5407  void  concatwav(int wav[], int **dh, int
              modmaxcovj=ij;                modmaxcovj=ij; 
            else if (ij < modmincovj)              else if (ij < modmincovj) 
              modmincovj=ij;                modmincovj=ij; 
            if ((ij < -1) && (ij > NCOVMAX)){             if (ij <0 || ij >1 ){
                printf("Information, IMaCh doesn't treat covariate with missing values (-1), individual %d will be skipped.\n",i);
                fprintf(ficlog,"Information, currently IMaCh doesn't treat covariate with missing values (-1), individual %d will be skipped.\n",i);
              }
              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
Line 5363  void  concatwav(int wav[], int **dh, int Line 5457  void  concatwav(int wav[], int **dh, int
          /* 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 */           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*/  
            /* 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*/
            /* Skipping the case of missing values by reducing nbcode to 0 and 1 and not -1, 0, 1 */
            /* model=V1+V2+V3, if V2=-1, 0 or 1, then nbcode[2][1]=0 and nbcode[2][2]=1 instead of
             * nbcode[2][1]=-1, nbcode[2][2]=0 and nbcode[2][3]=1 */
            /*, could be restored in the future */
            for (i=0; i<=1; i++) { /* i= 1 to 2 for dichotomous, or from 1 to 3 or from -1 or 0 to 1 currently*/
            if (Ndum[i] == 0) { /* If nobody responded to this modality k */             if (Ndum[i] == 0) { /* If nobody responded to this modality k */
              break;               break;
            }             }
            ij++;             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*/             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 . Could be -1*/
            cptcode = ij; /* New max modality for covar j */             cptcode = ij; /* New max modality for covar j */
          } /* end of loop on modality i=-1 to 1 or more */           } /* end of loop on modality i=-1 to 1 or more */
          break;           break;
Line 5384  void  concatwav(int wav[], int **dh, int Line 5484  void  concatwav(int wav[], int **dh, int
          break;           break;
        } /* end switch */         } /* end switch */
      } /* end dummy test */       } /* end dummy test */
          } /* end of loop on model-covariate k. nbcode[Tvark][1]=-1, nbcode[Tvark][1]=0 and nbcode[Tvark][2]=1 sets the value of covariate k*/  
      /*   for (k=0; k<= cptcode; k++) { /\* k=-1 ? k=0 to 1 *\//\* Could be 1 to 4 *\//\* cptcode=modmaxcovj *\/ */  
      /*         /\*recode from 0 *\/ */  
      /*                                      k is a modality. If we have model=V1+V1*sex  */  
      /*                                      then: nbcode[1][1]=0 ; nbcode[1][2]=1; nbcode[2][1]=0 ; nbcode[2][2]=1; */  
      /*                                   But if some modality were not used, it is recoded from 0 to a newer modmaxcovj=cptcode *\/ */  
      /*         } */  
      /*         /\* cptcode = ij; *\/ /\* New max modality for covar j *\/ */  
      /*         if (ij > ncodemax[j]) { */  
      /*           printf( " Error ij=%d > ncodemax[%d]=%d\n", ij, j, ncodemax[j]);  */  
      /*           fprintf(ficlog, " Error ij=%d > ncodemax[%d]=%d\n", ij, j, ncodemax[j]); */  
      /*           break; */  
      /*         } */  
      /*   }  /\* end of loop on modality k *\/ */  
    } /* end of loop on model-covariate j. nbcode[Tvarj][1]=0 and nbcode[Tvarj][2]=1 sets the value of covariate j*/    
       
    for (k=-1; k< maxncov; k++) Ndum[k]=0;      for (k=-1; k< maxncov; k++) Ndum[k]=0; 
    /* Look at fixed dummy (single or product) covariates to check empty modalities */     /* Look at fixed dummy (single or product) covariates to check empty modalities */
Line 5772  void  concatwav(int wav[], int **dh, int Line 5858  void  concatwav(int wav[], int **dh, int
 /************ 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[], int nres)   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);
    /* double **newm;*/      * double **newm;
    /* int movingaverage(double ***probs, double bage,double fage, double ***mobaverage, int mobilav)*/      * int movingaverage(double ***probs, double bage,double fage, double ***mobaverage, int mobilav) 
       */
       
    /* int movingaverage(); */     /* int movingaverage(); */
    double **dnewm,**doldm;     double **dnewm,**doldm;
    double **dnewmp,**doldmp;     double **dnewmp,**doldmp;
    int i, j, nhstepm, hstepm, h, nstepm ;     int i, j, nhstepm, hstepm, h, nstepm ;
      int first=0;
    int k;     int k;
    double *xp;     double *xp;
    double **gp, **gm;  /* for var eij */     double **gp, **gm;  /**< for var eij */
    double ***gradg, ***trgradg; /*for var eij */     double ***gradg, ***trgradg; /**< for var eij */
    double **gradgp, **trgradgp; /* for var p point j */     double **gradgp, **trgradgp; /**< for var p point j */
    double *gpp, *gmp; /* for var p point j */     double *gpp, *gmp; /**< for var p point j */
    double **varppt; /* for var p point j nlstate to nlstate+ndeath */     double **varppt; /**< for var p point j nlstate to nlstate+ndeath */
    double ***p3mat;     double ***p3mat;
    double age,agelim, hf;     double age,agelim, hf;
    /* double ***mobaverage; */     /* double ***mobaverage; */
Line 5848  void  concatwav(int wav[], int **dh, int Line 5936  void  concatwav(int wav[], int **dh, int
    /* fprintf(fichtm, "#Local time at start: %s", strstart);*/     /* fprintf(fichtm, "#Local time at start: %s", strstart);*/
    fprintf(fichtm,"\n<li><h4> Computing probabilities of dying over estepm months as a weighted average (i.e global mortality independent of initial healh state)</h4></li>\n");     fprintf(fichtm,"\n<li><h4> Computing probabilities of dying over estepm months as a weighted average (i.e global mortality independent of initial healh state)</h4></li>\n");
    fprintf(fichtm,"\n<br>%s  <br>\n",digitp);     fprintf(fichtm,"\n<br>%s  <br>\n",digitp);
    /*   } */  
    varppt = matrix(nlstate+1,nlstate+ndeath,nlstate+1,nlstate+ndeath);     varppt = matrix(nlstate+1,nlstate+ndeath,nlstate+1,nlstate+ndeath);
    pstamp(ficresvij);     pstamp(ficresvij);
    fprintf(ficresvij,"# Variance and covariance of health expectancies e.j \n#  (weighted average of eij where weights are ");     fprintf(ficresvij,"# Variance and covariance of health expectancies e.j \n#  (weighted average of eij where weights are ");
Line 5903  void  concatwav(int wav[], int **dh, int Line 5991  void  concatwav(int wav[], int **dh, int
        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);
        }         }
                                  /**< Computes the prevalence limit with parameter theta shifted of delta up to ftolpl precision and 
           * returns into prlim .
           */
        prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyearp,ij, nres);         prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyearp,ij, nres);
                           
          /* If popbased = 1 we use crossection prevalences. Previous step is useless but prlim is created */
        if (popbased==1) {         if (popbased==1) {
          if(mobilav ==0){           if(mobilav ==0){
            for(i=1; i<=nlstate;i++)             for(i=1; i<=nlstate;i++)
Line 5915  void  concatwav(int wav[], int **dh, int Line 6006  void  concatwav(int wav[], int **dh, int
              prlim[i][i]=mobaverage[(int)age][i][ij];               prlim[i][i]=mobaverage[(int)age][i][ij];
          }           }
        }         }
                                  /**< Computes the shifted transition matrix \f$ {}{h}_p^{ij}_x\f$ at horizon h.
        hpxij(p3mat,nhstepm,age,hstepm,xp,nlstate,stepm,oldm,savm, ij,nres);  /* 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=0 to nhstepm */
          /**< And for each alive state j, sums over i \f$ w^i_x {}{h}_p^{ij}_x\f$, which are the probability
           * at horizon h in state j including mortality.
           */
        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++)
              gp[h][j] += prlim[i][i]*p3mat[i][j][h];               gp[h][j] += prlim[i][i]*p3mat[i][j][h];
          }           }
        }         }
        /* Next for computing probability of death (h=1 means         /* Next for computing shifted+ probability of death (h=1 means
           computed over hstepm matrices product = hstepm*stepm months)             computed over hstepm matrices product = hstepm*stepm months) 
           as a weighted average of prlim.            as a weighted average of prlim(i) * p(i,j) p.3=w1*p13 + w2*p23 .
        */         */
        for(j=nlstate+1;j<=nlstate+ndeath;j++){         for(j=nlstate+1;j<=nlstate+ndeath;j++){
          for(i=1,gpp[j]=0.; i<= nlstate; i++)           for(i=1,gpp[j]=0.; i<= nlstate; i++)
            gpp[j] += prlim[i][i]*p3mat[i][j][1];             gpp[j] += prlim[i][i]*p3mat[i][j][1];
        }             }
        /* end probability of death */         
          /* Again with minus shift */
                                                   
        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, nres);         prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyearp, ij, nres);
                                                   
        if (popbased==1) {         if (popbased==1) {
Line 5964  void  concatwav(int wav[], int **dh, int Line 6060  void  concatwav(int wav[], int **dh, int
          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];
        }             }    
        /* end probability of death */         /* end shifting computations */
                           
          /**< Computing gradient matrix at horizon h 
           */
        for(j=1; j<= nlstate; j++) /* vareij */         for(j=1; j<= nlstate; j++) /* vareij */
          for(h=0; h<=nhstepm; h++){           for(h=0; h<=nhstepm; h++){
            gradg[h][theta][j]= (gp[h][j]-gm[h][j])/2./delti[theta];             gradg[h][theta][j]= (gp[h][j]-gm[h][j])/2./delti[theta];
          }           }
                                  /**< Gradient of overall mortality p.3 (or p.j) 
        for(j=nlstate+1; j<= nlstate+ndeath; j++){ /* var mu */          */
          for(j=nlstate+1; j<= nlstate+ndeath; j++){ /* var mu mortality from j */
          gradgp[theta][j]= (gpp[j]-gmp[j])/2./delti[theta];           gradgp[theta][j]= (gpp[j]-gmp[j])/2./delti[theta];
        }         }
                                                   
      } /* End theta */       } /* End theta */
                        
        /* We got the gradient matrix for each theta and state j */                
      trgradg =ma3x(0,nhstepm,1,nlstate,1,npar); /* veij */       trgradg =ma3x(0,nhstepm,1,nlstate,1,npar); /* veij */
                                   
      for(h=0; h<=nhstepm; h++) /* veij */       for(h=0; h<=nhstepm; h++) /* veij */
Line 5987  void  concatwav(int wav[], int **dh, int Line 6087  void  concatwav(int wav[], int **dh, int
      for(j=nlstate+1; j<=nlstate+ndeath;j++) /* mu */       for(j=nlstate+1; j<=nlstate+ndeath;j++) /* mu */
        for(theta=1; theta <=npar; theta++)         for(theta=1; theta <=npar; theta++)
          trgradgp[j][theta]=gradgp[theta][j];           trgradgp[j][theta]=gradgp[theta][j];
                        /**< as well as its transposed matrix 
         */                
                                   
      hf=hstepm*stepm/YEARM;  /* Duration of hstepm expressed in year unit. */       hf=hstepm*stepm/YEARM;  /* Duration of hstepm expressed in year unit. */
      for(i=1;i<=nlstate;i++)       for(i=1;i<=nlstate;i++)
        for(j=1;j<=nlstate;j++)         for(j=1;j<=nlstate;j++)
          vareij[i][j][(int)age] =0.;           vareij[i][j][(int)age] =0.;
                   
        /* Computing trgradg by matcov by gradg at age and summing over h
         * and k (nhstepm) formula 15 of article
         * Lievre-Brouard-Heathcote
         */
        
      for(h=0;h<=nhstepm;h++){       for(h=0;h<=nhstepm;h++){
        for(k=0;k<=nhstepm;k++){         for(k=0;k<=nhstepm;k++){
          matprod2(dnewm,trgradg[h],1,nlstate,1,npar,1,npar,matcov);           matprod2(dnewm,trgradg[h],1,nlstate,1,npar,1,npar,matcov);
Line 6004  void  concatwav(int wav[], int **dh, int Line 6110  void  concatwav(int wav[], int **dh, int
        }         }
      }       }
                                   
      /* pptj */       /* pptj is p.3 or p.j = trgradgp by cov by gradgp, variance of
         * p.j overall mortality formula 49 but computed directly because
         * we compute the grad (wix pijx) instead of grad (pijx),even if
         * wix is independent of theta.
         */
      matprod2(dnewmp,trgradgp,nlstate+1,nlstate+ndeath,1,npar,1,npar,matcov);       matprod2(dnewmp,trgradgp,nlstate+1,nlstate+ndeath,1,npar,1,npar,matcov);
      matprod2(doldmp,dnewmp,nlstate+1,nlstate+ndeath,1,npar,nlstate+1,nlstate+ndeath,gradgp);       matprod2(doldmp,dnewmp,nlstate+1,nlstate+ndeath,1,npar,nlstate+1,nlstate+ndeath,gradgp);
      for(j=nlstate+1;j<=nlstate+ndeath;j++)       for(j=nlstate+1;j<=nlstate+ndeath;j++)
Line 6107  void  concatwav(int wav[], int **dh, int Line 6217  void  concatwav(int wav[], int **dh, int
   int theta;    int theta;
       
   pstamp(ficresvpl);    pstamp(ficresvpl);
   fprintf(ficresvpl,"# Standard deviation of period (stable) prevalences \n");    fprintf(ficresvpl,"# Standard deviation of period (forward stable) prevalences \n");
   fprintf(ficresvpl,"# Age ");    fprintf(ficresvpl,"# Age ");
   if(nresult >=1)    if(nresult >=1)
     fprintf(ficresvpl," Result# ");      fprintf(ficresvpl," Result# ");
Line 6136  void  concatwav(int wav[], int **dh, int Line 6246  void  concatwav(int wav[], int **dh, int
       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,nres);        /*        prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyearp,ij,nres); */
       else        /* else */
         prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyearp,ij,nres);        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];
       }        }
       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,nres);        /*        prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyearp,ij,nres); */
       else        /* else */
         prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyearp,ij,nres);        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 6198  void  concatwav(int wav[], int **dh, int Line 6308  void  concatwav(int wav[], int **dh, int
     fprintf(ficresvpl,"%.0f ",age );      fprintf(ficresvpl,"%.0f ",age );
     if(nresult >=1)      if(nresult >=1)
       fprintf(ficresvpl,"%d ",nres );        fprintf(ficresvpl,"%d ",nres );
     for(i=1; i<=nlstate;i++)      for(i=1; i<=nlstate;i++){
       fprintf(ficresvpl," %.5f (%.5f)",prlim[i][i],sqrt(varpl[i][(int)age]));        fprintf(ficresvpl," %.5f (%.5f)",prlim[i][i],sqrt(varpl[i][(int)age]));
         /* for(j=1;j<=nlstate;j++) */
         /*        fprintf(ficresvpl," %d %.5f ",j,prlim[j][i]); */
       }
     fprintf(ficresvpl,"\n");      fprintf(ficresvpl,"\n");
     free_vector(gp,1,nlstate);      free_vector(gp,1,nlstate);
     free_vector(gm,1,nlstate);      free_vector(gm,1,nlstate);
Line 6416  void varprob(char optionfilefiname[], do Line 6529  void varprob(char optionfilefiname[], do
    fprintf(fichtm,"\n<li><h4> Computing and drawing one step probabilities with their confidence intervals</h4></li>\n");     fprintf(fichtm,"\n<li><h4> Computing and drawing one step probabilities with their confidence intervals</h4></li>\n");
    fprintf(fichtm,"\n");     fprintf(fichtm,"\n");
   
    fprintf(fichtm,"\n<li><h4> <a href=\"%s\">Matrix of variance-covariance of one-step probabilities (drawings)</a></h4> this page is important in order to visualize confidence intervals and especially correlation between disability and recovery, or more generally, way in and way back. %s</li>\n",optionfilehtmcov,optionfilehtmcov);     fprintf(fichtm,"\n<li><h4> <a href=\"%s\">Matrix of variance-covariance of one-step probabilities (drawings)</a></h4> this page is important in order to visualize confidence intervals and especially correlation between disability and recovery, or more generally, way in and way back. File %s</li>\n",optionfilehtmcov,optionfilehtmcov);
    fprintf(fichtmcov,"Current page is file <a href=\"%s\">%s</a><br>\n\n<h4>Matrix of variance-covariance of pairs of step probabilities</h4>\n",optionfilehtmcov, optionfilehtmcov);     fprintf(fichtmcov,"Current page is file <a href=\"%s\">%s</a><br>\n\n<h4>Matrix of variance-covariance of pairs of step probabilities</h4>\n",optionfilehtmcov, optionfilehtmcov);
    fprintf(fichtmcov,"\nEllipsoids of confidence centered on point (p<inf>ij</inf>, p<inf>kl</inf>) are estimated \     fprintf(fichtmcov,"\nEllipsoids of confidence centered on point (p<inf>ij</inf>, p<inf>kl</inf>) are estimated \
 and drawn. It helps understanding how is the covariance between two incidences.\  and drawn. It helps understanding how is the covariance between two incidences.\
Line 6613  To be simple, these graphs help to under Line 6726  To be simple, these graphs help to under
                  }                   }
                                                                                                                                   
                  /* Eigen vectors */                   /* Eigen vectors */
                  v11=(1./sqrt(1+(v1-lc1)*(v1-lc1)/cv12/cv12));                   if(1+(v1-lc1)*(v1-lc1)/cv12/cv12 <1.e-5){
                      printf(" Error sqrt of a negative number: %lf\n",1+(v1-lc1)*(v1-lc1)/cv12/cv12);
                      fprintf(ficlog," Error sqrt of a negative number: %lf\n",1+(v1-lc1)*(v1-lc1)/cv12/cv12);
                      v11=(1./sqrt(fabs(1+(v1-lc1)*(v1-lc1)/cv12/cv12)));
                    }else
                      v11=(1./sqrt(1+(v1-lc1)*(v1-lc1)/cv12/cv12));
                  /*v21=sqrt(1.-v11*v11); *//* error */                   /*v21=sqrt(1.-v11*v11); *//* error */
                  v21=(lc1-v1)/cv12*v11;                   v21=(lc1-v1)/cv12*v11;
                  v12=-v21;                   v12=-v21;
Line 6644  To be simple, these graphs help to under Line 6762  To be simple, these graphs help to under
                    fprintf(ficgp,"\nset label \"%d\" at %11.3e,%11.3e center",(int) age, mu1,mu2);                     fprintf(ficgp,"\nset label \"%d\" at %11.3e,%11.3e center",(int) age, mu1,mu2);
                    fprintf(ficgp,"\n# Age %d, p%1d%1d - p%1d%1d",(int) age, k1,l1,k2,l2);                     fprintf(ficgp,"\n# Age %d, p%1d%1d - p%1d%1d",(int) age, k1,l1,k2,l2);
                    fprintf(ficgp,"\nplot [-pi:pi] %11.3e+ %.3f*(%11.3e*%11.3e*cos(t)+%11.3e*%11.3e*sin(t)), %11.3e +%.3f*(%11.3e*%11.3e*cos(t)+%11.3e*%11.3e*sin(t)) not",      \                     fprintf(ficgp,"\nplot [-pi:pi] %11.3e+ %.3f*(%11.3e*%11.3e*cos(t)+%11.3e*%11.3e*sin(t)), %11.3e +%.3f*(%11.3e*%11.3e*cos(t)+%11.3e*%11.3e*sin(t)) not",      \
                            mu1,std,v11,sqrt(lc1),v12,sqrt(fabs(lc2)),   \                             mu1,std,v11,sqrt(fabs(lc1)),v12,sqrt(fabs(lc2)), \
                            mu2,std,v21,sqrt(lc1),v22,sqrt(fabs(lc2))); /* For gnuplot only */                             mu2,std,v21,sqrt(fabs(lc1)),v22,sqrt(fabs(lc2))); /* For gnuplot only */
                  }else{                   }else{
                    first=0;                     first=0;
                    fprintf(fichtmcov," %d (%.3f),",(int) age, c12);                     fprintf(fichtmcov," %d (%.3f),",(int) age, c12);
Line 6704  void printinghtml(char fileresu[], char Line 6822  void printinghtml(char fileresu[], char
  - Estimated back transition probabilities over %d (stepm) months: <a href=\"%s\">%s</a><br>\n ",   - Estimated back transition probabilities over %d (stepm) months: <a href=\"%s\">%s</a><br>\n ",
            stepm,subdirf2(fileresu,"PIJB_"),subdirf2(fileresu,"PIJB_"));             stepm,subdirf2(fileresu,"PIJB_"),subdirf2(fileresu,"PIJB_"));
    fprintf(fichtm,"\     fprintf(fichtm,"\
  - Period (stable) prevalence in each health state: <a href=\"%s\">%s</a> <br>\n",   - Period (forward) prevalence in each health state: <a href=\"%s\">%s</a> <br>\n",
            subdirf2(fileresu,"PL_"),subdirf2(fileresu,"PL_"));             subdirf2(fileresu,"PL_"),subdirf2(fileresu,"PL_"));
    fprintf(fichtm,"\     fprintf(fichtm,"\
  - Period (stable) back prevalence in each health state: <a href=\"%s\">%s</a> <br>\n",   - Backward prevalence in each health state: <a href=\"%s\">%s</a> <br>\n",
            subdirf2(fileresu,"PLB_"),subdirf2(fileresu,"PLB_"));             subdirf2(fileresu,"PLB_"),subdirf2(fileresu,"PLB_"));
    fprintf(fichtm,"\     fprintf(fichtm,"\
  - (a) Life expectancies by health status at initial age, e<sub>i.</sub> (b) health expectancies by health status at initial age, e<sub>ij</sub> . If one or more covariates are included, specific tables for each value of the covariate are output in sequences within the same file (estepm=%2d months): \   - (a) Life expectancies by health status at initial age, e<sub>i.</sub> (b) health expectancies by health status at initial age, e<sub>ij</sub> . If one or more covariates are included, specific tables for each value of the covariate are output in sequences within the same file (estepm=%2d months): \
Line 6820  divided by h: <sub>h</sub>P<sub>ij</sub> Line 6938  divided by h: <sub>h</sub>P<sub>ij</sub>
      for(cpt=1; cpt<=nlstate;cpt++){       for(cpt=1; cpt<=nlstate;cpt++){
        fprintf(fichtm,"<br>\n- Survival functions from state %d in each live state and total.\         fprintf(fichtm,"<br>\n- Survival functions from state %d in each live state and total.\
  Or probability to survive in various states (1 to %d) being in state %d at different ages.     \   Or probability to survive in various states (1 to %d) being in state %d at different ages.     \
  <a href=\"%s_%d-%d-%d.svg\">%s_%d%d-%d.svg</a><br> <img src=\"%s_%d-%d-%d.svg\">", cpt, nlstate, cpt, subdirf2(optionfilefiname,"LIJT_"),cpt,k1,nres,subdirf2(optionfilefiname,"LIJT_"),cpt,k1,nres,subdirf2(optionfilefiname,"LIJT_"),cpt,k1,nres);   <a href=\"%s_%d-%d-%d.svg\">%s_%d-%d-%d.svg</a><br> <img src=\"%s_%d-%d-%d.svg\">", cpt, nlstate, cpt, subdirf2(optionfilefiname,"LIJT_"),cpt,k1,nres,subdirf2(optionfilefiname,"LIJT_"),cpt,k1,nres,subdirf2(optionfilefiname,"LIJT_"),cpt,k1,nres);
      }       }
      /* Period (stable) prevalence in each health state */       /* Period (forward stable) prevalence in each health state */
      for(cpt=1; cpt<=nlstate;cpt++){       for(cpt=1; cpt<=nlstate;cpt++){
        fprintf(fichtm,"<br>\n- Convergence to period (stable) prevalence in state %d. Or probability for a person being in state (1 to %d) at different ages, to be in state %d some years after. <a href=\"%s_%d-%d-%d.svg\">%s_%d-%d-%d.svg</a><br> \         fprintf(fichtm,"<br>\n- Convergence to period (stable) prevalence in state %d. Or probability for a person being in state (1 to %d) at different ages, to be in state %d some years after. <a href=\"%s_%d-%d-%d.svg\">%s_%d-%d-%d.svg</a><br> \
 <img src=\"%s_%d-%d-%d.svg\">", cpt, nlstate, cpt, subdirf2(optionfilefiname,"P_"),cpt,k1,nres,subdirf2(optionfilefiname,"P_"),cpt,k1,nres,subdirf2(optionfilefiname,"P_"),cpt,k1,nres);  <img src=\"%s_%d-%d-%d.svg\">", cpt, nlstate, cpt, subdirf2(optionfilefiname,"P_"),cpt,k1,nres,subdirf2(optionfilefiname,"P_"),cpt,k1,nres,subdirf2(optionfilefiname,"P_"),cpt,k1,nres);
      }       }
      if(backcast==1){       if(backcast==1){
        /* Period (stable) back prevalence in each health state */         /* Backward prevalence in each health state */
        for(cpt=1; cpt<=nlstate;cpt++){         for(cpt=1; cpt<=nlstate;cpt++){
          fprintf(fichtm,"<br>\n- Convergence to mixed (stable) back prevalence in state %d. Or probability for a person to be in state %d at a younger age, knowing that she/he was in state (1 to %d) at different older ages. <a href=\"%s_%d-%d-%d.svg\">%s_%d-%d-%d.svg</a><br> \           fprintf(fichtm,"<br>\n- Convergence to mixed (stable) back prevalence in state %d. Or probability for a person to be in state %d at a younger age, knowing that she/he was in state (1 to %d) at different older ages. <a href=\"%s_%d-%d-%d.svg\">%s_%d-%d-%d.svg</a><br> \
 <img src=\"%s_%d-%d-%d.svg\">", cpt, cpt, nlstate, subdirf2(optionfilefiname,"PB_"),cpt,k1,nres,subdirf2(optionfilefiname,"PB_"),cpt,k1,nres,subdirf2(optionfilefiname,"PB_"),cpt,k1,nres);  <img src=\"%s_%d-%d-%d.svg\">", cpt, cpt, nlstate, subdirf2(optionfilefiname,"PB_"),cpt,k1,nres,subdirf2(optionfilefiname,"PB_"),cpt,k1,nres,subdirf2(optionfilefiname,"PB_"),cpt,k1,nres);
        }         }
      }       }
      if(prevfcast==1){       if(prevfcast==1){
        /* Projection of prevalence up to period (stable) prevalence in each health state */         /* Projection of prevalence up to period (forward stable) prevalence in each health state */
        for(cpt=1; cpt<=nlstate;cpt++){         for(cpt=1; cpt<=nlstate;cpt++){
          fprintf(fichtm,"<br>\n- Projection of cross-sectional prevalence (estimated with cases observed from %.1f to %.1f and mobil_average=%d), from year %.1f up to year %.1f tending to period (stable) prevalence in state %d. Or probability to be in state %d being in an observed weighted state (from 1 to %d). <a href=\"%s_%d-%d-%d.svg\">%s_%d-%d-%d.svg</a><br> \           fprintf(fichtm,"<br>\n- Projection of cross-sectional prevalence (estimated with cases observed from %.1f to %.1f and mobil_average=%d), from year %.1f up to year %.1f tending to period (stable) forward prevalence in state %d. Or probability to be in state %d being in an observed weighted state (from 1 to %d). <a href=\"%s_%d-%d-%d.svg\">%s_%d-%d-%d.svg</a><br> \
 <img src=\"%s_%d-%d-%d.svg\">", dateprev1, dateprev2, mobilavproj, dateproj1, dateproj2, cpt, cpt, nlstate, subdirf2(optionfilefiname,"PROJ_"),cpt,k1,nres,subdirf2(optionfilefiname,"PROJ_"),cpt,k1,nres,subdirf2(optionfilefiname,"PROJ_"),cpt,k1,nres);  <img src=\"%s_%d-%d-%d.svg\">", dateprev1, dateprev2, mobilavproj, dateproj1, dateproj2, cpt, cpt, nlstate, subdirf2(optionfilefiname,"PROJ_"),cpt,k1,nres,subdirf2(optionfilefiname,"PROJ_"),cpt,k1,nres,subdirf2(optionfilefiname,"PROJ_"),cpt,k1,nres);
        }         }
      }       }
Line 6890  See page 'Matrix of variance-covariance Line 7008  See page 'Matrix of variance-covariance
    <a href=\"%s\">%s</a> <br>\n</li>",     <a href=\"%s\">%s</a> <br>\n</li>",
            estepm,subdirf2(fileresu,"STDE_"),subdirf2(fileresu,"STDE_"));             estepm,subdirf2(fileresu,"STDE_"),subdirf2(fileresu,"STDE_"));
    fprintf(fichtm,"\     fprintf(fichtm,"\
  - Variances and covariances of health expectancies by age. Status (i) based health expectancies (in state j), e<sup>ij</sup> are weighted by the period prevalences in each state i (if popbased=1, an additional computation is done using the cross-sectional prevalences, i.e population based) (estepm=%d months): <a href=\"%s\">%s</a><br>\n",   - Variances and covariances of health expectancies by age. Status (i) based health expectancies (in state j), e<sup>ij</sup> are weighted by the forward (period) prevalences in each state i (if popbased=1, an additional computation is done using the cross-sectional prevalences, i.e population based) (estepm=%d months): <a href=\"%s\">%s</a><br>\n",
            estepm, subdirf2(fileresu,"V_"),subdirf2(fileresu,"V_"));             estepm, subdirf2(fileresu,"V_"),subdirf2(fileresu,"V_"));
    fprintf(fichtm,"\     fprintf(fichtm,"\
  - Total life expectancy and total health expectancies to be spent in each health state e<sup>.j</sup> with their standard errors (if popbased=1, an additional computation is done using the cross-sectional prevalences, i.e population based) (estepm=%d months): <a href=\"%s\">%s</a> <br>\n",   - Total life expectancy and total health expectancies to be spent in each health state e<sup>.j</sup> with their standard errors (if popbased=1, an additional computation is done using the cross-sectional prevalences, i.e population based) (estepm=%d months): <a href=\"%s\">%s</a> <br>\n",
            estepm, subdirf2(fileresu,"T_"),subdirf2(fileresu,"T_"));             estepm, subdirf2(fileresu,"T_"),subdirf2(fileresu,"T_"));
    fprintf(fichtm,"\     fprintf(fichtm,"\
  - Standard deviation of period (stable) prevalences: <a href=\"%s\">%s</a> <br>\n",\   - Standard deviation of forward (period) prevalences: <a href=\"%s\">%s</a> <br>\n",\
            subdirf2(fileresu,"VPL_"),subdirf2(fileresu,"VPL_"));             subdirf2(fileresu,"VPL_"),subdirf2(fileresu,"VPL_"));
   
 /*  if(popforecast==1) fprintf(fichtm,"\n */  /*  if(popforecast==1) fprintf(fichtm,"\n */
Line 7032  void printinggnuplot(char fileresu[], ch Line 7150  void printinggnuplot(char fileresu[], ch
           continue;            continue;
         /* We are interested in selected combination by the resultline */          /* We are interested in selected combination by the resultline */
         /* printf("\n# 1st: Period (stable) prevalence with CI: 'VPL_' files and live state =%d ", cpt); */          /* 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);          fprintf(ficgp,"\n# 1st: Forward (stable period) prevalence with CI: 'VPL_' files  and live state =%d ", cpt);
         strcpy(gplotlabel,"(");          strcpy(gplotlabel,"(");
         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 */
Line 7070  void printinggnuplot(char fileresu[], ch Line 7188  void printinggnuplot(char fileresu[], ch
           if (i==cpt) fprintf(ficgp," %%lf (%%lf)");            if (i==cpt) fprintf(ficgp," %%lf (%%lf)");
           else        fprintf(ficgp," %%*lf (%%*lf)");            else        fprintf(ficgp," %%*lf (%%*lf)");
         }          }
         fprintf(ficgp,"\" t\"Period (stable) prevalence\" w l lt 0,\"%s\" every :::%d::%d u 1:($2==%d ? $3+1.96*$4 : 1/0) \"%%lf %%lf",subdirf2(fileresu,"VPL_"),nres-1,nres-1,nres);          fprintf(ficgp,"\" t\"Forward prevalence\" w l lt 0,\"%s\" every :::%d::%d u 1:($2==%d ? $3+1.96*$4 : 1/0) \"%%lf %%lf",subdirf2(fileresu,"VPL_"),nres-1,nres-1,nres);
         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 7399  set ter svg size 640, 480\nunset log y\n Line 7517  set ter svg size 640, 480\nunset log y\n
       continue;        continue;
     for (cpt=1; cpt<=nlstate ; cpt ++) { /* For each life state of arrival */      for (cpt=1; cpt<=nlstate ; cpt ++) { /* For each life state of arrival */
       strcpy(gplotlabel,"(");              strcpy(gplotlabel,"(");      
       fprintf(ficgp,"\n#\n#\n#CV preval stable (period): 'pij' files, covariatecombination#=%d state=%d",k1, cpt);        fprintf(ficgp,"\n#\n#\n#CV preval stable (forward): 'pij' files, covariatecombination#=%d state=%d",k1, cpt);
       for (k=1; k<=cptcoveff; k++){    /* For each covariate and each value */        for (k=1; k<=cptcoveff; k++){    /* For each covariate and each value */
         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 */
Line 7443  set ter svg size 640, 480\nunset log y\n Line 7561  set ter svg size 640, 480\nunset log y\n
       
 /* 7eme */  /* 7eme */
   if(backcast == 1){    if(backcast == 1){
     /* CV back preval stable (period) for each covariate */      /* CV backward prevalence  for each covariate */
     for (k1=1; k1<= m ; k1 ++) /* For each covariate combination if any */      for (k1=1; k1<= m ; k1 ++) /* For each covariate combination if any */
     for(nres=1; nres <= nresult; nres++){ /* For each resultline */      for(nres=1; nres <= nresult; nres++){ /* For each resultline */
       if(m != 1 && TKresult[nres]!= k1)        if(m != 1 && TKresult[nres]!= k1)
         continue;          continue;
       for (cpt=1; cpt<=nlstate ; cpt ++) { /* For each life origin state */        for (cpt=1; cpt<=nlstate ; cpt ++) { /* For each life origin state */
         strcpy(gplotlabel,"(");                strcpy(gplotlabel,"(");      
         fprintf(ficgp,"\n#\n#\n#CV Back preval stable (period): 'pijb' files, covariatecombination#=%d state=%d",k1, cpt);          fprintf(ficgp,"\n#\n#\n#CV Backward stable prevalence: 'pijb' files, covariatecombination#=%d state=%d",k1, cpt);
         for (k=1; k<=cptcoveff; k++){    /* For each covariate and each value */          for (k=1; k<=cptcoveff; k++){    /* For each covariate and each value */
           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 */
Line 7498  set ter svg size 640, 480\nunset log y\n Line 7616  set ter svg size 640, 480\nunset log y\n
       
   /* 8eme */    /* 8eme */
   if(prevfcast==1){    if(prevfcast==1){
     /* Projection from cross-sectional to stable (period) for each covariate */      /* Projection from cross-sectional to forward stable (period) prevalence for each covariate */
           
     for (k1=1; k1<= m ; k1 ++) /* For each covariate combination if any */      for (k1=1; k1<= m ; k1 ++) /* For each covariate combination if any */
     for(nres=1; nres <= nresult; nres++){ /* For each resultline */      for(nres=1; nres <= nresult; nres++){ /* For each resultline */
Line 7506  set ter svg size 640, 480\nunset log y\n Line 7624  set ter svg size 640, 480\nunset log y\n
         continue;          continue;
       for (cpt=1; cpt<=nlstate ; cpt ++) { /* For each life state */        for (cpt=1; cpt<=nlstate ; cpt ++) { /* For each life state */
         strcpy(gplotlabel,"(");                strcpy(gplotlabel,"(");      
         fprintf(ficgp,"\n#\n#\n#Projection of prevalence to stable (period): 'PROJ_' files, covariatecombination#=%d state=%d",k1, cpt);          fprintf(ficgp,"\n#\n#\n#Projection of prevalence to forward stable prevalence (period): 'PROJ_' files, covariatecombination#=%d state=%d",k1, cpt);
         for (k=1; k<=cptcoveff; k++){    /* For each correspondig covariate value  */          for (k=1; k<=cptcoveff; k++){    /* For each correspondig covariate value  */
           lv= decodtabm(k1,k,cptcoveff); /* Should be the covariate value corresponding to k1 combination and kth covariate */            lv= decodtabm(k1,k,cptcoveff); /* Should be the covariate value corresponding to k1 combination and kth covariate */
           /* 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 7940  set ter svg size 640, 480\nunset log y\n Line 8058  set ter svg size 640, 480\nunset log y\n
    int modcovmax =1;     int modcovmax =1;
    int mobilavrange, mob;     int mobilavrange, mob;
    int iage=0;     int iage=0;
      int firstA1=0, firstA2=0;
   
    double sum=0., sumr=0.;     double sum=0., sumr=0.;
    double age;     double age;
Line 8037  set ter svg size 640, 480\nunset log y\n Line 8156  set ter svg size 640, 480\nunset log y\n
      } /* age */       } /* age */
      /* Thus we have agemingood and agemaxgood as well as goodr for raw (preobs) */       /* Thus we have agemingood and agemaxgood as well as goodr for raw (preobs) */
      /* but they will change */       /* but they will change */
        firstA1=0;firstA2=0;
      for (age=fage-(mob-1)/2; age>=bage; age--){/* From oldest to youngest, filling up to the youngest */       for (age=fage-(mob-1)/2; age>=bage; age--){/* From oldest to youngest, filling up to the youngest */
        sumnewm[cptcod]=0.;         sumnewm[cptcod]=0.;
        sumnewmr[cptcod]=0.;         sumnewmr[cptcod]=0.;
Line 8069  set ter svg size 640, 480\nunset log y\n Line 8189  set ter svg size 640, 480\nunset log y\n
          sumr+=probs[(int)age][i][cptcod];           sumr+=probs[(int)age][i][cptcod];
        }         }
        if(fabs(sum - 1.) > 1.e-3) { /* bad */         if(fabs(sum - 1.) > 1.e-3) { /* bad */
          printf("Moving average A1: For this combination of covariate cptcod=%d, we can't get a smoothed prevalence which sums to one (%f) at any descending age! age=%d, could you increase bage=%d\n",cptcod,sumr, (int)age, (int)bage);           if(!firstA1){
              firstA1=1;
              printf("Moving average A1: For this combination of covariate cptcod=%d, we can't get a smoothed prevalence which sums to one (%f) at any descending age! age=%d, could you increase bage=%d. Others in log file...\n",cptcod,sumr, (int)age, (int)bage);
            }
            fprintf(ficlog,"Moving average A1: For this combination of covariate cptcod=%d, we can't get a smoothed prevalence which sums to one (%f) at any descending age! age=%d, could you increase bage=%d\n",cptcod,sumr, (int)age, (int)bage);
        } /* end bad */         } /* end bad */
        /* else{ /\* We found some ages summing to one, we will smooth the oldest *\/ */         /* else{ /\* We found some ages summing to one, we will smooth the oldest *\/ */
        if(fabs(sumr - 1.) > 1.e-3) { /* bad */         if(fabs(sumr - 1.) > 1.e-3) { /* bad */
          printf("Moving average A2: For this combination of covariate cptcod=%d, the raw prevalence doesn't sums to one (%f) even with smoothed values at young ages! age=%d, could you increase bage=%d\n",cptcod,sumr, (int)age, (int)bage);           if(!firstA2){
              firstA2=1;
              printf("Moving average A2: For this combination of covariate cptcod=%d, the raw prevalence doesn't sums to one (%f) even with smoothed values at young ages! age=%d, could you increase bage=%d. Others in log file...\n",cptcod,sumr, (int)age, (int)bage);
            }
            fprintf(ficlog,"Moving average A2: For this combination of covariate cptcod=%d, the raw prevalence doesn't sums to one (%f) even with smoothed values at young ages! age=%d, could you increase bage=%d\n",cptcod,sumr, (int)age, (int)bage);
        } /* end bad */         } /* end bad */
      }/* age */       }/* age */
   
Line 8448  set ter svg size 640, 480\nunset log y\n Line 8576  set ter svg size 640, 480\nunset log y\n
   
 /* Variance of prevalence limit: varprlim */  /* Variance of prevalence limit: varprlim */
  void varprlim(char fileresu[], int nresult, double ***prevacurrent, int mobilavproj, double bage, double fage, double **prlim, int *ncvyearp, double ftolpl, double p[], double **matcov, double *delti, int stepm, int cptcoveff){   void varprlim(char fileresu[], int nresult, double ***prevacurrent, int mobilavproj, double bage, double fage, double **prlim, int *ncvyearp, double ftolpl, double p[], double **matcov, double *delti, int stepm, int cptcoveff){
     /*------- Variance of period (stable) prevalence------*/         /*------- Variance of forward period (stable) prevalence------*/   
     
    char fileresvpl[FILENAMELENGTH];       char fileresvpl[FILENAMELENGTH];  
    FILE *ficresvpl;     FILE *ficresvpl;
Line 8459  set ter svg size 640, 480\nunset log y\n Line 8587  set ter svg size 640, 480\nunset log y\n
     strcpy(fileresvpl,"VPL_");      strcpy(fileresvpl,"VPL_");
     strcat(fileresvpl,fileresu);      strcat(fileresvpl,fileresu);
     if((ficresvpl=fopen(fileresvpl,"w"))==NULL) {      if((ficresvpl=fopen(fileresvpl,"w"))==NULL) {
       printf("Problem with variance of period (stable) prevalence  resultfile: %s\n", fileresvpl);        printf("Problem with variance of forward period (stable) prevalence  resultfile: %s\n", fileresvpl);
       exit(0);        exit(0);
     }      }
     printf("Computing Variance-covariance of period (stable) prevalence: file '%s' ...", fileresvpl);fflush(stdout);      printf("Computing Variance-covariance of forward period (stable) prevalence: file '%s' ...", fileresvpl);fflush(stdout);
     fprintf(ficlog, "Computing Variance-covariance of period (stable) prevalence: file '%s' ...", fileresvpl);fflush(ficlog);      fprintf(ficlog, "Computing Variance-covariance of forward period (stable) prevalence: file '%s' ...", fileresvpl);fflush(ficlog);
           
     /*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++){*/
Line 8500  set ter svg size 640, 480\nunset log y\n Line 8628  set ter svg size 640, 480\nunset log y\n
     }      }
           
     fclose(ficresvpl);      fclose(ficresvpl);
     printf("done variance-covariance of period prevalence\n");fflush(stdout);      printf("done variance-covariance of forward period prevalence\n");fflush(stdout);
     fprintf(ficlog,"done variance-covariance of period prevalence\n");fflush(ficlog);      fprintf(ficlog,"done variance-covariance of forward period prevalence\n");fflush(ficlog);
   
  }   }
 /* Variance of back prevalence: varbprlim */  /* Variance of back prevalence: varbprlim */
Line 9644  Dummy[k] 0=dummy (0 1), 1 quantitative ( Line 9772  Dummy[k] 0=dummy (0 1), 1 quantitative (
 Typevar: 0 for simple covariate (dummy, quantitative, fixed or varying), 1 for age product, 2 for  product \n\  Typevar: 0 for simple covariate (dummy, quantitative, fixed or varying), 1 for age product, 2 for  product \n\
 Fixed[k] 0=fixed (product or simple), 1 varying, 2 fixed with age product, 3 varying with age product \n\  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;k<=cptcovt; k++){ Fixed[k]=0; Dummy[k]=0;}    for(k=-1;k<=cptcovt; k++){ Fixed[k]=0; Dummy[k]=0;}
   for(k=1, ncovf=0, nsd=0, nsq=0, ncovv=0, ncova=0, ncoveff=0, nqfveff=0, ntveff=0, nqtveff=0;k<=cptcovt; k++){ /* or cptocvt */    for(k=1, ncovf=0, nsd=0, nsq=0, ncovv=0, ncova=0, ncoveff=0, nqfveff=0, ntveff=0, nqtveff=0;k<=cptcovt; k++){ /* or cptocvt */
     if (Tvar[k] <=ncovcol && Typevar[k]==0 ){ /* Simple fixed dummy (<=ncovcol) covariates */      if (Tvar[k] <=ncovcol && Typevar[k]==0 ){ /* Simple fixed dummy (<=ncovcol) covariates */
       Fixed[k]= 0;        Fixed[k]= 0;
Line 9894  Dummy[k] 0=dummy (0 1), 1 quantitative ( Line 10022  Dummy[k] 0=dummy (0 1), 1 quantitative (
   /* 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]==Typevar[k2]) && (Fixed[k1]==Fixed[k2]) && (Dummy[k1]==Dummy[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[k1],Dummy[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[k1],Dummy[k1]); fflush(ficlog);
             return(1);              return(1);
           }            }
         }else if (Typevar[k1] ==2){          }else if (Typevar[k1] ==2){
Line 10209  void syscompilerinfo(int logged) Line 10338  void syscompilerinfo(int logged)
 #endif  #endif
 #endif  #endif
   
    //   void main()     //   void main ()
    //   {     //   {
 #if defined(_MSC_VER)  #if defined(_MSC_VER)
    if (IsWow64()){     if (IsWow64()){
Line 10230  void syscompilerinfo(int logged) Line 10359  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  (forward period or forward stable prevalence) --------------*/
   int i, j, k, i1, k4=0, nres=0 ;    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;
Line 10239  int prevalence_limit(double *p, double * Line 10368  int prevalence_limit(double *p, double *
   strcpy(filerespl,"PL_");    strcpy(filerespl,"PL_");
   strcat(filerespl,fileresu);    strcat(filerespl,fileresu);
   if((ficrespl=fopen(filerespl,"w"))==NULL) {    if((ficrespl=fopen(filerespl,"w"))==NULL) {
     printf("Problem with period (stable) prevalence resultfile: %s\n", filerespl);return 1;      printf("Problem with forward period (stable) prevalence resultfile: %s\n", filerespl);return 1;
     fprintf(ficlog,"Problem with period (stable) prevalence resultfile: %s\n", filerespl);return 1;      fprintf(ficlog,"Problem with forward period (stable) prevalence resultfile: %s\n", filerespl);return 1;
   }    }
   printf("\nComputing period (stable) prevalence: result on file '%s' \n", filerespl);    printf("\nComputing forward period (stable) prevalence: result on file '%s' \n", filerespl);
   fprintf(ficlog,"\nComputing period (stable) prevalence: result on file '%s' \n", filerespl);    fprintf(ficlog,"\nComputing forward period (stable) prevalence: result on file '%s' \n", filerespl);
   pstamp(ficrespl);    pstamp(ficrespl);
   fprintf(ficrespl,"# Period (stable) prevalence. Precision given by ftolpl=%g \n", ftolpl);    fprintf(ficrespl,"# Forward period (stable) prevalence. Precision given by ftolpl=%g \n", ftolpl);
   fprintf(ficrespl,"#Age ");    fprintf(ficrespl,"#Age ");
   for(i=1; i<=nlstate;i++) fprintf(ficrespl,"%d-%d ",i,i);    for(i=1; i<=nlstate;i++) fprintf(ficrespl,"%d-%d ",i,i);
   fprintf(ficrespl,"\n");    fprintf(ficrespl,"\n");
Line 10320  int prevalence_limit(double *p, double * Line 10449  int prevalence_limit(double *p, double *
 }  }
   
 int back_prevalence_limit(double *p, double **bprlim, double ageminpar, double agemaxpar, double ftolpl, int *ncvyearp, double dateprev1,double dateprev2, int firstpass, int lastpass, int mobilavproj){  int back_prevalence_limit(double *p, double **bprlim, double ageminpar, double agemaxpar, double ftolpl, int *ncvyearp, double dateprev1,double dateprev2, int firstpass, int lastpass, int mobilavproj){
         /*--------------- Back Prevalence limit  (period or stable prevalence) --------------*/          /*--------------- Back Prevalence limit  (backward stable prevalence) --------------*/
                   
         /* 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
Line 10335  int back_prevalence_limit(double *p, dou Line 10464  int back_prevalence_limit(double *p, dou
   strcpy(fileresplb,"PLB_");    strcpy(fileresplb,"PLB_");
   strcat(fileresplb,fileresu);    strcat(fileresplb,fileresu);
   if((ficresplb=fopen(fileresplb,"w"))==NULL) {    if((ficresplb=fopen(fileresplb,"w"))==NULL) {
     printf("Problem with period (stable) back prevalence resultfile: %s\n", fileresplb);return 1;      printf("Problem with backward prevalence resultfile: %s\n", fileresplb);return 1;
     fprintf(ficlog,"Problem with period (stable) back prevalence resultfile: %s\n", fileresplb);return 1;      fprintf(ficlog,"Problem with backward prevalence resultfile: %s\n", fileresplb);return 1;
   }    }
   printf("Computing period (stable) back prevalence: result on file '%s' \n", fileresplb);    printf("Computing backward prevalence: result on file '%s' \n", fileresplb);
   fprintf(ficlog,"Computing period (stable) back prevalence: result on file '%s' \n", fileresplb);    fprintf(ficlog,"Computing backward prevalence: result on file '%s' \n", fileresplb);
   pstamp(ficresplb);    pstamp(ficresplb);
   fprintf(ficresplb,"# Period (stable) back prevalence. Precision given by ftolpl=%g \n", ftolpl);    fprintf(ficresplb,"# Backward prevalence. Precision given by ftolpl=%g \n", ftolpl);
   fprintf(ficresplb,"#Age ");    fprintf(ficresplb,"#Age ");
   for(i=1; i<=nlstate;i++) fprintf(ficresplb,"%d-%d ",i,i);    for(i=1; i<=nlstate;i++) fprintf(ficresplb,"%d-%d ",i,i);
   fprintf(ficresplb,"\n");    fprintf(ficresplb,"\n");
Line 10530  int hPijx(double *p, int bage, int fage) Line 10659  int hPijx(double *p, int bage, int fage)
   /*if (stepm<=24) stepsize=2;*/    /*if (stepm<=24) stepsize=2;*/
       
   /* agelim=AGESUP; */    /* agelim=AGESUP; */
   ageminl=30;    ageminl=AGEINF; /* was 30 */
   hstepm=stepsize*YEARM; /* Every year of age */    hstepm=stepsize*YEARM; /* Every year of age */
   hstepm=hstepm/stepm; /* Typically 2 years, = 2/6 months = 4 */    hstepm=hstepm/stepm; /* Typically 2 years, = 2/6 months = 4 */
       
Line 10609  int main(int argc, char *argv[]) Line 10738  int main(int argc, char *argv[])
   double ssval;    double ssval;
 #endif  #endif
   int movingaverage(double ***probs, double bage,double fage, double ***mobaverage, int mobilav);    int movingaverage(double ***probs, double bage,double fage, double ***mobaverage, int mobilav);
   int i,j, k, n=MAXN,iter=0,m,size=100, cptcod;    int i,j, k, iter=0,m,size=100, cptcod; /* Suppressing because nobs */
     /* int i,j, k, n=MAXN,iter=0,m,size=100, cptcod; */
   int ncvyear=0; /* Number of years needed for the period prevalence to converge */    int ncvyear=0; /* Number of years needed for the period prevalence to converge */
   int jj, ll, li, lj, lk;    int jj, ll, li, lj, lk;
   int numlinepar=0; /* Current linenumber of parameter file */    int numlinepar=0; /* Current linenumber of parameter file */
Line 10644  int main(int argc, char *argv[]) Line 10774  int main(int argc, char *argv[])
       
   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; /* nobs = lastobs-firstobs declared globally ;*/
   int c,  h , cpt, c2;    int c,  h , cpt, c2;
   int jl=0;    int jl=0;
   int i1, j1, jk, stepsize=0;    int i1, j1, jk, stepsize=0;
Line 10756  int main(int argc, char *argv[]) Line 10886  int main(int argc, char *argv[])
       if(pathr[0] == '\0') break; /* Dirty */        if(pathr[0] == '\0') break; /* Dirty */
     }      }
   }    }
     else if (argc<=2){
       strcpy(pathtot,argv[1]);
     }
   else{    else{
     strcpy(pathtot,argv[1]);      strcpy(pathtot,argv[1]);
       strcpy(z,argv[2]);
       printf("\nargv[2]=%s z=%c\n",argv[2],z[0]);
   }    }
   /*if(getcwd(pathcd, MAXLINE)!= NULL)printf ("Error pathcd\n");*/    /*if(getcwd(pathcd, MAXLINE)!= NULL)printf ("Error pathcd\n");*/
   /*cygwin_split_path(pathtot,path,optionfile);    /*cygwin_split_path(pathtot,path,optionfile);
Line 10835  int main(int argc, char *argv[]) Line 10970  int main(int argc, char *argv[])
     exit(70);       exit(70); 
   }    }
   
   
   
   strcpy(filereso,"o");    strcpy(filereso,"o");
   strcat(filereso,fileresu);    strcat(filereso,fileresu);
   if((ficparo=fopen(filereso,"w"))==NULL) { /* opened on subdirectory */    if((ficparo=fopen(filereso,"w"))==NULL) { /* opened on subdirectory */
Line 10900  int main(int argc, char *argv[]) Line 11033  int main(int argc, char *argv[])
                         title, datafile, &lastobs, &firstpass,&lastpass)) !=EOF){                          title, datafile, &lastobs, &firstpass,&lastpass)) !=EOF){
     if (num_filled != 5) {      if (num_filled != 5) {
       printf("Should be 5 parameters\n");        printf("Should be 5 parameters\n");
         fprintf(ficlog,"Should be 5 parameters\n");
     }      }
     numlinepar++;      numlinepar++;
     printf("title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\n", title, datafile, lastobs, firstpass,lastpass);      printf("title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\n", title, datafile, lastobs, firstpass,lastpass);
       fprintf(ficparo,"title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\n", title, datafile, lastobs, firstpass,lastpass);
       fprintf(ficres,"title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\n", title, datafile, lastobs, firstpass,lastpass);
       fprintf(ficlog,"title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\n", title, datafile, lastobs, firstpass,lastpass);
   }    }
   /* Second parameter line */    /* Second parameter line */
   while(fgets(line, MAXLINE, ficpar)) {    while(fgets(line, MAXLINE, ficpar)) {
     /* If line starts with a # it is a comment */      /* while(fscanf(ficpar,"%[^\n]", line)) { */
       /* If line starts with a # it is a comment. Strangely fgets reads the EOL and fputs doesn't */
     if (line[0] == '#') {      if (line[0] == '#') {
       numlinepar++;        numlinepar++;
       fputs(line,stdout);        printf("%s",line);
       fputs(line,ficparo);        fprintf(ficres,"%s",line);
       fputs(line,ficres);        fprintf(ficparo,"%s",line);
       fputs(line,ficlog);        fprintf(ficlog,"%s",line);
       continue;        continue;
     }else      }else
       break;        break;
Line 10922  int main(int argc, char *argv[]) Line 11060  int main(int argc, char *argv[])
     if (num_filled != 11) {      if (num_filled != 11) {
       printf("Not 11 parameters, for example:ftol=1.e-8 stepm=12 ncovcol=2 nqv=1 ntv=2 nqtv=1  nlstate=2 ndeath=1 maxwav=3 mle=1 weight=1\n");        printf("Not 11 parameters, for example:ftol=1.e-8 stepm=12 ncovcol=2 nqv=1 ntv=2 nqtv=1  nlstate=2 ndeath=1 maxwav=3 mle=1 weight=1\n");
       printf("but line=%s\n",line);        printf("but line=%s\n",line);
         fprintf(ficlog,"Not 11 parameters, for example:ftol=1.e-8 stepm=12 ncovcol=2 nqv=1 ntv=2 nqtv=1  nlstate=2 ndeath=1 maxwav=3 mle=1 weight=1\n");
         fprintf(ficlog,"but line=%s\n",line);
       }
       if( lastpass > maxwav){
         printf("Error (lastpass = %d) > (maxwav = %d)\n",lastpass, maxwav);
         fprintf(ficlog,"Error (lastpass = %d) > (maxwav = %d)\n",lastpass, maxwav);
         fflush(ficlog);
         goto end;
     }      }
     printf("ftol=%e stepm=%d ncovcol=%d nqv=%d ntv=%d nqtv=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d\n",ftol, stepm, ncovcol, nqv, ntv, nqtv, nlstate, ndeath, maxwav, mle, weightopt);        printf("ftol=%e stepm=%d ncovcol=%d nqv=%d ntv=%d nqtv=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d\n",ftol, stepm, ncovcol, nqv, ntv, nqtv, nlstate, ndeath, maxwav, mle, weightopt);
       fprintf(ficparo,"ftol=%e stepm=%d ncovcol=%d nqv=%d ntv=%d nqtv=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d\n",ftol, stepm, ncovcol, nqv, ntv, nqtv, nlstate, ndeath, maxwav, mle, weightopt);
       fprintf(ficres,"ftol=%e stepm=%d ncovcol=%d nqv=%d ntv=%d nqtv=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d\n",ftol, stepm, ncovcol, nqv, ntv, nqtv, nlstate, ndeath, maxwav, 0, weightopt);
       fprintf(ficlog,"ftol=%e stepm=%d ncovcol=%d nqv=%d ntv=%d nqtv=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d\n",ftol, stepm, ncovcol, nqv, ntv, nqtv, nlstate, ndeath, maxwav, mle, weightopt);
   }    }
   /* ftolpl=6*ftol*1.e5; /\* 6.e-3 make convergences in less than 80 loops for the prevalence limit *\/ */    /* ftolpl=6*ftol*1.e5; /\* 6.e-3 make convergences in less than 80 loops for the prevalence limit *\/ */
   /*ftolpl=6.e-4; *//* 6.e-3 make convergences in less than 80 loops for the prevalence limit */    /*ftolpl=6.e-4; *//* 6.e-3 make convergences in less than 80 loops for the prevalence limit */
Line 10932  int main(int argc, char *argv[]) Line 11081  int main(int argc, char *argv[])
     /* If line starts with a # it is a comment */      /* If line starts with a # it is a comment */
     if (line[0] == '#') {      if (line[0] == '#') {
       numlinepar++;        numlinepar++;
       fputs(line,stdout);        printf("%s",line);
       fputs(line,ficparo);        fprintf(ficres,"%s",line);
       fputs(line,ficres);        fprintf(ficparo,"%s",line);
       fputs(line,ficlog);        fprintf(ficlog,"%s",line);
       continue;        continue;
     }else      }else
       break;        break;
   }    }
   if((num_filled=sscanf(line,"model=1+age%[^.\n]", model)) !=EOF){    if((num_filled=sscanf(line,"model=1+age%[^.\n]", model)) !=EOF){
     if (num_filled == 0){      if (num_filled != 1){
       printf("ERROR %d: Model should be at minimum 'model=1+age.' WITHOUT space:'%s'\n",num_filled, line);        printf("ERROR %d: Model should be at minimum 'model=1+age' %s\n",num_filled, line);
       fprintf(ficlog,"ERROR %d: Model should be at minimum 'model=1+age.' WITHOUT space:'%s'\n",num_filled, line);        fprintf(ficlog,"ERROR %d: Model should be at minimum 'model=1+age' %s\n",num_filled, line);
       model[0]='\0';  
       goto end;  
     } else if (num_filled != 1){  
       printf("ERROR %d: Model should be at minimum 'model=1+age.' %s\n",num_filled, line);  
       fprintf(ficlog,"ERROR %d: Model should be at minimum 'model=1+age.' %s\n",num_filled, line);  
       model[0]='\0';        model[0]='\0';
       goto end;        goto end;
     }      }
Line 10961  int main(int argc, char *argv[]) Line 11105  int main(int argc, char *argv[])
     }      }
     /* printf(" model=1+age%s modeltemp= %s, model=%s\n",model, modeltemp, model);fflush(stdout); */      /* printf(" model=1+age%s modeltemp= %s, model=%s\n",model, modeltemp, model);fflush(stdout); */
     printf("model=1+age+%s\n",model);fflush(stdout);      printf("model=1+age+%s\n",model);fflush(stdout);
       fprintf(ficparo,"model=1+age+%s\n",model);fflush(stdout);
       fprintf(ficres,"model=1+age+%s\n",model);fflush(stdout);
       fprintf(ficlog,"model=1+age+%s\n",model);fflush(stdout);
   }    }
   /* fscanf(ficpar,"title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\nftol=%lf stepm=%d ncovcol=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d model=1+age+%s\n",title, datafile, &lastobs, &firstpass,&lastpass,&ftol, &stepm, &ncovcol, &nlstate,&ndeath, &maxwav, &mle, &weightopt,model); */    /* fscanf(ficpar,"title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\nftol=%lf stepm=%d ncovcol=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d model=1+age+%s\n",title, datafile, &lastobs, &firstpass,&lastpass,&ftol, &stepm, &ncovcol, &nlstate,&ndeath, &maxwav, &mle, &weightopt,model); */
   /* numlinepar=numlinepar+3; /\* In general *\/ */    /* numlinepar=numlinepar+3; /\* In general *\/ */
   /* printf("title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\nftol=%e stepm=%d ncovcol=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d\nmodel=1+age+%s\n", title, datafile, lastobs, firstpass,lastpass,ftol, stepm, ncovcol, nlstate,ndeath, maxwav, mle, weightopt,model); */    /* printf("title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\nftol=%e stepm=%d ncovcol=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d\nmodel=1+age+%s\n", title, datafile, lastobs, firstpass,lastpass,ftol, stepm, ncovcol, nlstate,ndeath, maxwav, mle, weightopt,model); */
   fprintf(ficparo,"title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\nftol=%e stepm=%d ncovcol=%d nqv=%d ntv=%d nqtv=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d\nmodel=1+age+%s.\n", title, datafile, lastobs, firstpass,lastpass,ftol,stepm,ncovcol, nqv, ntv, nqtv, nlstate,ndeath,maxwav, mle, weightopt,model);    /* fprintf(ficparo,"title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\nftol=%e stepm=%d ncovcol=%d nqv=%d ntv=%d nqtv=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d\nmodel=1+age+%s.\n", title, datafile, lastobs, firstpass,lastpass,ftol,stepm,ncovcol, nqv, ntv, nqtv, nlstate,ndeath,maxwav, mle, weightopt,model); */
   fprintf(ficlog,"title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\nftol=%e stepm=%d ncovcol=%d nqv=%d ntv=%d nqtv=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d\nmodel=1+age+%s.\n", title, datafile, lastobs, firstpass,lastpass,ftol,stepm,ncovcol, nqv, ntv, nqtv, nlstate,ndeath,maxwav, mle, weightopt,model);    /* fprintf(ficlog,"title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\nftol=%e stepm=%d ncovcol=%d nqv=%d ntv=%d nqtv=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d\nmodel=1+age+%s.\n", title, datafile, lastobs, firstpass,lastpass,ftol,stepm,ncovcol, nqv, ntv, nqtv, nlstate,ndeath,maxwav, mle, weightopt,model); */
   fflush(ficlog);    fflush(ficlog);
   /* if(model[0]=='#'|| model[0]== '\0'){ */    /* if(model[0]=='#'|| model[0]== '\0'){ */
   if(model[0]=='#'){    if(model[0]=='#'){
     printf("Error in 'model' line: model should start with 'model=1+age+' and end with '.' \n \      printf("Error in 'model' line: model should start with 'model=1+age+' and end without space \n \
  'model=1+age+.' or 'model=1+age+V1.' or 'model=1+age+age*age+V1+V1*age.' or \n \   'model=1+age+' or 'model=1+age+V1.' or 'model=1+age+age*age+V1+V1*age' or \n \
  'model=1+age+V1+V2.' or 'model=1+age+V1+V2+V1*V2.' etc. \n");          \   'model=1+age+V1+V2' or 'model=1+age+V1+V2+V1*V2' etc. \n");            \
     if(mle != -1){      if(mle != -1){
       printf("Fix the model line and run imach with mle=-1 to get a correct template of the parameter file.\n");        printf("Fix the model line and run imach with mle=-1 to get a correct template of the parameter vectors and subdiagonal covariance matrix.\n");
       exit(1);        exit(1);
     }      }
   }    }
Line 10994  int main(int argc, char *argv[]) Line 11141  int main(int argc, char *argv[])
   ungetc(c,ficpar);    ungetc(c,ficpar);
   
         
   covar=matrix(0,NCOVMAX,1,n);  /**< used in readdata */    covar=matrix(0,NCOVMAX,firstobs,lastobs);  /**< used in readdata */
   if(nqv>=1)coqvar=matrix(1,nqv,1,n);  /**< Fixed quantitative covariate */    if(nqv>=1)coqvar=matrix(1,nqv,firstobs,lastobs);  /**< Fixed quantitative covariate */
   if(nqtv>=1)cotqvar=ma3x(1,maxwav,1,nqtv,1,n);  /**< Time varying quantitative covariate */    if(nqtv>=1)cotqvar=ma3x(1,maxwav,1,nqtv,firstobs,lastobs);  /**< Time varying quantitative covariate */
   if(ntv+nqtv>=1)cotvar=ma3x(1,maxwav,1,ntv+nqtv,1,n);  /**< Time varying covariate (dummy and quantitative)*/    if(ntv+nqtv>=1)cotvar=ma3x(1,maxwav,1,ntv+nqtv,firstobs,lastobs);  /**< Time varying covariate (dummy and quantitative)*/
   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
      v1+v2*age+v2*v3 makes cptcovn = 3       v1+v2*age+v2*v3 makes cptcovn = 3
Line 11200  Please run with mle=-1 to get a correct Line 11347  Please run with mle=-1 to get a correct
       
   /*  Main data    /*  Main data
    */     */
   n= lastobs;    nobs=lastobs-firstobs+1; /* was = lastobs;*/
   num=lvector(1,n);    /* num=lvector(1,n); */
   moisnais=vector(1,n);    /* moisnais=vector(1,n); */
   annais=vector(1,n);    /* annais=vector(1,n); */
   moisdc=vector(1,n);    /* moisdc=vector(1,n); */
   andc=vector(1,n);    /* andc=vector(1,n); */
   weight=vector(1,n);    /* weight=vector(1,n); */
   agedc=vector(1,n);    /* agedc=vector(1,n); */
   cod=ivector(1,n);    /* cod=ivector(1,n); */
   for(i=1;i<=n;i++){    /* for(i=1;i<=n;i++){ */
     num=lvector(firstobs,lastobs);
     moisnais=vector(firstobs,lastobs);
     annais=vector(firstobs,lastobs);
     moisdc=vector(firstobs,lastobs);
     andc=vector(firstobs,lastobs);
     weight=vector(firstobs,lastobs);
     agedc=vector(firstobs,lastobs);
     cod=ivector(firstobs,lastobs);
     for(i=firstobs;i<=lastobs;i++){
     num[i]=0;      num[i]=0;
     moisnais[i]=0;      moisnais[i]=0;
     annais[i]=0;      annais[i]=0;
Line 11219  Please run with mle=-1 to get a correct Line 11375  Please run with mle=-1 to get a correct
     cod[i]=0;      cod[i]=0;
     weight[i]=1.0; /* Equal weights, 1 by default */      weight[i]=1.0; /* Equal weights, 1 by default */
   }    }
   mint=matrix(1,maxwav,1,n);    mint=matrix(1,maxwav,firstobs,lastobs);
   anint=matrix(1,maxwav,1,n);    anint=matrix(1,maxwav,firstobs,lastobs);
   s=imatrix(1,maxwav+1,1,n); /* s[i][j] health state for wave i and individual j */     s=imatrix(1,maxwav+1,firstobs,lastobs); /* s[i][j] health state for wave i and individual j */ 
   tab=ivector(1,NCOVMAX);    tab=ivector(1,NCOVMAX);
   ncodemax=ivector(1,NCOVMAX); /* Number of code per covariate; if O and 1 only, 2**ncov; V1+V2+V3+V4=>16 */    ncodemax=ivector(1,NCOVMAX); /* Number of code per covariate; if O and 1 only, 2**ncov; V1+V2+V3+V4=>16 */
   ncodemaxwundef=ivector(1,NCOVMAX); /* Number of code per covariate; if - 1 O and 1 only, 2**ncov; V1+V2+V3+V4=>16 */    ncodemaxwundef=ivector(1,NCOVMAX); /* Number of code per covariate; if - 1 O and 1 only, 2**ncov; V1+V2+V3+V4=>16 */
Line 11323  Please run with mle=-1 to get a correct Line 11479  Please run with mle=-1 to get a correct
   
   
   agegomp=(int)agemin;    agegomp=(int)agemin;
   free_vector(moisnais,1,n);    free_vector(moisnais,firstobs,lastobs);
   free_vector(annais,1,n);    free_vector(annais,firstobs,lastobs);
   /* free_matrix(mint,1,maxwav,1,n);    /* free_matrix(mint,1,maxwav,1,n);
      free_matrix(anint,1,maxwav,1,n);*/       free_matrix(anint,1,maxwav,1,n);*/
   /* free_vector(moisdc,1,n); */    /* free_vector(moisdc,1,n); */
Line 11350  Please run with mle=-1 to get a correct Line 11506  Please run with mle=-1 to get a correct
   concatwav(wav, dh, bh, mw, s, agedc, agev,  firstpass, lastpass, imx, nlstate, stepm);    concatwav(wav, dh, bh, mw, s, agedc, agev,  firstpass, lastpass, imx, nlstate, stepm);
   /* Concatenates waves */    /* Concatenates waves */
     
   free_vector(moisdc,1,n);    free_vector(moisdc,firstobs,lastobs);
   free_vector(andc,1,n);    free_vector(andc,firstobs,lastobs);
   
   /* Routine tricode is to calculate cptcoveff (real number of unique covariates) and to associate covariable number and modality */    /* Routine tricode is to calculate cptcoveff (real number of unique covariates) and to associate covariable number and modality */
   nbcode=imatrix(0,NCOVMAX,0,NCOVMAX);     nbcode=imatrix(0,NCOVMAX,0,NCOVMAX); 
Line 11533  Title=%s <br>Datafile=%s Firstpass=%d La Line 11689  Title=%s <br>Datafile=%s Firstpass=%d La
               firstpass, lastpass,  stepm,  weightopt, model);                firstpass, lastpass,  stepm,  weightopt, model);
   
   fprintf(fichtm,"\n");    fprintf(fichtm,"\n");
   fprintf(fichtm,"<h4>Parameter line 2</h4><ul><li>Tolerance for the convergence of the likelihood: ftol=%f \n<li>Interval for the elementary matrix (in month): stepm=%d",\    fprintf(fichtm,"<h4>Parameter line 2</h4><ul><li>Tolerance for the convergence of the likelihood: ftol=%g \n<li>Interval for the elementary matrix (in month): stepm=%d",\
           ftol, stepm);            ftol, stepm);
   fprintf(fichtm,"\n<li>Number of fixed dummy covariates: ncovcol=%d ", ncovcol);    fprintf(fichtm,"\n<li>Number of fixed dummy covariates: ncovcol=%d ", ncovcol);
   ncurrv=1;    ncurrv=1;
Line 11541  Title=%s <br>Datafile=%s Firstpass=%d La Line 11697  Title=%s <br>Datafile=%s Firstpass=%d La
   fprintf(fichtm,"\n<li> Number of fixed quantitative variables: nqv=%d ", nqv);     fprintf(fichtm,"\n<li> Number of fixed quantitative variables: nqv=%d ", nqv); 
   ncurrv=i;    ncurrv=i;
   for(i=ncurrv; i <=ncurrv-1+nqv; i++) fprintf(fichtm,"V%d ", i);    for(i=ncurrv; i <=ncurrv-1+nqv; i++) fprintf(fichtm,"V%d ", i);
   fprintf(fichtm,"\n<li> Number of time varying (wave varying) covariates: ntv=%d ", ntv);    fprintf(fichtm,"\n<li> Number of time varying (wave varying) dummy covariates: ntv=%d ", ntv);
   ncurrv=i;    ncurrv=i;
   for(i=ncurrv; i <=ncurrv-1+ntv; i++) fprintf(fichtm,"V%d ", i);    for(i=ncurrv; i <=ncurrv-1+ntv; i++) fprintf(fichtm,"V%d ", i);
   fprintf(fichtm,"\n<li>Number of quantitative time varying covariates: nqtv=%d ", nqtv);    fprintf(fichtm,"\n<li>Number of time varying  quantitative covariates: nqtv=%d ", nqtv);
   ncurrv=i;    ncurrv=i;
   for(i=ncurrv; i <=ncurrv-1+nqtv; i++) fprintf(fichtm,"V%d ", i);    for(i=ncurrv; i <=ncurrv-1+nqtv; i++) fprintf(fichtm,"V%d ", i);
   fprintf(fichtm,"\n<li>Weights column \n<br>Number of alive states: nlstate=%d <br>Number of death states (not really implemented): ndeath=%d \n<li>Number of waves: maxwav=%d \n<li>Parameter for maximization (1), using parameter values (0), for design of parameters and variance-covariance matrix: mle=%d \n<li>Does the weight column be taken into account (1), or not (0): weight=%d</ul>\n", \    fprintf(fichtm,"\n<li>Weights column \n<br>Number of alive states: nlstate=%d <br>Number of death states (not really implemented): ndeath=%d \n<li>Number of waves: maxwav=%d \n<li>Parameter for maximization (1), using parameter values (0), for design of parameters and variance-covariance matrix: mle=%d \n<li>Does the weight column be taken into account (1), or not (0): weight=%d</ul>\n", \
Line 11576  Interval (in months) between two waves: Line 11732  Interval (in months) between two waves:
       for(j=1;j<=NDIM;j++)        for(j=1;j<=NDIM;j++)
         ximort[i][j]=0.;          ximort[i][j]=0.;
     /*     ximort=gsl_matrix_alloc(1,NDIM,1,NDIM); */      /*     ximort=gsl_matrix_alloc(1,NDIM,1,NDIM); */
     cens=ivector(1,n);      cens=ivector(firstobs,lastobs);
     ageexmed=vector(1,n);      ageexmed=vector(firstobs,lastobs);
     agecens=vector(1,n);      agecens=vector(firstobs,lastobs);
     dcwave=ivector(1,n);      dcwave=ivector(firstobs,lastobs);
                                   
     for (i=1; i<=imx; i++){      for (i=1; i<=imx; i++){
       dcwave[i]=-1;        dcwave[i]=-1;
Line 11793  Please run with mle=-1 to get a correct Line 11949  Please run with mle=-1 to get a correct
     free_vector(lpop,1,AGESUP);      free_vector(lpop,1,AGESUP);
     free_vector(tpop,1,AGESUP);      free_vector(tpop,1,AGESUP);
     free_matrix(ximort,1,NDIM,1,NDIM);      free_matrix(ximort,1,NDIM,1,NDIM);
     free_ivector(cens,1,n);      free_ivector(dcwave,firstobs,lastobs);
     free_vector(agecens,1,n);      free_vector(agecens,firstobs,lastobs);
     free_ivector(dcwave,1,n);      free_vector(ageexmed,firstobs,lastobs);
       free_ivector(cens,firstobs,lastobs);
 #ifdef GSL  #ifdef GSL
 #endif  #endif
   } /* Endof if mle==-3 mortality only */    } /* Endof if mle==-3 mortality only */
Line 11829  Please run with mle=-1 to get a correct Line 11986  Please run with mle=-1 to get a correct
     printf("\n");      printf("\n");
           
     /*--------- results files --------------*/      /*--------- results files --------------*/
     fprintf(ficres,"title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\nftol=%e stepm=%d ncovcol=%d nqv=%d ntv=%d nqtv=%d nlstate=%d ndeath=%d maxwav=%d mle= 0 weight=%d\nmodel=1+age+%s.\n", title, datafile, lastobs, firstpass,lastpass,ftol, stepm, ncovcol, nqv, ntv, nqtv, nlstate, ndeath, maxwav, weightopt,model);      /* fprintf(ficres,"title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\nftol=%e stepm=%d ncovcol=%d nqv=%d ntv=%d nqtv=%d nlstate=%d ndeath=%d maxwav=%d mle= 0 weight=%d\nmodel=1+age+%s.\n", title, datafile, lastobs, firstpass,lastpass,ftol, stepm, ncovcol, nqv, ntv, nqtv, nlstate, ndeath, maxwav, weightopt,model); */
           
           
     fprintf(ficres,"# Parameters nlstate*nlstate*ncov a12*1 + b12 * age + ...\n");      fprintf(ficres,"# Parameters nlstate*nlstate*ncov a12*1 + b12 * age + ...\n");
Line 12201  Please run with mle=-1 to get a correct Line 12358  Please run with mle=-1 to get a correct
     /* free_imatrix(dh,1,lastpass-firstpass+2,1,imx); */      /* free_imatrix(dh,1,lastpass-firstpass+2,1,imx); */
     /* free_imatrix(bh,1,lastpass-firstpass+2,1,imx); */      /* free_imatrix(bh,1,lastpass-firstpass+2,1,imx); */
     /* free_imatrix(mw,1,lastpass-firstpass+2,1,imx);    */      /* free_imatrix(mw,1,lastpass-firstpass+2,1,imx);    */
     free_lvector(num,1,n);      free_lvector(num,firstobs,lastobs);
     free_vector(agedc,1,n);      free_vector(agedc,firstobs,lastobs);
     /*free_matrix(covar,0,NCOVMAX,1,n);*/      /*free_matrix(covar,0,NCOVMAX,1,n);*/
     /*free_matrix(covar,1,NCOVMAX,1,n);*/      /*free_matrix(covar,1,NCOVMAX,1,n);*/
     fclose(ficparo);      fclose(ficparo);
Line 12459  Please run with mle=-1 to get a correct Line 12616  Please run with mle=-1 to get a correct
         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);
         else          else
           fprintf(ficrest,"the age specific period (stable) prevalences in each health state \n");            fprintf(ficrest,"the age specific forward period (stable) prevalences in each health state \n");
         fprintf(ficrest,"# Age popbased mobilav e.. (std) ");          fprintf(ficrest,"# Age popbased mobilav e.. (std) ");
         for (i=1;i<=nlstate;i++) fprintf(ficrest,"e.%d (std) ",i);          for (i=1;i<=nlstate;i++) fprintf(ficrest,"e.%d (std) ",i);
         fprintf(ficrest,"\n");          fprintf(ficrest,"\n");
         /* printf("Which p?\n"); for(i=1;i<=npar;i++)printf("p[i=%d]=%lf,",i,p[i]);printf("\n"); */          /* printf("Which p?\n"); for(i=1;i<=npar;i++)printf("p[i=%d]=%lf,",i,p[i]);printf("\n"); */
         printf("Computing age specific period (stable) prevalences in each health state \n");          printf("Computing age specific forward 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 forward 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, nres); /*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) {
Line 12512  Please run with mle=-1 to get a correct Line 12669  Please run with mle=-1 to get a correct
     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);
   
     /* variance-covariance of period prevalence*/      /* variance-covariance of forward period prevalence*/
     varprlim(fileresu, nresult, mobaverage, mobilavproj, bage, fage, prlim, &ncvyear, ftolpl, p, matcov, delti, stepm, cptcoveff);      varprlim(fileresu, nresult, mobaverage, mobilavproj, bage, fage, prlim, &ncvyear, ftolpl, p, matcov, delti, stepm, cptcoveff);
   
           
     free_vector(weight,1,n);      free_vector(weight,firstobs,lastobs);
     free_imatrix(Tvard,1,NCOVMAX,1,2);      free_imatrix(Tvard,1,NCOVMAX,1,2);
     free_imatrix(s,1,maxwav+1,1,n);      free_imatrix(s,1,maxwav+1,firstobs,lastobs);
     free_matrix(anint,1,maxwav,1,n);       free_matrix(anint,1,maxwav,firstobs,lastobs); 
     free_matrix(mint,1,maxwav,1,n);      free_matrix(mint,1,maxwav,firstobs,lastobs);
     free_ivector(cod,1,n);      free_ivector(cod,firstobs,lastobs);
     free_ivector(tab,1,NCOVMAX);      free_ivector(tab,1,NCOVMAX);
     fclose(ficresstdeij);      fclose(ficresstdeij);
     fclose(ficrescveij);      fclose(ficrescveij);
Line 12541  Please run with mle=-1 to get a correct Line 12698  Please run with mle=-1 to get a correct
   free_matrix(oldms, 1,nlstate+ndeath,1,nlstate+ndeath);    free_matrix(oldms, 1,nlstate+ndeath,1,nlstate+ndeath);
   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);
   if(ntv+nqtv>=1)free_ma3x(cotvar,1,maxwav,1,ntv+nqtv,1,n);    if(ntv+nqtv>=1)free_ma3x(cotvar,1,maxwav,1,ntv+nqtv,firstobs,lastobs);
   if(nqtv>=1)free_ma3x(cotqvar,1,maxwav,1,nqtv,1,n);    if(nqtv>=1)free_ma3x(cotqvar,1,maxwav,1,nqtv,firstobs,lastobs);
   if(nqv>=1)free_matrix(coqvar,1,nqv,1,n);    if(nqv>=1)free_matrix(coqvar,1,nqv,firstobs,lastobs);
   free_matrix(covar,0,NCOVMAX,1,n);    free_matrix(covar,0,NCOVMAX,firstobs,lastobs);
   free_matrix(matcov,1,npar,1,npar);    free_matrix(matcov,1,npar,1,npar);
   free_matrix(hess,1,npar,1,npar);    free_matrix(hess,1,npar,1,npar);
   /*free_vector(delti,1,npar);*/    /*free_vector(delti,1,npar);*/
Line 12627  Please run with mle=-1 to get a correct Line 12784  Please run with mle=-1 to get a correct
   fclose(ficlog);    fclose(ficlog);
   /*------ End -----------*/    /*------ End -----------*/
       
   
   /* Executes gnuplot */
       
   printf("Before Current directory %s!\n",pathcd);    printf("Before Current directory %s!\n",pathcd);
 #ifdef WIN32  #ifdef WIN32
Line 12695  end: Line 12854  end:
     printf("\nType  q for exiting: "); fflush(stdout);      printf("\nType  q for exiting: "); fflush(stdout);
     scanf("%s",z);      scanf("%s",z);
   }    }
     printf("End\n");
     exit(0);
 }  }

Removed from v.1.278  
changed lines
  Added in v.1.291


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