Diff for /imach/src/imach.c between versions 1.232 and 1.233

version 1.232, 2016/08/22 14:20:21 version 1.233, 2016/08/23 07:40:50
Line 1 Line 1
 /* $Id$  /* $Id$
   $State$    $State$
   $Log$    $Log$
     Revision 1.233  2016/08/23 07:40:50  brouard
     Summary: not working
   
   Revision 1.232  2016/08/22 14:20:21  brouard    Revision 1.232  2016/08/22 14:20:21  brouard
   Summary: not working    Summary: not working
   
Line 914  int cptcovsnq=0; /**< cptcovsnq number o Line 917  int cptcovsnq=0; /**< cptcovsnq number o
 int cptcovage=0; /**< Number of covariates with age: V3*age only =1 */  int cptcovage=0; /**< Number of covariates with age: V3*age only =1 */
 int cptcovprodnoage=0; /**< Number of covariate products without age */     int cptcovprodnoage=0; /**< Number of covariate products without age */   
 int cptcoveff=0; /* Total number of covariates to vary for printing results */  int cptcoveff=0; /* Total number of covariates to vary for printing results */
 int ncovf=0; /* Total number of effective fixed covariates (dummy of quantitative) in the model */  int ncovf=0; /* Total number of effective fixed covariates (dummy or quantitative) in the model */
 int ncovv=0; /* Total number of effective (wave) varying covariates (dummy of quantitative) in the model */  int ncovv=0; /* Total number of effective (wave) varying covariates (dummy or quantitative) in the model */
 int ncova=0; /* Total number of effective (wave and stepm) varying with age covariates (dummy of quantitative) in the model */  int ncova=0; /* Total number of effective (wave and stepm) varying with age covariates (dummy of quantitative) in the model */
   
 int ncoveff=0; /* Total number of effective fixed dummy covariates in the model */  int ncoveff=0; /* Total number of effective fixed dummy covariates in the model */
Line 3037  double func( double *x) Line 3040  double func( double *x)
          to be observed in j being in i according to the model.           to be observed in j being in i according to the model.
       */        */
       ioffset=2+nagesqr+cptcovage;        ioffset=2+nagesqr+cptcovage;
       /* for (k=1; k<=cptcovn;k++){ /\* Simple and product covariates without age* products *\/ */     /* Fixed */
       for (k=1; k<=ncoveff;k++){ /* Simple and product covariates without age* products */                          for (k=1; k<=ncovf;k++){ /* Simple and product fixed covariates without age* products */
                                 cov[++ioffset]=covar[Tvar[k]][i];                                  cov[ioffset+TvarFind[k]]=covar[Tvar[TvarFind[k]]][i];/* V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1, only V1 is fixed (k=6)*/
       }                          }
       for(iqv=1; iqv <= nqfveff; iqv++){ /* Quantitatives and Fixed covariates */  
                                 cov[++ioffset]=coqvar[Tvar[iqv]][i];  
       }  
   
       /* In model V2+V1*V4+age*V3+V3*V2 Tvar[1] is V2, Tvar[2=V1*V4]         /* In model V2+V1*V4+age*V3+V3*V2 Tvar[1] is V2, Tvar[2=V1*V4] 
          is 6, Tvar[3=age*V3] should not be computed because of age Tvar[4=V3*V2]            is 6, Tvar[3=age*V3] should not be computed because of age Tvar[4=V3*V2] 
          has been calculated etc */           has been calculated etc */
