Diff for /imach/src/imach.c between versions 1.59 and 1.66

version 1.59, 2002/11/18 23:01:13 version 1.66, 2003/01/28 17:23:35
Line 32 Line 32
   hPijx is the probability to be observed in state i at age x+h    hPijx is the probability to be observed in state i at age x+h
   conditional to the observed state i at age x. The delay 'h' can be    conditional to the observed state i at age x. The delay 'h' can be
   split into an exact number (nh*stepm) of unobserved intermediate    split into an exact number (nh*stepm) of unobserved intermediate
   states. This elementary transition (by month or quarter trimester,    states. This elementary transition (by month, quarter,
   semester or year) is model as a multinomial logistic.  The hPx    semester or year) is modelled as a multinomial logistic.  The hPx
   matrix is simply the matrix product of nh*stepm elementary matrices    matrix is simply the matrix product of nh*stepm elementary matrices
   and the contribution of each individual to the likelihood is simply    and the contribution of each individual to the likelihood is simply
   hPijx.    hPijx.
Line 83 Line 83
 #define ODIRSEPARATOR '\\'  #define ODIRSEPARATOR '\\'
 #endif  #endif
   
 char version[80]="Imach version 0.9, November 2002, INED-EUROREVES ";  char version[80]="Imach version 0.91, November 2002, INED-EUROREVES ";
 int erreur; /* Error number */  int erreur; /* Error number */
 int nvar;  int nvar;
 int cptcovn=0, cptcovage=0, cptcoveff=0,cptcov;  int cptcovn=0, cptcovage=0, cptcoveff=0,cptcov;
