Diff for /imach/src/imach.c between versions 1.227 and 1.228

version 1.227, 2016/07/21 08:43:33 version 1.228, 2016/07/22 17:45:30
Line 1 Line 1
 /* $Id$  /* $Id$
   $State$    $State$
   $Log$    $Log$
   Revision 1.227  2016/07/21 08:43:33  brouard    Revision 1.228  2016/07/22 17:45:30  brouard
   Summary: 0.99 working (more or less) for Asian Workshop on multitate methods    Summary: Fixing some arrays, still debugging
   
   Revision 1.226  2016/07/12 18:42:34  brouard    Revision 1.226  2016/07/12 18:42:34  brouard
   Summary: temp    Summary: temp
Line 1061  int *Fixed; /** Fixed[k] 0=fixed, 1 vary Line 1061  int *Fixed; /** Fixed[k] 0=fixed, 1 vary
 int *Dummy; /** Dummy[k] 0=dummy (0 1), 1 quantitative (single or product without age), 2 dummy with age product, 3 quant with age product */   int *Dummy; /** Dummy[k] 0=dummy (0 1), 1 quantitative (single or product without age), 2 dummy with age product, 3 quant with age product */ 
 int *Tage;  int *Tage;
 int anyvaryingduminmodel=0; /**< Any varying dummy in Model=1 yes, 0 no, to avoid a loop on waves in freq */   int anyvaryingduminmodel=0; /**< Any varying dummy in Model=1 yes, 0 no, to avoid a loop on waves in freq */ 
 int *Tmodelind; /** Tmodelind[Tvaraff[3]]=9,Tvaraff[1]@9={4, 3, 1, 0, 0, 0, 0, 0, 0}, model=V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1*/  int *Tmodelind; /** Tmodelind[Tvaraff[3]]=9 for V1 position,Tvaraff[1]@9={4, 3, 1, 0, 0, 0, 0, 0, 0}, model=V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1*/
   int *TmodelInvind; /** Tmodelind[Tvaraff[3]]=9 for V1 position,Tvaraff[1]@9={4, 3, 1, 0, 0, 0, 0, 0, 0}, model=V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1*/
   int *TmodelInvQind; /** Tmodelqind[1]=1 for V5(quantitative varying) position,Tvaraff[1]@9={4, 3, 1, 0, 0, 0, 0, 0, 0}, model=V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1*/
 int *Ndum; /** Freq of modality (tricode */  int *Ndum; /** Freq of modality (tricode */
 /* int **codtab;*/ /**< codtab=imatrix(1,100,1,10); */  /* int **codtab;*/ /**< codtab=imatrix(1,100,1,10); */
 int **Tvard;  int **Tvard;
Line 2946  double func( double *x) Line 2948  double func( double *x)
   int ioffset=0;    int ioffset=0;
   double l, ll[NLSTATEMAX+1], cov[NCOVMAX+1];    double l, ll[NLSTATEMAX+1], cov[NCOVMAX+1];
   double **out;    double **out;
   double sw; /* Sum of weights */  
   double lli; /* Individual log likelihood */    double lli; /* Individual log likelihood */
   int s1, s2;    int s1, s2;
   int iv=0, iqv=0, itv=0, iqtv=0 ; /* Index of varying covariate, fixed quantitative cov, time varying covariate, quatitative time varying covariate */    int iv=0, iqv=0, itv=0, iqtv=0 ; /* Index of varying covariate, fixed quantitative cov, time varying covariate, quantitative time varying covariate */
   double bbh, survp;    double bbh, survp;
   long ipmx;    long ipmx;
   double agexact;    double agexact;
