Diff for /imach/src/imach.c between versions 1.12 and 1.14

version 1.12, 2002/02/20 16:57:00 version 1.14, 2002/02/20 17:05:44
Line 73  int npar=NPARMAX; Line 73  int npar=NPARMAX;
 int nlstate=2; /* Number of live states */  int nlstate=2; /* Number of live states */
 int ndeath=1; /* Number of dead states */  int ndeath=1; /* Number of dead states */
 int ncovmodel, ncov;     /* Total number of covariables including constant a12*1 +b12*x ncovmodel=2 */  int ncovmodel, ncov;     /* Total number of covariables including constant a12*1 +b12*x ncovmodel=2 */
   int popbased=0, fprev,lprev;
   
 int *wav; /* Number of waves for this individuual 0 is possible */  int *wav; /* Number of waves for this individuual 0 is possible */
 int maxwav; /* Maxim number of waves */  int maxwav; /* Maxim number of waves */
Line 83  int **dh; /* dh[mi][i] is number of step Line 84  int **dh; /* dh[mi][i] is number of step
 double jmean; /* Mean space between 2 waves */  double jmean; /* Mean space between 2 waves */
 double **oldm, **newm, **savm; /* Working pointers to matrices */  double **oldm, **newm, **savm; /* Working pointers to matrices */
 double **oldms, **newms, **savms; /* Fixed working pointers to matrices */  double **oldms, **newms, **savms; /* Fixed working pointers to matrices */
 FILE *fic,*ficpar, *ficparo,*ficres,  *ficrespl, *ficrespij, *ficrest;  FILE *fic,*ficpar, *ficparo,*ficres,  *ficrespl, *ficrespij, *ficrest,*ficresf;
 FILE *ficgp, *fichtm;  FILE *ficgp, *fichtm,*ficresprob;
 FILE *ficreseij;  FILE *ficreseij;
   char filerese[FILENAMELENGTH];    char filerese[FILENAMELENGTH];
  FILE  *ficresvij;   FILE  *ficresvij;
Line 127  int stepm; Line 128  int stepm;
 int m,nb;  int m,nb;
 int *num, firstpass=0, lastpass=4,*cod, *ncodemax, *Tage;  int *num, firstpass=0, lastpass=4,*cod, *ncodemax, *Tage;
 double **agev,*moisnais, *annais, *moisdc, *andc,**mint, **anint;  double **agev,*moisnais, *annais, *moisdc, *andc,**mint, **anint;
 double **pmmij;  double **pmmij, ***probs, ***mobaverage;
   
 double *weight;  double *weight;
 int **s; /* Status */  int **s; /* Status */
