--- imach/src/imach.c 2016/07/21 08:43:33 1.227 +++ imach/src/imach.c 2016/07/22 17:45:30 1.228 @@ -1,8 +1,8 @@ -/* $Id: imach.c,v 1.227 2016/07/21 08:43:33 brouard Exp $ +/* $Id: imach.c,v 1.228 2016/07/22 17:45:30 brouard Exp $ $State: Exp $ $Log: imach.c,v $ - Revision 1.227 2016/07/21 08:43:33 brouard - Summary: 0.99 working (more or less) for Asian Workshop on multitate methods + Revision 1.228 2016/07/22 17:45:30 brouard + Summary: Fixing some arrays, still debugging Revision 1.226 2016/07/12 18:42:34 brouard Summary: temp @@ -884,12 +884,12 @@ typedef struct { #define ODIRSEPARATOR '\\' #endif -/* $Id: imach.c,v 1.227 2016/07/21 08:43:33 brouard Exp $ */ +/* $Id: imach.c,v 1.228 2016/07/22 17:45:30 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.227 $ $Date: 2016/07/21 08:43:33 $"; +char fullversion[]="$Revision: 1.228 $ $Date: 2016/07/22 17:45:30 $"; char strstart[80]; char optionfilext[10], optionfilefiname[FILENAMELENGTH]; int erreur=0, nberr=0, nbwarn=0; /* Error number, number of errors number of warnings */ @@ -1061,7 +1061,9 @@ 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 *Tage; 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 **codtab;*/ /**< codtab=imatrix(1,100,1,10); */ int **Tvard; @@ -2946,10 +2948,9 @@ double func( double *x) int ioffset=0; double l, ll[NLSTATEMAX+1], cov[NCOVMAX+1]; double **out; - double sw; /* Sum of weights */ double lli; /* Individual log likelihood */ 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; long ipmx; double agexact; @@ -2979,7 +2980,7 @@ double func( double *x) cov[++ioffset]=covar[Tvar[k]][i]; } 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] @@ -2996,7 +2997,7 @@ double func( double *x) */ for(mi=1; mi<= wav[i]-1; mi++){ 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 */ if(cotqvar[mw[mi][i]][iqtv][i] == -1){ @@ -3275,15 +3276,16 @@ double func( double *x) /*************** log-likelihood *************/ 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 ioffset=0; + int ioffset=0; double l, ll[NLSTATEMAX+1], cov[NCOVMAX+1]; double **out; double lli; /* Individual log likelihood */ double llt; 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 agexact; double agebegin, ageend; @@ -3309,10 +3311,16 @@ double funcone( double *x) for(mi=1; mi<= wav[i]-1; mi++){ /* Varying with waves */ 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 */ - 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 (j=1;j<=nlstate+ndeath;j++){ @@ -4713,6 +4721,7 @@ void concatwav(int wav[], int **dh, int ++ij; Tvaraff[ij]=Tvar[k]; /*For printing */ Tmodelind[ij]=k; + TmodelInvind[k]=Tvar[k]- ncovcol-nqv; if(Fixed[k]!=0) anyvaryingduminmodel=1; /* }else if((Ndum[i]!=0) && (i<=ncovcol+nqv)){ */ @@ -4732,6 +4741,9 @@ void concatwav(int wav[], int **dh, int Tvaraff[j]=0; Tmodelind[j]=0; } + for(j=ntveff+1; j<= cptcovt; j++){ + TmodelInvind[j]=0; + } /* To be sorted */ ; } @@ -8006,10 +8018,15 @@ Dummy[k] 0=dummy (0 1), 1 quantitative ( Fixed[k]= 1; Dummy[k]= 0; 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){ Fixed[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 */ if (Tvar[k] <=ncovcol ){ /* Simple or product fixed dummy covariatee */ Fixed[k]= 2; @@ -9390,6 +9407,12 @@ Please run with mle=-1 to get a correct * 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*/ + 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 */ @@ -10540,6 +10563,8 @@ Please run with mle=-1 to get a correct free_ivector(invalidvarcomb,1,ncovcombmax); free_ivector(Tage,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(codtab,1,100,1,10); */