Diff for /imach/src/imach.c between versions 1.324 and 1.325

version 1.324, 2022/07/23 17:44:26 version 1.325, 2022/07/25 14:27:23
Line 1 Line 1
 /* $Id$  /* $Id$
   $State$    $State$
   $Log$    $Log$
     Revision 1.325  2022/07/25 14:27:23  brouard
     Summary: r30
   
     * imach.c (Module): Error cptcovn instead of nsd in bmij (was
     coredumped, revealed by Feiuno, thank you.
   
   Revision 1.324  2022/07/23 17:44:26  brouard    Revision 1.324  2022/07/23 17:44:26  brouard
   *** empty log message ***    *** empty log message ***
   
Line 1051  Important routines Line 1057  Important routines
 - Tricode which tests the modality of dummy variables (in order to warn with wrong or empty modalities)  - Tricode which tests the modality of dummy variables (in order to warn with wrong or empty modalities)
   and returns the number of efficient covariates cptcoveff and modalities nbcode[Tvar[k]][1]= 0 and nbcode[Tvar[k]][2]= 1 usually.    and returns the number of efficient covariates cptcoveff and modalities nbcode[Tvar[k]][1]= 0 and nbcode[Tvar[k]][2]= 1 usually.
 - printinghtml which outputs results like life expectancy in and from a state for a combination of modalities of dummy variables  - printinghtml which outputs results like life expectancy in and from a state for a combination of modalities of dummy variables
   o There are 2*cptcoveff combinations of (0,1) for cptcoveff variables. Outputting only combinations with people, eĢliminating 1 1 if    o There are 2**cptcoveff combinations of (0,1) for cptcoveff variables. Outputting only combinations with people, eĢliminating 1 1 if
     race White (0 0), Black vs White (1 0), Hispanic (0 1) and 1 1 being meaningless.      race White (0 0), Black vs White (1 0), Hispanic (0 1) and 1 1 being meaningless.
   
   
Line 1188  typedef struct { Line 1194  typedef struct {
 #define NINTERVMAX 8  #define NINTERVMAX 8
 #define NLSTATEMAX 8 /**< Maximum number of live states (for func) */  #define NLSTATEMAX 8 /**< Maximum number of live states (for func) */
 #define NDEATHMAX 8 /**< Maximum number of dead states (for func) */  #define NDEATHMAX 8 /**< Maximum number of dead states (for func) */
 #define NCOVMAX 30  /**< Maximum number of covariates, including generated covariates V1*V2 */  #define NCOVMAX 30  /**< Maximum number of covariates used in the model, including generated covariates V1*V2 or V1*age */
 #define codtabm(h,k)  (1 & (h-1) >> (k-1))+1  #define codtabm(h,k)  (1 & (h-1) >> (k-1))+1
 /*#define decodtabm(h,k,cptcoveff)= (h <= (1<<cptcoveff)?(((h-1) >> (k-1)) & 1) +1 : -1)*/  /*#define decodtabm(h,k,cptcoveff)= (h <= (1<<cptcoveff)?(((h-1) >> (k-1)) & 1) +1 : -1)*/
 #define decodtabm(h,k,cptcoveff) (((h-1) >> (k-1)) & 1) +1   #define decodtabm(h,k,cptcoveff) (((h-1) >> (k-1)) & 1) +1 