Line 856  double **matprod2(double **out, double * Line 856  double **matprod2(double **out, double *
   
 double ***hpxij(double ***po, int nhstepm, double age, int hstepm, double *x, int nlstate, int stepm, double **oldm, double **savm, int ij )  double ***hpxij(double ***po, int nhstepm, double age, int hstepm, double *x, int nlstate, int stepm, double **oldm, double **savm, int ij )
 {  {
   /* Computes the transition matrix starting at age 'age' over 'nhstepm*hstepm*stepm' month     /* Computes the transition matrix starting at age 'age' over 
      duration (i.e. until       'nhstepm*hstepm*stepm' months (i.e. until
      age (in years)  age+nhstepm*stepm/12) by multiplying nhstepm*hstepm matrices.        age (in years)  age+nhstepm*hstepm*stepm/12) by multiplying 
        nhstepm*hstepm matrices. 
      Output is stored in matrix po[i][j][h] for h every 'hstepm' step        Output is stored in matrix po[i][j][h] for h every 'hstepm' step 
      (typically every 2 years instead of every month which is too big).       (typically every 2 years instead of every month which is too big 
        for the memory).
      Model is determined by parameters x and covariates have to be        Model is determined by parameters x and covariates have to be 
      included manually here.        included manually here. 
   
Line 928  double func( double *x) Line 930  double func( double *x)
   cov[1]=1.;    cov[1]=1.;
   
   for(k=1; k<=nlstate; k++) ll[k]=0.;    for(k=1; k<=nlstate; k++) ll[k]=0.;
   for (i=1,ipmx=0, sw=0.; i<=imx; i++){  
     for (k=1; k<=cptcovn;k++) cov[2+k]=covar[Tvar[k]][i];    if(mle==1){
     for(mi=1; mi<= wav[i]-1; mi++){      for (i=1,ipmx=0, sw=0.; i<=imx; i++){
       for (ii=1;ii<=nlstate+ndeath;ii++)        for (k=1; k<=cptcovn;k++) cov[2+k]=covar[Tvar[k]][i];
         for (j=1;j<=nlstate+ndeath;j++){        for(mi=1; mi<= wav[i]-1; mi++){
           oldm[ii][j]=(ii==j ? 1.0 : 0.0);          for (ii=1;ii<=nlstate+ndeath;ii++)
           savm[ii][j]=(ii==j ? 1.0 : 0.0);            for (j=1;j<=nlstate+ndeath;j++){
         }              oldm[ii][j]=(ii==j ? 1.0 : 0.0);
       for(d=0; d<dh[mi][i]; d++){              savm[ii][j]=(ii==j ? 1.0 : 0.0);
         newm=savm;            }
         cov[2]=agev[mw[mi][i]][i]+d*stepm/YEARM;          for(d=0; d<dh[mi][i]; d++){
         for (kk=1; kk<=cptcovage;kk++) {            newm=savm;
           cov[Tage[kk]+2]=covar[Tvar[Tage[kk]]][i]*cov[2];            cov[2]=agev[mw[mi][i]][i]+d*stepm/YEARM;
         }            for (kk=1; kk<=cptcovage;kk++) {
                       cov[Tage[kk]+2]=covar[Tvar[Tage[kk]]][i]*cov[2];
         out=matprod2(newm,oldm,1,nlstate+ndeath,1,nlstate+ndeath,            }
                      1,nlstate+ndeath,pmij(pmmij,cov,ncovmodel,x,nlstate));            out=matprod2(newm,oldm,1,nlstate+ndeath,1,nlstate+ndeath,
         savm=oldm;                         1,nlstate+ndeath,pmij(pmmij,cov,ncovmodel,x,nlstate));
         oldm=newm;            savm=oldm;
                     oldm=newm;
           } /* end mult */
         
           /*lli=log(out[s[mw[mi][i]][i]][s[mw[mi+1][i]][i]]);*/ /* Original formula */
           /* But now since version 0.9 we anticipate for bias and large stepm.
            * If stepm is larger than one month (smallest stepm) and if the exact delay 
            * (in months) between two waves is not a multiple of stepm, we rounded to 
            * the nearest (and in case of equal distance, to the lowest) interval but now
            * we keep into memory the bias bh[mi][i] and also the previous matrix product
            * (i.e to dh[mi][i]-1) saved in 'savm'. The we inter(extra)polate the
            * probability in order to take into account the bias as a fraction of the way
            * from savm to out if bh is neagtive or even beyond if bh is positive. bh varies
            * -stepm/2 to stepm/2 .
            * For stepm=1 the results are the same as for previous versions of Imach.
            * For stepm > 1 the results are less biased than in previous versions. 
            */
           s1=s[mw[mi][i]][i];
           s2=s[mw[mi+1][i]][i];
           bbh=(double)bh[mi][i]/(double)stepm; 
           /* bias is positive if real duration
            * is higher than the multiple of stepm and negative otherwise.
            */
           /* lli= (savm[s1][s2]>1.e-8 ?(1.+bbh)*log(out[s1][s2])- bbh*log(savm[s1][s2]):log((1.+bbh)*out[s1][s2]));*/
           lli= (savm[s1][s2]>(double)1.e-8 ?log((1.+bbh)*out[s1][s2]- bbh*(savm[s1][s2])):log((1.+bbh)*out[s1][s2]));  /* linear interpolation */
           /*lli=(1.+bbh)*log(out[s1][s2])- bbh*log(savm[s1][s2]);*/
           /*if(lli ==000.0)*/
           /*printf("bbh= %f lli=%f savm=%f out=%f %d\n",bbh,lli,savm[s1][s2], out[s[mw[mi][i]][i]][s[mw[mi+1][i]][i]],i); */
           ipmx +=1;
           sw += weight[i];
           ll[s[mw[mi][i]][i]] += 2*weight[i]*lli;
         } /* end of wave */
       } /* end of individual */
     }  else if(mle==2){
       for (i=1,ipmx=0, sw=0.; i<=imx; i++){
         for (k=1; k<=cptcovn;k++) cov[2+k]=covar[Tvar[k]][i];
         for(mi=1; mi<= wav[i]-1; mi++){
           for (ii=1;ii<=nlstate+ndeath;ii++)
             for (j=1;j<=nlstate+ndeath;j++){
               oldm[ii][j]=(ii==j ? 1.0 : 0.0);
               savm[ii][j]=(ii==j ? 1.0 : 0.0);
             }
           for(d=0; d<=dh[mi][i]; d++){
             newm=savm;
             cov[2]=agev[mw[mi][i]][i]+d*stepm/YEARM;
             for (kk=1; kk<=cptcovage;kk++) {
               cov[Tage[kk]+2]=covar[Tvar[Tage[kk]]][i]*cov[2];
             }
             out=matprod2(newm,oldm,1,nlstate+ndeath,1,nlstate+ndeath,
                          1,nlstate+ndeath,pmij(pmmij,cov,ncovmodel,x,nlstate));
             savm=oldm;
             oldm=newm;
           } /* end mult */
         
           /*lli=log(out[s[mw[mi][i]][i]][s[mw[mi+1][i]][i]]);*/ /* Original formula */
           /* But now since version 0.9 we anticipate for bias and large stepm.
            * If stepm is larger than one month (smallest stepm) and if the exact delay 
            * (in months) between two waves is not a multiple of stepm, we rounded to 
            * the nearest (and in case of equal distance, to the lowest) interval but now
            * we keep into memory the bias bh[mi][i] and also the previous matrix product
            * (i.e to dh[mi][i]-1) saved in 'savm'. The we inter(extra)polate the
            * probability in order to take into account the bias as a fraction of the way
            * from savm to out if bh is neagtive or even beyond if bh is positive. bh varies
            * -stepm/2 to stepm/2 .
            * For stepm=1 the results are the same as for previous versions of Imach.
            * For stepm > 1 the results are less biased than in previous versions. 
            */
           s1=s[mw[mi][i]][i];
           s2=s[mw[mi+1][i]][i];
           bbh=(double)bh[mi][i]/(double)stepm; 
           /* bias is positive if real duration
            * is higher than the multiple of stepm and negative otherwise.
            */
           lli= (savm[s1][s2]>(double)1.e-8 ?log((1.+bbh)*out[s1][s2]- bbh*(savm[s1][s2])):log((1.+bbh)*out[s1][s2])); /* linear interpolation */
           /* lli= (savm[s1][s2]>1.e-8 ?(1.+bbh)*log(out[s1][s2])- bbh*log(savm[s1][s2]):log((1.+bbh)*out[s1][s2]));*/
           /*lli= (savm[s1][s2]>1.e-8 ?(1.+bbh)*log(out[s1][s2])- bbh*log(savm[s1][s2]):log((1.-+bh)*out[s1][s2])); */ /* exponential interpolation */
           /*lli=(1.+bbh)*log(out[s1][s2])- bbh*log(savm[s1][s2]);*/
           /*if(lli ==000.0)*/
           /*printf("bbh= %f lli=%f savm=%f out=%f %d\n",bbh,lli,savm[s1][s2], out[s[mw[mi][i]][i]][s[mw[mi+1][i]][i]],i); */
           ipmx +=1;
           sw += weight[i];
           ll[s[mw[mi][i]][i]] += 2*weight[i]*lli;
         } /* end of wave */
       } /* end of individual */
     }  else if(mle==3){  /* exponential inter-extrapolation */
       for (i=1,ipmx=0, sw=0.; i<=imx; i++){
         for (k=1; k<=cptcovn;k++) cov[2+k]=covar[Tvar[k]][i];
         for(mi=1; mi<= wav[i]-1; mi++){
           for (ii=1;ii<=nlstate+ndeath;ii++)
             for (j=1;j<=nlstate+ndeath;j++){
               oldm[ii][j]=(ii==j ? 1.0 : 0.0);
               savm[ii][j]=(ii==j ? 1.0 : 0.0);
             }
           for(d=0; d<dh[mi][i]; d++){
             newm=savm;
             cov[2]=agev[mw[mi][i]][i]+d*stepm/YEARM;
             for (kk=1; kk<=cptcovage;kk++) {
               cov[Tage[kk]+2]=covar[Tvar[Tage[kk]]][i]*cov[2];
             }
             out=matprod2(newm,oldm,1,nlstate+ndeath,1,nlstate+ndeath,
                          1,nlstate+ndeath,pmij(pmmij,cov,ncovmodel,x,nlstate));
             savm=oldm;
             oldm=newm;
           } /* end mult */
         
           /*lli=log(out[s[mw[mi][i]][i]][s[mw[mi+1][i]][i]]);*/ /* Original formula */
           /* But now since version 0.9 we anticipate for bias and large stepm.
            * If stepm is larger than one month (smallest stepm) and if the exact delay 
            * (in months) between two waves is not a multiple of stepm, we rounded to 
            * the nearest (and in case of equal distance, to the lowest) interval but now
            * we keep into memory the bias bh[mi][i] and also the previous matrix product
            * (i.e to dh[mi][i]-1) saved in 'savm'. The we inter(extra)polate the
            * probability in order to take into account the bias as a fraction of the way
            * from savm to out if bh is neagtive or even beyond if bh is positive. bh varies
            * -stepm/2 to stepm/2 .
            * For stepm=1 the results are the same as for previous versions of Imach.
            * For stepm > 1 the results are less biased than in previous versions. 
            */
           s1=s[mw[mi][i]][i];
           s2=s[mw[mi+1][i]][i];
           bbh=(double)bh[mi][i]/(double)stepm; 
           /* bias is positive if real duration
            * is higher than the multiple of stepm and negative otherwise.
            */
           /* lli= (savm[s1][s2]>(double)1.e-8 ?log((1.+bbh)*out[s1][s2]- bbh*(savm[s1][s2])):log((1.+bbh)*out[s1][s2])); */ /* linear interpolation */
           lli= (savm[s1][s2]>1.e-8 ?(1.+bbh)*log(out[s1][s2])- bbh*log(savm[s1][s2]):log((1.+bbh)*out[s1][s2])); /* exponential inter-extrapolation */
           /*lli=(1.+bbh)*log(out[s1][s2])- bbh*log(savm[s1][s2]);*/
           /*if(lli ==000.0)*/
           /*printf("bbh= %f lli=%f savm=%f out=%f %d\n",bbh,lli,savm[s1][s2], out[s[mw[mi][i]][i]][s[mw[mi+1][i]][i]],i); */
           ipmx +=1;
           sw += weight[i];
           ll[s[mw[mi][i]][i]] += 2*weight[i]*lli;
         } /* end of wave */
       } /* end of individual */
     }else{  /* ml=4 no inter-extrapolation */
       for (i=1,ipmx=0, sw=0.; i<=imx; i++){
         for (k=1; k<=cptcovn;k++) cov[2+k]=covar[Tvar[k]][i];
         for(mi=1; mi<= wav[i]-1; mi++){
           for (ii=1;ii<=nlstate+ndeath;ii++)
             for (j=1;j<=nlstate+ndeath;j++){
               oldm[ii][j]=(ii==j ? 1.0 : 0.0);
               savm[ii][j]=(ii==j ? 1.0 : 0.0);
             }
           for(d=0; d<dh[mi][i]; d++){
             newm=savm;
             cov[2]=agev[mw[mi][i]][i]+d*stepm/YEARM;
             for (kk=1; kk<=cptcovage;kk++) {
               cov[Tage[kk]+2]=covar[Tvar[Tage[kk]]][i]*cov[2];
             }
                   
       } /* end mult */            out=matprod2(newm,oldm,1,nlstate+ndeath,1,nlstate+ndeath,
                          1,nlstate+ndeath,pmij(pmmij,cov,ncovmodel,x,nlstate));
             savm=oldm;
             oldm=newm;
           } /* end mult */
               
       /*lli=log(out[s[mw[mi][i]][i]][s[mw[mi+1][i]][i]]);*/ /* Original formula */          lli=log(out[s[mw[mi][i]][i]][s[mw[mi+1][i]][i]]); /* Original formula */
       /* But now since version 0.9 we anticipate for bias and large stepm.          ipmx +=1;
        * If stepm is larger than one month (smallest stepm) and if the exact delay           sw += weight[i];
        * (in months) between two waves is not a multiple of stepm, we rounded to           ll[s[mw[mi][i]][i]] += 2*weight[i]*lli;
        * the nearest (and in case of equal distance, to the lowest) interval but now        } /* end of wave */
        * we keep into memory the bias bh[mi][i] and also the previous matrix product      } /* end of individual */
        * (i.e to dh[mi][i]-1) saved in 'savm'. The we inter(extra)polate the    } /* End of if */
        * probability in order to take into account the bias as a fraction of the way  
        * from savm to out if bh is neagtive or even beyond if bh is positive. bh varies  
        * -stepm/2 to stepm/2 .  
        * For stepm=1 the results are the same as for previous versions of Imach.  
        * For stepm > 1 the results are less biased than in previous versions.   
        */  
       s1=s[mw[mi][i]][i];  
       s2=s[mw[mi+1][i]][i];  
       bbh=(double)bh[mi][i]/(double)stepm;  
       lli= (savm[s1][s2]>(double)1.e-8 ?(1.+bbh)*log(out[s1][s2])- bbh*log(savm[s1][s2]):log((1.-bbh)*out[s1][s2]));  
       /*lli= (savm[s1][s2]>1.e-8 ?(1.+bbh)*log(out[s1][s2])- bbh*log(savm[s1][s2]):log((1.-bbh)*out[s1][s2]));*/  
       /*lli=(1.+bbh)*log(out[s1][s2])- bbh*log(savm[s1][s2]);*/  
       /*if(lli ==000.0)*/  
       /*printf("bbh= %f lli=%f savm=%f out=%f %d\n",bbh,lli,savm[s1][s2], out[s[mw[mi][i]][i]][s[mw[mi+1][i]][i]],i); */  
       ipmx +=1;  
       sw += weight[i];  
       ll[s[mw[mi][i]][i]] += 2*weight[i]*lli;  
     } /* end of wave */  
   } /* end of individual */  
   
   for(k=1,l=0.; k<=nlstate; k++) l += ll[k];    for(k=1,l=0.; k<=nlstate; k++) l += ll[k];
   /* printf("l1=%f l2=%f ",ll[1],ll[2]); */    /* printf("l1=%f l2=%f ",ll[1],ll[2]); */
   l= l*ipmx/sw; /* To get the same order of magnitude as if weight=1 for every body */    l= l*ipmx/sw; /* To get the same order of magnitude as if weight=1 for every body */
