]> henry.ined.fr Git - .git/commitdiff
Summary: not working
authorN. Brouard <brouard@ined.fr>
Tue, 23 Aug 2016 07:40:50 +0000 (07:40 +0000)
committerN. Brouard <brouard@ined.fr>
Tue, 23 Aug 2016 07:40:50 +0000 (07:40 +0000)
src/imach.c

index f458575c6e8b05e2f9beab1c14352acc80c7024d..8d929bc163d1019bf5a7939d3538b421b3cb4f25 100644 (file)
@@ -1,6 +1,9 @@
 /* $Id$
   $State$
   $Log$
+  Revision 1.232  2016/08/22 14:20:21  brouard
+  Summary: not working
+
   Revision 1.231  2016/08/22 07:17:15  brouard
   Summary: not working
 
@@ -911,8 +914,8 @@ int cptcovsnq=0; /**< cptcovsnq number of simple covariates in the model but non
 int cptcovage=0; /**< Number of covariates with age: V3*age only =1 */
 int cptcovprodnoage=0; /**< Number of covariate products without age */   
 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 ncovv=0; /* Total number of effective (wave) varying 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 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 ncoveff=0; /* Total number of effective fixed dummy covariates in the model */
@@ -3034,14 +3037,10 @@ double func( double *x)
         to be observed in j being in i according to the model.
       */
       ioffset=2+nagesqr+cptcovage;
-      /* for (k=1; k<=cptcovn;k++){ /\* Simple and product covariates without age* products *\/ */
-      for (k=1; k<=ncoveff;k++){ /* Simple and product covariates without age* products */
-                               cov[++ioffset]=covar[Tvar[k]][i];
-      }
-      for(iqv=1; iqv <= nqfveff; iqv++){ /* Quantitatives and Fixed covariates */
-                               cov[++ioffset]=coqvar[Tvar[iqv]][i];
-      }
-
+   /* Fixed */
+                       for (k=1; k<=ncovf;k++){ /* Simple and product fixed covariates without age* products */
+                               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)*/
+                       }
       /* 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] 
         has been calculated etc */
