--- imach/src/imach.c 2016/08/22 14:20:21 1.232 +++ imach/src/imach.c 2016/08/23 07:40:50 1.233 @@ -1,6 +1,9 @@ -/* $Id: imach.c,v 1.232 2016/08/22 14:20:21 brouard Exp $ +/* $Id: imach.c,v 1.233 2016/08/23 07:40:50 brouard Exp $ $State: Exp $ $Log: imach.c,v $ + Revision 1.233 2016/08/23 07:40:50 brouard + Summary: not working + Revision 1.232 2016/08/22 14:20:21 brouard Summary: not working @@ -896,12 +899,12 @@ typedef struct { #define ODIRSEPARATOR '\\' #endif -/* $Id: imach.c,v 1.232 2016/08/22 14:20:21 brouard Exp $ */ +/* $Id: imach.c,v 1.233 2016/08/23 07:40:50 brouard Exp $ */ /* $State: Exp $ */ #include "version.h" char version[]=__IMACH_VERSION__; char copyright[]="February 2016,INED-EUROREVES-Institut de longevite-Japan Society for the Promotion of Science (Grant-in-Aid for Scientific Research 25293121), Intel Software 2015-2018"; -char fullversion[]="$Revision: 1.232 $ $Date: 2016/08/22 14:20:21 $"; +char fullversion[]="$Revision: 1.233 $ $Date: 2016/08/23 07:40:50 $"; char strstart[80]; char optionfilext[10], optionfilefiname[FILENAMELENGTH]; int erreur=0, nberr=0, nbwarn=0; /* Error number, number of errors number of warnings */ @@ -914,8 +917,8 @@ int cptcovsnq=0; /**< cptcovsnq number o 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 */ @@ -3037,14 +3040,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 */ @@ -3058,18 +3057,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); @@ -3387,10 +3377,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 *\/ */ @@ -7873,7 +7864,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); @@ -8210,30 +8201,39 @@ Dummy[k] 0=dummy (0 1), 1 quantitative ( } }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){ @@ -8241,16 +8241,28 @@ Dummy[k] 0=dummy (0 1), 1 quantitative ( 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){ @@ -8258,21 +8270,33 @@ Dummy[k] 0=dummy (0 1), 1 quantitative ( 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){ @@ -8280,21 +8304,33 @@ Dummy[k] 0=dummy (0 1), 1 quantitative ( 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]); @@ -9330,7 +9366,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 @@ -9591,6 +9627,7 @@ Please run with mle=-1 to get a correct 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 */ @@ -10796,7 +10833,7 @@ Please run with mle=-1 to get a correct 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);