Line 1000  void mlikeli(FILE *ficres,double p[], in Line 1133  void mlikeli(FILE *ficres,double p[], in
   powell(p,xi,npar,ftol,&iter,&fret,func);    powell(p,xi,npar,ftol,&iter,&fret,func);
   
    printf("\n#Number of iterations = %d, -2 Log likelihood = %.12f\n",iter,func(p));     printf("\n#Number of iterations = %d, -2 Log likelihood = %.12f\n",iter,func(p));
   fprintf(ficlog,"#Number of iterations = %d, -2 Log likelihood = %.12f \n",iter,func(p));    fprintf(ficlog,"\n#Number of iterations = %d, -2 Log likelihood = %.12f \n",iter,func(p));
   fprintf(ficres,"#Number of iterations = %d, -2 Log likelihood = %.12f \n",iter,func(p));    fprintf(ficres,"#Number of iterations = %d, -2 Log likelihood = %.12f \n",iter,func(p));
   
 }  }
Line 1584  void  concatwav(int wav[], int **dh, int Line 1717  void  concatwav(int wav[], int **dh, int
         jk= j/stepm;          jk= j/stepm;
         jl= j -jk*stepm;          jl= j -jk*stepm;
         ju= j -(jk+1)*stepm;          ju= j -(jk+1)*stepm;
         if(jl <= -ju){          if(mle <=1){ 
           dh[mi][i]=jk;            if(jl==0){
           bh[mi][i]=jl;              dh[mi][i]=jk;
         }              bh[mi][i]=0;
         else{            }else{ /* We want a negative bias in order to only have interpolation ie
           dh[mi][i]=jk+1;                    * at the price of an extra matrix product in likelihood */
           bh[mi][i]=ju;              dh[mi][i]=jk+1;
         }              bh[mi][i]=ju;
         if(dh[mi][i]==0){            }
           dh[mi][i]=1; /* At least one step */          }else{
           bh[mi][i]=ju; /* At least one step */            if(jl <= -ju){
           printf(" bh=%d ju=%d jl=%d dh=%d jk=%d stepm=%d %d\n",bh[mi][i],ju,jl,dh[mi][i],jk,stepm,i);              dh[mi][i]=jk;
               bh[mi][i]=jl;       /* bias is positive if real duration
                                    * is higher than the multiple of stepm and negative otherwise.
                                    */
             }
             else{
               dh[mi][i]=jk+1;
               bh[mi][i]=ju;
             }
             if(dh[mi][i]==0){
               dh[mi][i]=1; /* At least one step */
               bh[mi][i]=ju; /* At least one step */
               printf(" bh=%d ju=%d jl=%d dh=%d jk=%d stepm=%d %d\n",bh[mi][i],ju,jl,dh[mi][i],jk,stepm,i);
             }
             if(i==298 || i==287 || i==763 ||i==1061)printf(" bh=%d ju=%d jl=%d dh=%d jk=%d stepm=%d",bh[mi][i],ju,jl,dh[mi][i],jk,stepm);
         }          }
         if(i==298 || i==287 || i==763 ||i==1061)printf(" bh=%d ju=%d jl=%d dh=%d jk=%d stepm=%d",bh[mi][i],ju,jl,dh[mi][i],jk,stepm);        } /* end if mle */
       }      } /* end wave */
     }  
   }    }
   jmean=sum/k;    jmean=sum/k;
   printf("Delay (in months) between two waves Min=%d Max=%d Mean=%f\n\n ",jmin, jmax,jmean);    printf("Delay (in months) between two waves Min=%d Max=%d Mean=%f\n\n ",jmin, jmax,jmean);
