Diff for /imach/src/imach.c between versions 1.200 and 1.202

version 1.200, 2015/09/09 16:53:55 version 1.202, 2015/09/22 19:45:16
Line 1 Line 1
 /* $Id$  /* $Id$
   $State$    $State$
   $Log$    $Log$
     Revision 1.202  2015/09/22 19:45:16  brouard
     Summary: Adding some overall graph on contribution to likelihood. Might change
   
     Revision 1.201  2015/09/15 17:34:58  brouard
     Summary: 0.98r0
   
     - Some new graphs like suvival functions
     - Some bugs fixed like model=1+age+V2.
   
   Revision 1.200  2015/09/09 16:53:55  brouard    Revision 1.200  2015/09/09 16:53:55  brouard
   Summary: Big bug thanks to Flavia    Summary: Big bug thanks to Flavia
   
Line 638 Line 647
   
 /* #define DEBUG */  /* #define DEBUG */
 /* #define DEBUGBRENT */  /* #define DEBUGBRENT */
   #define DEBUGLINMIN
 #define POWELL /* Instead of NLOPT */  #define POWELL /* Instead of NLOPT */
 #define POWELLF1F3 /* Skip test */  #define POWELLF1F3 /* Skip test */
 /* #define POWELLORIGINAL /\* Don't use Directest to decide new direction but original Powell test *\/ */  /* #define POWELLORIGINAL /\* Don't use Directest to decide new direction but original Powell test *\/ */
Line 796  char command[FILENAMELENGTH]; Line 806  char command[FILENAMELENGTH];
 int  outcmd=0;  int  outcmd=0;
   
 char fileres[FILENAMELENGTH], filerespij[FILENAMELENGTH], filereso[FILENAMELENGTH], rfileres[FILENAMELENGTH];  char fileres[FILENAMELENGTH], filerespij[FILENAMELENGTH], filereso[FILENAMELENGTH], rfileres[FILENAMELENGTH];
   char fileresu[FILENAMELENGTH]; /* fileres without r in front */
 char filelog[FILENAMELENGTH]; /* Log file */  char filelog[FILENAMELENGTH]; /* Log file */
 char filerest[FILENAMELENGTH];  char filerest[FILENAMELENGTH];
 char fileregp[FILENAMELENGTH];  char fileregp[FILENAMELENGTH];