Line 760  double **pmij(double **ps, double *cov, Line 761  double **pmij(double **ps, double *cov,
   
 double **matprod2(double **out, double **in,long nrl, long nrh, long ncl, long nch, long ncolol, long ncoloh, double **b)  double **matprod2(double **out, double **in,long nrl, long nrh, long ncl, long nch, long ncolol, long ncoloh, double **b)
 {  {
   /* Computes the matric product of in(1,nrh-nrl+1)(1,nch-ncl+1) times    /* Computes the matrix product of in(1,nrh-nrl+1)(1,nch-ncl+1) times
      b(1,nch-ncl+1)(1,ncoloh-ncolol+1) into out(...) */       b(1,nch-ncl+1)(1,ncoloh-ncolol+1) into out(...) */
   /* in, b, out are matrice of pointers which should have been initialized    /* in, b, out are matrice of pointers which should have been initialized
      before: only the contents of out is modified. The function returns       before: only the contents of out is modified. The function returns
Line 1160  void  freqsummary(char fileres[], int ag Line 1161  void  freqsummary(char fileres[], int ag
   char fileresp[FILENAMELENGTH];    char fileresp[FILENAMELENGTH];
   
   pp=vector(1,nlstate);    pp=vector(1,nlstate);
    probs= ma3x(1,130 ,1,8, 1,8);
   strcpy(fileresp,"p");    strcpy(fileresp,"p");
   strcat(fileresp,fileres);    strcat(fileresp,fileres);
   if((ficresp=fopen(fileresp,"w"))==NULL) {    if((ficresp=fopen(fileresp,"w"))==NULL) {
Line 1191  void  freqsummary(char fileres[], int ag Line 1192  void  freqsummary(char fileres[], int ag
                bool=0;                 bool=0;
          }           }
           if (bool==1) {            if (bool==1) {
            for(m=firstpass; m<=lastpass-1; m++){             for(m=fprev; m<=lprev; m++){
              if(agev[m][i]==0) agev[m][i]=agemax+1;               if(agev[m][i]==0) agev[m][i]=agemax+1;
              if(agev[m][i]==1) agev[m][i]=agemax+2;               if(agev[m][i]==1) agev[m][i]=agemax+2;
              freq[s[m][i]][s[m+1][i]][(int)agev[m][i]] += weight[i];               freq[s[m][i]][s[m+1][i]][(int)agev[m][i]] += weight[i];
Line 1215  void  freqsummary(char fileres[], int ag Line 1216  void  freqsummary(char fileres[], int ag
       printf("Age %d", i);        printf("Age %d", i);
     for(jk=1; jk <=nlstate ; jk++){      for(jk=1; jk <=nlstate ; jk++){
       for(m=-1, pp[jk]=0; m <=nlstate+ndeath ; m++)        for(m=-1, pp[jk]=0; m <=nlstate+ndeath ; m++)
         pp[jk] += freq[jk][m][i];          pp[jk] += freq[jk][m][i];
     }      }
     for(jk=1; jk <=nlstate ; jk++){      for(jk=1; jk <=nlstate ; jk++){
       for(m=-1, pos=0; m <=0 ; m++)        for(m=-1, pos=0; m <=0 ; m++)
Line 1225  void  freqsummary(char fileres[], int ag Line 1226  void  freqsummary(char fileres[], int ag
       else        else
         printf(" %d.=%.0f loss[%d]=NaNQ%%",jk,pp[jk],jk);          printf(" %d.=%.0f loss[%d]=NaNQ%%",jk,pp[jk],jk);
     }      }
     for(jk=1; jk <=nlstate ; jk++){  
       for(m=1, pp[jk]=0; m <=nlstate+ndeath; m++)       for(jk=1; jk <=nlstate ; jk++){
         for(m=0, pp[jk]=0; m <=nlstate+ndeath; m++)
         pp[jk] += freq[jk][m][i];          pp[jk] += freq[jk][m][i];
     }       }
   
     for(jk=1,pos=0; jk <=nlstate ; jk++)      for(jk=1,pos=0; jk <=nlstate ; jk++)
       pos += pp[jk];        pos += pp[jk];
     for(jk=1; jk <=nlstate ; jk++){      for(jk=1; jk <=nlstate ; jk++){
Line 1237  void  freqsummary(char fileres[], int ag Line 1240  void  freqsummary(char fileres[], int ag
       else        else
         printf(" %d.=%.0f prev[%d]=NaNQ%%",jk,pp[jk],jk);          printf(" %d.=%.0f prev[%d]=NaNQ%%",jk,pp[jk],jk);
       if( i <= (int) agemax){        if( i <= (int) agemax){
         if(pos>=1.e-5)          if(pos>=1.e-5){
           fprintf(ficresp," %d %.5f %.0f %.0f",i,pp[jk]/pos, pp[jk],pos);            fprintf(ficresp," %d %.5f %.0f %.0f",i,pp[jk]/pos, pp[jk],pos);
             probs[i][jk][j1]= pp[jk]/pos;
             /*printf("\ni=%d jk=%d j1=%d %.5f %.0f %.0f %f",i,jk,j1,pp[jk]/pos, pp[jk],pos,probs[i][jk][j1]);*/
           }
       else        else
           fprintf(ficresp," %d NaNq %.0f %.0f",i,pp[jk],pos);            fprintf(ficresp," %d NaNq %.0f %.0f",i,pp[jk],pos);
       }        }
Line 1489  void varevsij(char fileres[], double *** Line 1495  void varevsij(char fileres[], double ***
       }        }
       hpxij(p3mat,nhstepm,age,hstepm,xp,nlstate,stepm,oldm,savm, ij);          hpxij(p3mat,nhstepm,age,hstepm,xp,nlstate,stepm,oldm,savm, ij);  
       prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ij);        prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ij);
   
         if (popbased==1) {
           for(i=1; i<=nlstate;i++)
             prlim[i][i]=probs[(int)age][i][ij];
         }
        
       for(j=1; j<= nlstate; j++){        for(j=1; j<= nlstate; j++){
         for(h=0; h<=nhstepm; h++){          for(h=0; h<=nhstepm; h++){
           for(i=1, gp[h][j]=0.;i<=nlstate;i++)            for(i=1, gp[h][j]=0.;i<=nlstate;i++)
Line 1500  void varevsij(char fileres[], double *** Line 1512  void varevsij(char fileres[], double ***
         xp[i] = x[i] - (i==theta ?delti[theta]:0);          xp[i] = x[i] - (i==theta ?delti[theta]:0);
       hpxij(p3mat,nhstepm,age,hstepm,xp,nlstate,stepm,oldm,savm, ij);          hpxij(p3mat,nhstepm,age,hstepm,xp,nlstate,stepm,oldm,savm, ij);  
       prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ij);        prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ij);
   
         if (popbased==1) {
           for(i=1; i<=nlstate;i++)
             prlim[i][i]=probs[(int)age][i][ij];
         }
   
       for(j=1; j<= nlstate; j++){        for(j=1; j<= nlstate; j++){
         for(h=0; h<=nhstepm; h++){          for(h=0; h<=nhstepm; h++){
           for(i=1, gm[h][j]=0.;i<=nlstate;i++)            for(i=1, gm[h][j]=0.;i<=nlstate;i++)
             gm[h][j] += prlim[i][i]*p3mat[i][j][h];              gm[h][j] += prlim[i][i]*p3mat[i][j][h];
         }          }
       }        }
   
       for(j=1; j<= nlstate; j++)        for(j=1; j<= nlstate; j++)
         for(h=0; h<=nhstepm; h++){          for(h=0; h<=nhstepm; h++){
           gradg[h][theta][j]= (gp[h][j]-gm[h][j])/2./delti[theta];            gradg[h][theta][j]= (gp[h][j]-gm[h][j])/2./delti[theta];
Line 1635  void varprevlim(char fileres[], double * Line 1654  void varprevlim(char fileres[], double *
   
 }  }
   
   /************ Variance of one-step probabilities  ******************/
   void varprob(char fileres[], double **matcov, double x[], double delti[], int nlstate, double bage, double fage, int ij)
   {
     int i, j;
     int k=0, cptcode;
     double **dnewm,**doldm;
     double *xp;
     double *gp, *gm;
     double **gradg, **trgradg;
     double age,agelim, cov[NCOVMAX];
     int theta;
     char fileresprob[FILENAMELENGTH];
   
     strcpy(fileresprob,"prob");
     strcat(fileresprob,fileres);
     if((ficresprob=fopen(fileresprob,"w"))==NULL) {
       printf("Problem with resultfile: %s\n", fileresprob);
     }
     printf("Computing variance of one-step probabilities: result on file '%s' \n",fileresprob);
    
   
     xp=vector(1,npar);
     dnewm=matrix(1,(nlstate+ndeath)*(nlstate+ndeath),1,npar);
     doldm=matrix(1,(nlstate+ndeath)*(nlstate+ndeath),1,(nlstate+ndeath)*(nlstate+ndeath));
    
     cov[1]=1;
     for (age=bage; age<=fage; age ++){
       cov[2]=age;
       gradg=matrix(1,npar,1,9);
       trgradg=matrix(1,9,1,npar);
       gp=vector(1,(nlstate+ndeath)*(nlstate+ndeath));
       gm=vector(1,(nlstate+ndeath)*(nlstate+ndeath));
      
       for(theta=1; theta <=npar; theta++){
         for(i=1; i<=npar; i++)
           xp[i] = x[i] + (i==theta ?delti[theta]:0);
        
         pmij(pmmij,cov,ncovmodel,xp,nlstate);
      
         k=0;
         for(i=1; i<= (nlstate+ndeath); i++){
           for(j=1; j<=(nlstate+ndeath);j++){
              k=k+1;
             gp[k]=pmmij[i][j];
           }
         }
   
         for(i=1; i<=npar; i++)
           xp[i] = x[i] - (i==theta ?delti[theta]:0);
      
   
         pmij(pmmij,cov,ncovmodel,xp,nlstate);
         k=0;
         for(i=1; i<=(nlstate+ndeath); i++){
           for(j=1; j<=(nlstate+ndeath);j++){
             k=k+1;
             gm[k]=pmmij[i][j];
           }
         }
        
          for(i=1; i<= (nlstate+ndeath)*(nlstate+ndeath); i++)
              gradg[theta][i]=(gp[i]-gm[i])/2./delti[theta];  
       }
   
        for(j=1; j<=(nlstate+ndeath)*(nlstate+ndeath);j++)
         for(theta=1; theta <=npar; theta++)
         trgradg[j][theta]=gradg[theta][j];
    
        matprod2(dnewm,trgradg,1,9,1,npar,1,npar,matcov);
        matprod2(doldm,dnewm,1,9,1,npar,1,9,gradg);
   
        pmij(pmmij,cov,ncovmodel,x,nlstate);
   
        k=0;
        for(i=1; i<=(nlstate+ndeath); i++){
          for(j=1; j<=(nlstate+ndeath);j++){
            k=k+1;
            gm[k]=pmmij[i][j];
           }
        }
        
        /*printf("\n%d ",(int)age);
        for (i=1; i<=(nlstate+ndeath)*(nlstate+ndeath-1);i++){
          
   
          printf("%e [%e ;%e] ",gm[i],gm[i]-2*sqrt(doldm[i][i]),gm[i]+2*sqrt(doldm[i][i]));
        }*/
   
     fprintf(ficresprob,"\n%d ",(int)age);
   
     for (i=1; i<=(nlstate+ndeath)*(nlstate+ndeath-1);i++){
       if (i== 2) fprintf(ficresprob,"%.3e %.3e ",gm[i],doldm[i][i]);
   if (i== 4) fprintf(ficresprob,"%.3e %.3e ",gm[i],doldm[i][i]);
     }
   
       free_vector(gp,1,(nlstate+ndeath)*(nlstate+ndeath));
       free_vector(gm,1,(nlstate+ndeath)*(nlstate+ndeath));
       free_matrix(trgradg,1,(nlstate+ndeath)*(nlstate+ndeath),1,npar);
       free_matrix(gradg,1,(nlstate+ndeath)*(nlstate+ndeath),1,npar);
   }
    free_vector(xp,1,npar);
   fclose(ficresprob);
    exit(0);
   }
   
 /***********************************************/  /***********************************************/
 /**************** Main Program *****************/  /**************** Main Program *****************/
Line 1658  int main() Line 1780  int main()
   char line[MAXLINE], linepar[MAXLINE];    char line[MAXLINE], linepar[MAXLINE];
   char title[MAXLINE];    char title[MAXLINE];
   char optionfile[FILENAMELENGTH], datafile[FILENAMELENGTH],  filerespl[FILENAMELENGTH], optionfilehtm[FILENAMELENGTH];    char optionfile[FILENAMELENGTH], datafile[FILENAMELENGTH],  filerespl[FILENAMELENGTH], optionfilehtm[FILENAMELENGTH];
   char fileres[FILENAMELENGTH], filerespij[FILENAMELENGTH], filereso[FILENAMELENGTH];    char fileres[FILENAMELENGTH], filerespij[FILENAMELENGTH], filereso[FILENAMELENGTH], fileresf[FILENAMELENGTH];
   char filerest[FILENAMELENGTH];    char filerest[FILENAMELENGTH];
   char fileregp[FILENAMELENGTH];    char fileregp[FILENAMELENGTH];
   char path[80],pathc[80],pathcd[80],pathtot[80],model[20];    char path[80],pathc[80],pathcd[80],pathtot[80],model[20];
Line 1667  int main() Line 1789  int main()
   int c,  h , cpt,l;    int c,  h , cpt,l;
   int ju,jl, mi;    int ju,jl, mi;
   int i1,j1, k1,k2,k3,jk,aa,bb, stepsize, ij;    int i1,j1, k1,k2,k3,jk,aa,bb, stepsize, ij;
   int jnais,jdc,jint4,jint1,jint2,jint3,**outcome,**adl,*tab;    int jnais,jdc,jint4,jint1,jint2,jint3,**outcome,**adl,*tab;
      int mobilav=0, fprevfore=1, lprevfore=1;
   int hstepm, nhstepm;    int hstepm, nhstepm;
   
   double bage, fage, age, agelim, agebase;    double bage, fage, age, agelim, agebase;
   double ftolpl=FTOL;    double ftolpl=FTOL;
   double **prlim;    double **prlim;
Line 1682  int main() Line 1805  int main()
   double ***eij, ***vareij;    double ***eij, ***vareij;
   double **varpl; /* Variances of prevalence limits by age */    double **varpl; /* Variances of prevalence limits by age */
   double *epj, vepp;    double *epj, vepp;
     double kk1;
   
   char version[80]="Imach version 64b, May 2001, INED-EUROREVES ";    char version[80]="Imach version 64b, May 2001, INED-EUROREVES ";
   char *alph[]={"a","a","b","c","d","e"}, str[4];    char *alph[]={"a","a","b","c","d","e"}, str[4];
   
   
   char z[1]="c", occ;    char z[1]="c", occ;
 #include <sys/time.h>  #include <sys/time.h>
 #include <time.h>  #include <time.h>
Line 1743  split(pathtot, path,optionfile); Line 1869  split(pathtot, path,optionfile);
   fscanf(ficpar,"title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\nftol=%lf stepm=%d ncov=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d\nmodel=%s\n",title, datafile, &lastobs, &firstpass,&lastpass,&ftol, &stepm, &ncov, &nlstate,&ndeath, &maxwav, &mle, &weightopt,model);    fscanf(ficpar,"title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\nftol=%lf stepm=%d ncov=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d\nmodel=%s\n",title, datafile, &lastobs, &firstpass,&lastpass,&ftol, &stepm, &ncov, &nlstate,&ndeath, &maxwav, &mle, &weightopt,model);
   printf("title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\nftol=%e stepm=%d ncov=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d\nmodel=%s\n", title, datafile, lastobs, firstpass,lastpass,ftol, stepm, ncov, nlstate,ndeath, maxwav, mle, weightopt,model);    printf("title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\nftol=%e stepm=%d ncov=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d\nmodel=%s\n", title, datafile, lastobs, firstpass,lastpass,ftol, stepm, ncov, nlstate,ndeath, maxwav, mle, weightopt,model);
   fprintf(ficparo,"title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\nftol=%e stepm=%d ncov=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d\nmodel=%s\n", title, datafile, lastobs, firstpass,lastpass,ftol,stepm,ncov,nlstate,ndeath,maxwav, mle, weightopt,model);    fprintf(ficparo,"title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\nftol=%e stepm=%d ncov=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d\nmodel=%s\n", title, datafile, lastobs, firstpass,lastpass,ftol,stepm,ncov,nlstate,ndeath,maxwav, mle, weightopt,model);
   while((c=getc(ficpar))=='#' && c!= EOF){
       ungetc(c,ficpar);
       fgets(line, MAXLINE, ficpar);
       puts(line);
       fputs(line,ficparo);
     }
     ungetc(c,ficpar);
    
     fscanf(ficpar,"fprevalence=%d lprevalence=%d pop_based=%d\n",&fprev,&lprev,&popbased);
    while((c=getc(ficpar))=='#' && c!= EOF){
       ungetc(c,ficpar);
       fgets(line, MAXLINE, ficpar);
       puts(line);
       fputs(line,ficparo);
     }
     ungetc(c,ficpar);
    
     fscanf(ficpar,"fprevalence=%d lprevalence=%d mob_average=%d\n",&fprevfore,&lprevfore,&mobilav);
    
   covar=matrix(0,NCOVMAX,1,n);    covar=matrix(0,NCOVMAX,1,n);
   cptcovn=0;    cptcovn=0;
   if (strlen(model)>1) cptcovn=nbocc(model,'+')+1;    if (strlen(model)>1) cptcovn=nbocc(model,'+')+1;
Line 1905  split(pathtot, path,optionfile); Line 2049  split(pathtot, path,optionfile);
     if ((s[1][i]==3) && (s[2][i]==2)) s[2][i]=3;      if ((s[1][i]==3) && (s[2][i]==2)) s[2][i]=3;
     if ((s[2][i]==3) && (s[3][i]==2)) s[3][i]=3;      if ((s[2][i]==3) && (s[3][i]==2)) s[3][i]=3;
     if ((s[3][i]==3) && (s[4][i]==2)) s[4][i]=3;      if ((s[3][i]==3) && (s[4][i]==2)) s[4][i]=3;
   }      }
   for (i=1; i<=imx; i++) printf("%d %.lf %.lf %.lf %.lf/%.lf %.lf/%.lf %.lf/%.lf %d %.lf/%.lf %d %.lf/%.lf %d %.lf/%.lf %d\n",num[i],(covar[1][i]), (covar[2][i]), (weight[i]), (moisnais[i]), (annais[i]), (moisdc[i]), (andc[i]), (mint[1][i]), (anint[1][i]), (s[1][i]),  (mint[2][i]), (anint[2][i]), (s[2][i]),  (mint[3][i]), (anint[3][i]), (s[3][i]),  (mint[4][i]), (anint[4][i]), (s[4][i]));*/      for (i=1; i<=imx; i++) printf("%d %.lf %.lf %.lf %.lf/%.lf %.lf/%.lf %.lf/%.lf %d %.lf/%.lf %d %.lf/%.lf %d %.lf/%.lf %d\n",num[i],(covar[1][i]), (covar[2][i]), (weight[i]), (moisnais[i]), (annais[i]), (moisdc[i]), (andc[i]), (mint[1][i]), (anint[1][i]), (s[1][i]),  (mint[2][i]), (anint[2][i]), (s[2][i]),  (mint[3][i]), (anint[3][i]), (s[3][i]),  (mint[4][i]), (anint[4][i]), (s[4][i]));*/
   
   /* Calculation of the number of parameter from char model*/    /* Calculation of the number of parameter from char model*/
   Tvar=ivector(1,15);    Tvar=ivector(1,15);
Line 2300  fprintf(ficgp,"\nset out \"v%s%d%d.gif\" Line 2444  fprintf(ficgp,"\nset out \"v%s%d%d.gif\"
       fprintf(ficgp,")) t\"prev(%d,%d)\" w l\n",cpt+1,cpt+1);          fprintf(ficgp,")) t\"prev(%d,%d)\" w l\n",cpt+1,cpt+1);  
       fprintf(ficgp,"set out \"p%s%d%d.gif\" \nreplot\n\n",strtok(optionfile, "."),cpt,k1);        fprintf(ficgp,"set out \"p%s%d%d.gif\" \nreplot\n\n",strtok(optionfile, "."),cpt,k1);
     }      }
   }    }  
   
   /* proba elementaires */    /* proba elementaires */
    for(i=1,jk=1; i <=nlstate; i++){     for(i=1,jk=1; i <=nlstate; i++){
Line 2416  Interval (in months) between two waves: Line 2560  Interval (in months) between two waves:
         - Life expectancies by age and initial health status: <a href=\"e%s\">e%s</a> <br>          - Life expectancies by age and initial health status: <a href=\"e%s\">e%s</a> <br>
         - Variances of life expectancies by age and initial health status: <a href=\"v%s\">v%s</a><br>          - Variances of life expectancies by age and initial health status: <a href=\"v%s\">v%s</a><br>
         - Health expectancies with their variances: <a href=\"t%s\">t%s</a> <br>          - Health expectancies with their variances: <a href=\"t%s\">t%s</a> <br>
         - Standard deviation of stationary prevalences: <a href=\"vpl%s\">vpl%s</a> <br><br>",title,datafile,firstpass,lastpass,stepm, weightopt,model,imx,jmin,jmax,jmean,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres);          - Standard deviation of stationary prevalences: <a href=\"vpl%s\">vpl%s</a> <br>
           - Prevalences forecasting: <a href=\"f%s\">f%s</a> <br>
   <br>",title,datafile,firstpass,lastpass,stepm, weightopt,model,imx,jmin,jmax,jmean,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres);
   
  fprintf(fichtm," <li>Graphs</li><p>");   fprintf(fichtm," <li>Graphs</li><p>");
   
Line 2501  fclose(fichtm); Line 2647  fclose(fichtm);
       }        }
     }      }
   fclose(ficrespl);    fclose(ficrespl);
   
   /*------------- h Pij x at various ages ------------*/    /*------------- h Pij x at various ages ------------*/
     
   strcpy(filerespij,"pij");  strcat(filerespij,fileres);    strcpy(filerespij,"pij");  strcat(filerespij,fileres);
