--- imach/src/imach.c 2022/09/09 17:55:22 1.339
+++ imach/src/imach.c 2022/09/14 19:33:30 1.344
@@ -1,6 +1,40 @@
-/* $Id: imach.c,v 1.339 2022/09/09 17:55:22 brouard Exp $
+/* $Id: imach.c,v 1.344 2022/09/14 19:33:30 brouard Exp $
$State: Exp $
$Log: imach.c,v $
+ Revision 1.344 2022/09/14 19:33:30 brouard
+ Summary: version 0.99r40
+
+ * imach.c (Module): Fixing names of variables in T_ (thanks to Feinuo)
+
+ Revision 1.343 2022/09/14 14:22:16 brouard
+ Summary: version 0.99r39
+
+ * imach.c (Module): Version 0.99r39 with colored dummy covariates
+ (fixed or time varying), using new last columns of
+ ILK_parameter.txt file.
+
+ Revision 1.342 2022/09/11 19:54:09 brouard
+ Summary: 0.99r38
+
+ * imach.c (Module): Adding timevarying products of any kinds,
+ should work before shifting cotvar from ncovcol+nqv columns in
+ order to have a correspondance between the column of cotvar and
+ the id of column.
+ (Module): Some cleaning and adding covariates in ILK.txt
+
+ 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
+
+ * imach.c (Module): Adding timevarying products of any kinds,
+ should work before shifting cotvar from ncovcol+nqv columns in
+ order to have a correspondance between the column of cotvar and
+ the id of column.
+
Revision 1.339 2022/09/09 17:55:22 brouard
Summary: version 0.99r37
@@ -1272,6 +1306,8 @@ typedef struct {
#define MAXLINE 2048 /* Was 256 and 1024. Overflow with 312 with 2 states and 4 covariates. Should be ok */
#define GNUPLOTPROGRAM "gnuplot"
+#define GNUPLOTVERSION 5.1
+double gnuplotversion=GNUPLOTVERSION;
/*#define GNUPLOTPROGRAM "..\\gp37mgw\\wgnuplot"*/
#define FILENAMELENGTH 256
@@ -1308,15 +1344,16 @@ typedef struct {
#define ODIRSEPARATOR '\\'
#endif
-/* $Id: imach.c,v 1.339 2022/09/09 17:55:22 brouard Exp $ */
+/* $Id: imach.c,v 1.344 2022/09/14 19:33:30 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.339 $ $Date: 2022/09/09 17:55:22 $";
+char fullversion[]="$Revision: 1.344 $ $Date: 2022/09/14 19:33:30 $";
char strstart[80];
char optionfilext[10], optionfilefiname[FILENAMELENGTH];
int erreur=0, nberr=0, nbwarn=0; /* Error number, number of errors number of warnings */
+int debugILK=0; /* debugILK is set by a #d in a comment line */
int nagesqr=0, nforce=0; /* nagesqr=1 if model is including age*age, number of forces */
/* Number of covariates model (1)=V2+V1+ V3*age+V2*V4 */
/* Model(2) V1 + V2 + V3 + V8 + V7*V8 + V5*V6 + V8*age + V3*age + age*age */
@@ -1495,7 +1532,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 */
@@ -1507,7 +1544,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:
@@ -1520,8 +1557,8 @@ int **nbcode, *Tvar; /**< model=V2 => Tv
# States 1=Coresidence, 2 Living alone, 3 Institution
# V1=sex, V2=raedyrs Quant Fixed, State=livarnb4..livarnb11, V3=iadl4..iald11, V4=adlw4..adlw11, V5=r4bmi..r11bmi
*/
-/* V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */
-/* k 1 2 3 4 5 6 7 8 9 */
+/* V5+V4+ V3+V4*V3 +V5*age+V2 +V1*V2+V1*age+V1 */
+/* kmodel 1 2 3 4 5 6 7 8 9 */
/*Typevar[k]= 0 0 0 2 1 0 2 1 0 *//*0 for simple covariate (dummy, quantitative,*/
/* fixed or varying), 1 for age product, 2 for*/
/* product */
@@ -3880,6 +3917,7 @@ double func( double *x)
int ioffset=0;
int ipos=0,iposold=0,ncovv=0;
+ double cotvarv, cotvarvold;
double l, ll[NLSTATEMAX+1], cov[NCOVMAX+1];
double **out;
double lli; /* Individual log likelihood */
@@ -3927,7 +3965,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][i]
+ 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]
*/
@@ -3937,25 +3975,21 @@ double func( double *x)
/* /\* cov[ioffset+TvarVind[k]]=cotvar[mw[mi][i]][Tvar[TvarVind[k]]][i]; but where is the crossproduct? *\/ */
/* cov[ioffset+TvarVind[k]]=cotvar[mw[mi][i]][Tvar[TvarVind[k]]-ncovcol-nqv][i]; */
/* } */
- for(ncovv=1, ipos=0; ncovv <= ncovvt ; ncovv++){ /* Varying covariates (single and product but no age )*/
- itv=TvarVV[ncovv]; /* TvarVV={3, 1, 3} */
- ipos=TvarVVind[ncovv]; /* TvarVVind={2, 5, 5] */
+ for(ncovv=1, iposold=0; ncovv <= ncovvt ; ncovv++){ /* Varying covariates (single and product but no age )*/
+ 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]][i]; /* cotvar[wav][ncovcol+nqv+iv][i] */
+ }else{ /* fixed covariate */
+ cotvarv=covar[Tvar[TvarFind[itv]]][i];
+ }
if(ipos!=iposold){ /* Not a product or first of a product */
- /* TvarFind={1,0,0,0} */
- if(TvarFind[itv]==0){
- cov[ioffset+ipos]= cotvar[mw[mi][i]][ncovv][i]; /* Should be covar if fixed covar[Tvar[TvarFind[itv]]][i]*/
- }else{
- cov[ioffset+ipos]=covar[Tvar[TvarFind[itv]]][i];
- }
- }else{
- if(TvarFind[itv]==0){
- cov[ioffset+ipos]*= cotvar[mw[mi][i]][ncovv][i]; /* Should be covar if fixed covar[Tvar[TvarFind[itv]]][i]*/
- }else{
- cov[ioffset+ipos]*=covar[Tvar[TvarFind[itv]]][i];
- }
+ cotvarvold=cotvarv;
+ }else{ /* A second product */
+ cotvarv=cotvarv*cotvarvold;
}
iposold=ipos;
- /* For products */
+ cov[ioffset+ipos]=cotvarv;
}
/* 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 *\/ */
@@ -3988,7 +4022,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]]][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) */
}
out=matprod2(newm,oldm,1,nlstate+ndeath,1,nlstate+ndeath,
1,nlstate+ndeath,pmij(pmmij,cov,ncovmodel,x,nlstate));
@@ -4084,7 +4118,7 @@ double func( double *x)
}
/*lli=(1.+bbh)*log(out[s1][s2])- bbh*log(savm[s1][s2]);*/
/*if(lli ==000.0)*/
- /*printf("bbh= %f lli=%f savm=%f out=%f %d\n",bbh,lli,savm[s1][s2], out[s[mw[mi][i]][i]][s[mw[mi+1][i]][i]],i); */
+ /* printf("num[i], i=%d, bbh= %f lli=%f savm=%f out=%f %d\n",bbh,lli,savm[s1][s2], out[s[mw[mi][i]][i]][s[mw[mi+1][i]][i]],i); */
ipmx +=1;
sw += weight[i];
ll[s[mw[mi][i]][i]] += 2*weight[i]*lli;
@@ -4101,7 +4135,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];
+ 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++){
@@ -4148,7 +4182,10 @@ double func( double *x)
if(nagesqr==1)
cov[3]= agexact*agexact;
for (kk=1; kk<=cptcovage;kk++) {
- cov[Tage[kk]+2+nagesqr]=covar[Tvar[Tage[kk]]][i]*agexact;
+ 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]]][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));
@@ -4204,7 +4241,7 @@ double func( double *x)
ipmx +=1;
sw += weight[i];
ll[s[mw[mi][i]][i]] += 2*weight[i]*lli;
-/* printf("i=%6d s1=%1d s2=%1d mi=%1d mw=%1d dh=%3d prob=%10.6f w=%6.4f out=%10.6f sav=%10.6f\n",i,s1,s2,mi,mw[mi][i],dh[mi][i],exp(lli),weight[i],out[s1][s2],savm[s1][s2]); */
+ /* printf("num[i]=%09ld, i=%6d s1=%1d s2=%1d mi=%1d mw=%1d dh=%3d prob=%10.6f w=%6.4f out=%10.6f sav=%10.6f\n",num[i],i,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])); */
} /* end of wave */
} /* end of individual */
}else{ /* ml=5 no inter-extrapolation no jackson =0.8a */
@@ -4223,7 +4260,10 @@ double func( double *x)
if(nagesqr==1)
cov[3]= agexact*agexact;
for (kk=1; kk<=cptcovage;kk++) {
- cov[Tage[kk]+2+nagesqr]=covar[Tvar[Tage[kk]]][i]*agexact;
+ 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]]][i]*agexact; /* because cotvar starts now at first ncovcol+nqv+ (1 to nqtv) */
}
out=matprod2(newm,oldm,1,nlstate+ndeath,1,nlstate+ndeath,
@@ -4256,6 +4296,7 @@ double funcone( double *x)
int ioffset=0;
int ipos=0,iposold=0,ncovv=0;
+ double cotvarv, cotvarvold;
double l, ll[NLSTATEMAX+1], cov[NCOVMAX+1];
double **out;
double lli; /* Individual log likelihood */
@@ -4310,9 +4351,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 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 *\/ */
@@ -4337,24 +4376,29 @@ double funcone( double *x)
/* We need the position of the time varying or product in the model */
/* TvarVVind={2,5,5}, for V3 at position 2 and then the product V1*V3 is decomposed into V1 and V3 but at same position 5 */
/* TvarVV gives the variable name */
- for(ncovv=1, ipos=0; ncovv <= ncovvt ; ncovv++){ /* Varying covariates (single and product but no age )*/
- itv=TvarVV[ncovv]; /* TvarVV={3, 1, 3} */
- ipos=TvarVVind[ncovv]; /* TvarVVind={2, 5, 5] */
+ /* Other example V1 + V3 + V5 + age*V1 + age*V3 + age*V5 + V1*V3 + V3*V5 + V1*V5
+ * k= 1 2 3 4 5 6 7 8 9
+ * varying 1 2 3 4 5
+ * ncovv 1 2 3 4 5 6 7 8
+ * TvarVV[ncovv] V3 5 1 3 3 5 1 5
+ * TvarVVind 2 3 7 7 8 8 9 9
+ * TvarFind[k] 1 0 0 0 0 0 0 0 0
+ */
+ for(ncovv=1, iposold=0; ncovv <= ncovvt ; ncovv++){ /* Varying covariates (single and product but no age) including individual from products */
+ 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]][i]; /* because cotvar starts now at first ncovcol+nqv+ (1 to nqtv) */
+ }else{ /* fixed covariate */
+ cotvarv=covar[Tvar[TvarFind[itv]]][i];
+ }
if(ipos!=iposold){ /* Not a product or first of a product */
- /* TvarFind={1,0,0,0} */
- if(TvarFind[itv]==0){
- cov[ioffset+ipos]= cotvar[mw[mi][i]][ncovv][i]; /* Should be covar if fixed covar[Tvar[TvarFind[itv]]][i]*/
- }else{
- cov[ioffset+ipos]=covar[Tvar[TvarFind[itv]]][i];
- }
- }else{
- if(TvarFind[itv]==0){
- cov[ioffset+ipos]*= cotvar[mw[mi][i]][ncovv][i]; /* Should be covar if fixed covar[Tvar[TvarFind[itv]]][i]*/
- }else{
- cov[ioffset+ipos]*=covar[Tvar[TvarFind[itv]]][i];
- }
+ cotvarvold=cotvarv;
+ }else{ /* A second product */
+ cotvarv=cotvarv*cotvarvold;
}
iposold=ipos;
+ cov[ioffset+ipos]=cotvarv;
/* For products */
}
/* for(itv=1; itv <= ntveff; itv++){ /\* Varying dummy covariates single *\/ */
@@ -4397,7 +4441,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]]][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); */
@@ -4452,24 +4496,53 @@ double funcone( double *x)
ipmx +=1;
sw += weight[i];
ll[s[mw[mi][i]][i]] += 2*weight[i]*lli;
- /* printf("Funcone i=%6d s1=%1d s2=%1d mi=%1d mw=%1d dh=%3d prob=%10.6f w=%6.4f out=%10.6f sav=%10.6f\n",i,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])); */
+ /* Printing covariates values for each contribution for checking */
+ /* printf("num[i]=%09ld, i=%6d s1=%1d s2=%1d mi=%1d mw=%1d dh=%3d prob=%10.6f w=%6.4f out=%10.6f sav=%10.6f\n",num[i],i,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){
fprintf(ficresilk,"%09ld %6.1f %6.1f %6d %2d %2d %2d %2d %3d %15.6f %8.4f %8.3f\
%11.6f %11.6f %11.6f ", \
num[i], agebegin, ageend, i,s1,s2,mi,mw[mi][i],dh[mi][i],exp(lli),weight[i],weight[i]*gipmx/gsw,
2*weight[i]*lli,(s2==-1? -1: out[s1][s2]),(s2==-1? -1: savm[s1][s2]));
- /* printf("%09ld %6.1f %6.1f %6d %2d %2d %2d %2d %3d %15.6f %8.4f %8.3f\ */
- /* %11.6f %11.6f %11.6f ", \ */
- /* num[i], agebegin, ageend, i,s1,s2,mi,mw[mi][i],dh[mi][i],exp(lli),weight[i],weight[i]*gipmx/gsw, */
- /* 2*weight[i]*lli,(s2==-1? -1: out[s1][s2]),(s2==-1? -1: savm[s1][s2])); */
+ /* printf("%09ld %6.1f %6.1f %6d %2d %2d %2d %2d %3d %15.6f %8.4f %8.3f\ */
+ /* %11.6f %11.6f %11.6f ", \ */
+ /* num[i], agebegin, ageend, i,s1,s2,mi,mw[mi][i],dh[mi][i],exp(lli),weight[i],weight[i]*gipmx/gsw, */
+ /* 2*weight[i]*lli,(s2==-1? -1: out[s1][s2]),(s2==-1? -1: savm[s1][s2])); */
for(k=1,llt=0.,l=0.; k<=nlstate; k++){
llt +=ll[k]*gipmx/gsw;
fprintf(ficresilk," %10.6f",-ll[k]*gipmx/gsw);
/* printf(" %10.6f",-ll[k]*gipmx/gsw); */
}
- fprintf(ficresilk," %10.6f\n", -llt);
+ fprintf(ficresilk," %10.6f ", -llt);
/* printf(" %10.6f\n", -llt); */
- }
+ /* if(debugILK){ /\* debugILK is set by a #d in a comment line *\/ */
+ /* fprintf(ficresilk,"%09ld ", num[i]); */ /* not necessary */
+ for (kf=1; kf<=ncovf;kf++){ /* Simple and product fixed covariates without age* products *//* Missing values are set to -1 but should be dropped */
+ fprintf(ficresilk," %g",covar[Tvar[TvarFind[kf]]][i]);
+ }
+ for(ncovv=1, iposold=0; ncovv <= ncovvt ; ncovv++){ /* Varying covariates (single and product but no age) including individual from products */
+ ipos=TvarVVind[ncovv]; /* TvarVVind={2, 5, 5] gives the position in the model of the ncovv th varying covariate*/
+ if(ipos!=iposold){ /* Not a product or first of a product */
+ fprintf(ficresilk," %g",cov[ioffset+ipos]);
+ /* printf(" %g",cov[ioffset+ipos]); */
+ }else{
+ fprintf(ficresilk,"*");
+ /* printf("*"); */
+ }
+ iposold=ipos;
+ }
+ for (kk=1; kk<=cptcovage;kk++) {
+ if(!FixedV[Tvar[Tage[kk]]]){
+ fprintf(ficresilk," %g*age",covar[Tvar[Tage[kk]]][i]);
+ /* printf(" %g*age",covar[Tvar[Tage[kk]]][i]); */
+ }else{
+ fprintf(ficresilk," %g*age",cotvar[mw[mi][i]][Tvar[Tage[kk]]][i]);/* because cotvar starts now at first ncovcol+nqv+ (1 to nqtv) */
+ /* printf(" %g*age",cotvar[mw[mi][i]][Tvar[Tage[kk]]][i]);/\* because cotvar starts now at first ncovcol+nqv+ (1 to nqtv) *\/ */
+ }
+ }
+ /* printf("\n"); */
+ /* } /\* End debugILK *\/ */
+ fprintf(ficresilk,"\n");
+ } /* End if globpr */
} /* end of wave */
} /* end of individual */
for(k=1,l=0.; k<=nlstate; k++) l += ll[k];
@@ -4479,7 +4552,7 @@ double funcone( double *x)
gipmx=ipmx;
gsw=sw;
}
-return -l;
+ return -l;
}
@@ -4490,8 +4563,9 @@ void likelione(FILE *ficres,double p[],
the selection of individuals/waves and
to check the exact contribution to the likelihood.
Plotting could be done.
- */
- int k;
+ */
+ void pstamp(FILE *ficres);
+ int k, kf, kk, kvar, ncovv, iposold, ipos;
if(*globpri !=0){ /* Just counts and sums, no printings */
strcpy(fileresilk,"ILK_");
@@ -4500,13 +4574,43 @@ void likelione(FILE *ficres,double p[],
printf("Problem with resultfile: %s\n", fileresilk);
fprintf(ficlog,"Problem with resultfile: %s\n", fileresilk);
}
+ pstamp(ficresilk);fprintf(ficresilk,"# model=1+age+%s\n",model);
fprintf(ficresilk, "#individual(line's_record) count ageb ageend s1 s2 wave# effective_wave# number_of_matrices_product pij weight weight/gpw -2ln(pij)*weight 0pij_x 0pij_(x-stepm) cumulating_loglikeli_by_health_state(reweighted=-2ll*weightXnumber_of_contribs/sum_of_weights) and_total\n");
fprintf(ficresilk, "#num_i ageb agend i s1 s2 mi mw dh likeli weight %%weight 2wlli out sav ");
/* i,s1,s2,mi,mw[mi][i],dh[mi][i],exp(lli),weight[i],2*weight[i]*lli,out[s1][s2],savm[s1][s2]); */
for(k=1; k<=nlstate; k++)
fprintf(ficresilk," -2*gipw/gsw*weight*ll[%d]++",k);
- fprintf(ficresilk," -2*gipw/gsw*weight*ll(total)\n");
- }
+ fprintf(ficresilk," -2*gipw/gsw*weight*ll(total) ");
+
+ /* if(debugILK){ /\* debugILK is set by a #d in a comment line *\/ */
+ for(kf=1;kf <= ncovf; kf++){
+ fprintf(ficresilk,"V%d",Tvar[TvarFind[kf]]);
+ /* printf("V%d",Tvar[TvarFind[kf]]); */
+ }
+ for(ncovv=1, iposold=0; ncovv <= ncovvt ; ncovv++){
+ ipos=TvarVVind[ncovv]; /* TvarVVind={2, 5, 5] gives the position in the model of the ncovv th varying covariate */
+ if(ipos!=iposold){ /* Not a product or first of a product */
+ /* printf(" %d",ipos); */
+ fprintf(ficresilk," V%d",TvarVV[ncovv]);
+ }else{
+ /* printf("*"); */
+ fprintf(ficresilk,"*");
+ }
+ iposold=ipos;
+ }
+ for (kk=1; kk<=cptcovage;kk++) {
+ if(!FixedV[Tvar[Tage[kk]]]){
+ /* printf(" %d*age(Fixed)",Tvar[Tage[kk]]); */
+ fprintf(ficresilk," %d*age(Fixed)",Tvar[Tage[kk]]);
+ }else{
+ fprintf(ficresilk," %d*age(Varying)",Tvar[Tage[kk]]);/* because cotvar starts now at first ncovcol+nqv+ (1 to nqtv) */
+ /* printf(" %d*age(Varying)",Tvar[Tage[kk]]);/\* because cotvar starts now at first ncovcol+nqv+ (1 to nqtv) *\/ */
+ }
+ }
+ /* } /\* End if debugILK *\/ */
+ /* printf("\n"); */
+ fprintf(ficresilk,"\n");
+ } /* End glogpri */
*fretone=(*func)(p);
if(*globpri !=0){
@@ -4518,16 +4622,68 @@ void likelione(FILE *ficres,double p[],
fprintf(fichtm," You should at least run with mle >= 1 to get starting values corresponding to the optimized parameters in order to visualize the real contribution of each individual/wave: %s
\n",subdirf(fileresilk),subdirf(fileresilk));
fprintf(fichtm,"\n
Equation of the model: model=1+age+%s
\n",model);
- for (k=1; k<= nlstate ; k++) {
- fprintf(fichtm,"
- Probability p%dj by origin %d and destination j. Dot's sizes are related to corresponding weight: %s-p%dj.png
\
-",k,k,subdirf2(optionfilefiname,"ILK_"),k,subdirf2(optionfilefiname,"ILK_"),k,subdirf2(optionfilefiname,"ILK_"),k);
- }
fprintf(fichtm,"
- The function drawn is -2Log(L) in Log scale: by state of origin %s-ori.png
\
-",subdirf2(optionfilefiname,"ILK_"),subdirf2(optionfilefiname,"ILK_"),subdirf2(optionfilefiname,"ILK_"));
+\n",subdirf2(optionfilefiname,"ILK_"),subdirf2(optionfilefiname,"ILK_"),subdirf2(optionfilefiname,"ILK_"));
fprintf(fichtm,"
- and by state of destination %s-dest.png
\
-",subdirf2(optionfilefiname,"ILK_"),subdirf2(optionfilefiname,"ILK_"),subdirf2(optionfilefiname,"ILK_"));
+\n",subdirf2(optionfilefiname,"ILK_"),subdirf2(optionfilefiname,"ILK_"),subdirf2(optionfilefiname,"ILK_"));
+
+ for (k=1; k<= nlstate ; k++) {
+ fprintf(fichtm,"
- Probability p%dj by origin %d and destination j. Dot's sizes are related to corresponding weight: %s-p%dj.png
\n \
+\n",k,k,subdirf2(optionfilefiname,"ILK_"),k,subdirf2(optionfilefiname,"ILK_"),k,subdirf2(optionfilefiname,"ILK_"),k);
+ for(kf=1; kf <= ncovf; kf++){ /* For each simple dummy covariate of the model */
+ /* kvar=Tvar[TvarFind[kf]]; */ /* variable */
+ fprintf(fichtm,"
- Probability p%dj by origin %d and destination j with colored covariate V%d. Same dot size of all points but with a different color for transitions with dummy variable V%d=1 at beginning of transition (keeping former color for V%d=0): %s-p%dj.png
\
+",k,k,Tvar[TvarFind[kf]],Tvar[TvarFind[kf]],Tvar[TvarFind[kf]],subdirf2(optionfilefiname,"ILK_"),k,subdirf2(optionfilefiname,"ILK_"),k,subdirf2(optionfilefiname,"ILK_"),k,Tvar[TvarFind[kf]]);
+ }
+ for(ncovv=1, iposold=0; ncovv <= ncovvt ; ncovv++){ /* Loop on the time varying extended covariates (with extension of Vn*Vm */
+ ipos=TvarVVind[ncovv]; /* TvarVVind={2, 5, 5] gives the position in the model of the ncovv th varying covariate */
+ kvar=TvarVV[ncovv]; /* TvarVV={3, 1, 3} gives the name of each varying covariate */
+ /* printf("DebugILK fichtm ncovv=%d, kvar=TvarVV[ncovv]=V%d, ipos=TvarVVind[ncovv]=%d, Dummy[ipos]=%d, Typevar[ipos]=%d\n", ncovv,kvar,ipos,Dummy[ipos],Typevar[ipos]); */
+ if(ipos!=iposold){ /* Not a product or first of a product */
+ /* fprintf(ficresilk," V%d",TvarVV[ncovv]); */
+ /* printf(" DebugILK fichtm ipos=%d != iposold=%d\n", ipos, iposold); */
+ if(Dummy[ipos]==0 && Typevar[ipos]==0){ /* Only if dummy time varying: Dummy(0, 1=quant singor prod without age,2 dummy*age, 3quant*age) Typevar (0 single, 1=*age,2=Vn*vm) */
+ fprintf(fichtm,"
- Probability p%dj by origin %d and destination j with colored time varying dummy covariate V%d. Same dot size of all points but with a different color for transitions with dummy variable V%d=1 at beginning of transition (keeping former color for V%d=0): %s-p%dj.png
\
+",k,k,kvar,kvar,kvar,subdirf2(optionfilefiname,"ILK_"),k,subdirf2(optionfilefiname,"ILK_"),k,subdirf2(optionfilefiname,"ILK_"),k,kvar);
+ } /* End only for dummies time varying (single?) */
+ }else{ /* Useless product */
+ /* printf("*"); */
+ /* fprintf(ficresilk,"*"); */
+ }
+ iposold=ipos;
+ } /* For each time varying covariate */
+ } /* End loop on states */
+
+/* if(debugILK){ */
+/* for(kf=1; kf <= ncovf; kf++){ /\* For each simple dummy covariate of the model *\/ */
+/* /\* kvar=Tvar[TvarFind[kf]]; *\/ /\* variable *\/ */
+/* for (k=1; k<= nlstate ; k++) { */
+/* fprintf(fichtm,"
- Probability p%dj by origin %d and destination j with colored covariate V%. Same dot size of all points but with a different color for transitions with dummy variable V%d=1 at beginning of transition (keeping former color for V%d=0): %s-p%dj.png
\ */
+/* ",k,k,Tvar[TvarFind[kf]],Tvar[TvarFind[kf]],Tvar[TvarFind[kf]],subdirf2(optionfilefiname,"ILK_"),k,subdirf2(optionfilefiname,"ILK_"),k,subdirf2(optionfilefiname,"ILK_"),k,Tvar[TvarFind[kf]]); */
+/* } */
+/* } */
+/* for(ncovv=1, iposold=0; ncovv <= ncovvt ; ncovv++){ /\* Loop on the time varying extended covariates (with extension of Vn*Vm *\/ */
+/* ipos=TvarVVind[ncovv]; /\* TvarVVind={2, 5, 5] gives the position in the model of the ncovv th varying covariate *\/ */
+/* kvar=TvarVV[ncovv]; /\* TvarVV={3, 1, 3} gives the name of each varying covariate *\/ */
+/* /\* printf("DebugILK fichtm ncovv=%d, kvar=TvarVV[ncovv]=V%d, ipos=TvarVVind[ncovv]=%d, Dummy[ipos]=%d, Typevar[ipos]=%d\n", ncovv,kvar,ipos,Dummy[ipos],Typevar[ipos]); *\/ */
+/* if(ipos!=iposold){ /\* Not a product or first of a product *\/ */
+/* /\* fprintf(ficresilk," V%d",TvarVV[ncovv]); *\/ */
+/* /\* printf(" DebugILK fichtm ipos=%d != iposold=%d\n", ipos, iposold); *\/ */
+/* if(Dummy[ipos]==0 && Typevar[ipos]==0){ /\* Only if dummy time varying: Dummy(0, 1=quant singor prod without age,2 dummy*age, 3quant*age) Typevar (0 single, 1=*age,2=Vn*vm) *\/ */
+/* for (k=1; k<= nlstate ; k++) { */
+/* fprintf(fichtm,"
- Probability p%dj by origin %d and destination j. Same dot size of all points but with a different color for transitions with dummy variable V%d=1 at beginning of transition (keeping former color for V%d=0): %s-p%dj.png
\ */
+/* ",k,k,kvar,kvar,subdirf2(optionfilefiname,"ILK_"),k,subdirf2(optionfilefiname,"ILK_"),k,subdirf2(optionfilefiname,"ILK_"),k,kvar); */
+/* } /\* End state *\/ */
+/* } /\* End only for dummies time varying (single?) *\/ */
+/* }else{ /\* Useless product *\/ */
+/* /\* printf("*"); *\/ */
+/* /\* fprintf(ficresilk,"*"); *\/ */
+/* } */
+/* iposold=ipos; */
+/* } /\* For each time varying covariate *\/ */
+/* }/\* End debugILK *\/ */
fflush(fichtm);
- }
+ }/* End globpri */
return;
}
@@ -5249,7 +5405,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;
+ /* 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. */
@@ -5330,7 +5487,7 @@ Title=%s
Datafile=%s Firstpass=%d La
fprintf(ficresphtm, "\n