Line 2979  double func( double *x) Line 2980  double func( double *x)
         cov[++ioffset]=covar[Tvar[k]][i];          cov[++ioffset]=covar[Tvar[k]][i];
       }        }
       for(iqv=1; iqv <= nqfveff; iqv++){ /* Quantitatives and Fixed covariates */        for(iqv=1; iqv <= nqfveff; iqv++){ /* Quantitatives and Fixed covariates */
         cov[++ioffset]=coqvar[iqv][i];          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] 
Line 2996  double func( double *x) Line 2997  double func( double *x)
       */        */
       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(itv=1; itv <= ntveff; itv++){ /* Varying dummy covariates */
           cov[ioffset+itv]=cotvar[mw[mi][i]][itv][i];            cov[ioffset+itv]=cotvar[mw[mi][i]][Tvar[itv]][i]; /* Not sure, Tvar V4+V3+V5 Tvaraff ? */
         }          }
         for(iqtv=1; iqtv <= nqtveff; iqtv++){ /* Varying quantitatives covariates */          for(iqtv=1; iqtv <= nqtveff; iqtv++){ /* Varying quantitatives covariates */
           if(cotqvar[mw[mi][i]][iqtv][i] == -1){            if(cotqvar[mw[mi][i]][iqtv][i] == -1){
Line 3275  double func( double *x) Line 3276  double func( double *x)
 /*************** log-likelihood *************/  /*************** log-likelihood *************/
 double funcone( double *x)  double funcone( double *x)
 {  {
   /* Same as likeli but slower because of a lot of printf and if */    /* Same as func but slower because of a lot of printf and if */
   int i, ii, j, k, mi, d, kk;    int i, ii, j, k, mi, d, kk;
         int ioffset=0;    int ioffset=0;
   double l, ll[NLSTATEMAX+1], cov[NCOVMAX+1];    double l, ll[NLSTATEMAX+1], cov[NCOVMAX+1];
   double **out;    double **out;
   double lli; /* Individual log likelihood */    double lli; /* Individual log likelihood */
   double llt;    double llt;
   int s1, s2;    int s1, s2;
         int iv=0, iqv=0, itv=0, iqtv=0 ; /* Index of varying covariate, fixed quantitative cov, time varying covariate */    int iv=0, iqv=0, itv=0, iqtv=0 ; /* Index of varying covariate, fixed quantitative cov, time varying covariate, quantitative time varying covariate */
   
   double bbh, survp;    double bbh, survp;
   double agexact;    double agexact;
   double agebegin, ageend;    double agebegin, ageend;
Line 3309  double funcone( double *x) Line 3311  double funcone( double *x)
           
     for(mi=1; mi<= wav[i]-1; mi++){  /* Varying with waves */      for(mi=1; mi<= wav[i]-1; mi++){  /* Varying with waves */
       for(itv=1; itv <= ntveff; itv++){ /* Varying dummy covariates */        for(itv=1; itv <= ntveff; itv++){ /* Varying dummy covariates */
         cov[ioffset+itv]=cotvar[mw[mi][i]][itv][i];          /* iv= Tvar[Tmodelind[ioffset-2-nagesqr-cptcovage+itv]]-ncovcol-nqv; /\* Counting the # varying covariate from 1 to ntveff *\/ */
           /* cov[ioffset+iv]=cotvar[mw[mi][i]][iv][i]; */
           k=ioffset-2-nagesqr-cptcovage+itv; /* position in simple model */
           cov[ioffset+itv]=cotvar[mw[mi][i]][TmodelInvind[itv]][i];
           printf(" i=%d,mi=%d,itv=%d,TmodelInvind[itv]=%d,cotvar[mw[mi][i]][TmodelInvind[itv]][i]=%f\n", i, mi, itv, TmodelInvind[itv],cotvar[mw[mi][i]][TmodelInvind[itv]][i]);
       }        }
       for(iqtv=1; iqtv <= nqtveff; iqtv++){ /* Varying quantitatives covariates */        for(iqtv=1; iqtv <= nqtveff; iqtv++){ /* Varying quantitatives covariates */
         cov[ioffset+ntveff+iqtv]=cotqvar[mw[mi][i]][iqtv][i];          iv=TmodelInvQind[iqtv]; /* Counting the # varying covariate from 1 to ntveff */
           printf(" i=%d,mi=%d,iqtv=%d,TmodelInvQind[iqtv]=%d,cotqvar[mw[mi][i]][TmodelInvQind[iqtv]][i]=%f\n", i, mi, iqtv, TmodelInvQind[iqtv],cotqvar[mw[mi][i]][TmodelInvQind[iqtv]][i]);
           cov[ioffset+ntveff+iqtv]=cotqvar[mw[mi][i]][TmodelInvQind[iqtv]][i];
       }        }
       for (ii=1;ii<=nlstate+ndeath;ii++)        for (ii=1;ii<=nlstate+ndeath;ii++)
         for (j=1;j<=nlstate+ndeath;j++){          for (j=1;j<=nlstate+ndeath;j++){
Line 4713  void  concatwav(int wav[], int **dh, int Line 4721  void  concatwav(int wav[], int **dh, int
       ++ij;        ++ij;
       Tvaraff[ij]=Tvar[k]; /*For printing */        Tvaraff[ij]=Tvar[k]; /*For printing */
       Tmodelind[ij]=k;        Tmodelind[ij]=k;
         TmodelInvind[k]=Tvar[k]- ncovcol-nqv;
       if(Fixed[k]!=0)        if(Fixed[k]!=0)
         anyvaryingduminmodel=1;          anyvaryingduminmodel=1;
     /* }else if((Ndum[i]!=0) && (i<=ncovcol+nqv)){ */      /* }else if((Ndum[i]!=0) && (i<=ncovcol+nqv)){ */
Line 4732  void  concatwav(int wav[], int **dh, int Line 4741  void  concatwav(int wav[], int **dh, int
     Tvaraff[j]=0;      Tvaraff[j]=0;
     Tmodelind[j]=0;      Tmodelind[j]=0;
   }    }
     for(j=ntveff+1; j<= cptcovt; j++){
       TmodelInvind[j]=0;
     }
   /* To be sorted */    /* To be sorted */
   ;    ;
 }  }
Line 8006  Dummy[k] 0=dummy (0 1), 1 quantitative ( Line 8018  Dummy[k] 0=dummy (0 1), 1 quantitative (
       Fixed[k]= 1;        Fixed[k]= 1;
       Dummy[k]= 0;        Dummy[k]= 0;
       ntveff++; /* Only simple time varying dummy variable */        ntveff++; /* Only simple time varying dummy variable */
         printf("Quasi Tmodelind[%d]=%d,Tvar[Tmodelind[%d]]=V%d, ncovcol=%d, nqv=%d,Tvar[k]- ncovcol-nqv=%d\n",ntveff,k,ntveff,Tvar[k], ncovcol, nqv,Tvar[k]- ncovcol-nqv);
         printf("Quasi TmodelInvind[%d]=%d\n",k,Tvar[k]- ncovcol-nqv);
     }else if( Tvar[k] <=ncovcol+nqv+ntv+nqtv  && Typevar[k]==0){      }else if( Tvar[k] <=ncovcol+nqv+ntv+nqtv  && Typevar[k]==0){
         Fixed[k]= 1;          Fixed[k]= 1;
         Dummy[k]= 1;          Dummy[k]= 1;
         nqtveff++;/* Only simple time varying quantitative variable */          TmodelInvQind[++nqtveff]=Tvar[k]- ncovcol-nqv-ntv;/* Only simple time varying quantitative variable */
           /* Tmodeliqind[k]=nqtveff;/\* Only simple time varying quantitative variable *\/ */
           printf("Quasi TmodelQind[%d]=%d,Tvar[TmodelQind[%d]]=V%d, ncovcol=%d, nqv=%d, ntv=%d,Tvar[k]- ncovcol-nqv-ntv=%d\n",nqtveff,k,nqtveff,Tvar[k], ncovcol, nqv, ntv, Tvar[k]- ncovcol-nqv-ntv);
         printf("Quasi TmodelInvQind[%d]=%d\n",k,Tvar[k]- ncovcol-nqv-ntv);
     }else if (Typevar[k] == 1) {  /* product with age */      }else if (Typevar[k] == 1) {  /* product with age */
       if (Tvar[k] <=ncovcol ){ /* Simple or product fixed dummy covariatee */        if (Tvar[k] <=ncovcol ){ /* Simple or product fixed dummy covariatee */
         Fixed[k]= 2;          Fixed[k]= 2;
Line 9390  Please run with mle=-1 to get a correct Line 9407  Please run with mle=-1 to get a correct
                                 * Tmodelind[Tvaraff[3]]=9,Tvaraff[1]@9={4,                                  * Tmodelind[Tvaraff[3]]=9,Tvaraff[1]@9={4,
                                 * 3, 1, 0, 0, 0, 0, 0, 0},                                  * 3, 1, 0, 0, 0, 0, 0, 0},
                                 * model=V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1*/                                  * model=V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1*/
    TmodelInvind=ivector(1,NCOVMAX);
     TmodelInvQind=ivector(1,NCOVMAX);/** five the k model position of an
                                   * individual quantitative, fixed or varying:
                                   * Tmodelqind[1]=1,Tvaraff[1]@9={4,
                                   * 3, 1, 0, 0, 0, 0, 0, 0},
                                   * model=V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1*/
 /* Main decodemodel */  /* Main decodemodel */
   
   
Line 10540  Please run with mle=-1 to get a correct Line 10563  Please run with mle=-1 to get a correct
   free_ivector(invalidvarcomb,1,ncovcombmax);    free_ivector(invalidvarcomb,1,ncovcombmax);
   free_ivector(Tage,1,NCOVMAX);    free_ivector(Tage,1,NCOVMAX);
   free_ivector(Tmodelind,1,NCOVMAX);    free_ivector(Tmodelind,1,NCOVMAX);
     free_ivector(TmodelInvind,1,NCOVMAX);
     free_ivector(TmodelInvQind,1,NCOVMAX);
       
   free_imatrix(nbcode,0,NCOVMAX,0,NCOVMAX);    free_imatrix(nbcode,0,NCOVMAX,0,NCOVMAX);
   /* free_imatrix(codtab,1,100,1,10); */    /* free_imatrix(codtab,1,100,1,10); */

Removed from v.1.227  
changed lines
  Added in v.1.228


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