Line 3058  double func( double *x) Line 3057  double func( double *x)
          meaning that decodemodel should be used cotvar[mw[mi+1][i]][TTvar[iv]][i]           meaning that decodemodel should be used cotvar[mw[mi+1][i]][TTvar[iv]][i]
       */        */
       for(mi=1; mi<= wav[i]-1; mi++){        for(mi=1; mi<= wav[i]-1; mi++){
                                 for(itv=1; itv <= ntveff; itv++){ /* Varying dummy covariates */                                  for(k=1; k <= ncovv ; k++){ /* Varying  covariates (single and product but no age )*/
                                         /* cov[ioffset+itv]=cotvar[mw[mi][i]][Tvar[itv]][i]; /\* Not sure, Tvar V4+V3+V5 Tvaraff ? *\/ */                                          cov[ioffset+TvarVind[k]]=cotvar[mw[mi][i]][Tvar[TvarVind[k]]][i];
                                         cov[ioffset+itv]=cotvar[mw[mi][i]][TmodelInvind[itv]][i];  
                                 }                                  }
                                 for(iqtv=1; iqtv <= nqtveff; iqtv++){ /* Varying quantitatives covariates */  
                                         if(cotqvar[mw[mi][i]][iqtv][i] == -1){  
                                                 printf("i=%d, mi=%d, iqtv=%d, cotqvar[mw[mi][i]][iqtv][i]=%f",i,mi,iqtv,cotqvar[mw[mi][i]][iqtv][i]);  
                                         }  
                                         cov[ioffset+ntveff+iqtv]=cotqvar[mw[mi][i]][TmodelInvQind[iqtv]][i];  
                                         /* cov[ioffset+ntveff+iqtv]=cotqvar[mw[mi][i]][iqtv][i]; */  
                                 }  
                                 /* ioffset=2+nagesqr+cptcovn+nqv+ntv+nqtv; */  
                                 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++){
                                                 oldm[ii][j]=(ii==j ? 1.0 : 0.0);                                                  oldm[ii][j]=(ii==j ? 1.0 : 0.0);
Line 3387  double funcone( double *x) Line 3377  double funcone( double *x)
     /*   cov[++ioffset]=coqvar[Tvar[iqv]][i]; /\* Only V2 k=6 and V1*V2 7 *\/ */      /*   cov[++ioffset]=coqvar[Tvar[iqv]][i]; /\* Only V2 k=6 and V1*V2 7 *\/ */
     /* } */      /* } */
           
     /* Wave varying (but not age varying) */  
     for(mi=1; mi<= wav[i]-1; mi++){  /* Varying with waves */      for(mi=1; mi<= wav[i]-1; mi++){  /* Varying with waves */
       /* Wave varying (but not age varying) */
       for(k=1; k <= ncovv ; k++){ /* Varying  covariates (single and product but no age )*/        for(k=1; k <= ncovv ; k++){ /* Varying  covariates (single and product but no age )*/
                                 cov[ioffset+TvarVind[k]]=cotvar[mw[mi][i]][Tvar[TvarFind[k]]][i];                                  cov[ioffset+TvarVind[k]]=cotvar[mw[mi][i]][Tvar[TvarVind[k]]][i];
                         }                          }
       /* for(itv=1; itv <= ntveff; itv++){ /\* Varying dummy covariates (single??)*\/ */        /* for(itv=1; itv <= ntveff; itv++){ /\* Varying dummy covariates (single??)*\/ */
                                 /* iv= Tvar[Tmodelind[ioffset-2-nagesqr-cptcovage+itv]]-ncovcol-nqv; /\* Counting the # varying covariate from 1 to ntveff *\/ */                                  /* iv= Tvar[Tmodelind[ioffset-2-nagesqr-cptcovage+itv]]-ncovcol-nqv; /\* Counting the # varying covariate from 1 to ntveff *\/ */
Line 7873  int decoderesult ( char resultline[]) Line 7864  int decoderesult ( char resultline[])
   char stra[80], strb[80], strc[80], strd[80],stre[80];    char stra[80], strb[80], strc[80], strd[80],stre[80];
   
   removespace(&resultline);    removespace(&resultline);
   printf("decoderesult=%s\n",resultline);    printf("decoderesult:%s\n",resultline);
   
   if (strstr(resultline,"v") !=0){    if (strstr(resultline,"v") !=0){
     printf("Error. 'v' must be in upper case 'V' result: %s ",resultline);      printf("Error. 'v' must be in upper case 'V' result: %s ",resultline);
Line 8210  Dummy[k] 0=dummy (0 1), 1 quantitative ( Line 8201  Dummy[k] 0=dummy (0 1), 1 quantitative (
       }        }
     }else if (Typevar[k] == 2) {  /* product without age */      }else if (Typevar[k] == 2) {  /* product without age */
       k1=Tposprod[k];        k1=Tposprod[k];
                         ncovv++; /* Only time varying variables */  
                         TvarV[ncovv]=Tvar[k];  
                         TvarVind[ncovv]=k;  
       if(Tvard[k1][1] <=ncovcol){        if(Tvard[k1][1] <=ncovcol){
                                 if(Tvard[k1][2] <=ncovcol){                                  if(Tvard[k1][2] <=ncovcol){
                                         Fixed[k]= 1;                                          Fixed[k]= 1;
                                         Dummy[k]= 0;                                          Dummy[k]= 0;
                                         modell[k].maintype= FTYPE;                                          modell[k].maintype= FTYPE;
                                         modell[k].subtype= FPDD;                /*      Product fixed dummy * fixed dummy */                                          modell[k].subtype= FPDD;                /*      Product fixed dummy * fixed dummy */
                                           ncovf++; /* Fixed variables without age */
                                           TvarF[ncovf]=Tvar[k];
                                           TvarFind[ncovf]=k;
                                 }else if(Tvard[k1][2] <=ncovcol+nqv){                                  }else if(Tvard[k1][2] <=ncovcol+nqv){
                                         Fixed[k]= 0;  /* or 2 ?*/                                          Fixed[k]= 0;  /* or 2 ?*/
                                         Dummy[k]= 1;                                          Dummy[k]= 1;
                                         modell[k].maintype= FTYPE;                                          modell[k].maintype= FTYPE;
                                         modell[k].subtype= FPDQ;                /*      Product fixed dummy * fixed quantitative */                                          modell[k].subtype= FPDQ;                /*      Product fixed dummy * fixed quantitative */
                                           ncovf++; /* Varying variables without age */
                                           TvarF[ncovf]=Tvar[k];
                                           TvarFind[ncovf]=k;
                                 }else if(Tvard[k1][2] <=ncovcol+nqv+ntv){                                  }else if(Tvard[k1][2] <=ncovcol+nqv+ntv){
                                         Fixed[k]= 1;                                          Fixed[k]= 1;
                                         Dummy[k]= 0;                                          Dummy[k]= 0;
                                         modell[k].maintype= VTYPE;                                          modell[k].maintype= VTYPE;
                                         modell[k].subtype= VPDD;                /*      Product fixed dummy * varying dummy */                                          modell[k].subtype= VPDD;                /*      Product fixed dummy * varying dummy */
                                           ncovv++; /* Varying variables without age */
                                           TvarV[ncovv]=Tvar[k];
                                           TvarVind[ncovv]=k;
                                 }else if(Tvard[k1][2] <=ncovcol+nqv+ntv+nqtv){                                  }else if(Tvard[k1][2] <=ncovcol+nqv+ntv+nqtv){
                                         Fixed[k]= 1;                                          Fixed[k]= 1;
                                         Dummy[k]= 1;                                          Dummy[k]= 1;
                                         modell[k].maintype= VTYPE;                                          modell[k].maintype= VTYPE;
                                         modell[k].subtype= VPDQ;                /*      Product fixed dummy * varying quantitative */                                          modell[k].subtype= VPDQ;                /*      Product fixed dummy * varying quantitative */
                                           ncovv++; /* Varying variables without age */
                                           TvarV[ncovv]=Tvar[k];
                                           TvarVind[ncovv]=k;
                                 }                                   } 
       }else if(Tvard[k1][1] <=ncovcol+nqv){        }else if(Tvard[k1][1] <=ncovcol+nqv){
                                 if(Tvard[k1][2] <=ncovcol){                                  if(Tvard[k1][2] <=ncovcol){
Line 8241  Dummy[k] 0=dummy (0 1), 1 quantitative ( Line 8241  Dummy[k] 0=dummy (0 1), 1 quantitative (
                                         Dummy[k]= 1;                                          Dummy[k]= 1;
                                         modell[k].maintype= FTYPE;                                          modell[k].maintype= FTYPE;
                                         modell[k].subtype= FPDQ;                /*      Product fixed quantitative * fixed dummy */                                          modell[k].subtype= FPDQ;                /*      Product fixed quantitative * fixed dummy */
                                           ncovf++; /* Fixed variables without age */
                                           TvarF[ncovf]=Tvar[k];
                                           TvarFind[ncovf]=k;
                                 }else if(Tvard[k1][2] <=ncovcol+nqv+ntv){                                  }else if(Tvard[k1][2] <=ncovcol+nqv+ntv){
                                         Fixed[k]= 1;                                          Fixed[k]= 1;
                                         Dummy[k]= 1;                                          Dummy[k]= 1;
                                         modell[k].maintype= VTYPE;                                          modell[k].maintype= VTYPE;
                                         modell[k].subtype= VPDQ;                /*      Product fixed quantitative * varying dummy */                                          modell[k].subtype= VPDQ;                /*      Product fixed quantitative * varying dummy */
                                           ncovv++; /* Varying variables without age */
                                           TvarV[ncovv]=Tvar[k];
                                           TvarVind[ncovv]=k;
                                 }else if(Tvard[k1][2] <=ncovcol+nqv+ntv+nqtv){                                  }else if(Tvard[k1][2] <=ncovcol+nqv+ntv+nqtv){
                                         Fixed[k]= 1;                                          Fixed[k]= 1;
                                         Dummy[k]= 1;                                          Dummy[k]= 1;
                                         modell[k].maintype= VTYPE;                                          modell[k].maintype= VTYPE;
                                         modell[k].subtype= VPQQ;                /*      Product fixed quantitative * varying quantitative */                                          modell[k].subtype= VPQQ;                /*      Product fixed quantitative * varying quantitative */
                                           ncovv++; /* Varying variables without age */
                                           TvarV[ncovv]=Tvar[k];
                                           TvarVind[ncovv]=k;
                                           ncovv++; /* Varying variables without age */
                                           TvarV[ncovv]=Tvar[k];
                                           TvarVind[ncovv]=k;
                                 }                                   } 
       }else if(Tvard[k1][1] <=ncovcol+nqv+ntv){        }else if(Tvard[k1][1] <=ncovcol+nqv+ntv){
                                 if(Tvard[k1][2] <=ncovcol){                                  if(Tvard[k1][2] <=ncovcol){
Line 8258  Dummy[k] 0=dummy (0 1), 1 quantitative ( Line 8270  Dummy[k] 0=dummy (0 1), 1 quantitative (
                                         Dummy[k]= 1;                                          Dummy[k]= 1;
                                         modell[k].maintype= VTYPE;                                          modell[k].maintype= VTYPE;
                                         modell[k].subtype= VPDD;                /*      Product time varying dummy * fixed dummy */                                          modell[k].subtype= VPDD;                /*      Product time varying dummy * fixed dummy */
                                           ncovv++; /* Varying variables without age */
                                           TvarV[ncovv]=Tvar[k];
                                           TvarVind[ncovv]=k;
                                 }else if(Tvard[k1][2] <=ncovcol+nqv){                                  }else if(Tvard[k1][2] <=ncovcol+nqv){
                                         Fixed[k]= 1;                                          Fixed[k]= 1;
                                         Dummy[k]= 1;                                          Dummy[k]= 1;
                                         modell[k].maintype= VTYPE;                                          modell[k].maintype= VTYPE;
                                         modell[k].subtype= VPDQ;                /*      Product time varying dummy * fixed quantitative */                                          modell[k].subtype= VPDQ;                /*      Product time varying dummy * fixed quantitative */
                                           ncovv++; /* Varying variables without age */
                                           TvarV[ncovv]=Tvar[k];
                                           TvarVind[ncovv]=k;
                                 }else if(Tvard[k1][2] <=ncovcol+nqv+ntv){                                  }else if(Tvard[k1][2] <=ncovcol+nqv+ntv){
                                         Fixed[k]= 1;                                          Fixed[k]= 1;
                                         Dummy[k]= 0;                                          Dummy[k]= 0;
                                         modell[k].maintype= VTYPE;                                          modell[k].maintype= VTYPE;
                                         modell[k].subtype= VPDD;                /*      Product time varying dummy * time varying dummy */                                          modell[k].subtype= VPDD;                /*      Product time varying dummy * time varying dummy */
                                           ncovv++; /* Varying variables without age */
                                           TvarV[ncovv]=Tvar[k];
                                           TvarVind[ncovv]=k;
                                 }else if(Tvard[k1][2] <=ncovcol+nqv+ntv+nqtv){                                  }else if(Tvard[k1][2] <=ncovcol+nqv+ntv+nqtv){
                                         Fixed[k]= 1;                                          Fixed[k]= 1;
                                         Dummy[k]= 1;                                          Dummy[k]= 1;
                                         modell[k].maintype= VTYPE;                                          modell[k].maintype= VTYPE;
                                         modell[k].subtype= VPDQ;                /*      Product time varying dummy * time varying quantitative */                                          modell[k].subtype= VPDQ;                /*      Product time varying dummy * time varying quantitative */
                                           ncovv++; /* Varying variables without age */
                                           TvarV[ncovv]=Tvar[k];
                                           TvarVind[ncovv]=k;
                                 }                                   } 
       }else if(Tvard[k1][1] <=ncovcol+nqv+ntv+nqtv){        }else if(Tvard[k1][1] <=ncovcol+nqv+ntv+nqtv){
                                 if(Tvard[k1][2] <=ncovcol){                                  if(Tvard[k1][2] <=ncovcol){
Line 8280  Dummy[k] 0=dummy (0 1), 1 quantitative ( Line 8304  Dummy[k] 0=dummy (0 1), 1 quantitative (
                                         Dummy[k]= 1;                                          Dummy[k]= 1;
                                         modell[k].maintype= VTYPE;                                          modell[k].maintype= VTYPE;
                                         modell[k].subtype= VPDQ;                /*      Product time varying quantitative * fixed dummy */                                          modell[k].subtype= VPDQ;                /*      Product time varying quantitative * fixed dummy */
                                           ncovv++; /* Varying variables without age */
                                           TvarV[ncovv]=Tvar[k];
                                           TvarVind[ncovv]=k;
                                 }else if(Tvard[k1][2] <=ncovcol+nqv){                                  }else if(Tvard[k1][2] <=ncovcol+nqv){
                                         Fixed[k]= 1;                                          Fixed[k]= 1;
                                         Dummy[k]= 1;                                          Dummy[k]= 1;
                                         modell[k].maintype= VTYPE;                                          modell[k].maintype= VTYPE;
                                         modell[k].subtype= VPQQ;                /*      Product time varying quantitative * fixed quantitative */                                          modell[k].subtype= VPQQ;                /*      Product time varying quantitative * fixed quantitative */
                                           ncovv++; /* Varying variables without age */
                                           TvarV[ncovv]=Tvar[k];
                                           TvarVind[ncovv]=k;
                                 }else if(Tvard[k1][2] <=ncovcol+nqv+ntv){                                  }else if(Tvard[k1][2] <=ncovcol+nqv+ntv){
                                         Fixed[k]= 1;                                          Fixed[k]= 1;
                                         Dummy[k]= 1;                                          Dummy[k]= 1;
                                         modell[k].maintype= VTYPE;                                          modell[k].maintype= VTYPE;
                                         modell[k].subtype= VPDQ;                /*      Product time varying quantitative * time varying dummy */                                          modell[k].subtype= VPDQ;                /*      Product time varying quantitative * time varying dummy */
                                           ncovv++; /* Varying variables without age */
                                           TvarV[ncovv]=Tvar[k];
                                           TvarVind[ncovv]=k;
                                 }else if(Tvard[k1][2] <=ncovcol+nqv+ntv+nqtv){                                  }else if(Tvard[k1][2] <=ncovcol+nqv+ntv+nqtv){
                                         Fixed[k]= 1;                                          Fixed[k]= 1;
                                         Dummy[k]= 1;                                          Dummy[k]= 1;
                                         modell[k].maintype= VTYPE;                                          modell[k].maintype= VTYPE;
                                         modell[k].subtype= VPQQ;                /*      Product time varying quantitative * time varying quantitative */                                          modell[k].subtype= VPQQ;                /*      Product time varying quantitative * time varying quantitative */
                                           ncovv++; /* Varying variables without age */
                                           TvarV[ncovv]=Tvar[k];
                                           TvarVind[ncovv]=k;
                                 }                                   } 
       }else{        }else{
                                 printf("Error unknown type of covariate: Tvard[%d][1]=%d,Tvard[%d][2]=%d\n",k1,Tvard[k1][1],k1,Tvard[k1][2]);                                  printf("Error unknown type of covariate: Tvard[%d][1]=%d,Tvard[%d][2]=%d\n",k1,Tvard[k1][1],k1,Tvard[k1][2]);
Line 9330  int main(int argc, char *argv[]) Line 9366  int main(int argc, char *argv[])
         
   covar=matrix(0,NCOVMAX,1,n);  /**< used in readdata */    covar=matrix(0,NCOVMAX,1,n);  /**< used in readdata */
   coqvar=matrix(1,nqv,1,n);  /**< Fixed quantitative covariate */    coqvar=matrix(1,nqv,1,n);  /**< Fixed quantitative covariate */
   cotvar=ma3x(1,maxwav,1,ntv,1,n);  /**< Time varying covariate */    cotvar=ma3x(1,maxwav,1,ntv+nqtv,1,n);  /**< Time varying covariate (dummy and quantitative)*/
   cotqvar=ma3x(1,maxwav,1,nqtv,1,n);  /**< Time varying quantitative covariate */    cotqvar=ma3x(1,maxwav,1,nqtv,1,n);  /**< Time varying quantitative covariate */
   cptcovn=0; /*Number of covariates, i.e. number of '+' in model statement plus one, indepently of n in Vn*/    cptcovn=0; /*Number of covariates, i.e. number of '+' in model statement plus one, indepently of n in Vn*/
   /* v1+v2+v3+v2*v4+v5*age makes cptcovn = 5    /* v1+v2+v3+v2*v4+v5*age makes cptcovn = 5
Line 9591  Please run with mle=-1 to get a correct Line 9627  Please run with mle=-1 to get a correct
   TvarVQind=ivector(1,NCOVMAX); /*  */    TvarVQind=ivector(1,NCOVMAX); /*  */
   
   Tvalsel=vector(1,NCOVMAX); /*  */    Tvalsel=vector(1,NCOVMAX); /*  */
     Tvarsel=ivector(1,NCOVMAX); /*  */
   Typevar=ivector(-1,NCOVMAX); /* -1 to 2 */    Typevar=ivector(-1,NCOVMAX); /* -1 to 2 */
   Fixed=ivector(-1,NCOVMAX); /* -1 to 3 */    Fixed=ivector(-1,NCOVMAX); /* -1 to 3 */
   Dummy=ivector(-1,NCOVMAX); /* -1 to 3 */    Dummy=ivector(-1,NCOVMAX); /* -1 to 3 */
Line 10796  Please run with mle=-1 to get a correct Line 10833  Please run with mle=-1 to get a correct
   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_ma3x(cotqvar,1,maxwav,1,nqtv,1,n);    free_ma3x(cotqvar,1,maxwav,1,nqtv,1,n);
   free_ma3x(cotvar,1,maxwav,1,ntv,1,n);    free_ma3x(cotvar,1,maxwav,1,ntv+nqtv,1,n);
   free_matrix(coqvar,1,maxwav,1,n);    free_matrix(coqvar,1,maxwav,1,n);
   free_matrix(covar,0,NCOVMAX,1,n);    free_matrix(covar,0,NCOVMAX,1,n);
   free_matrix(matcov,1,npar,1,npar);    free_matrix(matcov,1,npar,1,npar);

Removed from v.1.232  
changed lines
  Added in v.1.233


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