Line 2510  fclose(fichtm); Line 2657  fclose(fichtm);
   printf("Computing pij: result on file '%s' \n", filerespij);    printf("Computing pij: result on file '%s' \n", filerespij);
     
   stepsize=(int) (stepm+YEARM-1)/YEARM;    stepsize=(int) (stepm+YEARM-1)/YEARM;
   if (stepm<=24) stepsize=2;    /*if (stepm<=24) stepsize=2;*/
   
   agelim=AGESUP;    agelim=AGESUP;
   hstepm=stepsize*YEARM; /* Every year of age */    hstepm=stepsize*YEARM; /* Every year of age */
Line 2549  fclose(fichtm); Line 2696  fclose(fichtm);
     }      }
   }    }
   
     /* varprob(fileres, matcov, p, delti, nlstate, (int) bage, (int) fage,k);*/
   
   fclose(ficrespij);    fclose(ficrespij);
   
     /*---------- Forecasting ------------------*/
   
     strcpy(fileresf,"f");
     strcat(fileresf,fileres);
     if((ficresf=fopen(fileresf,"w"))==NULL) {
       printf("Problem with forecast resultfile: %s\n", fileresf);goto end;
     }
     printf("Computing forecasting: result on file '%s' \n", fileresf);
   
     /* Mobile average */
   
     /* for (agedeb=bage; agedeb<=fage; agedeb++)
       for (i=1; i<=nlstate;i++)
         for (cptcod=1;cptcod<=ncodemax[cptcoveff];cptcod++)
         printf("%f %d i=%d j1=%d\n", probs[(int)agedeb][i][cptcod],(int) agedeb,i,cptcod);*/
   
     if (cptcoveff==0) ncodemax[cptcoveff]=1;
   
     if (mobilav==1) {
       mobaverage= ma3x(1, AGESUP,1,NCOVMAX, 1,NCOVMAX);
       for (agedeb=bage+3; agedeb<=fage-2; agedeb++)
         for (i=1; i<=nlstate;i++)
           for (cptcod=1;cptcod<=ncodemax[cptcov];cptcod++)
             mobaverage[(int)agedeb][i][cptcod]=0.;
      
       for (agedeb=bage+4; agedeb<=fage; agedeb++){
         for (i=1; i<=nlstate;i++){
           for (cptcod=1;cptcod<=ncodemax[cptcoveff];cptcod++){
             for (cpt=0;cpt<=4;cpt++){
               mobaverage[(int)agedeb-2][i][cptcod]=mobaverage[(int)agedeb-2][i][cptcod]+probs[(int)agedeb-cpt][i][cptcod];
             }
             mobaverage[(int)agedeb-2][i][cptcod]=mobaverage[(int)agedeb-2][i][cptcod]/5;
           }
         }
       }  
     }
   
     stepsize=(int) (stepm+YEARM-1)/YEARM;
     if (stepm<=24) stepsize=2;
   
     agelim=AGESUP;
     hstepm=stepsize*YEARM; /* Every year of age */
     hstepm=hstepm/stepm; /* Typically 2 years, = 2/6 months = 4 */
     hstepm=12;
      k=0;
     for(cptcov=1;cptcov<=i1;cptcov++){
       for(cptcod=1;cptcod<=ncodemax[cptcoveff];cptcod++){
         k=k+1;
         fprintf(ficresf,"\n#****** ");
         for(j=1;j<=cptcoveff;j++) {
           fprintf(ficresf,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtab[k][j]]);
         }
        
         fprintf(ficresf,"******\n");
   
         fprintf(ficresf,"# StartingAge FinalAge Horizon(in years)");
         for(j=1; j<=nlstate+ndeath;j++) fprintf(ficresf," P.%d",j);
   
         for (agedeb=fage; agedeb>=bage; agedeb--){
           fprintf(ficresf,"\n%d %.f %.f 0 ",k,agedeb, agedeb);
          if (mobilav==1) {
           for(j=1; j<=nlstate;j++)
             fprintf(ficresf,"%.5f ",mobaverage[(int)agedeb][j][cptcod]);
           }
           else {
             for(j=1; j<=nlstate;j++)
             fprintf(ficresf,"%.5f ",probs[(int)agedeb][j][cptcod]);
           }
          
         for(j=1; j<=ndeath;j++) fprintf(ficresf,"0.");
         }
         for (cpt=1; cpt<=NCOVMAX;cpt++)  
         for (agedeb=fage; agedeb>=bage; agedeb--){ /* If stepm=6 months */
          
           nhstepm=(int) rint((agelim-agedeb)*YEARM/stepm); /* Typically 20 years = 20*12/6=40 */
           nhstepm = nhstepm/hstepm; /* Typically 40/4=10 */
           /*printf("stepm=%d hstepm=%d nhstepm=%d \n",stepm,hstepm,nhstepm);*/
   
           p3mat=ma3x(1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);
           oldm=oldms;savm=savms;
           hpxij(p3mat,nhstepm,agedeb,hstepm,p,nlstate,stepm,oldm,savm, k);  
                  
           for (h=0; h<=nhstepm; h++){
          
             if (h*hstepm/YEARM*stepm==cpt)
    fprintf(ficresf,"\n%d %.f %.f %.f",k,agedeb, agedeb+ h*hstepm/YEARM*stepm, h*hstepm/YEARM*stepm);
            
             for(j=1; j<=nlstate+ndeath;j++) {
               kk1=0.;
               for(i=1; i<=nlstate;i++) {        
                 if (mobilav==1)
                 kk1=kk1+p3mat[i][j][h]*mobaverage[(int)agedeb][i][cptcod];
                 else kk1=kk1+p3mat[i][j][h]*probs[(int)agedeb][i][cptcod];
               }    
               if (h*hstepm/YEARM*stepm==cpt) fprintf(ficresf," %.5f ", kk1);
             }
           }
           free_ma3x(p3mat,1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);
         }
       }
     }
     if (mobilav==1) free_ma3x(mobaverage,1, AGESUP,1,NCOVMAX, 1,NCOVMAX);
     fclose(ficresf);
   /*---------- Health expectancies and variances ------------*/    /*---------- Health expectancies and variances ------------*/
   
   strcpy(filerest,"t");    strcpy(filerest,"t");