Line 1700  void evsij(char fileres[], double ***eij Line 1846  void evsij(char fileres[], double ***eij
    * This is mainly to measure the difference between two models: for example     * This is mainly to measure the difference between two models: for example
    * if stepm=24 months pijx are given only every 2 years and by summing them     * if stepm=24 months pijx are given only every 2 years and by summing them
    * we are calculating an estimate of the Life Expectancy assuming a linear      * we are calculating an estimate of the Life Expectancy assuming a linear 
    * progression inbetween and thus overestimating or underestimating according     * progression in between and thus overestimating or underestimating according
    * to the curvature of the survival function. If, for the same date, we      * to the curvature of the survival function. If, for the same date, we 
    * estimate the model with stepm=1 month, we can keep estepm to 24 months     * estimate the model with stepm=1 month, we can keep estepm to 24 months
    * to compare the new estimate of Life expectancy with the same linear      * to compare the new estimate of Life expectancy with the same linear 
Line 1890  void varevsij(char optionfilefiname[], d Line 2036  void varevsij(char optionfilefiname[], d
   }    }
   printf("Computing total mortality p.j=w1*p1j+w2*p2j+..: result on file '%s' \n",fileresprobmorprev);    printf("Computing total mortality p.j=w1*p1j+w2*p2j+..: result on file '%s' \n",fileresprobmorprev);
   fprintf(ficlog,"Computing total mortality p.j=w1*p1j+w2*p2j+..: result on file '%s' \n",fileresprobmorprev);    fprintf(ficlog,"Computing total mortality p.j=w1*p1j+w2*p2j+..: result on file '%s' \n",fileresprobmorprev);
   fprintf(ficresprobmorprev,"# probabilities of dying during a year and weighted mean w1*p1j+w2*p2j+... stand dev in()\n");    fprintf(ficresprobmorprev,"# probabilities of dying before estepm=%d months for people of exact age and weighted probabilities w1*p1j+w2*p2j+... stand dev in()\n",estepm);
   fprintf(ficresprobmorprev,"# Age cov=%-d",ij);    fprintf(ficresprobmorprev,"# Age cov=%-d",ij);
   for(j=nlstate+1; j<=(nlstate+ndeath);j++){    for(j=nlstate+1; j<=(nlstate+ndeath);j++){
     fprintf(ficresprobmorprev," p.%-d SE",j);      fprintf(ficresprobmorprev," p.%-d SE",j);
Line 1947  void varevsij(char optionfilefiname[], d Line 2093  void varevsij(char optionfilefiname[], d
      and note for a fixed period like k years */       and note for a fixed period like k years */
   /* We decided (b) to get a life expectancy respecting the most precise curvature of the    /* We decided (b) to get a life expectancy respecting the most precise curvature of the
      survival function given by stepm (the optimization length). Unfortunately it       survival function given by stepm (the optimization length). Unfortunately it
      means that if the survival funtion is printed only each two years of age and if       means that if the survival funtion is printed every two years of age and if
      you sum them up and add 1 year (area under the trapezoids) you won't get the same        you sum them up and add 1 year (area under the trapezoids) you won't get the same 
      results. So we changed our mind and took the option of the best precision.       results. So we changed our mind and took the option of the best precision.
   */    */
Line 1963  void varevsij(char optionfilefiname[], d Line 2109  void varevsij(char optionfilefiname[], d
   
   
     for(theta=1; theta <=npar; theta++){      for(theta=1; theta <=npar; theta++){
       for(i=1; i<=npar; i++){ /* Computes gradient */        for(i=1; i<=npar; i++){ /* Computes gradient x + delta*/
         xp[i] = x[i] + (i==theta ?delti[theta]:0);          xp[i] = x[i] + (i==theta ?delti[theta]:0);
       }        }
       hpxij(p3mat,nhstepm,age,hstepm,xp,nlstate,stepm,oldm,savm, ij);          hpxij(p3mat,nhstepm,age,hstepm,xp,nlstate,stepm,oldm,savm, ij);  
Line 1985  void varevsij(char optionfilefiname[], d Line 2131  void varevsij(char optionfilefiname[], d
             gp[h][j] += prlim[i][i]*p3mat[i][j][h];              gp[h][j] += prlim[i][i]*p3mat[i][j][h];
         }          }
       }        }
       /* This for computing forces of mortality (h=1)as a weighted average */        /* This for computing probability of death (h=1 means
            computed over hstepm matrices product = hstepm*stepm months) 
            as a weighted average of prlim.
         */
       for(j=nlstate+1,gpp[j]=0.;j<=nlstate+ndeath;j++){        for(j=nlstate+1,gpp[j]=0.;j<=nlstate+ndeath;j++){
         for(i=1; i<= nlstate; i++)          for(i=1; i<= nlstate; i++)
           gpp[j] += prlim[i][i]*p3mat[i][j][1];            gpp[j] += prlim[i][i]*p3mat[i][j][1];
       }            }    
       /* end force of mortality */        /* end probability of death */
   
       for(i=1; i<=npar; i++) /* Computes gradient */        for(i=1; i<=npar; i++) /* Computes gradient x - delta */
         xp[i] = x[i] - (i==theta ?delti[theta]:0);          xp[i] = x[i] - (i==theta ?delti[theta]:0);
       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);
Line 2013  void varevsij(char optionfilefiname[], d Line 2162  void varevsij(char optionfilefiname[], d
             gm[h][j] += prlim[i][i]*p3mat[i][j][h];              gm[h][j] += prlim[i][i]*p3mat[i][j][h];
         }          }
       }        }
       /* This for computing force of mortality (h=1)as a weighted average */        /* This for computing probability of death (h=1 means
            computed over hstepm matrices product = hstepm*stepm months) 
            as a weighted average of prlim.
         */
       for(j=nlstate+1,gmp[j]=0.;j<=nlstate+ndeath;j++){        for(j=nlstate+1,gmp[j]=0.;j<=nlstate+ndeath;j++){
         for(i=1; i<= nlstate; i++)          for(i=1; i<= nlstate; i++)
           gmp[j] += prlim[i][i]*p3mat[i][j][1];            gmp[j] += prlim[i][i]*p3mat[i][j][1];
       }            }    
       /* end force of mortality */        /* end probability of death */
   
       for(j=1; j<= nlstate; j++) /* vareij */        for(j=1; j<= nlstate; j++) /* vareij */
         for(h=0; h<=nhstepm; h++){          for(h=0; h<=nhstepm; h++){
Line 2063  void varevsij(char optionfilefiname[], d Line 2215  void varevsij(char optionfilefiname[], d
       for(i=nlstate+1;i<=nlstate+ndeath;i++)        for(i=nlstate+1;i<=nlstate+ndeath;i++)
         varppt[j][i]=doldmp[j][i];          varppt[j][i]=doldmp[j][i];
     /* end ppptj */      /* end ppptj */
       /*  x centered again */
     hpxij(p3mat,nhstepm,age,hstepm,x,nlstate,stepm,oldm,savm, ij);        hpxij(p3mat,nhstepm,age,hstepm,x,nlstate,stepm,oldm,savm, ij);  
     prevalim(prlim,nlstate,x,age,oldm,savm,ftolpl,ij);      prevalim(prlim,nlstate,x,age,oldm,savm,ftolpl,ij);
     
Line 2076  void varevsij(char optionfilefiname[], d Line 2229  void varevsij(char optionfilefiname[], d
       }        }
     }      }
           
     /* This for computing force of mortality (h=1)as a weighted average */      /* This for computing probability of death (h=1 means
          computed over hstepm (estepm) matrices product = hstepm*stepm months) 
          as a weighted average of prlim.
       */
     for(j=nlstate+1,gmp[j]=0.;j<=nlstate+ndeath;j++){      for(j=nlstate+1,gmp[j]=0.;j<=nlstate+ndeath;j++){
       for(i=1; i<= nlstate; i++)        for(i=1; i<= nlstate; i++)
         gmp[j] += prlim[i][i]*p3mat[i][j][1];           gmp[j] += prlim[i][i]*p3mat[i][j][1]; 
     }          }    
     /* end force of mortality */      /* end probability of death */
   
     fprintf(ficresprobmorprev,"%3d %d ",(int) age, ij);      fprintf(ficresprobmorprev,"%3d %d ",(int) age, ij);
     for(j=nlstate+1; j<=(nlstate+ndeath);j++){      for(j=nlstate+1; j<=(nlstate+ndeath);j++){
Line 2115  void varevsij(char optionfilefiname[], d Line 2271  void varevsij(char optionfilefiname[], d
   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);
   fprintf(fichtm,"\n<br> File (multiple files are possible if covariates are present): <A href=\"%s\">%s</a>\n",fileresprobmorprev,fileresprobmorprev);    fprintf(fichtm,"\n<br> File (multiple files are possible if covariates are present): <A href=\"%s\">%s</a>\n",fileresprobmorprev,fileresprobmorprev);
   fprintf(fichtm,"\n<br> Probability is computed over estepm=%d months. <br> <img src=\"varmuptjgr%s%s.png\"> <br>\n", stepm,digitp,digit);    fprintf(fichtm,"\n<br> Probability is computed over estepm=%d months. <br> <img src=\"varmuptjgr%s%s.png\"> <br>\n", estepm,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.png\"> <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.png\"> <br>\n", stepm,YEARM,digitp,digit);
 */  */
   fprintf(ficgp,"\nset out \"varmuptjgr%s%s.png\";replot;",digitp,digit);    fprintf(ficgp,"\nset out \"varmuptjgr%s%s.png\";replot;",digitp,digit);
Line 3122  populforecast(char fileres[], double anp Line 3278  populforecast(char fileres[], double anp
   
 int main(int argc, char *argv[])  int main(int argc, char *argv[])
 {  {
     int movingaverage(double ***probs, double bage,double fage, double ***mobaverage, int mobilav);
   int i,j, k, n=MAXN,iter,m,size,cptcode, cptcod;    int i,j, k, n=MAXN,iter,m,size,cptcode, cptcod;
   double agedeb, agefin,hf;    double agedeb, agefin,hf;
   double ageminpar=1.e20,agemin=1.e20, agemaxpar=-1.e20, agemax=-1.e20;    double ageminpar=1.e20,agemin=1.e20, agemaxpar=-1.e20, agemax=-1.e20;
Line 3160  int main(int argc, char *argv[]) Line 3316  int main(int argc, char *argv[])
   double *epj, vepp;    double *epj, vepp;
   double kk1, kk2;    double kk1, kk2;
   double dateprev1, dateprev2,jproj1,mproj1,anproj1,jproj2,mproj2,anproj2;    double dateprev1, dateprev2,jproj1,mproj1,anproj1,jproj2,mproj2,anproj2;
   /*int *movingaverage; */  
   
   char *alph[]={"a","a","b","c","d","e"}, str[4];    char *alph[]={"a","a","b","c","d","e"}, str[4];
   
Line 3652  int main(int argc, char *argv[]) Line 3807  int main(int argc, char *argv[])
   /* Calculates basic frequencies. Computes observed prevalence at single age    /* Calculates basic frequencies. Computes observed prevalence at single age
      and prints on file fileres'p'. */       and prints on file fileres'p'. */
   
       pmmij= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */
       oldms= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */
       newms= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */
       savms= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */
       oldm=oldms; newm=newms; savm=savms; /* Keeps fixed addresses to free */
           
         
   /* For Powell, parameters are in a vector p[] starting at p[1]    /* For Powell, parameters are in a vector p[] starting at p[1]
      so we point p on param[1][1] so that p[1] maps on param[1][1][1] */       so we point p on param[1][1] so that p[1] maps on param[1][1][1] */
   p=param[1][1]; /* *(*(*(param +1)+1)+0) */    p=param[1][1]; /* *(*(*(param +1)+1)+0) */
   
   if(mle==1){    if(mle>=1){ /* Could be 1 or 2 */
     mlikeli(ficres,p, npar, ncovmodel, nlstate, ftol, func);      mlikeli(ficres,p, npar, ncovmodel, nlstate, ftol, func);
   }    }
           
Line 3862  Interval (in months) between two waves: Line 4022  Interval (in months) between two waves:
   free_imatrix(mw,1,lastpass-firstpass+1,1,imx);       free_imatrix(mw,1,lastpass-firstpass+1,1,imx);   
   free_ivector(num,1,n);    free_ivector(num,1,n);
   free_vector(agedc,1,n);    free_vector(agedc,1,n);
   free_matrix(covar,0,NCOVMAX,1,n);    /*free_matrix(covar,0,NCOVMAX,1,n);*/
   /*free_matrix(covar,1,NCOVMAX,1,n);*/    /*free_matrix(covar,1,NCOVMAX,1,n);*/
   fclose(ficparo);    fclose(ficparo);
   fclose(ficres);    fclose(ficres);
Line 3884  Interval (in months) between two waves: Line 4044  Interval (in months) between two waves:
   fprintf(ficrespl,"\n");    fprintf(ficrespl,"\n");
       
   prlim=matrix(1,nlstate,1,nlstate);    prlim=matrix(1,nlstate,1,nlstate);
   pmmij= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */  
   oldms= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */  
   newms= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */  
   savms= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */  
   oldm=oldms; newm=newms; savm=savms; /* Keeps fixed addresses to free */  
   
   agebase=ageminpar;    agebase=ageminpar;
   agelim=agemaxpar;    agelim=agemaxpar;
Line 4150  Interval (in months) between two waves: Line 4305  Interval (in months) between two waves:
   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(covar,0,NCOVMAX,1,n);
   free_matrix(matcov,1,npar,1,npar);    free_matrix(matcov,1,npar,1,npar);
   free_vector(delti,1,npar);    free_vector(delti,1,npar);
   free_matrix(agev,1,maxwav,1,imx);    free_matrix(agev,1,maxwav,1,imx);

Removed from v.1.59  
changed lines
  Added in v.1.66


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