Line 3138  double **pmij(double **ps, double *cov, Line 3144  double **pmij(double **ps, double *cov,
     ps[i][i]=1./(s1+1.);      ps[i][i]=1./(s1+1.);
     /* Computing other pijs */      /* Computing other pijs */
     for(j=1; j<i; j++)      for(j=1; j<i; j++)
       ps[i][j]= exp(ps[i][j])*ps[i][i];        ps[i][j]= exp(ps[i][j])*ps[i][i];/* Bug valgrind */
     for(j=i+1; j<=nlstate+ndeath; j++)      for(j=i+1; j<=nlstate+ndeath; j++)
       ps[i][j]= exp(ps[i][j])*ps[i][i];        ps[i][j]= exp(ps[i][j])*ps[i][i];
     /* ps[i][nlstate+1]=1.-s1- ps[i][i];*/ /* Sum should be 1 */      /* ps[i][nlstate+1]=1.-s1- ps[i][i];*/ /* Sum should be 1 */
Line 3196  double **pmij(double **ps, double *cov, Line 3202  double **pmij(double **ps, double *cov,
   /* dsavm=pmij(pmmij,cov,ncovmodel,x,nlstate); */    /* dsavm=pmij(pmmij,cov,ncovmodel,x,nlstate); */
   
   /* P_x */    /* P_x */
   pmmij=pmij(pmmij,cov,ncovmodel,x,nlstate); /*This is forward probability from agefin to agefin + stepm */    pmmij=pmij(pmmij,cov,ncovmodel,x,nlstate); /*This is forward probability from agefin to agefin + stepm *//* Bug valgrind */
   /* outputs pmmij which is a stochastic matrix in row */    /* outputs pmmij which is a stochastic matrix in row */
   
   /* Diag(w_x) */    /* Diag(w_x) */
Line 3541  double ***hbxij(double ***po, int nhstep Line 3547  double ***hbxij(double ***po, int nhstep
       cov[2]=agexact;        cov[2]=agexact;
       if(nagesqr==1)        if(nagesqr==1)
         cov[3]= agexact*agexact;          cov[3]= agexact*agexact;
       for (k=1; k<=cptcovn;k++){        for (k=1; k<=nsd;k++){ /* For single dummy covariates only *//* cptcovn error */
       /*        cov[2+nagesqr+k]=nbcode[Tvar[k]][codtabm(ij,k)]; */        /*        cov[2+nagesqr+k]=nbcode[Tvar[k]][codtabm(ij,k)]; */
       /* /\* cov[2+nagesqr+k]=nbcode[Tvar[k]][codtabm(ij,Tvar[k])]; *\/ */        /* /\* cov[2+nagesqr+k]=nbcode[Tvar[k]][codtabm(ij,Tvar[k])]; *\/ */
         cov[2+nagesqr+TvarsDind[k]]=nbcode[TvarsD[k]][codtabm(ij,k)];          cov[2+nagesqr+TvarsDind[k]]=nbcode[TvarsD[k]][codtabm(ij,k)];/* Bug valgrind */
         /* printf("hbxij Dummy agexact=%.0f combi=%d k=%d TvarsD[%d]=V%d TvarsDind[%d]=%d nbcode=%d cov[%d]=%lf codtabm(%d,Tvar[%d])=%d \n",agexact,ij,k, k, TvarsD[k],k,TvarsDind[k],nbcode[TvarsD[k]][codtabm(ij,k)],2+nagesqr+TvarsDind[k],cov[2+nagesqr+TvarsDind[k]], ij, k, codtabm(ij,k)); */          /* printf("hbxij Dummy agexact=%.0f combi=%d k=%d TvarsD[%d]=V%d TvarsDind[%d]=%d nbcode=%d cov[%d]=%lf codtabm(%d,Tvar[%d])=%d \n",agexact,ij,k, k, TvarsD[k],k,TvarsDind[k],nbcode[TvarsD[k]][codtabm(ij,k)],2+nagesqr+TvarsDind[k],cov[2+nagesqr+TvarsDind[k]], ij, k, codtabm(ij,k)); */
       }        }
       for (k=1; k<=nsq;k++) { /* For single varying covariates only */        for (k=1; k<=nsq;k++) { /* For single varying covariates only */
Line 3563  double ***hbxij(double ***po, int nhstep Line 3569  double ***hbxij(double ***po, int nhstep
       }        }
       for (k=1; k<=cptcovprod;k++){ /* Useless because included in cptcovn */        for (k=1; k<=cptcovprod;k++){ /* Useless because included in cptcovn */
         cov[2+nagesqr+Tprod[k]]=nbcode[Tvard[k][1]][codtabm(ij,k)]*nbcode[Tvard[k][2]][codtabm(ij,k)];          cov[2+nagesqr+Tprod[k]]=nbcode[Tvard[k][1]][codtabm(ij,k)]*nbcode[Tvard[k][2]][codtabm(ij,k)];
           if(Dummy[Tvard[k][1]==0]){
             if(Dummy[Tvard[k][2]==0]){
               cov[2+nagesqr+Tprod[k]]=nbcode[Tvard[k][1]][codtabm(ij,k)] * nbcode[Tvard[k][2]][codtabm(ij,k)];
             }else{
               cov[2+nagesqr+Tprod[k]]=nbcode[Tvard[k][1]][codtabm(ij,k)] * Tqresult[nres][k];
             }
           }else{
             if(Dummy[Tvard[k][2]==0]){
               cov[2+nagesqr+Tprod[k]]=nbcode[Tvard[k][2]][codtabm(ij,k)] * Tqinvresult[nres][Tvard[k][1]];
             }else{
               cov[2+nagesqr+Tprod[k]]=Tqinvresult[nres][Tvard[k][1]]*  Tqinvresult[nres][Tvard[k][2]];
             }
           }
       }                         }                 
       /*printf("hxi cptcov=%d cptcode=%d\n",cptcov,cptcode);*/        /*printf("hxi cptcov=%d cptcode=%d\n",cptcov,cptcode);*/
       /*printf("h=%d d=%d age=%f cov=%f\n",h,d,age,cov[2]);*/        /*printf("h=%d d=%d age=%f cov=%f\n",h,d,age,cov[2]);*/
Line 3572  double ***hbxij(double ***po, int nhstep Line 3591  double ***hbxij(double ***po, int nhstep
       /* out=matprod2(newm, bmij(pmmij,cov,ncovmodel,x,nlstate,prevacurrent, dnewm, doldm, dsavm,ij),\ */        /* out=matprod2(newm, bmij(pmmij,cov,ncovmodel,x,nlstate,prevacurrent, dnewm, doldm, dsavm,ij),\ */
       /*                                                 1,nlstate+ndeath,1,nlstate+ndeath,1,nlstate+ndeath, oldm); */        /*                                                 1,nlstate+ndeath,1,nlstate+ndeath,1,nlstate+ndeath, oldm); */
       out=matprod2(newm, bmij(pmmij,cov,ncovmodel,x,nlstate,prevacurrent,ij),\        out=matprod2(newm, bmij(pmmij,cov,ncovmodel,x,nlstate,prevacurrent,ij),\
                    1,nlstate+ndeath,1,nlstate+ndeath,1,nlstate+ndeath, oldm);                     1,nlstate+ndeath,1,nlstate+ndeath,1,nlstate+ndeath, oldm);/* Bug valgrind */
       /* if((int)age == 70){ */        /* if((int)age == 70){ */
       /*        printf(" Backward hbxij age=%d agexact=%f d=%d nhstepm=%d hstepm=%d\n", (int) age, agexact, d, nhstepm, hstepm); */        /*        printf(" Backward hbxij age=%d agexact=%f d=%d nhstepm=%d hstepm=%d\n", (int) age, agexact, d, nhstepm, hstepm); */
       /*        for(i=1; i<=nlstate+ndeath; i++) { */        /*        for(i=1; i<=nlstate+ndeath; i++) { */
Line 8349  set ter svg size 640, 480\nunset log y\n Line 8368  set ter svg size 640, 480\nunset log y\n
             for(j=1; j <=cptcovt; j++) { /* For each covariate of the simplified model */              for(j=1; j <=cptcovt; j++) { /* For each covariate of the simplified model */
               /* printf("Tage[%d]=%d, j=%d\n", ij, Tage[ij], j); */                /* printf("Tage[%d]=%d, j=%d\n", ij, Tage[ij], j); */
               if(cptcovage >0){ /* V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1, 2 V5 and V1 */                if(cptcovage >0){ /* V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1, 2 V5 and V1 */
                 if(j==Tage[ij]) { /* Product by age  To be looked at!!*/                  if(j==Tage[ij]) { /* Product by age  To be looked at!!*//* Bug valgrind */
                   if(ij <=cptcovage) { /* V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1, 2 V5 and V1 */                    if(ij <=cptcovage) { /* V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1, 2 V5 and V1 */
                     if(DummyV[j]==0){                      if(DummyV[j]==0){/* Bug valgrind */
                       fprintf(ficgp,"+p%d*%d*x",i+j+2+nagesqr-1,Tinvresult[nres][Tvar[j]]);;                        fprintf(ficgp,"+p%d*%d*x",i+j+2+nagesqr-1,Tinvresult[nres][Tvar[j]]);;
                     }else{ /* quantitative */                      }else{ /* quantitative */
                       fprintf(ficgp,"+p%d*%f*x",i+j+2+nagesqr-1,Tqinvresult[nres][Tvar[j]]); /* Tqinvresult in decoderesult */                        fprintf(ficgp,"+p%d*%f*x",i+j+2+nagesqr-1,Tqinvresult[nres][Tvar[j]]); /* Tqinvresult in decoderesult */
Line 11180  int hPijx(double *p, int bage, int fage) Line 11199  int hPijx(double *p, int bage, int fage)
   
         /* oldm=oldms;savm=savms; */          /* oldm=oldms;savm=savms; */
         /* hbxij(p3mat,nhstepm,agedeb,hstepm,p,nlstate,stepm,oldm,savm, k);   */          /* hbxij(p3mat,nhstepm,agedeb,hstepm,p,nlstate,stepm,oldm,savm, k);   */
         hbxij(p3mat,nhstepm,agedeb,hstepm,p,prevacurrent,nlstate,stepm, k, nres);          hbxij(p3mat,nhstepm,agedeb,hstepm,p,prevacurrent,nlstate,stepm, k, nres);/* Bug valgrind */
         /* hbxij(p3mat,nhstepm,agedeb,hstepm,p,prevacurrent,nlstate,stepm,oldm,savm, dnewm, doldm, dsavm, k); */          /* hbxij(p3mat,nhstepm,agedeb,hstepm,p,prevacurrent,nlstate,stepm,oldm,savm, dnewm, doldm, dsavm, k); */
         fprintf(ficrespijb,"# Cov Agex agex-h hbijx with i,j=");          fprintf(ficrespijb,"# Cov Agex agex-h hbijx with i,j=");
         for(i=1; i<=nlstate;i++)          for(i=1; i<=nlstate;i++)
Line 11193  int hPijx(double *p, int bage, int fage) Line 11212  int hPijx(double *p, int bage, int fage)
           /* fprintf(ficrespijb,"%d %3.f %3.f",k, agedeb, agedeb + h*hstepm/YEARM*stepm ); */            /* fprintf(ficrespijb,"%d %3.f %3.f",k, agedeb, agedeb + h*hstepm/YEARM*stepm ); */
           for(i=1; i<=nlstate;i++)            for(i=1; i<=nlstate;i++)
             for(j=1; j<=nlstate+ndeath;j++)              for(j=1; j<=nlstate+ndeath;j++)
               fprintf(ficrespijb," %.5f", p3mat[i][j][h]);                fprintf(ficrespijb," %.5f", p3mat[i][j][h]);/* Bug valgrind */
           fprintf(ficrespijb,"\n");            fprintf(ficrespijb,"\n");
         }          }
         free_ma3x(p3mat,1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);          free_ma3x(p3mat,1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);
Line 11878  Please run with mle=-1 to get a correct Line 11897  Please run with mle=-1 to get a correct
   }    }
   mint=matrix(1,maxwav,firstobs,lastobs);    mint=matrix(1,maxwav,firstobs,lastobs);
   anint=matrix(1,maxwav,firstobs,lastobs);    anint=matrix(1,maxwav,firstobs,lastobs);
   s=imatrix(1,maxwav+1,firstobs,lastobs); /* s[i][j] health state for wave i and individual j */     s=imatrix(1,maxwav+1,firstobs,lastobs); /* s[i][j] health state for wave i and individual j */
     printf("BUG ncovmodel=%d NCOVMAX=%d 2**ncovmodel=%f BUG\n",ncovmodel,NCOVMAX,pow(2,ncovmodel));
   tab=ivector(1,NCOVMAX);    tab=ivector(1,NCOVMAX);
   ncodemax=ivector(1,NCOVMAX); /* Number of code per covariate; if O and 1 only, 2**ncov; V1+V2+V3+V4=>16 */    ncodemax=ivector(1,NCOVMAX); /* Number of code per covariate; if O and 1 only, 2**ncov; V1+V2+V3+V4=>16 */
   ncodemaxwundef=ivector(1,NCOVMAX); /* Number of code per covariate; if - 1 O and 1 only, 2**ncov; V1+V2+V3+V4=>16 */    ncodemaxwundef=ivector(1,NCOVMAX); /* Number of code per covariate; if - 1 O and 1 only, 2**ncov; V1+V2+V3+V4=>16 */

Removed from v.1.324  
changed lines
  Added in v.1.325


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