--- imach/src/imach.c 2022/09/11 07:53:11 1.340 +++ imach/src/imach.c 2022/09/11 07:58:42 1.341 @@ -1,6 +1,11 @@ -/* $Id: imach.c,v 1.340 2022/09/11 07:53:11 brouard Exp $ +/* $Id: imach.c,v 1.341 2022/09/11 07:58:42 brouard Exp $ $State: Exp $ $Log: imach.c,v $ + Revision 1.341 2022/09/11 07:58:42 brouard + Summary: Version 0.99r38 + + After adding change in cotvar. + Revision 1.340 2022/09/11 07:53:11 brouard Summary: Version imach 0.99r37 @@ -1316,12 +1321,12 @@ typedef struct { #define ODIRSEPARATOR '\\' #endif -/* $Id: imach.c,v 1.340 2022/09/11 07:53:11 brouard Exp $ */ +/* $Id: imach.c,v 1.341 2022/09/11 07:58:42 brouard Exp $ */ /* $State: Exp $ */ #include "version.h" char version[]=__IMACH_VERSION__; char copyright[]="September 2022,INED-EUROREVES-Institut de longevite-Japan Society for the Promotion of Science (Grant-in-Aid for Scientific Research 25293121), Intel Software 2015-2020, Nihon University 2021-202, INED 2000-2022"; -char fullversion[]="$Revision: 1.340 $ $Date: 2022/09/11 07:53:11 $"; +char fullversion[]="$Revision: 1.341 $ $Date: 2022/09/11 07:58:42 $"; char strstart[80]; char optionfilext[10], optionfilefiname[FILENAMELENGTH]; int erreur=0, nberr=0, nbwarn=0; /* Error number, number of errors number of warnings */ @@ -1503,7 +1508,7 @@ double **covar; /**< covar[j,i], value * covar=matrix(0,NCOVMAX,1,n); * cov[Tage[kk]+2]=covar[Tvar[Tage[kk]]][i]*age; */ double **coqvar; /* Fixed quantitative covariate nqv */ -double ***cotvar; /* Time varying covariate ntv */ +double ***cotvar; /* Time varying covariate start at ncovcol + nqv + (1 to ntv) */ double ***cotqvar; /* Time varying quantitative covariate itqv */ double idx; int **nbcode, *Tvar; /**< model=V2 => Tvar[1]= 2 */ @@ -1515,7 +1520,7 @@ int **nbcode, *Tvar; /**< model=V2 => Tv * cptcovn number of covariates (not including constant and age or age*age) = number of plus sign + 1 = 10+1=11 * For time varying covariate, quanti or dummies * cotqvar[wav][iv(1 to nqtv)][i]= [1][12][i]=(V12) quanti - * cotvar[wav][ntv+iv][i]= [3+(1 to nqtv)][i]=(V12) quanti + * cotvar[wav][ncovcol+nqv+ iv(1 to nqtv)][i]= [(1 to nqtv)][i]=(V12) quanti * cotvar[wav][iv(1 to ntv)][i]= [1][1][i]=(V9) dummies at wav 1 * cotvar[wav][iv(1 to ntv)][i]= [1][2][i]=(V10) dummies at wav 1 * covar[Vk,i], value of the Vkth fixed covariate dummy or quanti for individual i: @@ -3936,7 +3941,7 @@ double func( double *x) mw[mi][i] is real wave of the mi th effectve wave */ /* Then statuses are computed at each begin and end of an effective wave s1=s[ mw[mi][i] ][i]; s2=s[mw[mi+1][i]][i]; - And the iv th varying covariate is the cotvar[mw[mi+1][i]][iv-ncovcol-nqv][i] because (-ncovcol-nqv) in the data + And the iv th varying covariate is the cotvar[mw[mi+1][i]][iv][i] because now is moved after nvocol+nqv But if the variable is not in the model TTvar[iv] is the real variable effective in the model: meaning that decodemodel should be used cotvar[mw[mi+1][i]][TTvar[iv]][i] */ @@ -3950,7 +3955,7 @@ double func( double *x) itv=TvarVV[ncovv]; /* TvarVV={3, 1, 3} gives the name of each varying covariate */ ipos=TvarVVind[ncovv]; /* TvarVVind={2, 5, 5] gives the position in the model of the ncovv th varying covariate*/ if(TvarFind[itv]==0){ /* Not a fixed covariate */ - cotvarv=cotvar[mw[mi][i]][TvarVV[ncovv]-ncovcol-nqv][i]; /* cotvar[wav][ntv+iv][i] */ + cotvarv=cotvar[mw[mi][i]][TvarVV[ncovv]][i]; /* cotvar[wav][ncovcol+nqv+iv][i] */ }else{ /* fixed covariate */ cotvarv=covar[Tvar[TvarFind[itv]]][i]; } @@ -3993,7 +3998,7 @@ double func( double *x) if(!FixedV[Tvar[Tage[kk]]]) cov[Tage[kk]+2+nagesqr]=covar[Tvar[Tage[kk]]][i]*agexact; /* Tage[kk] gives the data-covariate associated with age */ else - cov[Tage[kk]+2+nagesqr]=cotvar[mw[mi][i]][Tvar[Tage[kk]]-ncovcol-nqv][i]*agexact; /* -ntv because cotvar starts at ntv */ + cov[Tage[kk]+2+nagesqr]=cotvar[mw[mi][i]][Tvar[Tage[kk]]][i]*agexact; /* because cotvar starts now at first ncovcol+nqv+ (1 to nqtv) */ } out=matprod2(newm,oldm,1,nlstate+ndeath,1,nlstate+ndeath, 1,nlstate+ndeath,pmij(pmmij,cov,ncovmodel,x,nlstate)); @@ -4106,7 +4111,7 @@ double func( double *x) cov[ioffset+TvarFind[k]]=covar[Tvar[TvarFind[k]]][i]; for(mi=1; mi<= wav[i]-1; mi++){ for(k=1; k <= ncovv ; k++){ - cov[ioffset+TvarVind[k]]=cotvar[mw[mi][i]][Tvar[TvarVind[k]]-ncovcol-nqv][i]; /* Cotvar starts at ntv */ + cov[ioffset+TvarVind[k]]=cotvar[mw[mi][i]][Tvar[TvarVind[k]]][i]; /* because cotvar starts now at first ncovcol+nqv+ (1 to nqtv) */ } for (ii=1;ii<=nlstate+ndeath;ii++) for (j=1;j<=nlstate+ndeath;j++){ @@ -4156,7 +4161,7 @@ double func( double *x) if(!FixedV[Tvar[Tage[kk]]]) cov[Tage[kk]+2+nagesqr]=covar[Tvar[Tage[kk]]][i]*agexact; /* Tage[kk] gives the data-covariate associated with age */ else - cov[Tage[kk]+2+nagesqr]=cotvar[mw[mi][i]][Tvar[Tage[kk]]-ncovcol-nqv][i]*agexact; /* -ntv because cotvar starts at ntv */ + cov[Tage[kk]+2+nagesqr]=cotvar[mw[mi][i]][Tvar[Tage[kk]]][i]*agexact; /* because cotvar starts now at first ncovcol+nqv+ (1 to nqtv) */ } out=matprod2(newm,oldm,1,nlstate+ndeath,1,nlstate+ndeath, 1,nlstate+ndeath,pmij(pmmij,cov,ncovmodel,x,nlstate)); @@ -4234,7 +4239,7 @@ double func( double *x) if(!FixedV[Tvar[Tage[kk]]]) cov[Tage[kk]+2+nagesqr]=covar[Tvar[Tage[kk]]][i]*agexact; /* Tage[kk] gives the data-covariate associated with age */ else - cov[Tage[kk]+2+nagesqr]=cotvar[mw[mi][i]][Tvar[Tage[kk]]-ncovcol-nqv][i]*agexact; /* -ntv because cotvar starts at ntv */ + cov[Tage[kk]+2+nagesqr]=cotvar[mw[mi][i]][Tvar[Tage[kk]]][i]*agexact; /* because cotvar starts now at first ncovcol+nqv+ (1 to nqtv) */ } out=matprod2(newm,oldm,1,nlstate+ndeath,1,nlstate+ndeath, @@ -4322,9 +4327,7 @@ double funcone( double *x) mw[mi][i] is real wave of the mi th effectve wave */ /* Then statuses are computed at each begin and end of an effective wave s1=s[ mw[mi][i] ][i]; s2=s[mw[mi+1][i]][i]; - And the iv th varying covariate in the DATA is the cotvar[mw[mi+1][i]][iv][i] - But if the variable is not in the model TTvar[iv] is the real variable effective in the model: - meaning that decodemodel should be used cotvar[mw[mi+1][i]][TTvar[iv]][i] + And the iv th varying covariate in the DATA is the cotvar[mw[mi+1][i]][ncovcol+nqv+iv][i] */ /* This part may be useless now because everythin should be in covar */ /* for (k=1; k<=nqfveff;k++){ /\* Simple and product fixed Quantitative covariates without age* products *\/ */ @@ -4362,7 +4365,7 @@ double funcone( double *x) itv=TvarVV[ncovv]; /* TvarVV={3, 1, 3} gives the name of each varying covariate */ ipos=TvarVVind[ncovv]; /* TvarVVind={2, 5, 5] gives the position in the model of the ncovv th varying covariate*/ if(TvarFind[itv]==0){ /* Not a fixed covariate */ - cotvarv=cotvar[mw[mi][i]][TvarVV[ncovv]-ncovcol-nqv][i]; /* cotvar[wav][ntv+iv][i] */ + cotvarv=cotvar[mw[mi][i]][TvarVV[ncovv]][i]; /* because cotvar starts now at first ncovcol+nqv+ (1 to nqtv) */ }else{ /* fixed covariate */ cotvarv=covar[Tvar[TvarFind[itv]]][i]; } @@ -4415,7 +4418,7 @@ double funcone( double *x) if(!FixedV[Tvar[Tage[kk]]]) cov[Tage[kk]+2+nagesqr]=covar[Tvar[Tage[kk]]][i]*agexact; else - cov[Tage[kk]+2+nagesqr]=cotvar[mw[mi][i]][Tvar[Tage[kk]]-ncovcol-nqv][i]*agexact; + cov[Tage[kk]+2+nagesqr]=cotvar[mw[mi][i]][Tvar[Tage[kk]]][i]*agexact; /* because cotvar starts now at first ncovcol+nqv+ (1 to nqtv) */ } /* printf("i=%d,mi=%d,d=%d,mw[mi][i]=%d\n",i, mi,d,mw[mi][i]); */ /* savm=pmij(pmmij,cov,ncovmodel,x,nlstate); */ @@ -4487,7 +4490,7 @@ double funcone( double *x) if(!FixedV[Tvar[Tage[kk]]]) printf(" %g*age",covar[Tvar[Tage[kk]]][i]); else - printf(" %g*age",cotvar[mw[mi][i]][Tvar[Tage[kk]]-ncovcol-nqv][i]); + printf(" %g*age",cotvar[mw[mi][i]][Tvar[Tage[kk]]][i]);/* because cotvar starts now at first ncovcol+nqv+ (1 to nqtv) */ } printf(" s1=%1d s2=%1d mi=%1d mw=%1d dh=%3d prob=%10.6f w=%6.4f out=%10.6f sav=%10.6f\n",s1,s2,mi,mw[mi][i],dh[mi][i],exp(lli),weight[i],(s2==-1? -1: out[s1][s2]),(s2==-1? -1: savm[s1][s2])); if(globpr){ @@ -5286,7 +5289,8 @@ Title=%s
Datafile=%s Firstpass=%d La if(anyvaryingduminmodel==1){ /* Some are varying covariates */ for (z1=1; z1<=cptcoveff; z1++) { if( Fixed[Tmodelind[z1]]==1){ - iv= Tvar[Tmodelind[z1]]-ncovcol-nqv; /* Good */ + /* iv= Tvar[Tmodelind[z1]]-ncovcol-nqv; /\* Good *\/ */ + iv= Tvar[Tmodelind[z1]]; /* Good *//* because cotvar starts now at first at ncovcol+nqv+ntv */ if (cotvar[m][iv][iind]!= nbcode[Tvaraff[z1]][codtabm(j1,TnsdVar[Tvaraff[z1]])]) /* iv=1 to ntv, right modality. If covariate's value is -1, we don't select. It differs from the constant and age model which counts them. */ @@ -5823,7 +5827,7 @@ void prevalence(double ***probs, double /* Tvar[Tmodelind[z1]] is the n of Vn; n-ncovcol-nqv is the first time varying covariate or iv */ for (z1=1; z1<=cptcoveff; z1++){ if( Fixed[Tmodelind[z1]]==1){ - iv= Tvar[Tmodelind[z1]]-ncovcol-nqv; + iv= Tvar[Tmodelind[z1]];/* because cotvar starts now at first ncovcol+nqv+ (1 to nqtv) */ if (cotvar[m][iv][i]!= nbcode[Tvaraff[z1]][codtabm(j1,TnsdVar[Tvaraff[z1]])]) /* iv=1 to ntv, right modality */ bool=0; }else if( Fixed[Tmodelind[z1]]== 0) /* fixed */ @@ -10354,7 +10358,7 @@ int readdata(char datafile[], int firsto if(strb[0]=='.') { /* Missing value */ lval=-1; cotqvar[j][iv][i]=-1; /* 0.0/0.0 */ - cotvar[j][ntv+iv][i]=-1; /* For performance reasons */ + cotvar[j][ncovcol+nqv+ntv+iv][i]=-1; /* For performance reasons */ if(isalpha(strb[1])) { /* .m or .d Really Missing value */ printf("Error reading data around '%s' at line number %d for individual %d, '%s'\nShould be the %d th quantitative value out of %d measured at wave %d. If missing, you should remove this individual or impute a value. Exiting.\n", strb, linei,i,line,iv, nqtv, j); fprintf(ficlog,"Error reading data around '%s' at line number %d for individual %d, '%s'\nShould be the %d th quantitative value out of %d measured at wave %d. If missing, you should remove this individual or impute a value. Exiting.\n", strb, linei,i,line,iv, nqtv, j);fflush(ficlog); @@ -10374,7 +10378,7 @@ int readdata(char datafile[], int firsto return 1; } cotqvar[j][iv][i]=dval; - cotvar[j][ntv+iv][i]=dval; + cotvar[j][ncovcol+nqv+ntv+iv][i]=dval; /* because cotvar starts now at first ntv */ } strcpy(line,stra); }/* end loop ntqv */ @@ -10414,7 +10418,7 @@ int readdata(char datafile[], int firsto Exiting.\n",lval,linei, i,line,iv,j);fflush(ficlog); return 1; } - cotvar[j][iv][i]=(double)(lval); + cotvar[j][ncovcol+nqv+iv][i]=(double)(lval); strcpy(line,stra); }/* end loop ntv */ @@ -12527,8 +12531,8 @@ int main(int argc, char *argv[]) covar=matrix(0,NCOVMAX,firstobs,lastobs); /**< used in readdata */ if(nqv>=1)coqvar=matrix(1,nqv,firstobs,lastobs); /**< Fixed quantitative covariate */ if(nqtv>=1)cotqvar=ma3x(1,maxwav,1,nqtv,firstobs,lastobs); /**< Time varying quantitative covariate */ - if(ntv+nqtv>=1)cotvar=ma3x(1,maxwav,1,ntv+nqtv,firstobs,lastobs); /**< Time varying covariate (dummy and quantitative)*/ - /* if(ntv+nqtv>=1)cotvar=ma3x(1,maxwav,ncovcol+nqv+1,ncovcol+nqv+ntv+nqtv,firstobs,lastobs); /\**< Might be better *\/ */ + /* if(ntv+nqtv>=1)cotvar=ma3x(1,maxwav,1,ntv+nqtv,firstobs,lastobs); /\**< Time varying covariate (dummy and quantitative)*\/ */ + if(ntv+nqtv>=1)cotvar=ma3x(1,maxwav,ncovcol+nqv+1,ncovcol+nqv+ntv+nqtv,firstobs,lastobs); /**< Might be better */ 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*age+v2*v3 makes cptcovn = 3 @@ -14332,7 +14336,8 @@ Please run with mle=-1 to get a correct free_matrix(oldms, 1,nlstate+ndeath,1,nlstate+ndeath); free_matrix(newms, 1,nlstate+ndeath,1,nlstate+ndeath); free_matrix(savms, 1,nlstate+ndeath,1,nlstate+ndeath); - if(ntv+nqtv>=1)free_ma3x(cotvar,1,maxwav,1,ntv+nqtv,firstobs,lastobs); + /* if(ntv+nqtv>=1)free_ma3x(cotvar,1,maxwav,1,ntv+nqtv,firstobs,lastobs); */ + if(ntv+nqtv>=1)free_ma3x(cotvar,1,maxwav,ncovcol+nqv+1,ncovcol+nqv+ntv+nqtv,firstobs,lastobs); if(nqtv>=1)free_ma3x(cotqvar,1,maxwav,1,nqtv,firstobs,lastobs); if(nqv>=1)free_matrix(coqvar,1,nqv,firstobs,lastobs); free_matrix(covar,0,NCOVMAX,firstobs,lastobs);