Line 2610  fclose(fichtm); Line 2862  fclose(fichtm);
       epj=vector(1,nlstate+1);        epj=vector(1,nlstate+1);
       for(age=bage; age <=fage ;age++){        for(age=bage; age <=fage ;age++){
         prevalim(prlim, nlstate, p, age, oldm, savm,ftolpl,k);          prevalim(prlim, nlstate, p, age, oldm, savm,ftolpl,k);
           if (popbased==1) {
             for(i=1; i<=nlstate;i++)
               prlim[i][i]=probs[(int)age][i][k];
           }
          
         fprintf(ficrest," %.0f",age);          fprintf(ficrest," %.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 2629  fclose(fichtm); Line 2886  fclose(fichtm);
     }      }
   }    }
                 
          
   
   
  fclose(ficreseij);   fclose(ficreseij);
  fclose(ficresvij);   fclose(ficresvij);
   fclose(ficrest);    fclose(ficrest);
Line 2674  strcpy(fileresvpl,"vpl"); Line 2934  strcpy(fileresvpl,"vpl");
   free_matrix(oldms, 1,nlstate+ndeath,1,nlstate+ndeath);    free_matrix(oldms, 1,nlstate+ndeath,1,nlstate+ndeath);
   free_matrix(newms, 1,nlstate+ndeath,1,nlstate+ndeath);    free_matrix(newms, 1,nlstate+ndeath,1,nlstate+ndeath);
   free_matrix(savms, 1,nlstate+ndeath,1,nlstate+ndeath);    free_matrix(savms, 1,nlstate+ndeath,1,nlstate+ndeath);
     
   free_matrix(matcov,1,npar,1,npar);    free_matrix(matcov,1,npar,1,npar);
   free_vector(delti,1,npar);    free_vector(delti,1,npar);
     
Line 2692  strcpy(fileresvpl,"vpl"); Line 2952  strcpy(fileresvpl,"vpl");
 #ifdef windows  #ifdef windows
  chdir(pathcd);   chdir(pathcd);
 #endif  #endif
  /*system("wgnuplot graph.plt");*/   
  /*system("../gp37mgw/wgnuplot graph.plt");*/  
  /*system("cd ../gp37mgw");*/  
  system("..\\gp37mgw\\wgnuplot graph.plt");   system("..\\gp37mgw\\wgnuplot graph.plt");
   
 #ifdef windows  #ifdef windows

Removed from v.1.12  
changed lines
  Added in v.1.14


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