@@ -3055,18 +3054,9 @@ double func( double *x)
         meaning that decodemodel should be used cotvar[mw[mi+1][i]][TTvar[iv]][i]
       */
       for(mi=1; mi<= wav[i]-1; mi++){
-                               for(itv=1; itv <= ntveff; itv++){ /* Varying dummy covariates */
-                                       /* cov[ioffset+itv]=cotvar[mw[mi][i]][Tvar[itv]][i]; /\* Not sure, Tvar V4+V3+V5 Tvaraff ? *\/ */
-                                       cov[ioffset+itv]=cotvar[mw[mi][i]][TmodelInvind[itv]][i];
+                               for(k=1; k <= ncovv ; k++){ /* Varying  covariates (single and product but no age )*/
+                                       cov[ioffset+TvarVind[k]]=cotvar[mw[mi][i]][Tvar[TvarVind[k]]][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 (j=1;j<=nlstate+ndeath;j++){
                                                oldm[ii][j]=(ii==j ? 1.0 : 0.0);
@@ -3384,10 +3374,11 @@ double funcone( double *x)
     /*   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 */
+    /* Wave varying (but not age varying) */
       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??)*\/ */
                                /* iv= Tvar[Tmodelind[ioffset-2-nagesqr-cptcovage+itv]]-ncovcol-nqv; /\* Counting the # varying covariate from 1 to ntveff *\/ */
@@ -7870,7 +7861,7 @@ int decoderesult ( char resultline[])
   char stra[80], strb[80], strc[80], strd[80],stre[80];
 
   removespace(&resultline);
-  printf("decoderesult=%s\n",resultline);
+  printf("decoderesult:%s\n",resultline);
 
   if (strstr(resultline,"v") !=0){
     printf("Error. 'v' must be in upper case 'V' result: %s ",resultline);
@@ -8207,30 +8198,39 @@ Dummy[k] 0=dummy (0 1), 1 quantitative (single or product without age), 2 dummy
       }
     }else if (Typevar[k] == 2) {  /* product without age */
       k1=Tposprod[k];
-                       ncovv++; /* Only time varying variables */
-                       TvarV[ncovv]=Tvar[k];
-                       TvarVind[ncovv]=k;
       if(Tvard[k1][1] <=ncovcol){
                                if(Tvard[k1][2] <=ncovcol){
                                        Fixed[k]= 1;
                                        Dummy[k]= 0;
                                        modell[k].maintype= FTYPE;
                                        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){
                                        Fixed[k]= 0;  /* or 2 ?*/
                                        Dummy[k]= 1;
                                        modell[k].maintype= FTYPE;
                                        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){
                                        Fixed[k]= 1;
                                        Dummy[k]= 0;
                                        modell[k].maintype= VTYPE;
                                        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){
                                        Fixed[k]= 1;
                                        Dummy[k]= 1;
                                        modell[k].maintype= VTYPE;
                                        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){
                                if(Tvard[k1][2] <=ncovcol){
@@ -8238,16 +8238,28 @@ Dummy[k] 0=dummy (0 1), 1 quantitative (single or product without age), 2 dummy
                                        Dummy[k]= 1;
                                        modell[k].maintype= FTYPE;
                                        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){
                                        Fixed[k]= 1;
                                        Dummy[k]= 1;
                                        modell[k].maintype= VTYPE;
                                        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){
                                        Fixed[k]= 1;
                                        Dummy[k]= 1;
                                        modell[k].maintype= VTYPE;
                                        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){
                                if(Tvard[k1][2] <=ncovcol){
@@ -8255,21 +8267,33 @@ Dummy[k] 0=dummy (0 1), 1 quantitative (single or product without age), 2 dummy
                                        Dummy[k]= 1;
                                        modell[k].maintype= VTYPE;
                                        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){
                                        Fixed[k]= 1;
                                        Dummy[k]= 1;
                                        modell[k].maintype= VTYPE;
                                        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){
                                        Fixed[k]= 1;
                                        Dummy[k]= 0;
                                        modell[k].maintype= VTYPE;
                                        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){
                                        Fixed[k]= 1;
                                        Dummy[k]= 1;
                                        modell[k].maintype= VTYPE;
                                        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){
                                if(Tvard[k1][2] <=ncovcol){
@@ -8277,21 +8301,33 @@ Dummy[k] 0=dummy (0 1), 1 quantitative (single or product without age), 2 dummy
                                        Dummy[k]= 1;
                                        modell[k].maintype= VTYPE;
                                        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){
                                        Fixed[k]= 1;
                                        Dummy[k]= 1;
                                        modell[k].maintype= VTYPE;
                                        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){
                                        Fixed[k]= 1;
                                        Dummy[k]= 1;
                                        modell[k].maintype= VTYPE;
                                        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){
                                        Fixed[k]= 1;
                                        Dummy[k]= 1;
                                        modell[k].maintype= VTYPE;
                                        modell[k].subtype= VPQQ;                /*      Product time varying quantitative * time varying quantitative */
+                                       ncovv++; /* Varying variables without age */
+                                       TvarV[ncovv]=Tvar[k];
+                                       TvarVind[ncovv]=k;
                                } 
       }else{
                                printf("Error unknown type of covariate: Tvard[%d][1]=%d,Tvard[%d][2]=%d\n",k1,Tvard[k1][1],k1,Tvard[k1][2]);
@@ -9327,7 +9363,7 @@ int main(int argc, char *argv[])
    
   covar=matrix(0,NCOVMAX,1,n);  /**< used in readdata */
   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 */
   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
@@ -9588,6 +9624,7 @@ Please run with mle=-1 to get a correct covariance matrix.\n",optionfile,numline
   TvarVQind=ivector(1,NCOVMAX); /*  */
 
   Tvalsel=vector(1,NCOVMAX); /*  */
+  Tvarsel=ivector(1,NCOVMAX); /*  */
   Typevar=ivector(-1,NCOVMAX); /* -1 to 2 */
   Fixed=ivector(-1,NCOVMAX); /* -1 to 3 */
   Dummy=ivector(-1,NCOVMAX); /* -1 to 3 */
@@ -10793,7 +10830,7 @@ Please run with mle=-1 to get a correct covariance matrix.\n",ageminpar,agemaxpa
   free_matrix(newms, 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(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(covar,0,NCOVMAX,1,n);
   free_matrix(matcov,1,npar,1,npar);