Line 1600  void linmin(double p[], double xi[], int Line 1610  void linmin(double p[], double xi[], int
   nrfunc=func;     nrfunc=func; 
   for (j=1;j<=n;j++) {     for (j=1;j<=n;j++) { 
     pcom[j]=p[j];       pcom[j]=p[j]; 
     xicom[j]=xi[j];       xicom[j]=xi[j]; /* Former scale xi[j] of currrent direction i */
   }     } 
   
   /* axs=0.0; */    /* axs=0.0; */
Line 1624  void linmin(double p[], double xi[], int Line 1634  void linmin(double p[], double xi[], int
   
 #ifdef DEBUGLINMIN  #ifdef DEBUGLINMIN
   printf("\nLinmin after mnbrak: ax=%12.7f xx=%12.7f bx=%12.7f fa=%12.2f fx=%12.2f fb=%12.2f\n",  ax,xx,bx,fa,fx,fb);    printf("\nLinmin after mnbrak: ax=%12.7f xx=%12.7f bx=%12.7f fa=%12.2f fx=%12.2f fb=%12.2f\n",  ax,xx,bx,fa,fx,fb);
     fprintf(ficlog,"\nLinmin after mnbrak: ax=%12.7f xx=%12.7f bx=%12.7f fa=%12.2f fx=%12.2f fb=%12.2f\n",  ax,xx,bx,fa,fx,fb);
 #endif  #endif
   *fret=brent(ax,xx,bx,f1dim,TOL,&xmin); /* Giving a bracketting triplet (ax, xx, bx), find a minimum, xmin, according to f1dim, *fret(xmin),*/    *fret=brent(ax,xx,bx,f1dim,TOL,&xmin); /* Giving a bracketting triplet (ax, xx, bx), find a minimum, xmin, according to f1dim, *fret(xmin),*/
   /* fa = f(p[j] + ax * xi[j]), fx = f(p[j] + xx * xi[j]), fb = f(p[j] + bx * xi[j]) */    /* fa = f(p[j] + ax * xi[j]), fx = f(p[j] + xx * xi[j]), fb = f(p[j] + bx * xi[j]) */
Line 1636  void linmin(double p[], double xi[], int Line 1647  void linmin(double p[], double xi[], int
 #endif  #endif
 #ifdef DEBUGLINMIN  #ifdef DEBUGLINMIN
   printf("linmin end ");    printf("linmin end ");
     fprintf(ficlog,"linmin end ");
 #endif  #endif
   for (j=1;j<=n;j++) {     for (j=1;j<=n;j++) { 
     /* printf(" before xi[%d]=%12.8f", j,xi[j]); */      /* printf(" before xi[%d]=%12.8f", j,xi[j]); */
Line 1647  void linmin(double p[], double xi[], int Line 1659  void linmin(double p[], double xi[], int
   /* printf("\n"); */    /* printf("\n"); */
 #ifdef DEBUGLINMIN  #ifdef DEBUGLINMIN
   printf("Comparing last *frec(xmin=%12.8f)=%12.8f from Brent and frec(0.)=%12.8f \n", xmin, *fret, (*func)(p));    printf("Comparing last *frec(xmin=%12.8f)=%12.8f from Brent and frec(0.)=%12.8f \n", xmin, *fret, (*func)(p));
     fprintf(ficlog,"Comparing last *frec(xmin=%12.8f)=%12.8f from Brent and frec(0.)=%12.8f \n", xmin, *fret, (*func)(p));
   for (j=1;j<=n;j++) {     for (j=1;j<=n;j++) { 
     printf(" xi[%d]= %12.7f p[%d]= %12.7f",j,xi[j],j,p[j]);      printf(" xi[%d]= %14.10f p[%d]= %12.7f",j,xi[j],j,p[j]);
     if(j % ncovmodel == 0)      fprintf(ficlog," xi[%d]= %14.10f p[%d]= %12.7f",j,xi[j],j,p[j]);
       if(j % ncovmodel == 0){
       printf("\n");        printf("\n");
         fprintf(ficlog,"\n");
       }
   }    }
 #endif  #endif
   free_vector(xicom,1,n);     free_vector(xicom,1,n); 
Line 1685  void powell(double p[], double **xi, int Line 1701  void powell(double p[], double **xi, int
   xits=vector(1,n);     xits=vector(1,n); 
   *fret=(*func)(p);     *fret=(*func)(p); 
   for (j=1;j<=n;j++) pt[j]=p[j];     for (j=1;j<=n;j++) pt[j]=p[j]; 
     rcurr_time = time(NULL);      rcurr_time = time(NULL);  
   for (*iter=1;;++(*iter)) {     for (*iter=1;;++(*iter)) { 
     fp=(*fret); /* From former iteration or initial value */      fp=(*fret); /* From former iteration or initial value */
     ibig=0;       ibig=0; 
Line 1830  void powell(double p[], double **xi, int Line 1846  void powell(double p[], double **xi, int
       t=2.0*(fp-2.0*(*fret)+fptt)*SQR(fp-(*fret)-del); /* Intel compiler doesn't work on one line; bug reported */        t=2.0*(fp-2.0*(*fret)+fptt)*SQR(fp-(*fret)-del); /* Intel compiler doesn't work on one line; bug reported */
       t= t- del*SQR(fp-fptt);        t= t- del*SQR(fp-fptt);
 #endif  #endif
       directest = fp-2.0*(*fret)+fptt - 2.0 * del; /* If del was big enough we change it for a new direction */        directest = fp-2.0*(*fret)+fptt - 2.0 * del; /* If delta was big enough we change it for a new direction */
 #ifdef DEBUG  #ifdef DEBUG
       printf("t1= %.12lf, t2= %.12lf, t=%.12lf  directest=%.12lf\n", 2.0*(fp-2.0*(*fret)+fptt)*SQR(fp-(*fret)-del),del*SQR(fp-fptt),t,directest);        printf("t1= %.12lf, t2= %.12lf, t=%.12lf  directest=%.12lf\n", 2.0*(fp-2.0*(*fret)+fptt)*SQR(fp-(*fret)-del),del*SQR(fp-fptt),t,directest);
       fprintf(ficlog,"t1= %.12lf, t2= %.12lf, t=%.12lf directest=%.12lf\n", 2.0*(fp-2.0*(*fret)+fptt)*SQR(fp-(*fret)-del),del*SQR(fp-fptt),t,directest);        fprintf(ficlog,"t1= %.12lf, t2= %.12lf, t=%.12lf directest=%.12lf\n", 2.0*(fp-2.0*(*fret)+fptt)*SQR(fp-(*fret)-del),del*SQR(fp-fptt),t,directest);
Line 1845  void powell(double p[], double **xi, int Line 1861  void powell(double p[], double **xi, int
       if (t < 0.0) { /* Then we use it for new direction */        if (t < 0.0) { /* Then we use it for new direction */
 #else  #else
       if (directest*t < 0.0) { /* Contradiction between both tests */        if (directest*t < 0.0) { /* Contradiction between both tests */
         printf("directest= %.12lf, t= %.12lf, f1= %.12lf,f2= %.12lf,f3= %.12lf, del= %.12lf\n",directest, t, fp,(*fret),fptt,del);          printf("directest= %.12lf (if <0 we include P0 Pn as new direction), t= %.12lf, f1= %.12lf,f2= %.12lf,f3= %.12lf, del= %.12lf\n",directest, t, fp,(*fret),fptt,del);
         printf("f1-2f2+f3= %.12lf, f1-f2-del= %.12lf, f1-f3= %.12lf\n",fp-2.0*(*fret)+fptt, fp -(*fret) -del, fp-fptt);          printf("f1-2f2+f3= %.12lf, f1-f2-del= %.12lf, f1-f3= %.12lf\n",fp-2.0*(*fret)+fptt, fp -(*fret) -del, fp-fptt);
         fprintf(ficlog,"directest= %.12lf, t= %.12lf, f1= %.12lf,f2= %.12lf,f3= %.12lf, del= %.12lf\n",directest, t, fp,(*fret),fptt, del);          fprintf(ficlog,"directest= %.12lf (if <0 we include P0 Pn as new direction), t= %.12lf, f1= %.12lf,f2= %.12lf,f3= %.12lf, del= %.12lf\n",directest, t, fp,(*fret),fptt, del);
         fprintf(ficlog,"f1-2f2+f3= %.12lf, f1-f2-del= %.12lf, f1-f3= %.12lf\n",fp-2.0*(*fret)+fptt, fp -(*fret) -del, fp-fptt);          fprintf(ficlog,"f1-2f2+f3= %.12lf, f1-f2-del= %.12lf, f1-f3= %.12lf\n",fp-2.0*(*fret)+fptt, fp -(*fret) -del, fp-fptt);
       }         } 
       if (directest < 0.0) { /* Then we use it for new direction */        if (directest < 0.0) { /* Then we use it for new direction */
Line 1855  void powell(double p[], double **xi, int Line 1871  void powell(double p[], double **xi, int
 #ifdef DEBUGLINMIN  #ifdef DEBUGLINMIN
         printf("Before linmin in direction P%d-P0\n",n);          printf("Before linmin in direction P%d-P0\n",n);
         for (j=1;j<=n;j++) {           for (j=1;j<=n;j++) { 
           printf("Before xit[%d]= %12.7f p[%d]= %12.7f",j,xit[j],j,p[j]);            printf(" Before xit[%d]= %12.7f p[%d]= %12.7f",j,xit[j],j,p[j]);
           if(j % ncovmodel == 0)            fprintf(ficlog," Before xit[%d]= %12.7f p[%d]= %12.7f",j,xit[j],j,p[j]);
             if(j % ncovmodel == 0){
             printf("\n");              printf("\n");
               fprintf(ficlog,"\n");
             }
         }          }
 #endif  #endif
         linmin(p,xit,n,fret,func); /* computes minimum on the extrapolated direction: changes p and rescales xit.*/          linmin(p,xit,n,fret,func); /* computes minimum on the extrapolated direction: changes p and rescales xit.*/
 #ifdef DEBUGLINMIN  #ifdef DEBUGLINMIN
         for (j=1;j<=n;j++) {           for (j=1;j<=n;j++) { 
           printf("After xit[%d]= %12.7f p[%d]= %12.7f",j,xit[j],j,p[j]);            printf("After xit[%d]= %12.7f p[%d]= %12.7f",j,xit[j],j,p[j]);
           if(j % ncovmodel == 0)            fprintf(ficlog,"After xit[%d]= %12.7f p[%d]= %12.7f",j,xit[j],j,p[j]);
             if(j % ncovmodel == 0){
             printf("\n");              printf("\n");
               fprintf(ficlog,"\n");
             }
         }          }
 #endif  #endif
         for (j=1;j<=n;j++) {           for (j=1;j<=n;j++) { 
Line 1905  double **prevalim(double **prlim, int nl Line 1927  double **prevalim(double **prlim, int nl
   /* double **matprod2(); */ /* test */    /* double **matprod2(); */ /* test */
   double **out, cov[NCOVMAX+1], **pmij();    double **out, cov[NCOVMAX+1], **pmij();
   double **newm;    double **newm;
   double agefin, delaymax=50 ; /* Max number of years to converge */    double agefin, delaymax=100 ; /* Max number of years to converge */
     long int ncvyear=0, ncvloop=0;
       
   for (ii=1;ii<=nlstate+ndeath;ii++)    for (ii=1;ii<=nlstate+ndeath;ii++)
     for (j=1;j<=nlstate+ndeath;j++){      for (j=1;j<=nlstate+ndeath;j++){
Line 1915  double **prevalim(double **prlim, int nl Line 1938  double **prevalim(double **prlim, int nl
   cov[1]=1.;    cov[1]=1.;
       
   /* 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 */
   for(agefin=age-stepm/YEARM; agefin>=age-delaymax; agefin=agefin-stepm/YEARM){    for(agefin=age-stepm/YEARM; agefin>=age-delaymax; agefin=agefin-stepm/YEARM){
       ncvloop++;
     newm=savm;      newm=savm;
     /* Covariates have to be included here again */      /* Covariates have to be included here again */
     cov[2]=agefin;      cov[2]=agefin;
Line 1950  double **prevalim(double **prlim, int nl Line 1975  double **prevalim(double **prlim, int nl
         sumnew=0;          sumnew=0;
         for(k=1; k<=ndeath; k++) sumnew+=newm[i][nlstate+k];          for(k=1; k<=ndeath; k++) sumnew+=newm[i][nlstate+k];
         prlim[i][j]= newm[i][j]/(1-sumnew);          prlim[i][j]= newm[i][j]/(1-sumnew);
         /*printf(" prevalim i=%d, j=%d, prmlim[%d][%d]=%f, agefin=%d \n", i, j, i, j, prlim[i][j],(int)agefin);*/  
         max=FMAX(max,prlim[i][j]);          max=FMAX(max,prlim[i][j]);
         min=FMIN(min,prlim[i][j]);          min=FMIN(min,prlim[i][j]);
           /* printf(" age= %d prevalim i=%d, j=%d, prmlim[%d][%d]=%f, agefin=%d max=%f min=%f\n", (int)age, i, j, i, j, prlim[i][j],(int)agefin, max, min); */
       }        }
       maxmin=max-min;        maxmin=max-min;
       maxmax=FMAX(maxmax,maxmin);        maxmax=FMAX(maxmax,maxmin);
     } /* j loop */      } /* j loop */
     if(maxmax < ftolpl){      if(maxmax < ftolpl){
         /* printf("maxmax=%lf maxmin=%lf ncvloop=%ld, ncvyear=%d \n", maxmax, maxmin, ncvloop, (int)age-(int)agefin); */
       return prlim;        return prlim;
     }      }
   } /* age loop */    } /* age loop */
     printf("Warning: the stable prevalence did not converge with the required precision ftolpl=6*10^5*ftol=%g. \n\
   Earliest age to start was %d-%d=%d, ncvloop=%ld, ncvyear=%d\n\
   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);
   return prlim; /* should not reach here */    return prlim; /* should not reach here */
 }  }
   
Line 2536  double funcone( double *x) Line 2565  double funcone( double *x)
       ll[s[mw[mi][i]][i]] += 2*weight[i]*lli;        ll[s[mw[mi][i]][i]] += 2*weight[i]*lli;
       /*printf("i=%6d s1=%1d s2=%1d mi=%1d mw=%1d dh=%3d prob=%10.6f w=%6.4f out=%10.6f sav=%10.6f\n",i,s1,s2,mi,mw[mi][i],dh[mi][i],exp(lli),weight[i],out[s1][s2],savm[s1][s2]); */        /*printf("i=%6d s1=%1d s2=%1d mi=%1d mw=%1d dh=%3d prob=%10.6f w=%6.4f out=%10.6f sav=%10.6f\n",i,s1,s2,mi,mw[mi][i],dh[mi][i],exp(lli),weight[i],out[s1][s2],savm[s1][s2]); */
       if(globpr){        if(globpr){
         fprintf(ficresilk,"%9ld %6d %2d %2d %1d %1d %3d %11.6f %8.4f\          fprintf(ficresilk,"%9ld %6.1f %6d %2d %2d %2d %2d %3d %11.6f %8.4f\
  %11.6f %11.6f %11.6f ", \   %11.6f %11.6f %11.6f ", \
                 num[i],i,s1,s2,mi,mw[mi][i],dh[mi][i],exp(lli),weight[i],                  num[i], agexact, i,s1,s2,mi,mw[mi][i],dh[mi][i],exp(lli),weight[i],
                 2*weight[i]*lli,out[s1][s2],savm[s1][s2]);                  2*weight[i]*lli,out[s1][s2],savm[s1][s2]);
         for(k=1,llt=0.,l=0.; k<=nlstate; k++){          for(k=1,llt=0.,l=0.; k<=nlstate; k++){
           llt +=ll[k]*gipmx/gsw;            llt +=ll[k]*gipmx/gsw;
Line 2570  void likelione(FILE *ficres,double p[], Line 2599  void likelione(FILE *ficres,double p[],
   int k;    int k;
   
   if(*globpri !=0){ /* Just counts and sums, no printings */    if(*globpri !=0){ /* Just counts and sums, no printings */
     strcpy(fileresilk,"ilk");       strcpy(fileresilk,"ILK_"); 
     strcat(fileresilk,fileres);      strcat(fileresilk,fileresu);
     if((ficresilk=fopen(fileresilk,"w"))==NULL) {      if((ficresilk=fopen(fileresilk,"w"))==NULL) {
       printf("Problem with resultfile: %s\n", fileresilk);        printf("Problem with resultfile: %s\n", fileresilk);
       fprintf(ficlog,"Problem with resultfile: %s\n", fileresilk);        fprintf(ficlog,"Problem with resultfile: %s\n", fileresilk);
     }      }
     fprintf(ficresilk, "#individual(line's_record) s1 s2 wave# effective_wave# number_of_matrices_product pij weight -2ln(pij)*weight 0pij_x 0pij_(x-stepm) cumulating_loglikeli_by_health_state(reweighted=-2ll*weightXnumber_of_contribs/sum_of_weights) and_total\n");      fprintf(ficresilk, "#individual(line's_record) s1 s2 wave# effective_wave# number_of_matrices_product pij weight -2ln(pij)*weight 0pij_x 0pij_(x-stepm) cumulating_loglikeli_by_health_state(reweighted=-2ll*weightXnumber_of_contribs/sum_of_weights) and_total\n");
     fprintf(ficresilk, "#num_i i s1 s2 mi mw dh likeli weight 2wlli out sav ");      fprintf(ficresilk, "#num_i age i s1 s2 mi mw dh likeli weight 2wlli out sav ");
     /*  i,s1,s2,mi,mw[mi][i],dh[mi][i],exp(lli),weight[i],2*weight[i]*lli,out[s1][s2],savm[s1][s2]); */      /*  i,s1,s2,mi,mw[mi][i],dh[mi][i],exp(lli),weight[i],2*weight[i]*lli,out[s1][s2],savm[s1][s2]); */
     for(k=1; k<=nlstate; k++)       for(k=1; k<=nlstate; k++) 
       fprintf(ficresilk," -2*gipw/gsw*weight*ll[%d]++",k);        fprintf(ficresilk," -2*gipw/gsw*weight*ll[%d]++",k);
Line 2587  void likelione(FILE *ficres,double p[], Line 2616  void likelione(FILE *ficres,double p[],
   *fretone=(*funcone)(p);    *fretone=(*funcone)(p);
   if(*globpri !=0){    if(*globpri !=0){
     fclose(ficresilk);      fclose(ficresilk);
     fprintf(fichtm,"\n<br>File of contributions to the likelihood: <a href=\"%s\">%s</a><br>\n",subdirf(fileresilk),subdirf(fileresilk));      fprintf(fichtm,"\n<br>File of contributions to the likelihood computed with initial parameters and mle >= 1. You should at least run with mle >= 1 and starting values corresponding to the optimized parameters in order to visualize the real contribution of each individual/wave: <a href=\"%s\">%s</a><br>\n",subdirf(fileresilk),subdirf(fileresilk));
     fflush(fichtm);       fprintf(fichtm,"<br>- The first 3 individuals are drawn with lines. The function drawn is -2Log(L) in log scale: <a href=\"%s.png\">%s.png</a><br> \
   <img src=\"%s.png\">",subdirf2(optionfilefiname,"ILK_"),subdirf2(optionfilefiname,"ILK_"),subdirf2(optionfilefiname,"ILK_"));
       fflush(fichtm);
   }     } 
   return;    return;
 }  }
Line 2620  void mlikeli(FILE *ficres,double p[], in Line 2651  void mlikeli(FILE *ficres,double p[], in
     for (j=1;j<=npar;j++)      for (j=1;j<=npar;j++)
       xi[i][j]=(i==j ? 1.0 : 0.0);        xi[i][j]=(i==j ? 1.0 : 0.0);
   printf("Powell\n");  fprintf(ficlog,"Powell\n");    printf("Powell\n");  fprintf(ficlog,"Powell\n");
   strcpy(filerespow,"pow");     strcpy(filerespow,"POW_"); 
   strcat(filerespow,fileres);    strcat(filerespow,fileres);
   if((ficrespow=fopen(filerespow,"w"))==NULL) {    if((ficrespow=fopen(filerespow,"w"))==NULL) {
     printf("Problem with resultfile: %s\n", filerespow);      printf("Problem with resultfile: %s\n", filerespow);
Line 2947  void  freqsummary(char fileres[], int ia Line 2978  void  freqsummary(char fileres[], int ia
       
   pp=vector(1,nlstate);    pp=vector(1,nlstate);
   prop=matrix(1,nlstate,iagemin,iagemax+3);    prop=matrix(1,nlstate,iagemin,iagemax+3);
   strcpy(fileresp,"p");    strcpy(fileresp,"P_");
   strcat(fileresp,fileres);    strcat(fileresp,fileresu);
   if((ficresp=fopen(fileresp,"w"))==NULL) {    if((ficresp=fopen(fileresp,"w"))==NULL) {
     printf("Problem with prevalence resultfile: %s\n", fileresp);      printf("Problem with prevalence resultfile: %s\n", fileresp);
     fprintf(ficlog,"Problem with prevalence resultfile: %s\n", fileresp);      fprintf(ficlog,"Problem with prevalence resultfile: %s\n", fileresp);
Line 3816  void varevsij(char optionfilefiname[], d Line 3847  void varevsij(char optionfilefiname[], d
   
   if(popbased==1){    if(popbased==1){
     if(mobilav!=0)      if(mobilav!=0)
       strcpy(digitp,"-populbased-mobilav-");        strcpy(digitp,"-POPULBASED-MOBILAV_");
     else strcpy(digitp,"-populbased-nomobil-");      else strcpy(digitp,"-POPULBASED-NOMOBIL_");
   }    }
   else     else 
     strcpy(digitp,"-stablbased-");      strcpy(digitp,"-STABLBASED_");
   
   if (mobilav!=0) {    if (mobilav!=0) {
     mobaverage= ma3x(1, AGESUP,1,NCOVMAX, 1,NCOVMAX);      mobaverage= ma3x(1, AGESUP,1,NCOVMAX, 1,NCOVMAX);
Line 3830  void varevsij(char optionfilefiname[], d Line 3861  void varevsij(char optionfilefiname[], d
     }      }
   }    }
   
   strcpy(fileresprobmorprev,"prmorprev");     strcpy(fileresprobmorprev,"PRMORPREV-"); 
   sprintf(digit,"%-d",ij);    sprintf(digit,"%-d",ij);
   /*printf("DIGIT=%s, ij=%d ijr=%-d|\n",digit, ij,ij);*/    /*printf("DIGIT=%s, ij=%d ijr=%-d|\n",digit, ij,ij);*/
   strcat(fileresprobmorprev,digit); /* Tvar to be done */    strcat(fileresprobmorprev,digit); /* Tvar to be done */
   strcat(fileresprobmorprev,digitp); /* Popbased or not, mobilav or not */    strcat(fileresprobmorprev,digitp); /* Popbased or not, mobilav or not */
   strcat(fileresprobmorprev,fileres);    strcat(fileresprobmorprev,fileresu);
   if((ficresprobmorprev=fopen(fileresprobmorprev,"w"))==NULL) {    if((ficresprobmorprev=fopen(fileresprobmorprev,"w"))==NULL) {
     printf("Problem with resultfile: %s\n", fileresprobmorprev);      printf("Problem with resultfile: %s\n", fileresprobmorprev);
     fprintf(ficlog,"Problem with resultfile: %s\n", fileresprobmorprev);      fprintf(ficlog,"Problem with resultfile: %s\n", fileresprobmorprev);
Line 4070  void varevsij(char optionfilefiname[], d Line 4101  void varevsij(char optionfilefiname[], d
   fprintf(ficgp,"\nunset parametric;unset label; set ter svg size 640, 480");    fprintf(ficgp,"\nunset parametric;unset label; set ter svg size 640, 480");
   /* for(j=nlstate+1; j<= nlstate+ndeath; j++){ *//* Only the first actually */    /* for(j=nlstate+1; j<= nlstate+ndeath; j++){ *//* Only the first actually */
   fprintf(ficgp,"\n set log y; unset log x;set xlabel \"Age\"; set ylabel \"Force of mortality (year-1)\";");    fprintf(ficgp,"\n set log y; unset log x;set xlabel \"Age\"; set ylabel \"Force of mortality (year-1)\";");
   fprintf(ficgp,"\nset out \"%s%s.svg\";",subdirf3(optionfilefiname,"varmuptjgr",digitp),digit);    fprintf(ficgp,"\nset out \"%s%s.svg\";",subdirf3(optionfilefiname,"VARMUPTJGR-",digitp),digit);
 /*   fprintf(ficgp,"\n plot \"%s\"  u 1:($3*%6.3f) not w l 1 ",fileresprobmorprev,YEARM/estepm); */  /*   fprintf(ficgp,"\n plot \"%s\"  u 1:($3*%6.3f) not w l 1 ",fileresprobmorprev,YEARM/estepm); */
 /*   fprintf(ficgp,"\n replot \"%s\"  u 1:(($3+1.96*$4)*%6.3f) t \"95\%% interval\" w l 2 ",fileresprobmorprev,YEARM/estepm); */  /*   fprintf(ficgp,"\n replot \"%s\"  u 1:(($3+1.96*$4)*%6.3f) t \"95\%% interval\" w l 2 ",fileresprobmorprev,YEARM/estepm); */
 /*   fprintf(ficgp,"\n replot \"%s\"  u 1:(($3-1.96*$4)*%6.3f) not w l 2 ",fileresprobmorprev,YEARM/estepm); */  /*   fprintf(ficgp,"\n replot \"%s\"  u 1:(($3-1.96*$4)*%6.3f) not w l 2 ",fileresprobmorprev,YEARM/estepm); */
Line 4078  void varevsij(char optionfilefiname[], d Line 4109  void varevsij(char optionfilefiname[], d
   fprintf(ficgp,"\n replot \"%s\"  u 1:(($3+1.96*$4)) t \"95%% interval\" w l lt 2 ",subdirf(fileresprobmorprev));    fprintf(ficgp,"\n replot \"%s\"  u 1:(($3+1.96*$4)) t \"95%% interval\" w l lt 2 ",subdirf(fileresprobmorprev));
   fprintf(ficgp,"\n replot \"%s\"  u 1:(($3-1.96*$4)) not w l lt 2 ",subdirf(fileresprobmorprev));    fprintf(ficgp,"\n replot \"%s\"  u 1:(($3-1.96*$4)) not w l lt 2 ",subdirf(fileresprobmorprev));
   fprintf(fichtm,"\n<br> File (multiple files are possible if covariates are present): <A href=\"%s\">%s</a>\n",subdirf(fileresprobmorprev),subdirf(fileresprobmorprev));    fprintf(fichtm,"\n<br> File (multiple files are possible if covariates are present): <A href=\"%s\">%s</a>\n",subdirf(fileresprobmorprev),subdirf(fileresprobmorprev));
   fprintf(fichtm,"\n<br> Probability is computed over estepm=%d months. <br> <img src=\"%s%s.svg\"> <br>\n", estepm,subdirf3(optionfilefiname,"varmuptjgr",digitp),digit);    fprintf(fichtm,"\n<br> Probability is computed over estepm=%d months. <br> <img src=\"%s%s.svg\"> <br>\n", estepm,subdirf3(optionfilefiname,"VARMUPTJGR-",digitp),digit);
   /*  fprintf(fichtm,"\n<br> Probability is computed over estepm=%d months and then divided by estepm and multiplied by %.0f in order to have the probability to die over a year <br> <img src=\"varmuptjgr%s%s.svg\"> <br>\n", stepm,YEARM,digitp,digit);    /*  fprintf(fichtm,"\n<br> Probability is computed over estepm=%d months and then divided by estepm and multiplied by %.0f in order to have the probability to die over a year <br> <img src=\"varmuptjgr%s%s.svg\"> <br>\n", stepm,YEARM,digitp,digit);
 */  */
 /*   fprintf(ficgp,"\nset out \"varmuptjgr%s%s%s.svg\";replot;",digitp,optionfilefiname,digit); */  /*   fprintf(ficgp,"\nset out \"varmuptjgr%s%s%s.svg\";replot;",digitp,optionfilefiname,digit); */
   fprintf(ficgp,"\nset out;\nset out \"%s%s.svg\";replot;set out;\n",subdirf3(optionfilefiname,"varmuptjgr",digitp),digit);    fprintf(ficgp,"\nset out;\nset out \"%s%s.svg\";replot;set out;\n",subdirf3(optionfilefiname,"VARMUPTJGR-",digitp),digit);
   
   free_vector(xp,1,npar);    free_vector(xp,1,npar);
   free_matrix(doldm,1,nlstate,1,nlstate);    free_matrix(doldm,1,nlstate,1,nlstate);
Line 4200  void varprob(char optionfilefiname[], do Line 4231  void varprob(char optionfilefiname[], do
   char fileresprobcor[FILENAMELENGTH];    char fileresprobcor[FILENAMELENGTH];
   double ***varpij;    double ***varpij;
   
   strcpy(fileresprob,"prob");     strcpy(fileresprob,"PROB_"); 
   strcat(fileresprob,fileres);    strcat(fileresprob,fileres);
   if((ficresprob=fopen(fileresprob,"w"))==NULL) {    if((ficresprob=fopen(fileresprob,"w"))==NULL) {
     printf("Problem with resultfile: %s\n", fileresprob);      printf("Problem with resultfile: %s\n", fileresprob);
     fprintf(ficlog,"Problem with resultfile: %s\n", fileresprob);      fprintf(ficlog,"Problem with resultfile: %s\n", fileresprob);
   }    }
   strcpy(fileresprobcov,"probcov");     strcpy(fileresprobcov,"PROBCOV_"); 
   strcat(fileresprobcov,fileres);    strcat(fileresprobcov,fileresu);
   if((ficresprobcov=fopen(fileresprobcov,"w"))==NULL) {    if((ficresprobcov=fopen(fileresprobcov,"w"))==NULL) {
     printf("Problem with resultfile: %s\n", fileresprobcov);      printf("Problem with resultfile: %s\n", fileresprobcov);
     fprintf(ficlog,"Problem with resultfile: %s\n", fileresprobcov);      fprintf(ficlog,"Problem with resultfile: %s\n", fileresprobcov);
   }    }
   strcpy(fileresprobcor,"probcor");     strcpy(fileresprobcor,"PROBCOR_"); 
   strcat(fileresprobcor,fileres);    strcat(fileresprobcor,fileresu);
   if((ficresprobcor=fopen(fileresprobcor,"w"))==NULL) {    if((ficresprobcor=fopen(fileresprobcor,"w"))==NULL) {
     printf("Problem with resultfile: %s\n", fileresprobcor);      printf("Problem with resultfile: %s\n", fileresprobcor);
     fprintf(ficlog,"Problem with resultfile: %s\n", fileresprobcor);      fprintf(ficlog,"Problem with resultfile: %s\n", fileresprobcor);
Line 4471  To be simple, these graphs help to under Line 4502  To be simple, these graphs help to under
                     fprintf(ficgp,"\nset log y;set log x; set xlabel \"p%1d%1d (year-1)\";set ylabel \"p%1d%1d (year-1)\"",k1,l1,k2,l2);                      fprintf(ficgp,"\nset log y;set log x; set xlabel \"p%1d%1d (year-1)\";set ylabel \"p%1d%1d (year-1)\"",k1,l1,k2,l2);
                     fprintf(ficgp,"\nset ter svg size 640, 480");                      fprintf(ficgp,"\nset ter svg size 640, 480");
                     fprintf(fichtmcov,"\n<br>Ellipsoids of confidence cov(p%1d%1d,p%1d%1d) expressed in year<sup>-1</sup>\                      fprintf(fichtmcov,"\n<br>Ellipsoids of confidence cov(p%1d%1d,p%1d%1d) expressed in year<sup>-1</sup>\
  :<a href=\"%s%d%1d%1d-%1d%1d.svg\">\   :<a href=\"%s_%d%1d%1d-%1d%1d.svg\">\
 %s%d%1d%1d-%1d%1d.svg</A>, ",k1,l1,k2,l2,\  %s_%d%1d%1d-%1d%1d.svg</A>, ",k1,l1,k2,l2,\
                             subdirf2(optionfilefiname,"varpijgr"), j1,k1,l1,k2,l2,\                              subdirf2(optionfilefiname,"VARPIJGR_"), j1,k1,l1,k2,l2,\
                             subdirf2(optionfilefiname,"varpijgr"), j1,k1,l1,k2,l2);                              subdirf2(optionfilefiname,"VARPIJGR_"), j1,k1,l1,k2,l2);
                     fprintf(fichtmcov,"\n<br><img src=\"%s%d%1d%1d-%1d%1d.svg\"> ",subdirf2(optionfilefiname,"varpijgr"), j1,k1,l1,k2,l2);                      fprintf(fichtmcov,"\n<br><img src=\"%s_%d%1d%1d-%1d%1d.svg\"> ",subdirf2(optionfilefiname,"VARPIJGR_"), j1,k1,l1,k2,l2);
                     fprintf(fichtmcov,"\n<br> Correlation at age %d (%.3f),",(int) age, c12);                      fprintf(fichtmcov,"\n<br> Correlation at age %d (%.3f),",(int) age, c12);
                     fprintf(ficgp,"\nset out \"%s%d%1d%1d-%1d%1d.svg\"",subdirf2(optionfilefiname,"varpijgr"), j1,k1,l1,k2,l2);                      fprintf(ficgp,"\nset out \"%s_%d%1d%1d-%1d%1d.svg\"",subdirf2(optionfilefiname,"VARPIJGR_"), j1,k1,l1,k2,l2);
                     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",\
Line 4494  To be simple, these graphs help to under Line 4525  To be simple, these graphs help to under
                   }/* if first */                    }/* if first */
                 } /* age mod 5 */                  } /* age mod 5 */
               } /* end loop age */                } /* end loop age */
               fprintf(ficgp,"\nset out;\nset out \"%s%d%1d%1d-%1d%1d.svg\";replot;set out;",subdirf2(optionfilefiname,"varpijgr"), j1,k1,l1,k2,l2);                fprintf(ficgp,"\nset out;\nset out \"%s_%d%1d%1d-%1d%1d.svg\";replot;set out;",subdirf2(optionfilefiname,"VARPIJGR_"), j1,k1,l1,k2,l2);
               first=1;                first=1;
             } /*l12 */              } /*l12 */
           } /* k12 */            } /* k12 */
Line 4516  To be simple, these graphs help to under Line 4547  To be simple, these graphs help to under
   
   
 /******************* Printing html file ***********/  /******************* Printing html file ***********/
 void printinghtml(char fileres[], char title[], char datafile[], int firstpass, \  void printinghtml(char fileresu[], char title[], char datafile[], int firstpass, \
                   int lastpass, int stepm, int weightopt, char model[],\                    int lastpass, int stepm, int weightopt, char model[],\
                   int imx,int jmin, int jmax, double jmeanint,char rfileres[],\                    int imx,int jmin, int jmax, double jmeanint,char rfileres[],\
                   int popforecast, int estepm ,\                    int popforecast, int estepm ,\
Line 4529  void printinghtml(char fileres[], char t Line 4560  void printinghtml(char fileres[], char t
 </ul>");  </ul>");
    fprintf(fichtm,"<ul><li><h4><a name='firstorder'>Result files (first order: no variance)</a></h4>\n \     fprintf(fichtm,"<ul><li><h4><a name='firstorder'>Result files (first order: no variance)</a></h4>\n \
  - Observed prevalence in each state (during the period defined between %.lf/%.lf/%.lf and %.lf/%.lf/%.lf): <a href=\"%s\">%s</a> <br>\n ",   - Observed prevalence in each state (during the period defined between %.lf/%.lf/%.lf and %.lf/%.lf/%.lf): <a href=\"%s\">%s</a> <br>\n ",
            jprev1, mprev1,anprev1,jprev2, mprev2,anprev2,subdirf2(fileres,"p"),subdirf2(fileres,"p"));             jprev1, mprev1,anprev1,jprev2, mprev2,anprev2,subdirf2(fileresu,"P_"),subdirf2(fileresu,"P_"));
    fprintf(fichtm,"\     fprintf(fichtm,"\
  - Estimated transition probabilities over %d (stepm) months: <a href=\"%s\">%s</a><br>\n ",   - Estimated transition probabilities over %d (stepm) months: <a href=\"%s\">%s</a><br>\n ",
            stepm,subdirf2(fileres,"pij"),subdirf2(fileres,"pij"));             stepm,subdirf2(fileresu,"PIJ_"),subdirf2(fileresu,"PIJ_"));
    fprintf(fichtm,"\     fprintf(fichtm,"\
  - Period (stable) prevalence in each health state: <a href=\"%s\">%s</a> <br>\n",   - Period (stable) prevalence in each health state: <a href=\"%s\">%s</a> <br>\n",
            subdirf2(fileres,"pl"),subdirf2(fileres,"pl"));             subdirf2(fileresu,"PL_"),subdirf2(fileresu,"PL_"));
    fprintf(fichtm,"\     fprintf(fichtm,"\
  - (a) Life expectancies by health status at initial age, ei. (b) health expectancies by health status at initial age, eij . 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, ei. (b) health expectancies by health status at initial age, eij . 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 href=\"%s\">%s</a> <br>\n",     <a href=\"%s\">%s</a> <br>\n",
            estepm,subdirf2(fileres,"e"),subdirf2(fileres,"e"));             estepm,subdirf2(fileresu,"E_"),subdirf2(fileresu,"E_"));
    fprintf(fichtm,"\     fprintf(fichtm,"\
  - Population projections by age and states: \   - Population projections by age and states: \
    <a href=\"%s\">%s</a> <br>\n</li>", subdirf2(fileres,"f"),subdirf2(fileres,"f"));     <a href=\"%s\">%s</a> <br>\n</li>", subdirf2(fileresu,"F_"),subdirf2(fileresu,"F_"));
   
 fprintf(fichtm," \n<ul><li><b>Graphs</b></li><p>");  fprintf(fichtm," \n<ul><li><b>Graphs</b></li><p>");
   
Line 4561  fprintf(fichtm," \n<ul><li><b>Graphs</b> Line 4592  fprintf(fichtm," \n<ul><li><b>Graphs</b>
        }         }
        fprintf(fichtm," ************\n<hr size=\"2\" color=\"#EC5E5E\">");         fprintf(fichtm," ************\n<hr size=\"2\" color=\"#EC5E5E\">");
      }       }
        /* aij, bij */
        fprintf(fichtm,"<br>- Logit model, for example: logit(pij)=log(pij/pii)= aij+ bij age + V1 age + etc. as a function of age: <a href=\"%s_%d-1.svg\">%s_%d-1.svg</a><br> \
   <img src=\"%s_%d-1.svg\">",subdirf2(optionfilefiname,"PE_"),jj1,subdirf2(optionfilefiname,"PE_"),jj1,subdirf2(optionfilefiname,"PE_"),jj1);
      /* Pij */       /* Pij */
      fprintf(fichtm,"<br>- Pij or Conditional probabilities to be observed in state j being in state i, %d (stepm) months before: <a href=\"%s%d_1.svg\">%s%d_1.svg</a><br> \       fprintf(fichtm,"<br>\n- Pij or conditional probabilities to be observed in state j being in state i, %d (stepm) months before: <a href=\"%s_%d-2.svg\">%s_%d-2.svg</a><br> \
 <img src=\"%s%d_1.svg\">",stepm,subdirf2(optionfilefiname,"pe"),jj1,subdirf2(optionfilefiname,"pe"),jj1,subdirf2(optionfilefiname,"pe"),jj1);       <img src=\"%s_%d-2.svg\">",stepm,subdirf2(optionfilefiname,"PE_"),jj1,subdirf2(optionfilefiname,"PE_"),jj1,subdirf2(optionfilefiname,"PE_"),jj1);     
      /* Quasi-incidences */       /* Quasi-incidences */
      fprintf(fichtm,"<br>- Pij or Conditional probabilities to be observed in state j being in state i %d (stepm) months\       fprintf(fichtm,"<br>\n- Iij or Conditional probabilities to be observed in state j being in state i %d (stepm) months\
  before but expressed in per year i.e. quasi incidences if stepm is small and probabilities too: <a href=\"%s%d_2.svg\">%s%d_2.svg</a><br> \   before but expressed in per year i.e. quasi incidences if stepm is small and probabilities too,\
 <img src=\"%s%d_2.svg\">",stepm,subdirf2(optionfilefiname,"pe"),jj1,subdirf2(optionfilefiname,"pe"),jj1,subdirf2(optionfilefiname,"pe"),jj1);    incidence (rates) are the limit when h tends to zero of the ratio of the probability hPij \
        /* Period (stable) prevalence in each health state */  divided by h: hPij/h : <a href=\"%s_%d-3.svg\">%s_%d-3.svg</a><br> \
        for(cpt=1; cpt<=nlstate;cpt++){  <img src=\"%s_%d-3.svg\">",stepm,subdirf2(optionfilefiname,"PE_"),jj1,subdirf2(optionfilefiname,"PE_"),jj1,subdirf2(optionfilefiname,"PE_"),jj1); 
          fprintf(fichtm,"<br>- Convergence to period (stable) prevalence in state %d. Or probability to be in state %d being in state (1 to %d) at different ages. <a href=\"%s%d_%d.svg\">%s%d_%d.svg</a><br> \       /* Survival functions (period) in state j */
 <img src=\"%s%d_%d.svg\">", cpt, cpt, nlstate, subdirf2(optionfilefiname,"p"),cpt,jj1,subdirf2(optionfilefiname,"p"),cpt,jj1,subdirf2(optionfilefiname,"p"),cpt,jj1);       for(cpt=1; cpt<=nlstate;cpt++){
        }         fprintf(fichtm,"<br>\n- Survival functions in state %d. Or probability to survive in state %d being in state (1 to %d) at different ages. <a href=\"%s%d_%d.svg\">%s%d_%d.svg</a><br> \
   <img src=\"%s_%d-%d.svg\">", cpt, cpt, nlstate, subdirf2(optionfilefiname,"LIJ_"),cpt,jj1,subdirf2(optionfilefiname,"LIJ_"),cpt,jj1,subdirf2(optionfilefiname,"LIJ_"),cpt,jj1);
        }
        /* State specific survival functions (period) */
        for(cpt=1; cpt<=nlstate;cpt++){
          fprintf(fichtm,"<br>\n- Survival functions from state %d in any different live states and total.\
    Or probability to survive in various states (1 to %d) being in state %d at different ages.\
    <a href=\"%s%d_%d.svg\">%s%d_%d.svg</a><br> <img src=\"%s_%d-%d.svg\">", cpt, nlstate, cpt, subdirf2(optionfilefiname,"LIJT_"),cpt,jj1,subdirf2(optionfilefiname,"LIJT_"),cpt,jj1,subdirf2(optionfilefiname,"LIJT_"),cpt,jj1);
        }
        /* Period (stable) prevalence in each health state */
        for(cpt=1; cpt<=nlstate;cpt++){
          fprintf(fichtm,"<br>\n- Convergence to period (stable) prevalence in state %d. Or probability to be in state %d being in state (1 to %d) at different ages. <a href=\"%s%d_%d.svg\">%s%d_%d.svg</a><br> \
   <img src=\"%s_%d-%d.svg\">", cpt, cpt, nlstate, subdirf2(optionfilefiname,"P_"),cpt,jj1,subdirf2(optionfilefiname,"P_"),cpt,jj1,subdirf2(optionfilefiname,"P_"),cpt,jj1);
        }
      for(cpt=1; cpt<=nlstate;cpt++) {       for(cpt=1; cpt<=nlstate;cpt++) {
         fprintf(fichtm,"\n<br>- Life expectancy by health state (%d) at initial age and its decomposition into health expectancies in each alive state (1 to %d) : <a href=\"%s%d%d.svg\">%s%d%d.svg</a> <br> \         fprintf(fichtm,"\n<br>- Life expectancy by health state (%d) at initial age and its decomposition into health expectancies in each alive state (1 to %d) (or area under each survival functions): <a href=\"%s%d%d.svg\">%s%d%d.svg</a> <br> \
 <img src=\"%s%d%d.svg\">",cpt,nlstate,subdirf2(optionfilefiname,"exp"),cpt,jj1,subdirf2(optionfilefiname,"exp"),cpt,jj1,subdirf2(optionfilefiname,"exp"),cpt,jj1);  <img src=\"%s_%d%d.svg\">",cpt,nlstate,subdirf2(optionfilefiname,"EXP_"),cpt,jj1,subdirf2(optionfilefiname,"EXP_"),cpt,jj1,subdirf2(optionfilefiname,"EXP_"),cpt,jj1);
      }       }
    /* } /\* end i1 *\/ */     /* } /\* end i1 *\/ */
  }/* End k1 */   }/* End k1 */
Line 4594  covariance matrix of the one-step probab Line 4641  covariance matrix of the one-step probab
 See page 'Matrix of variance-covariance of one-step probabilities' below. \n", rfileres,rfileres);  See page 'Matrix of variance-covariance of one-step probabilities' below. \n", rfileres,rfileres);
   
  fprintf(fichtm," - Standard deviation of one-step probabilities: <a href=\"%s\">%s</a> <br>\n",   fprintf(fichtm," - Standard deviation of one-step probabilities: <a href=\"%s\">%s</a> <br>\n",
          subdirf2(fileres,"prob"),subdirf2(fileres,"prob"));           subdirf2(fileresu,"PROB_"),subdirf2(fileresu,"PROB_"));
  fprintf(fichtm,"\   fprintf(fichtm,"\
  - Variance-covariance of one-step probabilities: <a href=\"%s\">%s</a> <br>\n",   - Variance-covariance of one-step probabilities: <a href=\"%s\">%s</a> <br>\n",
          subdirf2(fileres,"probcov"),subdirf2(fileres,"probcov"));           subdirf2(fileresu,"PROBCOV_"),subdirf2(fileresu,"PROBCOV_"));
   
  fprintf(fichtm,"\   fprintf(fichtm,"\
  - Correlation matrix of one-step probabilities: <a href=\"%s\">%s</a> <br>\n",   - Correlation matrix of one-step probabilities: <a href=\"%s\">%s</a> <br>\n",
          subdirf2(fileres,"probcor"),subdirf2(fileres,"probcor"));           subdirf2(fileresu,"PROBCOR_"),subdirf2(fileresu,"PROBCOR_"));
  fprintf(fichtm,"\   fprintf(fichtm,"\
  - Variances and covariances of health expectancies by age and <b>initial health status</b> (cov(e<sup>ij</sup>,e<sup>kl</sup>)(estepm=%2d months): \   - Variances and covariances of health expectancies by age and <b>initial health status</b> (cov(e<sup>ij</sup>,e<sup>kl</sup>)(estepm=%2d months): \
    <a href=\"%s\">%s</a> <br>\n</li>",     <a href=\"%s\">%s</a> <br>\n</li>",
            estepm,subdirf2(fileres,"cve"),subdirf2(fileres,"cve"));             estepm,subdirf2(fileresu,"CVE_"),subdirf2(fileresu,"CVE_"));
  fprintf(fichtm,"\   fprintf(fichtm,"\
  - (a) Health expectancies by health status at initial age (e<sup>ij</sup>) and standard errors (in parentheses) (b) life expectancies and standard errors (e<sup>i.</sup>=e<sup>i1</sup>+e<sup>i2</sup>+...)(estepm=%2d months): \   - (a) Health expectancies by health status at initial age (e<sup>ij</sup>) and standard errors (in parentheses) (b) life expectancies and standard errors (e<sup>i.</sup>=e<sup>i1</sup>+e<sup>i2</sup>+...)(estepm=%2d months): \
    <a href=\"%s\">%s</a> <br>\n</li>",     <a href=\"%s\">%s</a> <br>\n</li>",
            estepm,subdirf2(fileres,"stde"),subdirf2(fileres,"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 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(fileres,"v"),subdirf2(fileres,"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(fileres,"t"),subdirf2(fileres,"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 period (stable) prevalences: <a href=\"%s\">%s</a> <br>\n",\
          subdirf2(fileres,"vpl"),subdirf2(fileres,"vpl"));           subdirf2(fileresu,"VPL_"),subdirf2(fileresu,"VPL_"));
   
 /*  if(popforecast==1) fprintf(fichtm,"\n */  /*  if(popforecast==1) fprintf(fichtm,"\n */
 /*  - Prevalences forecasting: <a href=\"f%s\">f%s</a> <br>\n */  /*  - Prevalences forecasting: <a href=\"f%s\">f%s</a> <br>\n */
Line 4645  See page 'Matrix of variance-covariance Line 4692  See page 'Matrix of variance-covariance
      for(cpt=1; cpt<=nlstate;cpt++) {       for(cpt=1; cpt<=nlstate;cpt++) {
        fprintf(fichtm,"<br>- Observed (cross-sectional) and period (incidence based) \         fprintf(fichtm,"<br>- Observed (cross-sectional) and period (incidence based) \
 prevalence (with 95%% confidence interval) in state (%d): %s%d_%d.svg <br>\  prevalence (with 95%% confidence interval) in state (%d): %s%d_%d.svg <br>\
 <img src=\"%s%d_%d.svg\">",cpt,subdirf2(optionfilefiname,"v"),cpt,jj1,subdirf2(optionfilefiname,"v"),cpt,jj1);    <img src=\"%s_%d-%d.svg\">",cpt,subdirf2(optionfilefiname,"V_"),cpt,jj1,subdirf2(optionfilefiname,"V_"),cpt,jj1);  
      }       }
      fprintf(fichtm,"\n<br>- Total life expectancy by age and \       fprintf(fichtm,"\n<br>- Total life expectancy by age and \
 health expectancies in states (1) and (2). If popbased=1 the smooth (due to the model) \  health expectancies in states (1) and (2). If popbased=1 the smooth (due to the model) \
 true period expectancies (those weighted with period prevalences are also\  true period expectancies (those weighted with period prevalences are also\
  drawn in addition to the population based expectancies computed using\   drawn in addition to the population based expectancies computed using\
  observed and cahotic prevalences: %s%d.svg<br>\   observed and cahotic prevalences: %s_%d.svg<br>\
 <img src=\"%s%d.svg\">",subdirf2(optionfilefiname,"e"),jj1,subdirf2(optionfilefiname,"e"),jj1);  <img src=\"%s_%d.svg\">",subdirf2(optionfilefiname,"E_"),jj1,subdirf2(optionfilefiname,"E_"),jj1);
    /* } /\* end i1 *\/ */     /* } /\* end i1 *\/ */
  }/* End k1 */   }/* End k1 */
  fprintf(fichtm,"</ul>");   fprintf(fichtm,"</ul>");
Line 4660  true period expectancies (those weighted Line 4707  true period expectancies (those weighted
 }  }
   
 /******************* Gnuplot file **************/  /******************* Gnuplot file **************/
 void printinggnuplot(char fileres[], char optionfilefiname[], double ageminpar, double agemaxpar, double fage , char pathc[], double p[]){  void printinggnuplot(char fileresu[], char optionfilefiname[], double ageminpar, double agemaxpar, double fage , char pathc[], double p[]){
   
   char dirfileres[132],optfileres[132];    char dirfileres[132],optfileres[132];
   int cpt=0,k1=0,i=0,k=0,j=0,jk=0,k2=0,k3=0,ij=0,l=0;    int cpt=0,k1=0,i=0,k=0,j=0,jk=0,k2=0,k3=0,ij=0,l=0;
   int ng=0;    int ng=0;
     int vpopbased;
 /*   if((ficgp=fopen(optionfilegnuplot,"a"))==NULL) { */  /*   if((ficgp=fopen(optionfilegnuplot,"a"))==NULL) { */
 /*     printf("Problem with file %s",optionfilegnuplot); */  /*     printf("Problem with file %s",optionfilegnuplot); */
 /*     fprintf(ficlog,"Problem with file %s",optionfilegnuplot); */  /*     fprintf(ficlog,"Problem with file %s",optionfilegnuplot); */
Line 4675  void printinggnuplot(char fileres[], cha Line 4723  void printinggnuplot(char fileres[], cha
     /*#endif */      /*#endif */
   m=pow(2,cptcoveff);    m=pow(2,cptcoveff);
   
     /* Contribution to likelihood */
     /* Plot the probability implied in the likelihood */
       fprintf(ficgp,"\n# Contributions to the Likelihood, mle >=1. For mle=4 no interpolation, pure matrix products.\n#\n");
       fprintf(ficgp,"\n set log y; unset log x;set xlabel \"Age\"; set ylabel \"Likelihood (-2Log(L))\";");
       /* fprintf(ficgp,"\nset ter svg size 640, 480"); */ /* Too big for svg */
       fprintf(ficgp,"\nset ter png size 640, 480");
   /* good for mle=4 plot by number of matrix products.
      replot  "rrtest1/toto.txt" u 2:($4 == 1 && $5==2 ? $9 : 1/0):5 t "p12" with point lc 1 */
   /* replot exp(p1+p2*x)/(1+exp(p1+p2*x)+exp(p3+p4*x)+exp(p5+p6*x)) t "p12(x)"  */
       /* fprintf(ficgp,"\nset out \"%s.svg\";",subdirf2(optionfilefiname,"ILK_")); */
       fprintf(ficgp,"\nset out \"%s.png\";",subdirf2(optionfilefiname,"ILK_"));
       fprintf(ficgp,"\nplot  \"%s\" u 2:(-$11):3 t \"All sample, all transitions\" with dots lc variable",subdirf(fileresilk));
       fprintf(ficgp,"\nreplot  \"%s\" u 2:($3 <= 3 ? -$11 : 1/0):3 t \"First 3 individuals\" with line lc variable", subdirf(fileresilk));
       fprintf(ficgp,"\nset out\n");
       /* fprintf(ficgp,"\nset out \"%s.svg\"; replot; set out; # bug gnuplot",subdirf2(optionfilefiname,"ILK_")); */
   
   strcpy(dirfileres,optionfilefiname);    strcpy(dirfileres,optionfilefiname);
   strcpy(optfileres,"vpl");    strcpy(optfileres,"vpl");
  /* 1eme*/   /* 1eme*/
   fprintf(ficgp,"\n# 1st: Period (stable) prevalence with CI: 'vpl' files\n");    fprintf(ficgp,"\n# 1st: Period (stable) prevalence with CI: 'VPL_' files\n");
   for (cpt=1; cpt<= nlstate ; cpt ++) {    for (cpt=1; cpt<= nlstate ; cpt ++) {
     for (k1=1; k1<= m ; k1 ++) { /* plot [100000000000000000000:-100000000000000000000] "mysbiaspar/vplrmysbiaspar.txt to check */      for (k1=1; k1<= m ; k1 ++) { /* plot [100000000000000000000:-100000000000000000000] "mysbiaspar/vplrmysbiaspar.txt to check */
      fprintf(ficgp,"\nset out \"%s%d_%d.svg\" \n",subdirf2(optionfilefiname,"v"),cpt,k1);       fprintf(ficgp,"\nset out \"%s_%d-%d.svg\" \n",subdirf2(optionfilefiname,"V_"),cpt,k1);
      fprintf(ficgp,"\n#set out \"v%s%d_%d.svg\" \n",optionfilefiname,cpt,k1);       fprintf(ficgp,"\n#set out \"V_%s_%d-%d.svg\" \n",optionfilefiname,cpt,k1);
      fprintf(ficgp,"set xlabel \"Age\" \n\       fprintf(ficgp,"set xlabel \"Age\" \n\
 set ylabel \"Probability\" \n\  set ylabel \"Probability\" \n\
 set ter svg size 640, 480\n\  set ter svg size 640, 480\n\
 plot [%.f:%.f] \"%s\" every :::%d::%d u 1:2 \"%%lf",ageminpar,fage,subdirf2(fileres,"vpl"),k1-1,k1-1);  plot [%.f:%.f] \"%s\" every :::%d::%d u 1:2 \"%%lf",ageminpar,fage,subdirf2(fileresu,"VPL_"),k1-1,k1-1);
   
      for (i=1; i<= nlstate ; i ++) {       for (i=1; i<= nlstate ; i ++) {
        if (i==cpt) fprintf(ficgp," %%lf (%%lf)");         if (i==cpt) fprintf(ficgp," %%lf (%%lf)");
        else        fprintf(ficgp," %%*lf (%%*lf)");         else        fprintf(ficgp," %%*lf (%%*lf)");
      }       }
      fprintf(ficgp,"\" t\"Period (stable) prevalence\" w l lt 0,\"%s\" every :::%d::%d u 1:($2+1.96*$3) \"%%lf",subdirf2(fileres,"vpl"),k1-1,k1-1);       fprintf(ficgp,"\" t\"Period (stable) prevalence\" w l lt 0,\"%s\" every :::%d::%d u 1:($2+1.96*$3) \"%%lf",subdirf2(fileresu,"VPL_"),k1-1,k1-1);
      for (i=1; i<= nlstate ; i ++) {       for (i=1; i<= nlstate ; i ++) {
        if (i==cpt) fprintf(ficgp," %%lf (%%lf)");         if (i==cpt) fprintf(ficgp," %%lf (%%lf)");
        else fprintf(ficgp," %%*lf (%%*lf)");         else fprintf(ficgp," %%*lf (%%*lf)");
      }        } 
      fprintf(ficgp,"\" t\"95%% CI\" w l lt 1,\"%s\" every :::%d::%d u 1:($2-1.96*$3) \"%%lf",subdirf2(fileres,"vpl"),k1-1,k1-1);        fprintf(ficgp,"\" t\"95%% CI\" w l lt 1,\"%s\" every :::%d::%d u 1:($2-1.96*$3) \"%%lf",subdirf2(fileresu,"VPL_"),k1-1,k1-1); 
      for (i=1; i<= nlstate ; i ++) {       for (i=1; i<= nlstate ; i ++) {
        if (i==cpt) fprintf(ficgp," %%lf (%%lf)");         if (i==cpt) fprintf(ficgp," %%lf (%%lf)");
        else fprintf(ficgp," %%*lf (%%*lf)");         else fprintf(ficgp," %%*lf (%%*lf)");
      }         }  
      fprintf(ficgp,"\" t\"\" w l lt 1,\"%s\" every :::%d::%d u 1:($%d) t\"Observed prevalence \" w l lt 2",subdirf2(fileres,"p"),k1-1,k1-1,2+4*(cpt-1));       fprintf(ficgp,"\" t\"\" w l lt 1,\"%s\" every :::%d::%d u 1:($%d) t\"Observed prevalence \" w l lt 2",subdirf2(fileresu,"P_"),k1-1,k1-1,2+4*(cpt-1));
    }       fprintf(ficgp,"\nset out \n");
   }      } /* k1 */
     } /* cpt */
   /*2 eme*/    /*2 eme*/
   fprintf(ficgp,"\n# 2nd: Total life expectancy with CI: 't' files\n");    fprintf(ficgp,"\n# 2nd: Total life expectancy with CI: 't' files\n");
   for (k1=1; k1<= m ; k1 ++) {     for (k1=1; k1<= m ; k1 ++) { 
     fprintf(ficgp,"\nset out \"%s%d.svg\" \n",subdirf2(optionfilefiname,"e"),k1);      fprintf(ficgp,"\nset out \"%s_%d.svg\" \n",subdirf2(optionfilefiname,"E_"),k1);
     fprintf(ficgp,"set ylabel \"Years\" \nset ter svg size 640, 480\nplot [%.f:%.f] ",ageminpar,fage);      for(vpopbased=0; vpopbased <= popbased; vpopbased++){ /* Done for vpopbased=0 and vpopbased=1 if popbased==1*/
             if(vpopbased==0)
     for (i=1; i<= nlstate+1 ; i ++) {          fprintf(ficgp,"set ylabel \"Years\" \nset ter svg size 640, 480\nplot [%.f:%.f] ",ageminpar,fage);
       k=2*i;        else
       fprintf(ficgp,"\"%s\" every :::%d::%d u 1:2 \"%%lf",subdirf2(fileres,"t"),k1-1,k1-1);          fprintf(ficgp,"\nreplot ");
       for (j=1; j<= nlstate+1 ; j ++) {        for (i=1; i<= nlstate+1 ; i ++) {
         if (j==i) fprintf(ficgp," %%lf (%%lf)");          k=2*i;
         else fprintf(ficgp," %%*lf (%%*lf)");          fprintf(ficgp,"\"%s\" every :::%d::%d u 1:($2==%d && $4!=0 ?$4 : 1/0) \"%%lf %%lf %%lf",subdirf2(fileresu,"T_"),k1-1,k1-1, vpopbased);
       }             for (j=1; j<= nlstate+1 ; j ++) {
       if (i== 1) fprintf(ficgp,"\" t\"TLE\" w l ,");            if (j==i) fprintf(ficgp," %%lf (%%lf)");
       else fprintf(ficgp,"\" t\"LE in state (%d)\" w l ,",i-1);            else fprintf(ficgp," %%*lf (%%*lf)");
       fprintf(ficgp,"\"%s\" every :::%d::%d u 1:($2-$3*2) \"%%lf",subdirf2(fileres,"t"),k1-1,k1-1);          }   
       for (j=1; j<= nlstate+1 ; j ++) {          if (i== 1) fprintf(ficgp,"\" t\"TLE\" w l lt %d, \\\n",i);
         if (j==i) fprintf(ficgp," %%lf (%%lf)");          else fprintf(ficgp,"\" t\"LE in state (%d)\" w l lt %d, \\\n",i-1,i+1);
         else fprintf(ficgp," %%*lf (%%*lf)");          fprintf(ficgp,"\"%s\" every :::%d::%d u 1:($2==%d && $4!=0 ? $4-$5*2 : 1/0) \"%%lf %%lf %%lf",subdirf2(fileresu,"T_"),k1-1,k1-1,vpopbased);
       }             for (j=1; j<= nlstate+1 ; j ++) {
       fprintf(ficgp,"\" t\"\" w l lt 0,");            if (j==i) fprintf(ficgp," %%lf (%%lf)");
       fprintf(ficgp,"\"%s\" every :::%d::%d u 1:($2+$3*2) \"%%lf",subdirf2(fileres,"t"),k1-1,k1-1);            else fprintf(ficgp," %%*lf (%%*lf)");
       for (j=1; j<= nlstate+1 ; j ++) {          }   
         if (j==i) fprintf(ficgp," %%lf (%%lf)");          fprintf(ficgp,"\" t\"\" w l lt 0,");
         else fprintf(ficgp," %%*lf (%%*lf)");          fprintf(ficgp,"\"%s\" every :::%d::%d u 1:($2==%d && $4!=0 ? $4+$5*2 : 1/0) \"%%lf %%lf %%lf",subdirf2(fileresu,"T_"),k1-1,k1-1,vpopbased);
       }             for (j=1; j<= nlstate+1 ; j ++) {
       if (i== (nlstate+1)) fprintf(ficgp,"\" t\"\" w l lt 0");            if (j==i) fprintf(ficgp," %%lf (%%lf)");
       else fprintf(ficgp,"\" t\"\" w l lt 0,");            else fprintf(ficgp," %%*lf (%%*lf)");
     }          }   
   }          if (i== (nlstate+1)) fprintf(ficgp,"\" t\"\" w l lt 0");
             else fprintf(ficgp,"\" t\"\" w l lt 0,\\\n");
         } /* state */
       } /* vpopbased */
       fprintf(ficgp,"\nset out;set out \"%s_%d.svg\"; replot; set out; \n",subdirf2(optionfilefiname,"E_"),k1); /* Buggy gnuplot */
     } /* k1 */
   /*3eme*/    /*3eme*/
       
   for (k1=1; k1<= m ; k1 ++) {     for (k1=1; k1<= m ; k1 ++) { 
     for (cpt=1; cpt<= nlstate ; cpt ++) {      for (cpt=1; cpt<= nlstate ; cpt ++) {
       /*       k=2+nlstate*(2*cpt-2); */        /*       k=2+nlstate*(2*cpt-2); */
       k=2+(nlstate+1)*(cpt-1);        k=2+(nlstate+1)*(cpt-1);
       fprintf(ficgp,"\nset out \"%s%d%d.svg\" \n",subdirf2(optionfilefiname,"exp"),cpt,k1);        fprintf(ficgp,"\nset out \"%s_%d%d.svg\" \n",subdirf2(optionfilefiname,"EXP_"),cpt,k1);
       fprintf(ficgp,"set ter svg size 640, 480\n\        fprintf(ficgp,"set ter svg size 640, 480\n\
 plot [%.f:%.f] \"%s\" every :::%d::%d u 1:%d t \"e%d1\" w l",ageminpar,fage,subdirf2(fileres,"e"),k1-1,k1-1,k,cpt);  plot [%.f:%.f] \"%s\" every :::%d::%d u 1:%d t \"e%d1\" w l",ageminpar,fage,subdirf2(fileresu,"E_"),k1-1,k1-1,k,cpt);
       /*fprintf(ficgp,",\"e%s\" every :::%d::%d u 1:($%d-2*$%d) \"\%%lf ",fileres,k1-1,k1-1,k,k+1);        /*fprintf(ficgp,",\"e%s\" every :::%d::%d u 1:($%d-2*$%d) \"\%%lf ",fileres,k1-1,k1-1,k,k+1);
         for (i=1; i<= nlstate*2 ; i ++) fprintf(ficgp,"\%%lf (\%%lf) ");          for (i=1; i<= nlstate*2 ; i ++) fprintf(ficgp,"\%%lf (\%%lf) ");
         fprintf(ficgp,"\" t \"e%d1\" w l",cpt);          fprintf(ficgp,"\" t \"e%d1\" w l",cpt);
Line 4754  plot [%.f:%.f] \"%s\" every :::%d::%d u Line 4823  plot [%.f:%.f] \"%s\" every :::%d::%d u
                   
       */        */
       for (i=1; i< nlstate ; i ++) {        for (i=1; i< nlstate ; i ++) {
         fprintf(ficgp," ,\"%s\" every :::%d::%d u 1:%d t \"e%d%d\" w l",subdirf2(fileres,"e"),k1-1,k1-1,k+i,cpt,i+1);          fprintf(ficgp," ,\"%s\" every :::%d::%d u 1:%d t \"e%d%d\" w l",subdirf2(fileresu,"E_"),k1-1,k1-1,k+i,cpt,i+1);
         /*      fprintf(ficgp," ,\"%s\" every :::%d::%d u 1:%d t \"e%d%d\" w l",subdirf2(fileres,"e"),k1-1,k1-1,k+2*i,cpt,i+1);*/          /*      fprintf(ficgp," ,\"%s\" every :::%d::%d u 1:%d t \"e%d%d\" w l",subdirf2(fileres,"e"),k1-1,k1-1,k+2*i,cpt,i+1);*/
                   
       }         } 
       fprintf(ficgp," ,\"%s\" every :::%d::%d u 1:%d t \"e%d.\" w l",subdirf2(fileres,"e"),k1-1,k1-1,k+nlstate,cpt);        fprintf(ficgp," ,\"%s\" every :::%d::%d u 1:%d t \"e%d.\" w l",subdirf2(fileresu,"E_"),k1-1,k1-1,k+nlstate,cpt);
     }      }
   }    }
       
   /* CV preval stable (period) */    /* Survival functions (period) from state i in state j by initial state i */
   for (k1=1; k1<= m ; k1 ++) { /* For each multivariate if any */    for (k1=1; k1<= m ; k1 ++) { /* For each multivariate if any */
     for (cpt=1; cpt<=nlstate ; cpt ++) { /* For each life state */      for (cpt=1; cpt<=nlstate ; cpt ++) { /* For each life state */
       k=3;        k=3;
         fprintf(ficgp,"\n#\n#\n# Survival functions in state j : 'lij' files, cov=%d state=%d",k1, cpt);
         fprintf(ficgp,"\nset out \"%s_%d-%d.svg\" \n",subdirf2(optionfilefiname,"LIJ_"),cpt,k1);
         fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability to be alive\" \n\
   set ter svg size 640, 480\n\
   unset log y\n\
   plot [%.f:%.f]  ", ageminpar, agemaxpar);
         for (i=1; i<= nlstate ; i ++){
           if(i==1)
             fprintf(ficgp,"\"%s\"",subdirf2(fileresu,"PIJ_"));
           else
             fprintf(ficgp,", '' ");
           l=(nlstate+ndeath)*(i-1)+1;
           fprintf(ficgp," u ($1==%d ? ($3):1/0):($%d/($%d",k1,k+l+(cpt-1),k+l);
           for (j=2; j<= nlstate+ndeath ; j ++)
             fprintf(ficgp,"+$%d",k+l+j-1);
           fprintf(ficgp,")) t \"l(%d,%d)\" w l",i,cpt);
         } /* nlstate */
         fprintf(ficgp,"\nset out\n");
       } /* end cpt state*/ 
     } /* end covariate */  
   
     /* Survival functions (period) from state i in state j by final state j */
     for (k1=1; k1<= m ; k1 ++) { /* For each covariate if any */
       for (cpt=1; cpt<=nlstate ; cpt ++) { /* For each inital state  */
         k=3;
         fprintf(ficgp,"\n#\n#\n# Survival functions in state j and all livestates from state i by final state j: 'lij' files, cov=%d state=%d",k1, cpt);
         fprintf(ficgp,"\nset out \"%s_%d-%d.svg\" \n",subdirf2(optionfilefiname,"LIJT_"),cpt,k1);
         fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability to be alive\" \n\
   set ter svg size 640, 480\n\
   unset log y\n\
   plot [%.f:%.f]  ", ageminpar, agemaxpar);
         for (j=1; j<= nlstate ; j ++){ /* Lived in state j */
           if(j==1)
             fprintf(ficgp,"\"%s\"",subdirf2(fileresu,"PIJ_"));
           else
             fprintf(ficgp,", '' ");
           l=(nlstate+ndeath)*(cpt-1) +j;
           fprintf(ficgp," u (($1==%d && (floor($2)%%5 == 0)) ? ($3):1/0):($%d",k1,k+l);
           /* for (i=2; i<= nlstate+ndeath ; i ++) */
           /*   fprintf(ficgp,"+$%d",k+l+i-1); */
           fprintf(ficgp,") t \"l(%d,%d)\" w l",cpt,j);
         } /* nlstate */
         fprintf(ficgp,", '' ");
         fprintf(ficgp," u (($1==%d && (floor($2)%%5 == 0)) ? ($3):1/0):(",k1);
         for (j=1; j<= nlstate ; j ++){ /* Lived in state j */
           l=(nlstate+ndeath)*(cpt-1) +j;
           if(j < nlstate)
             fprintf(ficgp,"$%d +",k+l);
           else
             fprintf(ficgp,"$%d) t\"l(%d,.)\" w l",k+l,cpt);
         }
         fprintf(ficgp,"\nset out\n");
       } /* end cpt state*/ 
     } /* end covariate */  
   
     /* CV preval stable (period) for each covariate */
     for (k1=1; k1<= m ; k1 ++) { /* For each covariate if any */
       for (cpt=1; cpt<=nlstate ; cpt ++) { /* For each life state */
         k=3;
       fprintf(ficgp,"\n#\n#\n#CV preval stable (period): 'pij' files, cov=%d state=%d",k1, cpt);        fprintf(ficgp,"\n#\n#\n#CV preval stable (period): 'pij' files, cov=%d state=%d",k1, cpt);
       fprintf(ficgp,"\nset out \"%s%d_%d.svg\" \n",subdirf2(optionfilefiname,"p"),cpt,k1);        fprintf(ficgp,"\nset out \"%s_%d-%d.svg\" \n",subdirf2(optionfilefiname,"P_"),cpt,k1);
       fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability\" \n\        fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability\" \n\
 set ter svg size 640, 480\n\  set ter svg size 640, 480\n\
 unset log y\n\  unset log y\n\
 plot [%.f:%.f]  ", ageminpar, agemaxpar);  plot [%.f:%.f]  ", ageminpar, agemaxpar);
       for (i=1; i<= nlstate ; i ++){        for (i=1; i<= nlstate ; i ++){
         if(i==1)          if(i==1)
           fprintf(ficgp,"\"%s\"",subdirf2(fileres,"pij"));            fprintf(ficgp,"\"%s\"",subdirf2(fileresu,"PIJ_"));
         else          else
           fprintf(ficgp,", '' ");            fprintf(ficgp,", '' ");
         l=(nlstate+ndeath)*(i-1)+1;          l=(nlstate+ndeath)*(i-1)+1;
         fprintf(ficgp," u ($1==%d ? ($3):1/0):($%d/($%d",k1,k+l+(cpt-1),k+l);          fprintf(ficgp," u ($1==%d ? ($3):1/0):($%d/($%d",k1,k+l+(cpt-1),k+l);
         for (j=1; j<= (nlstate-1) ; j ++)          for (j=2; j<= nlstate ; j ++)
           fprintf(ficgp,"+$%d",k+l+j);            fprintf(ficgp,"+$%d",k+l+j-1);
         fprintf(ficgp,")) t \"prev(%d,%d)\" w l",i,cpt);          fprintf(ficgp,")) t \"prev(%d,%d)\" w l",i,cpt);
       } /* nlstate */        } /* nlstate */
       fprintf(ficgp,"\n");        fprintf(ficgp,"\nset out\n");
     } /* end cpt state*/       } /* end cpt state*/ 
   } /* end covariate */      } /* end covariate */  
     
   /* proba elementaires */    /* proba elementaires */
   fprintf(ficgp,"\n##############\n#MLE estimated parameters\n#############\n");    fprintf(ficgp,"\n##############\n#MLE estimated parameters\n#############\n");
   for(i=1,jk=1; i <=nlstate; i++){    for(i=1,jk=1; i <=nlstate; i++){
Line 4819  plot [%.f:%.f]  ", ageminpar, agemaxpar) Line 4947  plot [%.f:%.f]  ", ageminpar, agemaxpar)
   fprintf(ficgp,"#       +exp(a13+b13*age+c13age*age+d13*V1+e13*V1*age))\n");    fprintf(ficgp,"#       +exp(a13+b13*age+c13age*age+d13*V1+e13*V1*age))\n");
   fprintf(ficgp,"#       +exp(a14+b14*age+c14age*age+d14*V1+e14*V1*age)+...)\n");    fprintf(ficgp,"#       +exp(a14+b14*age+c14age*age+d14*V1+e14*V1*age)+...)\n");
   fprintf(ficgp,"#\n");    fprintf(ficgp,"#\n");
    for(ng=1; ng<=2;ng++){ /* Number of graphics: first is probabilities second is incidence per year*/     for(ng=1; ng<=3;ng++){ /* Number of graphics: first is logit, 2nd is probabilities, third is incidences per year*/
      fprintf(ficgp,"# ng=%d\n",ng);       fprintf(ficgp,"# ng=%d\n",ng);
      fprintf(ficgp,"#   jk=1 to 2^%d=%d\n",cptcoveff,m);       fprintf(ficgp,"#   jk=1 to 2^%d=%d\n",cptcoveff,m);
      for(jk=1; jk <=m; jk++) {       for(jk=1; jk <=m; jk++) {
        fprintf(ficgp,"#    jk=%d\n",jk);         fprintf(ficgp,"#    jk=%d\n",jk);
        fprintf(ficgp,"\nset out \"%s%d_%d.svg\" \n",subdirf2(optionfilefiname,"pe"),jk,ng);          fprintf(ficgp,"\nset out \"%s_%d-%d.svg\" ",subdirf2(optionfilefiname,"PE_"),jk,ng);
        if (ng==2)         fprintf(ficgp,"\nset ter svg size 640, 480 ");
          if (ng==1){
            fprintf(ficgp,"\nset ylabel \"Value of the logit of the model\"\n"); /* exp(a12+b12*x) could be nice */
            fprintf(ficgp,"\nunset log y");
          }else if (ng==2){
            fprintf(ficgp,"\nset ylabel \"Probability\"\n");
            fprintf(ficgp,"\nset log y");
          }else if (ng==3){
          fprintf(ficgp,"\nset ylabel \"Quasi-incidence per year\"\n");           fprintf(ficgp,"\nset ylabel \"Quasi-incidence per year\"\n");
        else           fprintf(ficgp,"\nset log y");
          fprintf(ficgp,"\nunset title \n");         }else
        fprintf(ficgp,"\nset ter svg size 640, 480\nset log y\nplot  [%.f:%.f] ",ageminpar,agemaxpar);           fprintf(ficgp,"\nunset title ");
          fprintf(ficgp,"\nplot  [%.f:%.f] ",ageminpar,agemaxpar);
        i=1;         i=1;
        for(k2=1; k2<=nlstate; k2++) {         for(k2=1; k2<=nlstate; k2++) {
          k3=i;           k3=i;
          for(k=1; k<=(nlstate+ndeath); k++) {           for(k=1; k<=(nlstate+ndeath); k++) {
            if (k != k2){             if (k != k2){
              if(ng==2)               switch( ng) {
                case 1:
                if(nagesqr==0)                 if(nagesqr==0)
                  fprintf(ficgp," %f*exp(p%d+p%d*x",YEARM/stepm,i,i+1);                   fprintf(ficgp," p%d+p%d*x",i,i+1);
                else /* nagesqr =1 */                 else /* nagesqr =1 */
                  fprintf(ficgp," %f*exp(p%d+p%d*x+p%d*x*x",YEARM/stepm,i,i+1,i+1+nagesqr);                   fprintf(ficgp," p%d+p%d*x+p%d*x*x",i,i+1,i+1+nagesqr);
              else                 break;
                case 2: /* ng=2 */
                if(nagesqr==0)                 if(nagesqr==0)
                  fprintf(ficgp," exp(p%d+p%d*x",i,i+1);                   fprintf(ficgp," exp(p%d+p%d*x",i,i+1);
                else /* nagesqr =1 */                 else /* nagesqr =1 */
                  fprintf(ficgp," exp(p%d+p%d*x+p%d*x*x",i,i+1,i+1+nagesqr);                     fprintf(ficgp," exp(p%d+p%d*x+p%d*x*x",i,i+1,i+1+nagesqr);
                  break;
                case 3:
                  if(nagesqr==0)
                    fprintf(ficgp," %f*exp(p%d+p%d*x",YEARM/stepm,i,i+1);
                  else /* nagesqr =1 */
                    fprintf(ficgp," %f*exp(p%d+p%d*x+p%d*x*x",YEARM/stepm,i,i+1,i+1+nagesqr);
                  break;
                }
              ij=1;/* To be checked else nbcode[0][0] wrong */               ij=1;/* To be checked else nbcode[0][0] wrong */
              for(j=3; j <=ncovmodel-nagesqr; j++) {               for(j=3; j <=ncovmodel-nagesqr; j++) {
                /* printf("Tage[%d]=%d, j=%d\n", ij, Tage[ij], j); */                 /* printf("Tage[%d]=%d, j=%d\n", ij, Tage[ij], j); */
Line 4858  plot [%.f:%.f]  ", ageminpar, agemaxpar) Line 5004  plot [%.f:%.f]  ", ageminpar, agemaxpar)
                else                 else
                  fprintf(ficgp,"+p%d*%d",i+j+nagesqr-1,nbcode[Tvar[j-2]][codtabm(jk,j-2)]);                   fprintf(ficgp,"+p%d*%d",i+j+nagesqr-1,nbcode[Tvar[j-2]][codtabm(jk,j-2)]);
              }               }
              fprintf(ficgp,")/(1");               if(ng != 1){
                  fprintf(ficgp,")/(1");
                             
              for(k1=1; k1 <=nlstate; k1++){                  for(k1=1; k1 <=nlstate; k1++){ 
                if(nagesqr==0)                   if(nagesqr==0)
                  fprintf(ficgp,"+exp(p%d+p%d*x",k3+(k1-1)*ncovmodel,k3+(k1-1)*ncovmodel+1);                     fprintf(ficgp,"+exp(p%d+p%d*x",k3+(k1-1)*ncovmodel,k3+(k1-1)*ncovmodel+1);
                else /* nagesqr =1 */                   else /* nagesqr =1 */
                  fprintf(ficgp,"+exp(p%d+p%d*x+p%d*x*x",k3+(k1-1)*ncovmodel,k3+(k1-1)*ncovmodel+1,k3+(k1-1)*ncovmodel+1+nagesqr);                     fprintf(ficgp,"+exp(p%d+p%d*x+p%d*x*x",k3+(k1-1)*ncovmodel,k3+(k1-1)*ncovmodel+1,k3+(k1-1)*ncovmodel+1+nagesqr);
                      
                ij=1;                   ij=1;
                for(j=3; j <=ncovmodel-nagesqr; j++){                   for(j=3; j <=ncovmodel-nagesqr; j++){
                  if(ij <=cptcovage) { /* Bug valgrind */                     if(ij <=cptcovage) { /* Bug valgrind */
                    if((j-2)==Tage[ij]) { /* Bug valgrind */                       if((j-2)==Tage[ij]) { /* Bug valgrind */
                      fprintf(ficgp,"+p%d*%d*x",k3+(k1-1)*ncovmodel+1+j-2+nagesqr,nbcode[Tvar[j-2]][codtabm(jk,j-2)]);                         fprintf(ficgp,"+p%d*%d*x",k3+(k1-1)*ncovmodel+1+j-2+nagesqr,nbcode[Tvar[j-2]][codtabm(jk,j-2)]);
                      /* fprintf(ficgp,"+p%d*%d*x",k3+(k1-1)*ncovmodel+1+j-2+nagesqr,nbcode[Tvar[j-2]][codtabm(jk,Tvar[j-2])]); */                         /* fprintf(ficgp,"+p%d*%d*x",k3+(k1-1)*ncovmodel+1+j-2+nagesqr,nbcode[Tvar[j-2]][codtabm(jk,Tvar[j-2])]); */
                      ij++;                         ij++;
                        }
                    }                     }
                      else
                        fprintf(ficgp,"+p%d*%d",k3+(k1-1)*ncovmodel+1+j-2+nagesqr,nbcode[Tvar[j-2]][codtabm(jk,j-2)]);
                  }                   }
                  else                   fprintf(ficgp,")");
                    fprintf(ficgp,"+p%d*%d",k3+(k1-1)*ncovmodel+1+j-2+nagesqr,nbcode[Tvar[j-2]][codtabm(jk,j-2)]);  
                }                 }
                fprintf(ficgp,")");                 fprintf(ficgp,")");
                  if(ng ==2)
                    fprintf(ficgp," t \"p%d%d\" ", k2,k);
                  else /* ng= 3 */
                    fprintf(ficgp," t \"i%d%d\" ", k2,k);
                }else{ /* end ng <> 1 */
                  fprintf(ficgp," t \"logit(p%d%d)\" ", k2,k);
              }               }
              fprintf(ficgp,") t \"p%d%d\" ", k2,k);  
              if ((k+k2)!= (nlstate*2+ndeath)) fprintf(ficgp,",");               if ((k+k2)!= (nlstate*2+ndeath)) fprintf(ficgp,",");
              i=i+ncovmodel;               i=i+ncovmodel;
            }             }
          } /* end k */           } /* end k */
        } /* end k2 */         } /* end k2 */
          fprintf(ficgp,"\n set out\n");
      } /* end jk */       } /* end jk */
    } /* end ng */     } /* end ng */
  /* avoid: */   /* avoid: */
Line 4953  void prevforecast(char fileres[], double Line 5108  void prevforecast(char fileres[], double
   agelim=AGESUP;    agelim=AGESUP;
   prevalence(probs, ageminpar, agemax, s, agev, nlstate, imx, Tvar, nbcode, ncodemax, mint, anint, dateprev1, dateprev2, firstpass, lastpass);    prevalence(probs, ageminpar, agemax, s, agev, nlstate, imx, Tvar, nbcode, ncodemax, mint, anint, dateprev1, dateprev2, firstpass, lastpass);
     
   strcpy(fileresf,"f");     strcpy(fileresf,"F_"); 
   strcat(fileresf,fileres);    strcat(fileresf,fileresu);
   if((ficresf=fopen(fileresf,"w"))==NULL) {    if((ficresf=fopen(fileresf,"w"))==NULL) {
     printf("Problem with forecast resultfile: %s\n", fileresf);      printf("Problem with forecast resultfile: %s\n", fileresf);
     fprintf(ficlog,"Problem with forecast resultfile: %s\n", fileresf);      fprintf(ficlog,"Problem with forecast resultfile: %s\n", fileresf);
Line 5077  void populforecast(char fileres[], doubl Line 5232  void populforecast(char fileres[], doubl
   prevalence(probs, ageminpar, agemax, s, agev, nlstate, imx, Tvar, nbcode, ncodemax, mint, anint, dateprev1, dateprev2, firstpass, lastpass);    prevalence(probs, ageminpar, agemax, s, agev, nlstate, imx, Tvar, nbcode, ncodemax, mint, anint, dateprev1, dateprev2, firstpass, lastpass);
       
       
   strcpy(filerespop,"pop");     strcpy(filerespop,"POP_"); 
   strcat(filerespop,fileres);    strcat(filerespop,fileresu);
   if((ficrespop=fopen(filerespop,"w"))==NULL) {    if((ficrespop=fopen(filerespop,"w"))==NULL) {
     printf("Problem with forecast resultfile: %s\n", filerespop);      printf("Problem with forecast resultfile: %s\n", filerespop);
     fprintf(ficlog,"Problem with forecast resultfile: %s\n", filerespop);      fprintf(ficlog,"Problem with forecast resultfile: %s\n", filerespop);
Line 5431  double gompertz_f(const gsl_vector *v, v Line 5586  double gompertz_f(const gsl_vector *v, v
 #endif  #endif
   
 /******************* Printing html file ***********/  /******************* Printing html file ***********/
 void printinghtmlmort(char fileres[], char title[], char datafile[], int firstpass, \  void printinghtmlmort(char fileresu[], char title[], char datafile[], int firstpass, \
                   int lastpass, int stepm, int weightopt, char model[],\                    int lastpass, int stepm, int weightopt, char model[],\
                   int imx,  double p[],double **matcov,double agemortsup){                    int imx,  double p[],double **matcov,double agemortsup){
   int i,k;    int i,k;
Line 5455  fprintf(fichtm,"<ul><li><h4>Life table</ Line 5610  fprintf(fichtm,"<ul><li><h4>Life table</
 }  }
   
 /******************* Gnuplot file **************/  /******************* Gnuplot file **************/
 void printinggnuplotmort(char fileres[], char optionfilefiname[], double ageminpar, double agemaxpar, double fage , char pathc[], double p[]){  void printinggnuplotmort(char fileresu[], char optionfilefiname[], double ageminpar, double agemaxpar, double fage , char pathc[], double p[]){
   
   char dirfileres[132],optfileres[132];    char dirfileres[132],optfileres[132];
   
Line 6162  void syscompilerinfo(int logged) Line 6317  void syscompilerinfo(int logged)
   
  }   }
   
 int prevalence_limit(double *p, double **prlim, double ageminpar, double agemaxpar){   int prevalence_limit(double *p, double **prlim, double ageminpar, double agemaxpar, double ftolpl){
   /*--------------- Prevalence limit  (period or stable prevalence) --------------*/    /*--------------- Prevalence limit  (period or stable prevalence) --------------*/
   int i, j, k, i1 ;    int i, j, k, i1 ;
   double ftolpl = 1.e-10;    /* double ftolpl = 1.e-10; */
   double age, agebase, agelim;    double age, agebase, agelim;
   
     strcpy(filerespl,"pl");    strcpy(filerespl,"PL_");
     strcat(filerespl,fileres);    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 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 period (stable) prevalence resultfile: %s\n", filerespl);return 1;
     }    }
     printf("Computing period (stable) prevalence: result on file '%s' \n", filerespl);    printf("Computing period (stable) prevalence: result on file '%s' \n", filerespl);
     fprintf(ficlog,"Computing period (stable) prevalence: result on file '%s' \n", filerespl);    fprintf(ficlog,"Computing period (stable) prevalence: result on file '%s' \n", filerespl);
     pstamp(ficrespl);    pstamp(ficrespl);
     fprintf(ficrespl,"# Period (stable) prevalence \n");    fprintf(ficrespl,"# Period (stable) prevalence \n");
     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");
       
     /* prlim=matrix(1,nlstate,1,nlstate);*/ /* back in main */      /* prlim=matrix(1,nlstate,1,nlstate);*/ /* back in main */
   
Line 6242  int hPijx(double *p, int bage, int fage) Line 6397  int hPijx(double *p, int bage, int fage)
   double agedeb;    double agedeb;
   double ***p3mat;    double ***p3mat;
   
     strcpy(filerespij,"pij");  strcat(filerespij,fileres);      strcpy(filerespij,"PIJ_");  strcat(filerespij,fileresu);
     if((ficrespij=fopen(filerespij,"w"))==NULL) {      if((ficrespij=fopen(filerespij,"w"))==NULL) {
       printf("Problem with Pij resultfile: %s\n", filerespij); return 1;        printf("Problem with Pij resultfile: %s\n", filerespij); return 1;
       fprintf(ficlog,"Problem with Pij resultfile: %s\n", filerespij); return 1;        fprintf(ficlog,"Problem with Pij resultfile: %s\n", filerespij); return 1;
Line 6503  int main(int argc, char *argv[]) Line 6658  int main(int argc, char *argv[])
   /* */    /* */
   strcpy(fileres,"r");    strcpy(fileres,"r");
   strcat(fileres, optionfilefiname);    strcat(fileres, optionfilefiname);
     strcat(fileresu, optionfilefiname); /* Without r in front */
   strcat(fileres,".txt");    /* Other files have txt extension */    strcat(fileres,".txt");    /* Other files have txt extension */
     strcat(fileresu,".txt");    /* Other files have txt extension */
   
   /* Main ---------arguments file --------*/    /* Main ---------arguments file --------*/
   
Line 6518  int main(int argc, char *argv[]) Line 6675  int main(int argc, char *argv[])
   
   
   strcpy(filereso,"o");    strcpy(filereso,"o");
   strcat(filereso,fileres);    strcat(filereso,fileresu);
   if((ficparo=fopen(filereso,"w"))==NULL) { /* opened on subdirectory */    if((ficparo=fopen(filereso,"w"))==NULL) { /* opened on subdirectory */
     printf("Problem with Output resultfile: %s\n", filereso);      printf("Problem with Output resultfile: %s\n", filereso);
     fprintf(ficlog,"Problem with Output resultfile: %s\n", filereso);      fprintf(ficlog,"Problem with Output resultfile: %s\n", filereso);
Line 6568  int main(int argc, char *argv[]) Line 6725  int main(int argc, char *argv[])
     }      }
     printf("ftol=%e stepm=%d ncovcol=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d\n",ftol, stepm, ncovcol, nlstate,ndeath, maxwav, mle, weightopt);      printf("ftol=%e stepm=%d ncovcol=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d\n",ftol, stepm, ncovcol, nlstate,ndeath, maxwav, mle, weightopt);
   }    }
     ftolpl=6*ftol*1.e5; /* 6.e-3 make convergences in less than 80 loops for the prevalence limit */
   /* Third parameter line */    /* Third parameter line */
   while(fgets(line, MAXLINE, ficpar)) {    while(fgets(line, MAXLINE, ficpar)) {
     /* If line starts with a # it is a comment */      /* If line starts with a # it is a comment */
Line 6581  int main(int argc, char *argv[]) Line 6738  int main(int argc, char *argv[])
     }else      }else
       break;        break;
   }    }
   if((num_filled=sscanf(line,"model=1+age%[^.\n]\n", model)) !=EOF){    if((num_filled=sscanf(line,"model=1+age%[^.\n]", model)) !=EOF){
     if (num_filled != 1) {      if (num_filled == 0)
               model[0]='\0';
       else if (num_filled != 1){
       printf("ERROR %d: Model should be at minimum 'model=1+age.' %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.' %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';
Line 6592  int main(int argc, char *argv[]) Line 6751  int main(int argc, char *argv[])
       if (model[0]=='+'){        if (model[0]=='+'){
         for(i=1; i<=strlen(model);i++)          for(i=1; i<=strlen(model);i++)
           modeltemp[i-1]=model[i];            modeltemp[i-1]=model[i];
           strcpy(model,modeltemp); 
       }        }
       strcpy(model,modeltemp);   
     }      }
     /* 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); */
   }    }
Line 6827  Please run with mle=-1 to get a correct Line 6986  Please run with mle=-1 to get a correct
     strcat(rfileres,".");    /* */      strcat(rfileres,".");    /* */
     strcat(rfileres,optionfilext);    /* Other files have txt extension */      strcat(rfileres,optionfilext);    /* Other files have txt extension */
     if((ficres =fopen(rfileres,"w"))==NULL) {      if((ficres =fopen(rfileres,"w"))==NULL) {
       printf("Problem writing new parameter file: %s\n", fileres);goto end;        printf("Problem writing new parameter file: %s\n", rfileres);goto end;
       fprintf(ficlog,"Problem writing new parameter file: %s\n", fileres);goto end;        fprintf(ficlog,"Problem writing new parameter file: %s\n", rfileres);goto end;
     }      }
     fprintf(ficres,"#%s\n",version);      fprintf(ficres,"#%s\n",version);
   }    /* End of mle != -3 */    }    /* End of mle != -3 */
Line 6971  Please run with mle=-1 to get a correct Line 7130  Please run with mle=-1 to get a correct
            *    15 i=8 1     2     2     2             *    15 i=8 1     2     2     2
            *    16     2     2     2     2             *    16     2     2     2     2
            */             */
   for(h=1; h <=100 ;h++){     /* /\* for(h=1; h <=100 ;h++){  *\/ */
     /* printf("h=%2d ", h); */    /*   /\* printf("h=%2d ", h); *\/ */
      /* for(k=1; k <=10; k++){ */    /*    /\* for(k=1; k <=10; k++){ *\/ */
        /* printf("k=%d %d ",k,codtabm(h,k)); */    /*      /\* printf("k=%d %d ",k,codtabm(h,k)); *\/ */
      /*   codtab[h][k]=codtabm(h,k); */    /*    /\*   codtab[h][k]=codtabm(h,k); *\/ */
      /* } */    /*    /\* } *\/ */
      /* printf("\n"); */    /*    /\* printf("\n"); *\/ */
   }    /* } */
   /* for(k=1;k<=cptcoveff; k++){ /\* scans any effective covariate *\/ */    /* for(k=1;k<=cptcoveff; k++){ /\* scans any effective covariate *\/ */
   /*   for(i=1; i <=pow(2,cptcoveff-k);i++){ /\* i=1 to 8/1=8; i=1 to 8/2=4; i=1 to 8/8=1 *\/  */    /*   for(i=1; i <=pow(2,cptcoveff-k);i++){ /\* i=1 to 8/1=8; i=1 to 8/2=4; i=1 to 8/8=1 *\/  */
   /*     for(j=1; j <= ncodemax[k]; j++){ /\* For each modality of this covariate ncodemax=2*\/ */    /*     for(j=1; j <= ncodemax[k]; j++){ /\* For each modality of this covariate ncodemax=2*\/ */
Line 7011  Please run with mle=-1 to get a correct Line 7170  Please run with mle=-1 to get a correct
   /* Initialisation of ----------- gnuplot -------------*/    /* Initialisation of ----------- gnuplot -------------*/
   strcpy(optionfilegnuplot,optionfilefiname);    strcpy(optionfilegnuplot,optionfilefiname);
   if(mle==-3)    if(mle==-3)
     strcat(optionfilegnuplot,"-mort");      strcat(optionfilegnuplot,"-MORT_");
   strcat(optionfilegnuplot,".gp");    strcat(optionfilegnuplot,".gp");
   
   if((ficgp=fopen(optionfilegnuplot,"w"))==NULL) {    if((ficgp=fopen(optionfilegnuplot,"w"))==NULL) {
Line 7030  Please run with mle=-1 to get a correct Line 7189  Please run with mle=-1 to get a correct
   
   strcpy(optionfilehtm,optionfilefiname); /* Main html file */    strcpy(optionfilehtm,optionfilefiname); /* Main html file */
   if(mle==-3)    if(mle==-3)
     strcat(optionfilehtm,"-mort");      strcat(optionfilehtm,"-MORT_");
   strcat(optionfilehtm,".htm");    strcat(optionfilehtm,".htm");
   if((fichtm=fopen(optionfilehtm,"w"))==NULL)    {    if((fichtm=fopen(optionfilehtm,"w"))==NULL)    {
     printf("Problem with %s \n",optionfilehtm);      printf("Problem with %s \n",optionfilehtm);
Line 7146  Interval (in months) between two waves: Line 7305  Interval (in months) between two waves:
 #else  #else
     printf("Powell\n");  fprintf(ficlog,"Powell\n");      printf("Powell\n");  fprintf(ficlog,"Powell\n");
 #endif  #endif
     strcpy(filerespow,"pow-mort");       strcpy(filerespow,"POW-MORT_"); 
     strcat(filerespow,fileres);      strcat(filerespow,fileresu);
     if((ficrespow=fopen(filerespow,"w"))==NULL) {      if((ficrespow=fopen(filerespow,"w"))==NULL) {
       printf("Problem with resultfile: %s\n", filerespow);        printf("Problem with resultfile: %s\n", filerespow);
       fprintf(ficlog,"Problem with resultfile: %s\n", filerespow);        fprintf(ficlog,"Problem with resultfile: %s\n", filerespow);
Line 7301  Please run with mle=-1 to get a correct Line 7460  Please run with mle=-1 to get a correct
 This is probably because your parameter file doesn't \n  contain the exact number of lines (or columns) corresponding to your model line.\n\  This is probably because your parameter file doesn't \n  contain the exact number of lines (or columns) corresponding to your model line.\n\
 Please run with mle=-1 to get a correct covariance matrix.\n",ageminpar,agemaxpar);  Please run with mle=-1 to get a correct covariance matrix.\n",ageminpar,agemaxpar);
     }else      }else
       printinggnuplotmort(fileres, optionfilefiname,ageminpar,agemaxpar,fage, pathc,p);        printinggnuplotmort(fileresu, optionfilefiname,ageminpar,agemaxpar,fage, pathc,p);
     printinghtmlmort(fileres,title,datafile, firstpass, lastpass, \      printinghtmlmort(fileresu,title,datafile, firstpass, lastpass, \
                      stepm, weightopt,\                       stepm, weightopt,\
                      model,imx,p,matcov,agemortsup);                       model,imx,p,matcov,agemortsup);
           
Line 7572  Please run with mle=-1 to get a correct Line 7731  Please run with mle=-1 to get a correct
 This is probably because your parameter file doesn't \n  contain the exact number of lines (or columns) corresponding to your model line.\n\  This is probably because your parameter file doesn't \n  contain the exact number of lines (or columns) corresponding to your model line.\n\
 Please run with mle=-1 to get a correct covariance matrix.\n",ageminpar,agemaxpar);  Please run with mle=-1 to get a correct covariance matrix.\n",ageminpar,agemaxpar);
     }else      }else
       printinggnuplot(fileres, optionfilefiname,ageminpar,agemaxpar,fage, pathc,p);        printinggnuplot(fileresu, optionfilefiname,ageminpar,agemaxpar,fage, pathc,p);
           
     printinghtml(fileres,title,datafile, firstpass, lastpass, stepm, weightopt,\      printinghtml(fileresu,title,datafile, firstpass, lastpass, stepm, weightopt,\
                  model,imx,jmin,jmax,jmean,rfileres,popforecast,estepm,\                   model,imx,jmin,jmax,jmean,rfileres,popforecast,estepm,\
                  jprev1,mprev1,anprev1,jprev2,mprev2,anprev2);                   jprev1,mprev1,anprev1,jprev2,mprev2,anprev2);
               
Line 7599  Please run with mle=-1 to get a correct Line 7758  Please run with mle=-1 to get a correct
     /*--------------- Prevalence limit  (period or stable prevalence) --------------*/      /*--------------- Prevalence limit  (period or stable prevalence) --------------*/
     /*#include "prevlim.h"*/  /* Use ficrespl, ficlog */      /*#include "prevlim.h"*/  /* Use ficrespl, ficlog */
     prlim=matrix(1,nlstate,1,nlstate);      prlim=matrix(1,nlstate,1,nlstate);
     prevalence_limit(p, prlim,  ageminpar, agemaxpar);      prevalence_limit(p, prlim,  ageminpar, agemaxpar, ftolpl);
     fclose(ficrespl);      fclose(ficrespl);
   
 #ifdef FREEEXIT2  #ifdef FREEEXIT2
Line 7626  Please run with mle=-1 to get a correct Line 7785  Please run with mle=-1 to get a correct
     /*if((stepm == 1) && (strcmp(model,".")==0)){*/      /*if((stepm == 1) && (strcmp(model,".")==0)){*/
     if(prevfcast==1){      if(prevfcast==1){
       /*    if(stepm ==1){*/        /*    if(stepm ==1){*/
       prevforecast(fileres, anproj1, mproj1, jproj1, agemin, agemax, dateprev1, dateprev2, mobilavproj, bage, fage, firstpass, lastpass, anproj2, p, cptcoveff);        prevforecast(fileresu, anproj1, mproj1, jproj1, agemin, agemax, dateprev1, dateprev2, mobilavproj, bage, fage, firstpass, lastpass, anproj2, p, cptcoveff);
       /* (popforecast==1) populforecast(fileres, anpyram,mpyram,jpyram, agemin,agemax, dateprev1, dateprev2,mobilav, agedeb, fage, popforecast, popfile, anpyram1,p, i1);*/        /* (popforecast==1) populforecast(fileres, anpyram,mpyram,jpyram, agemin,agemax, dateprev1, dateprev2,mobilav, agedeb, fage, popforecast, popfile, anpyram1,p, i1);*/
       /*      }  */        /*      }  */
       /*      else{ */        /*      else{ */
Line 7656  Please run with mle=-1 to get a correct Line 7815  Please run with mle=-1 to get a correct
   
     /*---------- Health expectancies, no variances ------------*/      /*---------- Health expectancies, no variances ------------*/
   
     strcpy(filerese,"e");      strcpy(filerese,"E_");
     strcat(filerese,fileres);      strcat(filerese,fileresu);
     if((ficreseij=fopen(filerese,"w"))==NULL) {      if((ficreseij=fopen(filerese,"w"))==NULL) {
       printf("Problem with Health Exp. resultfile: %s\n", filerese); exit(0);        printf("Problem with Health Exp. resultfile: %s\n", filerese); exit(0);
       fprintf(ficlog,"Problem with Health Exp. resultfile: %s\n", filerese); exit(0);        fprintf(ficlog,"Problem with Health Exp. resultfile: %s\n", filerese); exit(0);
Line 7687  Please run with mle=-1 to get a correct Line 7846  Please run with mle=-1 to get a correct
     /*---------- Health expectancies and variances ------------*/      /*---------- Health expectancies and variances ------------*/
   
   
     strcpy(filerest,"t");      strcpy(filerest,"T_");
     strcat(filerest,fileres);      strcat(filerest,fileresu);
     if((ficrest=fopen(filerest,"w"))==NULL) {      if((ficrest=fopen(filerest,"w"))==NULL) {
       printf("Problem with total LE resultfile: %s\n", filerest);goto end;        printf("Problem with total LE resultfile: %s\n", filerest);goto end;
       fprintf(ficlog,"Problem with total LE resultfile: %s\n", filerest);goto end;        fprintf(ficlog,"Problem with total LE resultfile: %s\n", filerest);goto end;
Line 7697  Please run with mle=-1 to get a correct Line 7856  Please run with mle=-1 to get a correct
     fprintf(ficlog,"Computing Total Life expectancies with their standard errors: file '%s' \n", filerest);       fprintf(ficlog,"Computing Total Life expectancies with their standard errors: file '%s' \n", filerest); 
   
   
     strcpy(fileresstde,"stde");      strcpy(fileresstde,"STDE_");
     strcat(fileresstde,fileres);      strcat(fileresstde,fileresu);
     if((ficresstdeij=fopen(fileresstde,"w"))==NULL) {      if((ficresstdeij=fopen(fileresstde,"w"))==NULL) {
       printf("Problem with Health Exp. and std errors resultfile: %s\n", fileresstde); exit(0);        printf("Problem with Health Exp. and std errors resultfile: %s\n", fileresstde); exit(0);
       fprintf(ficlog,"Problem with Health Exp. and std errors resultfile: %s\n", fileresstde); exit(0);        fprintf(ficlog,"Problem with Health Exp. and std errors resultfile: %s\n", fileresstde); exit(0);
Line 7706  Please run with mle=-1 to get a correct Line 7865  Please run with mle=-1 to get a correct
     printf("Computing Health Expectancies and standard errors: result on file '%s' \n", fileresstde);      printf("Computing Health Expectancies and standard errors: result on file '%s' \n", fileresstde);
     fprintf(ficlog,"Computing Health Expectancies and standard errors: result on file '%s' \n", fileresstde);      fprintf(ficlog,"Computing Health Expectancies and standard errors: result on file '%s' \n", fileresstde);
   
     strcpy(filerescve,"cve");      strcpy(filerescve,"CVE_");
     strcat(filerescve,fileres);      strcat(filerescve,fileresu);
     if((ficrescveij=fopen(filerescve,"w"))==NULL) {      if((ficrescveij=fopen(filerescve,"w"))==NULL) {
       printf("Problem with Covar. Health Exp. resultfile: %s\n", filerescve); exit(0);        printf("Problem with Covar. Health Exp. resultfile: %s\n", filerescve); exit(0);
       fprintf(ficlog,"Problem with Covar. Health Exp. resultfile: %s\n", filerescve); exit(0);        fprintf(ficlog,"Problem with Covar. Health Exp. resultfile: %s\n", filerescve); exit(0);
Line 7715  Please run with mle=-1 to get a correct Line 7874  Please run with mle=-1 to get a correct
     printf("Computing Covar. of Health Expectancies: result on file '%s' \n", filerescve);      printf("Computing Covar. of Health Expectancies: result on file '%s' \n", filerescve);
     fprintf(ficlog,"Computing Covar. of Health Expectancies: result on file '%s' \n", filerescve);      fprintf(ficlog,"Computing Covar. of Health Expectancies: result on file '%s' \n", filerescve);
   
     strcpy(fileresv,"v");      strcpy(fileresv,"V_");
     strcat(fileresv,fileres);      strcat(fileresv,fileresu);
     if((ficresvij=fopen(fileresv,"w"))==NULL) {      if((ficresvij=fopen(fileresv,"w"))==NULL) {
       printf("Problem with variance resultfile: %s\n", fileresv);exit(0);        printf("Problem with variance resultfile: %s\n", fileresv);exit(0);
       fprintf(ficlog,"Problem with variance resultfile: %s\n", fileresv);exit(0);        fprintf(ficlog,"Problem with variance resultfile: %s\n", fileresv);exit(0);
Line 7767  Please run with mle=-1 to get a correct Line 7926  Please run with mle=-1 to get a correct
             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 period (stable) prevalences in each health state \n");
           fprintf(ficrest,"# Age 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"); */
Line 7784  Please run with mle=-1 to get a correct Line 7943  Please run with mle=-1 to get a correct
               }                }
             }              }
                   
             fprintf(ficrest," %4.0f",age);              fprintf(ficrest," %4.0f %d %d",age, vpopbased, mobilav);
             /* printf(" age %4.0f ",age); */              /* printf(" age %4.0f ",age); */
             for(j=1, epj[nlstate+1]=0.;j <=nlstate;j++){              for(j=1, epj[nlstate+1]=0.;j <=nlstate;j++){
               for(i=1, epj[j]=0.;i <=nlstate;i++) {                for(i=1, epj[j]=0.;i <=nlstate;i++) {
Line 7826  Please run with mle=-1 to get a correct Line 7985  Please run with mle=-1 to get a correct
       
     /*------- Variance of period (stable) prevalence------*/         /*------- Variance of period (stable) prevalence------*/   
   
     strcpy(fileresvpl,"vpl");      strcpy(fileresvpl,"VPL_");
     strcat(fileresvpl,fileres);      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 period (stable) prevalence  resultfile: %s\n", fileresvpl);
       exit(0);        exit(0);

Removed from v.1.200  
changed lines
  Added in v.1.202


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