");
m=pow(2,cptcoveff);
if (cptcovn < 1) {m=1;ncodemax[1]=1;}
+ fprintf(fichtm," \n
- Graphs
");
+
+ jj1=0;
+
+ fprintf(fichtm," \n
");
+ for(nres=1; nres <= nresult; nres++) /* For each resultline */
+ for(k1=1; k1<=m;k1++){ /* For each combination of covariate */
+ if(m != 1 && TKresult[nres]!= k1)
+ continue;
+ jj1++;
+ if (cptcovn > 0) {
+ fprintf(fichtm,"\n- ");
+
+ /* if(nqfveff+nqtveff 0) */ /* Test to be done */
+ fprintf(fichtm,"************ Results for covariates");
+ for (cpt=1; cpt<=cptcoveff;cpt++){
+ fprintf(fichtm," V%d=%d ",Tvresult[nres][cpt],(int)Tresult[nres][cpt]);
+ }
+ for (k4=1; k4<= nsq; k4++){ /* For each selected (single) quantitative value */
+ fprintf(fichtm," V%d=%f ",Tvqresult[nres][k4],Tqresult[nres][k4]);
+ }
+ if(invalidvarcomb[k1]){
+ fprintf(fichtm," Warning Combination (%d) ignored because no cases ",k1);
+ continue;
+ }
+ fprintf(fichtm,"
");
+ } /* cptcovn >0 */
+ }
+ fprintf(fichtm," \n
");
+
jj1=0;
for(nres=1; nres <= nresult; nres++) /* For each resultline */
@@ -6437,6 +6593,15 @@ void printinghtml(char fileresu[], char
/* for(i1=1; i1<=ncodemax[k1];i1++){ */
jj1++;
if (cptcovn > 0) {
+ fprintf(fichtm,"\n");
+
fprintf(fichtm,"
************ Results for covariates");
for (cpt=1; cpt<=cptcoveff;cpt++){
fprintf(fichtm," V%d=%d ",Tvresult[nres][cpt],(int)Tresult[nres][cpt]);
@@ -6482,13 +6647,13 @@ divided by h: hPij
}
/* Period (stable) prevalence in each health state */
for(cpt=1; cpt<=nlstate;cpt++){
- fprintf(fichtm,"
\n- Convergence to period (stable) prevalence in state %d. Or probability to be in state %d some years earlier, knowing that we will be in state (1 to %d) at different ages. %s_%d-%d-%d.svg
\
-", cpt, cpt, nlstate, subdirf2(optionfilefiname,"P_"),cpt,k1,nres,subdirf2(optionfilefiname,"P_"),cpt,k1,nres,subdirf2(optionfilefiname,"P_"),cpt,k1,nres);
+ fprintf(fichtm,"
\n- Convergence to period (stable) prevalence in state %d. Or probability for a person being in state (1 to %d) at different ages, to be in state %d some years after. %s_%d-%d-%d.svg
\
+", cpt, nlstate, cpt, subdirf2(optionfilefiname,"P_"),cpt,k1,nres,subdirf2(optionfilefiname,"P_"),cpt,k1,nres,subdirf2(optionfilefiname,"P_"),cpt,k1,nres);
}
if(backcast==1){
/* Period (stable) back prevalence in each health state */
for(cpt=1; cpt<=nlstate;cpt++){
- fprintf(fichtm,"
\n- Convergence to mixed (stable) back prevalence in state %d. Or probability to be in state %d at a younger age, knowing that we will be in state (1 to %d) at different older ages. %s_%d-%d-%d.svg
\
+ fprintf(fichtm,"
\n- Convergence to mixed (stable) back prevalence in state %d. Or probability for a person to be in state %d at a younger age, knowing that she/he was in state (1 to %d) at different older ages. %s_%d-%d-%d.svg
\
", cpt, cpt, nlstate, subdirf2(optionfilefiname,"PB_"),cpt,k1,nres,subdirf2(optionfilefiname,"PB_"),cpt,k1,nres,subdirf2(optionfilefiname,"PB_"),cpt,k1,nres);
}
}
@@ -6602,16 +6767,17 @@ true period expectancies (those weighted
}
/******************* Gnuplot file **************/
-void printinggnuplot(char fileresu[], char optionfilefiname[], double ageminpar, double agemaxpar, double fage , int prevfcast, int backcast, char pathc[], double p[]){
+ void printinggnuplot(char fileresu[], char optionfilefiname[], double ageminpar, double agemaxpar, double fage , int prevfcast, int backcast, char pathc[], double p[], int offyear){
char dirfileres[132],optfileres[132];
- char gplotcondition[132];
+ char gplotcondition[132], gplotlabel[132];
int cpt=0,k1=0,i=0,k=0,j=0,jk=0,k2=0,k3=0,k4=0,ij=0, ijp=0, l=0;
int lv=0, vlv=0, kl=0;
int ng=0;
int vpopbased;
int ioffset; /* variable offset for columns */
int nres=0; /* Index of resultline */
+ int istart=1; /* For starting graphs in projections */
/* if((ficgp=fopen(optionfilegnuplot,"a"))==NULL) { */
/* printf("Problem with file %s",optionfilegnuplot); */
@@ -6664,6 +6830,7 @@ void printinggnuplot(char fileresu[], ch
/* We are interested in selected combination by the resultline */
/* printf("\n# 1st: Period (stable) prevalence with CI: 'VPL_' files and live state =%d ", cpt); */
fprintf(ficgp,"\n# 1st: Period (stable) prevalence with CI: 'VPL_' files and live state =%d ", cpt);
+ strcpy(gplotlabel,"(");
for (k=1; k<=cptcoveff; k++){ /* For each covariate k get corresponding value lv for combination k1 */
lv= decodtabm(k1,k,cptcoveff); /* Should be the value of the covariate corresponding to k1 combination */
/* decodtabm(1,1,4) = 1 because h=1 k= (1) 1 1 1 */
@@ -6673,37 +6840,70 @@ void printinggnuplot(char fileresu[], ch
/* For each combination of covariate k1 (V1=1, V3=0), we printed the current covariate k and its value vlv */
/* printf(" V%d=%d ",Tvaraff[k],vlv); */
fprintf(ficgp," V%d=%d ",Tvaraff[k],vlv);
+ sprintf(gplotlabel+strlen(gplotlabel)," V%d=%d ",Tvaraff[k],vlv);
}
for (k4=1; k4<= nsq; k4++){ /* For each selected (single) quantitative value */
/* printf(" V%d=%f ",Tvqresult[nres][k4],Tqresult[nres][k4]); */
fprintf(ficgp," V%d=%f ",Tvqresult[nres][k4],Tqresult[nres][k4]);
- }
+ sprintf(gplotlabel+strlen(gplotlabel)," V%d=%f ",Tvqresult[nres][k4],Tqresult[nres][k4]);
+ }
+ strcpy(gplotlabel+strlen(gplotlabel),")");
/* printf("\n#\n"); */
fprintf(ficgp,"\n#\n");
if(invalidvarcomb[k1]){
+ /*k1=k1-1;*/ /* To be checked */
fprintf(ficgp,"#Combination (%d) ignored because no cases \n",k1);
continue;
}
fprintf(ficgp,"\nset out \"%s_%d-%d-%d.svg\" \n",subdirf2(optionfilefiname,"V_"),cpt,k1,nres);
fprintf(ficgp,"\n#set out \"V_%s_%d-%d-%d.svg\" \n",optionfilefiname,cpt,k1,nres);
- fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability\" \nset ter svg size 640, 480\nplot [%.f:%.f] \"%s\" every :::%d::%d u 1:($2==%d ? $3:1/0) \"%%lf %%lf",ageminpar,fage,subdirf2(fileresu,"VPL_"),k1-1,k1-1,nres);
-
+ fprintf(ficgp,"set label \"Alive state %d %s\" at graph 0.98,0.5 center rotate font \"Helvetica,12\"\n",cpt,gplotlabel);
+ fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability\" \nset ter svg size 640, 480\nplot [%.f:%.f] \"%s\" every :::%d::%d u 1:($2==%d ? $3:1/0) \"%%lf %%lf",ageminpar,fage,subdirf2(fileresu,"VPL_"),nres-1,nres-1,nres);
+ /* fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability\" \nset ter svg size 640, 480\nplot [%.f:%.f] \"%s\" every :::%d::%d u 1:($2==%d ? $3:1/0) \"%%lf %%lf",ageminpar,fage,subdirf2(fileresu,"VPL_"),k1-1,k1-1,nres); */
+ /* k1-1 error should be nres-1*/
for (i=1; i<= nlstate ; i ++) {
if (i==cpt) fprintf(ficgp," %%lf (%%lf)");
else fprintf(ficgp," %%*lf (%%*lf)");
}
- fprintf(ficgp,"\" t\"Period (stable) prevalence\" w l lt 0,\"%s\" every :::%d::%d u 1:($2==%d ? $3+1.96*$4 : 1/0) \"%%lf %%lf",subdirf2(fileresu,"VPL_"),k1-1,k1-1,nres);
+ fprintf(ficgp,"\" t\"Period (stable) prevalence\" w l lt 0,\"%s\" every :::%d::%d u 1:($2==%d ? $3+1.96*$4 : 1/0) \"%%lf %%lf",subdirf2(fileresu,"VPL_"),nres-1,nres-1,nres);
for (i=1; i<= nlstate ; i ++) {
if (i==cpt) fprintf(ficgp," %%lf (%%lf)");
else fprintf(ficgp," %%*lf (%%*lf)");
}
- fprintf(ficgp,"\" t\"95%% CI\" w l lt 1,\"%s\" every :::%d::%d u 1:($2==%d ? $3-1.96*$4 : 1/0) \"%%lf %%lf",subdirf2(fileresu,"VPL_"),k1-1,k1-1,nres);
+ fprintf(ficgp,"\" t\"95%% CI\" w l lt 1,\"%s\" every :::%d::%d u 1:($2==%d ? $3-1.96*$4 : 1/0) \"%%lf %%lf",subdirf2(fileresu,"VPL_"),nres-1,nres-1,nres);
for (i=1; i<= nlstate ; i ++) {
if (i==cpt) fprintf(ficgp," %%lf (%%lf)");
else fprintf(ficgp," %%*lf (%%*lf)");
}
- fprintf(ficgp,"\" t\"\" w l lt 1,\"%s\" every :::%d::%d u 1:($%d) t\"Observed prevalence\" w l lt 2",subdirf2(fileresu,"P_"),k1-1,k1-1,2+4*(cpt-1));
+ /* fprintf(ficgp,"\" t\"\" w l lt 1,\"%s\" every :::%d::%d u 1:($%d) t\"Observed prevalence\" w l lt 2",subdirf2(fileresu,"P_"),k1-1,k1-1,2+4*(cpt-1)); */
+
+ fprintf(ficgp,"\" t\"\" w l lt 1,\"%s\" u 1:((",subdirf2(fileresu,"P_"));
+ if(cptcoveff ==0){
+ fprintf(ficgp,"$%d)) t 'Observed prevalence in state %d' with line lt 3", 2+(cpt-1), cpt );
+ }else{
+ kl=0;
+ for (k=1; k<=cptcoveff; k++){ /* For each combination of covariate */
+ lv= decodtabm(k1,k,cptcoveff); /* Should be the covariate value corresponding to k1 combination and kth covariate */
+ /* decodtabm(1,1,4) = 1 because h=1 k= (1) 1 1 1 */
+ /* decodtabm(1,2,4) = 1 because h=1 k= 1 (1) 1 1 */
+ /* decodtabm(13,3,4)= 2 because h=13 k= 1 1 (2) 2 */
+ vlv= nbcode[Tvaraff[k]][lv];
+ kl++;
+ /* kl=6+(cpt-1)*(nlstate+1)+1+(i-1); /\* 6+(1-1)*(2+1)+1+(1-1)=7, 6+(2-1)(2+1)+1+(1-1)=10 *\/ */
+ /*6+(cpt-1)*(nlstate+1)+1+(i-1)+(nlstate+1)*nlstate; 6+(1-1)*(2+1)+1+(1-1) +(2+1)*2=13 */
+ /*6+1+(i-1)+(nlstate+1)*nlstate; 6+1+(1-1) +(2+1)*2=13 */
+ /* '' u 6:(($1==1 && $2==0 && $3==2 && $4==0)? $9/(1.-$15) : 1/0):($5==2000? 3:2) t 'p.1' with line lc variable*/
+ if(k==cptcoveff){
+ fprintf(ficgp,"$%d==%d && $%d==%d)? $%d : 1/0) t 'Observed prevalence in state %d' w l lt 2",kl+1, Tvaraff[k],kl+1+1,nbcode[Tvaraff[k]][lv], \
+ 2+cptcoveff*2+3*(cpt-1), cpt ); /* 4 or 6 ?*/
+ }else{
+ fprintf(ficgp,"$%d==%d && $%d==%d && ",kl+1, Tvaraff[k],kl+1+1,nbcode[Tvaraff[k]][lv]);
+ kl++;
+ }
+ } /* end covariate */
+ } /* end if no covariate */
+
if(backcast==1){ /* We need to get the corresponding values of the covariates involved in this combination k1 */
/* fprintf(ficgp,",\"%s\" every :::%d::%d u 1:($%d) t\"Backward stable prevalence\" w l lt 3",subdirf2(fileresu,"PLB_"),k1-1,k1-1,1+cpt); */
fprintf(ficgp,",\"%s\" u 1:((",subdirf2(fileresu,"PLB_")); /* Age is in 1, nres in 2 to be fixed */
@@ -6732,7 +6932,7 @@ void printinggnuplot(char fileresu[], ch
} /* end covariate */
} /* end if no covariate */
} /* end if backcast */
- fprintf(ficgp,"\nset out \n");
+ fprintf(ficgp,"\nset out ;unset label;\n");
} /* nres */
} /* k1 */
} /* cpt */
@@ -6744,6 +6944,7 @@ void printinggnuplot(char fileresu[], ch
if(m != 1 && TKresult[nres]!= k1)
continue;
fprintf(ficgp,"\n# 2nd: Total life expectancy with CI: 't' files ");
+ strcpy(gplotlabel,"(");
for (k=1; k<=cptcoveff; k++){ /* For each covariate and each value */
lv= decodtabm(k1,k,cptcoveff); /* Should be the covariate number corresponding to k1 combination */
/* decodtabm(1,1,4) = 1 because h=1 k= (1) 1 1 1 */
@@ -6751,12 +6952,15 @@ void printinggnuplot(char fileresu[], ch
/* decodtabm(13,3,4)= 2 because h=13 k= 1 1 (2) 2 */
vlv= nbcode[Tvaraff[k]][lv];
fprintf(ficgp," V%d=%d ",Tvaraff[k],vlv);
+ sprintf(gplotlabel+strlen(gplotlabel)," V%d=%d ",Tvaraff[k],vlv);
}
/* for(k=1; k <= ncovds; k++){ */
for (k4=1; k4<= nsq; k4++){ /* For each selected (single) quantitative value */
printf(" V%d=%f ",Tvqresult[nres][k4],Tqresult[nres][k4]);
fprintf(ficgp," V%d=%f ",Tvqresult[nres][k4],Tqresult[nres][k4]);
+ sprintf(gplotlabel+strlen(gplotlabel)," V%d=%f ",Tvqresult[nres][k4],Tqresult[nres][k4]);
}
+ strcpy(gplotlabel+strlen(gplotlabel),")");
fprintf(ficgp,"\n#\n");
if(invalidvarcomb[k1]){
fprintf(ficgp,"#Combination (%d) ignored because no cases \n",k1);
@@ -6765,26 +6969,27 @@ void printinggnuplot(char fileresu[], ch
fprintf(ficgp,"\nset out \"%s_%d-%d.svg\" \n",subdirf2(optionfilefiname,"E_"),k1,nres);
for(vpopbased=0; vpopbased <= popbased; vpopbased++){ /* Done for vpopbased=0 and vpopbased=1 if popbased==1*/
- if(vpopbased==0)
+ fprintf(ficgp,"\nset label \"popbased %d %s\" at graph 0.98,0.5 center rotate font \"Helvetica,12\"\n",vpopbased,gplotlabel);
+ if(vpopbased==0){
fprintf(ficgp,"set ylabel \"Years\" \nset ter svg size 640, 480\nplot [%.f:%.f] ",ageminpar,fage);
- else
+ }else
fprintf(ficgp,"\nreplot ");
for (i=1; i<= nlstate+1 ; i ++) {
k=2*i;
- fprintf(ficgp,"\"%s\" every :::%d::%d u 1:($2==%d && $4!=0 ?$4 : 1/0) \"%%lf %%lf %%lf",subdirf2(fileresu,"T_"),k1-1,k1-1, vpopbased);
+ fprintf(ficgp,"\"%s\" every :::%d::%d u 1:($2==%d && $4!=0 ?$4 : 1/0) \"%%lf %%lf %%lf",subdirf2(fileresu,"T_"),nres-1,nres-1, vpopbased);
for (j=1; j<= nlstate+1 ; j ++) {
if (j==i) fprintf(ficgp," %%lf (%%lf)");
else fprintf(ficgp," %%*lf (%%*lf)");
}
if (i== 1) fprintf(ficgp,"\" t\"TLE\" w l lt %d, \\\n",i);
else fprintf(ficgp,"\" t\"LE in state (%d)\" w l lt %d, \\\n",i-1,i+1);
- fprintf(ficgp,"\"%s\" every :::%d::%d u 1:($2==%d && $4!=0 ? $4-$5*2 : 1/0) \"%%lf %%lf %%lf",subdirf2(fileresu,"T_"),k1-1,k1-1,vpopbased);
+ fprintf(ficgp,"\"%s\" every :::%d::%d u 1:($2==%d && $4!=0 ? $4-$5*2 : 1/0) \"%%lf %%lf %%lf",subdirf2(fileresu,"T_"),nres-1,nres-1,vpopbased);
for (j=1; j<= nlstate+1 ; j ++) {
if (j==i) fprintf(ficgp," %%lf (%%lf)");
else fprintf(ficgp," %%*lf (%%*lf)");
}
fprintf(ficgp,"\" t\"\" w l lt 0,");
- fprintf(ficgp,"\"%s\" every :::%d::%d u 1:($2==%d && $4!=0 ? $4+$5*2 : 1/0) \"%%lf %%lf %%lf",subdirf2(fileresu,"T_"),k1-1,k1-1,vpopbased);
+ fprintf(ficgp,"\"%s\" every :::%d::%d u 1:($2==%d && $4!=0 ? $4+$5*2 : 1/0) \"%%lf %%lf %%lf",subdirf2(fileresu,"T_"),nres-1,nres-1,vpopbased);
for (j=1; j<= nlstate+1 ; j ++) {
if (j==i) fprintf(ficgp," %%lf (%%lf)");
else fprintf(ficgp," %%*lf (%%*lf)");
@@ -6793,7 +6998,7 @@ void printinggnuplot(char fileresu[], ch
else fprintf(ficgp,"\" t\"\" w l lt 0,\\\n");
} /* state */
} /* vpopbased */
- fprintf(ficgp,"\nset out;set out \"%s_%d-%d.svg\"; replot; set out; \n",subdirf2(optionfilefiname,"E_"),k1,nres); /* Buggy gnuplot */
+ fprintf(ficgp,"\nset out;set out \"%s_%d-%d.svg\"; replot; set out; unset label;\n",subdirf2(optionfilefiname,"E_"),k1,nres); /* Buggy gnuplot */
} /* end nres */
} /* k1 end 2 eme*/
@@ -6805,7 +7010,8 @@ void printinggnuplot(char fileresu[], ch
continue;
for (cpt=1; cpt<= nlstate ; cpt ++) {
- fprintf(ficgp,"\n# 3d: Life expectancy with EXP_ files: combination=%d state=%d",k1, cpt);
+ fprintf(ficgp,"\n\n# 3d: Life expectancy with EXP_ files: combination=%d state=%d",k1, cpt);
+ strcpy(gplotlabel,"(");
for (k=1; k<=cptcoveff; k++){ /* For each covariate and each value */
lv= decodtabm(k1,k,cptcoveff); /* Should be the covariate number corresponding to k1 combination */
/* decodtabm(1,1,4) = 1 because h=1 k= (1) 1 1 1 */
@@ -6813,10 +7019,13 @@ void printinggnuplot(char fileresu[], ch
/* decodtabm(13,3,4)= 2 because h=13 k= 1 1 (2) 2 */
vlv= nbcode[Tvaraff[k]][lv];
fprintf(ficgp," V%d=%d ",Tvaraff[k],vlv);
+ sprintf(gplotlabel+strlen(gplotlabel)," V%d=%d ",Tvaraff[k],vlv);
}
for (k4=1; k4<= nsq; k4++){ /* For each selected (single) quantitative value */
fprintf(ficgp," V%d=%f ",Tvqresult[nres][k4],Tqresult[nres][k4]);
+ sprintf(gplotlabel+strlen(gplotlabel)," V%d=%f ",Tvqresult[nres][k4],Tqresult[nres][k4]);
}
+ strcpy(gplotlabel+strlen(gplotlabel),")");
fprintf(ficgp,"\n#\n");
if(invalidvarcomb[k1]){
fprintf(ficgp,"#Combination (%d) ignored because no cases \n",k1);
@@ -6826,8 +7035,9 @@ void printinggnuplot(char fileresu[], ch
/* k=2+nlstate*(2*cpt-2); */
k=2+(nlstate+1)*(cpt-1);
fprintf(ficgp,"\nset out \"%s_%d-%d-%d.svg\" \n",subdirf2(optionfilefiname,"EXP_"),cpt,k1,nres);
+ fprintf(ficgp,"set label \"%s\" at graph 0.98,0.5 center rotate font \"Helvetica,12\"\n",gplotlabel);
fprintf(ficgp,"set ter svg size 640, 480\n\
-plot [%.f:%.f] \"%s\" every :::%d::%d u 1:%d t \"e%d1\" w l",ageminpar,fage,subdirf2(fileresu,"E_"),k1-1,k1-1,k,cpt);
+plot [%.f:%.f] \"%s\" every :::%d::%d u 1:%d t \"e%d1\" w l",ageminpar,fage,subdirf2(fileresu,"E_"),nres-1,nres-1,k,cpt);
/*fprintf(ficgp,",\"e%s\" every :::%d::%d u 1:($%d-2*$%d) \"\%%lf ",fileres,k1-1,k1-1,k,k+1);
for (i=1; i<= nlstate*2 ; i ++) fprintf(ficgp,"\%%lf (\%%lf) ");
fprintf(ficgp,"\" t \"e%d1\" w l",cpt);
@@ -6837,12 +7047,13 @@ plot [%.f:%.f] \"%s\" every :::%d::%d u
*/
for (i=1; i< nlstate ; i ++) {
- fprintf(ficgp," ,\"%s\" every :::%d::%d u 1:%d t \"e%d%d\" w l",subdirf2(fileresu,"E_"),k1-1,k1-1,k+i,cpt,i+1);
+ fprintf(ficgp," ,\"%s\" every :::%d::%d u 1:%d t \"e%d%d\" w l",subdirf2(fileresu,"E_"),nres-1,nres-1,k+i,cpt,i+1);
/* fprintf(ficgp," ,\"%s\" every :::%d::%d u 1:%d t \"e%d%d\" w l",subdirf2(fileres,"e"),k1-1,k1-1,k+2*i,cpt,i+1);*/
}
- fprintf(ficgp," ,\"%s\" every :::%d::%d u 1:%d t \"e%d.\" w l",subdirf2(fileresu,"E_"),k1-1,k1-1,k+nlstate,cpt);
+ fprintf(ficgp," ,\"%s\" every :::%d::%d u 1:%d t \"e%d.\" w l",subdirf2(fileresu,"E_"),nres-1,nres-1,k+nlstate,cpt);
}
+ fprintf(ficgp,"\nunset label;\n");
} /* end nres */
} /* end kl 3eme */
@@ -6853,6 +7064,7 @@ plot [%.f:%.f] \"%s\" every :::%d::%d u
if(m != 1 && TKresult[nres]!= k1)
continue;
for (cpt=1; cpt<=nlstate ; cpt ++) { /* For each life state cpt*/
+ strcpy(gplotlabel,"(");
fprintf(ficgp,"\n#\n#\n# Survival functions in state j : 'LIJ_' files, cov=%d state=%d",k1, cpt);
for (k=1; k<=cptcoveff; k++){ /* For each covariate and each value */
lv= decodtabm(k1,k,cptcoveff); /* Should be the covariate number corresponding to k1 combination */
@@ -6861,10 +7073,13 @@ plot [%.f:%.f] \"%s\" every :::%d::%d u
/* decodtabm(13,3,4)= 2 because h=13 k= 1 1 (2) 2 */
vlv= nbcode[Tvaraff[k]][lv];
fprintf(ficgp," V%d=%d ",Tvaraff[k],vlv);
+ sprintf(gplotlabel+strlen(gplotlabel)," V%d=%d ",Tvaraff[k],vlv);
}
for (k4=1; k4<= nsq; k4++){ /* For each selected (single) quantitative value */
fprintf(ficgp," V%d=%f ",Tvqresult[nres][k4],Tqresult[nres][k4]);
+ sprintf(gplotlabel+strlen(gplotlabel)," V%d=%f ",Tvqresult[nres][k4],Tqresult[nres][k4]);
}
+ strcpy(gplotlabel+strlen(gplotlabel),")");
fprintf(ficgp,"\n#\n");
if(invalidvarcomb[k1]){
fprintf(ficgp,"#Combination (%d) ignored because no cases \n",k1);
@@ -6872,6 +7087,7 @@ plot [%.f:%.f] \"%s\" every :::%d::%d u
}
fprintf(ficgp,"\nset out \"%s_%d-%d-%d.svg\" \n",subdirf2(optionfilefiname,"LIJ_"),cpt,k1,nres);
+ fprintf(ficgp,"set label \"Alive state %d %s\" at graph 0.98,0.5 center rotate font \"Helvetica,12\"\n",cpt,gplotlabel);
fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability to be alive\" \n\
set ter svg size 640, 480\nunset log y\nplot [%.f:%.f] ", ageminpar, agemaxpar);
k=3;
@@ -6887,7 +7103,7 @@ set ter svg size 640, 480\nunset log y\n
fprintf(ficgp,"+$%d",k+l+j-1);
fprintf(ficgp,")) t \"l(%d,%d)\" w l",i,cpt);
} /* nlstate */
- fprintf(ficgp,"\nset out\n");
+ fprintf(ficgp,"\nset out; unset label;\n");
} /* end cpt state*/
} /* end nres */
} /* end covariate k1 */
@@ -6899,6 +7115,7 @@ set ter svg size 640, 480\nunset log y\n
if(m != 1 && TKresult[nres]!= k1)
continue;
for (cpt=1; cpt<=nlstate ; cpt ++) { /* For each inital state */
+ strcpy(gplotlabel,"(");
fprintf(ficgp,"\n#\n#\n# Survival functions in state j and all livestates from state i by final state j: 'lij' files, cov=%d state=%d",k1, cpt);
for (k=1; k<=cptcoveff; k++){ /* For each covariate and each value */
lv= decodtabm(k1,k,cptcoveff); /* Should be the covariate number corresponding to k1 combination */
@@ -6907,10 +7124,13 @@ set ter svg size 640, 480\nunset log y\n
/* decodtabm(13,3,4)= 2 because h=13 k= 1 1 (2) 2 */
vlv= nbcode[Tvaraff[k]][lv];
fprintf(ficgp," V%d=%d ",Tvaraff[k],vlv);
+ sprintf(gplotlabel+strlen(gplotlabel)," V%d=%d ",Tvaraff[k],vlv);
}
for (k4=1; k4<= nsq; k4++){ /* For each selected (single) quantitative value */
fprintf(ficgp," V%d=%f ",Tvqresult[nres][k4],Tqresult[nres][k4]);
+ sprintf(gplotlabel+strlen(gplotlabel)," V%d=%f ",Tvqresult[nres][k4],Tqresult[nres][k4]);
}
+ strcpy(gplotlabel+strlen(gplotlabel),")");
fprintf(ficgp,"\n#\n");
if(invalidvarcomb[k1]){
fprintf(ficgp,"#Combination (%d) ignored because no cases \n",k1);
@@ -6918,6 +7138,7 @@ set ter svg size 640, 480\nunset log y\n
}
fprintf(ficgp,"\nset out \"%s_%d-%d-%d.svg\" \n",subdirf2(optionfilefiname,"LIJT_"),cpt,k1,nres);
+ fprintf(ficgp,"set label \"Alive state %d %s\" at graph 0.98,0.5 center rotate font \"Helvetica,12\"\n",cpt,gplotlabel);
fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability to be alive\" \n\
set ter svg size 640, 480\nunset log y\nplot [%.f:%.f] ", ageminpar, agemaxpar);
k=3;
@@ -6941,7 +7162,7 @@ set ter svg size 640, 480\nunset log y\n
else
fprintf(ficgp,"$%d) t\"l(%d,.)\" w l",k+l,cpt);
}
- fprintf(ficgp,"\nset out\n");
+ fprintf(ficgp,"\nset out; unset label;\n");
} /* end cpt state*/
} /* end covariate */
} /* end nres */
@@ -6953,7 +7174,7 @@ set ter svg size 640, 480\nunset log y\n
if(m != 1 && TKresult[nres]!= k1)
continue;
for (cpt=1; cpt<=nlstate ; cpt ++) { /* For each life state of arrival */
-
+ strcpy(gplotlabel,"(");
fprintf(ficgp,"\n#\n#\n#CV preval stable (period): 'pij' files, covariatecombination#=%d state=%d",k1, cpt);
for (k=1; k<=cptcoveff; k++){ /* For each covariate and each value */
lv= decodtabm(k1,k,cptcoveff); /* Should be the covariate number corresponding to k1 combination */
@@ -6962,10 +7183,13 @@ set ter svg size 640, 480\nunset log y\n
/* decodtabm(13,3,4)= 2 because h=13 k= 1 1 (2) 2 */
vlv= nbcode[Tvaraff[k]][lv];
fprintf(ficgp," V%d=%d ",Tvaraff[k],vlv);
+ sprintf(gplotlabel+strlen(gplotlabel)," V%d=%d ",Tvaraff[k],vlv);
}
for (k4=1; k4<= nsq; k4++){ /* For each selected (single) quantitative value */
fprintf(ficgp," V%d=%f ",Tvqresult[nres][k4],Tqresult[nres][k4]);
+ sprintf(gplotlabel+strlen(gplotlabel)," V%d=%f ",Tvqresult[nres][k4],Tqresult[nres][k4]);
}
+ strcpy(gplotlabel+strlen(gplotlabel),")");
fprintf(ficgp,"\n#\n");
if(invalidvarcomb[k1]){
fprintf(ficgp,"#Combination (%d) ignored because no cases \n",k1);
@@ -6973,6 +7197,7 @@ set ter svg size 640, 480\nunset log y\n
}
fprintf(ficgp,"\nset out \"%s_%d-%d-%d.svg\" \n",subdirf2(optionfilefiname,"P_"),cpt,k1,nres);
+ fprintf(ficgp,"set label \"Alive state %d %s\" at graph 0.98,0.5 center rotate font \"Helvetica,12\"\n",cpt,gplotlabel);
fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability\" \n\
set ter svg size 640, 480\nunset log y\nplot [%.f:%.f] ", ageminpar, agemaxpar);
k=3; /* Offset */
@@ -6987,7 +7212,7 @@ set ter svg size 640, 480\nunset log y\n
fprintf(ficgp,"+$%d",k+l+j-1);
fprintf(ficgp,")) t \"prev(%d,%d)\" w l",i,cpt);
} /* nlstate */
- fprintf(ficgp,"\nset out\n");
+ fprintf(ficgp,"\nset out; unset label;\n");
} /* end cpt state*/
} /* end covariate */
@@ -7000,7 +7225,8 @@ set ter svg size 640, 480\nunset log y\n
if(m != 1 && TKresult[nres]!= k1)
continue;
for (cpt=1; cpt<=nlstate ; cpt ++) { /* For each life ending state */
- fprintf(ficgp,"\n#\n#\n#CV Back preval stable (period): 'pijb' files, covariatecombination#=%d state=%d",k1, cpt);
+ strcpy(gplotlabel,"(");
+ fprintf(ficgp,"\n#\n#\n#CV Back preval stable (period): 'pijb' files, covariatecombination#=%d state=%d",k1, cpt);
for (k=1; k<=cptcoveff; k++){ /* For each covariate and each value */
lv= decodtabm(k1,k,cptcoveff); /* Should be the covariate number corresponding to k1 combination */
/* decodtabm(1,1,4) = 1 because h=1 k= (1) 1 1 1 */
@@ -7008,10 +7234,13 @@ set ter svg size 640, 480\nunset log y\n
/* decodtabm(13,3,4)= 2 because h=13 k= 1 1 (2) 2 */
vlv= nbcode[Tvaraff[k]][lv];
fprintf(ficgp," V%d=%d ",Tvaraff[k],vlv);
+ sprintf(gplotlabel+strlen(gplotlabel)," V%d=%d ",Tvaraff[k],vlv);
}
for (k4=1; k4<= nsq; k4++){ /* For each selected (single) quantitative value */
fprintf(ficgp," V%d=%f ",Tvqresult[nres][k4],Tqresult[nres][k4]);
+ sprintf(gplotlabel+strlen(gplotlabel)," V%d=%f ",Tvqresult[nres][k4],Tqresult[nres][k4]);
}
+ strcpy(gplotlabel+strlen(gplotlabel),")");
fprintf(ficgp,"\n#\n");
if(invalidvarcomb[k1]){
fprintf(ficgp,"#Combination (%d) ignored because no cases \n",k1);
@@ -7019,6 +7248,7 @@ set ter svg size 640, 480\nunset log y\n
}
fprintf(ficgp,"\nset out \"%s_%d-%d-%d.svg\" \n",subdirf2(optionfilefiname,"PB_"),cpt,k1,nres);
+ fprintf(ficgp,"set label \"Ending alive state %d %s\" at graph 0.98,0.5 center rotate font \"Helvetica,12\"\n",cpt,gplotlabel);
fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability\" \n\
set ter svg size 640, 480\nunset log y\nplot [%.f:%.f] ", ageminpar, agemaxpar);
k=3; /* Offset */
@@ -7037,7 +7267,7 @@ set ter svg size 640, 480\nunset log y\n
/* /\* fprintf(ficgp,"+$%d",k+l+j-1); *\/ */
fprintf(ficgp,") t \"bprev(%d,%d)\" w l",i,cpt);
} /* nlstate */
- fprintf(ficgp,"\nset out\n");
+ fprintf(ficgp,"\nset out; unset label;\n");
} /* end cpt state*/
} /* end covariate */
} /* End if backcast */
@@ -7051,6 +7281,7 @@ set ter svg size 640, 480\nunset log y\n
if(m != 1 && TKresult[nres]!= k1)
continue;
for (cpt=1; cpt<=nlstate ; cpt ++) { /* For each life state */
+ strcpy(gplotlabel,"(");
fprintf(ficgp,"\n#\n#\n#Projection of prevalence to stable (period): 'PROJ_' files, covariatecombination#=%d state=%d",k1, cpt);
for (k=1; k<=cptcoveff; k++){ /* For each correspondig covariate value */
lv= decodtabm(k1,k,cptcoveff); /* Should be the covariate value corresponding to k1 combination and kth covariate */
@@ -7059,10 +7290,13 @@ set ter svg size 640, 480\nunset log y\n
/* decodtabm(13,3,4)= 2 because h=13 k= 1 1 (2) 2 */
vlv= nbcode[Tvaraff[k]][lv];
fprintf(ficgp," V%d=%d ",Tvaraff[k],vlv);
+ sprintf(gplotlabel+strlen(gplotlabel)," V%d=%d ",Tvaraff[k],vlv);
}
for (k4=1; k4<= nsq; k4++){ /* For each selected (single) quantitative value */
fprintf(ficgp," V%d=%f ",Tvqresult[nres][k4],Tqresult[nres][k4]);
+ sprintf(gplotlabel+strlen(gplotlabel)," V%d=%f ",Tvqresult[nres][k4],Tqresult[nres][k4]);
}
+ strcpy(gplotlabel+strlen(gplotlabel),")");
fprintf(ficgp,"\n#\n");
if(invalidvarcomb[k1]){
fprintf(ficgp,"#Combination (%d) ignored because no cases \n",k1);
@@ -7071,14 +7305,19 @@ set ter svg size 640, 480\nunset log y\n
fprintf(ficgp,"# hpijx=probability over h years, hp.jx is weighted by observed prev\n ");
fprintf(ficgp,"\nset out \"%s_%d-%d-%d.svg\" \n",subdirf2(optionfilefiname,"PROJ_"),cpt,k1,nres);
+ fprintf(ficgp,"set label \"Alive state %d %s\" at graph 0.98,0.5 center rotate font \"Helvetica,12\"\n",cpt,gplotlabel);
fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Prevalence\" \n\
set ter svg size 640, 480\nunset log y\nplot [%.f:%.f] ", ageminpar, agemaxpar);
- for (i=1; i<= nlstate+1 ; i ++){ /* nlstate +1 p11 p21 p.1 */
+
+ /* for (i=1; i<= nlstate+1 ; i ++){ /\* nlstate +1 p11 p21 p.1 *\/ */
+ istart=nlstate+1; /* Could be one if by state, but nlstate+1 is w.i projection only */
+ /*istart=1;*/ /* Could be one if by state, but nlstate+1 is w.i projection only */
+ for (i=istart; i<= nlstate+1 ; i ++){ /* nlstate +1 p11 p21 p.1 */
/*# V1 = 1 V2 = 0 yearproj age p11 p21 p.1 p12 p22 p.2 p13 p23 p.3*/
/*# 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 */
/*# yearproj age p11 p21 p.1 p12 p22 p.2 p13 p23 p.3*/
/*# 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 */
- if(i==1){
+ if(i==istart){
fprintf(ficgp,"\"%s\"",subdirf2(fileresu,"F_"));
}else{
fprintf(ficgp,",\\\n '' ");
@@ -7090,10 +7329,15 @@ set ter svg size 640, 480\nunset log y\n
/*# V1 = 1 yearproj age p11 p21 p31 p.1 p12 p22 p32 p.2 p13 p23 p33 p.3 p14 p24 p34 p.4*/
/*# 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 */
fprintf(ficgp," u %d:(", ioffset);
- if(i==nlstate+1)
- fprintf(ficgp," $%d/(1.-$%d)) t 'pw.%d' with line ", \
+ if(i==nlstate+1){
+ fprintf(ficgp," $%d/(1.-$%d)):5 t 'pw.%d' with line lc variable ", \
ioffset+(cpt-1)*(nlstate+1)+1+(i-1), ioffset+1+(i-1)+(nlstate+1)*nlstate,cpt );
- else
+ fprintf(ficgp,",\\\n '' ");
+ fprintf(ficgp," u %d:(",ioffset);
+ fprintf(ficgp," (($5-$6) == %d ) ? $%d/(1.-$%d) : 1/0):5 with labels center not ", \
+ offyear, \
+ ioffset+(cpt-1)*(nlstate+1)+1+(i-1), ioffset+1+(i-1)+(nlstate+1)*nlstate,cpt );
+ }else
fprintf(ficgp," $%d/(1.-$%d)) t 'p%d%d' with line ", \
ioffset+(cpt-1)*(nlstate+1)+1+(i-1), ioffset+1+(i-1)+(nlstate+1)*nlstate,i,cpt );
}else{ /* more than 2 covariates */
@@ -7125,15 +7369,21 @@ set ter svg size 640, 480\nunset log y\n
/*6+1+(i-1)+(nlstate+1)*nlstate; 6+1+(1-1) +(2+1)*2=13 */
/* '' u 6:(($1==1 && $2==0 && $3==2 && $4==0)? $9/(1.-$15) : 1/0):($5==2000? 3:2) t 'p.1' with line lc variable*/
if(i==nlstate+1){
- fprintf(ficgp,"%s ? $%d/(1.-$%d) : 1/0) t 'p.%d' with line ", gplotcondition, \
+ fprintf(ficgp,"%s ? $%d/(1.-$%d) : 1/0):5 t 'p.%d' with line lc variable", gplotcondition, \
+ ioffset+(cpt-1)*(nlstate+1)+1+(i-1), ioffset+1+(i-1)+(nlstate+1)*nlstate,cpt );
+ fprintf(ficgp,",\\\n '' ");
+ fprintf(ficgp," u %d:(",ioffset);
+ fprintf(ficgp,"%s && (($5-$6) == %d ) ? $%d/(1.-$%d) : 1/0):5 with labels center not ", gplotcondition, \
+ offyear, \
ioffset+(cpt-1)*(nlstate+1)+1+(i-1), ioffset+1+(i-1)+(nlstate+1)*nlstate,cpt );
+/* '' u 6:(($1==1 && $2==0 && $3==2 && $4==0) && (($5-$6) == 1947) ? $10/(1.-$22) : 1/0):5 with labels center boxed not*/
}else{
fprintf(ficgp,"%s ? $%d/(1.-$%d) : 1/0) t 'p%d%d' with line ", gplotcondition, \
ioffset+(cpt-1)*(nlstate+1)+1+(i-1), ioffset +1+(i-1)+(nlstate+1)*nlstate,i,cpt );
}
} /* end if covariate */
} /* nlstate */
- fprintf(ficgp,"\nset out\n");
+ fprintf(ficgp,"\nset out; unset label;\n");
} /* end cpt state*/
} /* end covariate */
} /* End if prevfcast */
@@ -7176,17 +7426,31 @@ set ter svg size 640, 480\nunset log y\n
fprintf(ficgp,"#Number of graphics: first is logit, 2nd is probabilities, third is incidences per year\n");
fprintf(ficgp,"#model=%s \n",model);
fprintf(ficgp,"# Type of graphic ng=%d\n",ng);
- fprintf(ficgp,"# jk=1 to 2^%d=%d\n",cptcoveff,m);/* to be checked */
- for(jk=1; jk <=m; jk++) /* For each combination of covariate */
+ fprintf(ficgp,"# k1=1 to 2^%d=%d\n",cptcoveff,m);/* to be checked */
+ for(k1=1; k1 <=m; k1++) /* For each combination of covariate */
for(nres=1; nres <= nresult; nres++){ /* For each resultline */
- if(m != 1 && TKresult[nres]!= jk)
+ if(m != 1 && TKresult[nres]!= k1)
continue;
- fprintf(ficgp,"# Combination of dummy jk=%d and ",jk);
+ fprintf(ficgp,"\n\n# Combination of dummy k1=%d which is ",k1);
+ strcpy(gplotlabel,"(");
+ sprintf(gplotlabel+strlen(gplotlabel)," Dummy combination %d ",k1);
+ for (k=1; k<=cptcoveff; k++){ /* For each correspondig covariate value */
+ lv= decodtabm(k1,k,cptcoveff); /* Should be the covariate value corresponding to k1 combination and kth covariate */
+ /* decodtabm(1,1,4) = 1 because h=1 k= (1) 1 1 1 */
+ /* decodtabm(1,2,4) = 1 because h=1 k= 1 (1) 1 1 */
+ /* decodtabm(13,3,4)= 2 because h=13 k= 1 1 (2) 2 */
+ vlv= nbcode[Tvaraff[k]][lv];
+ fprintf(ficgp," V%d=%d ",Tvaraff[k],vlv);
+ sprintf(gplotlabel+strlen(gplotlabel)," V%d=%d ",Tvaraff[k],vlv);
+ }
for (k4=1; k4<= nsq; k4++){ /* For each selected (single) quantitative value */
fprintf(ficgp," V%d=%f ",Tvqresult[nres][k4],Tqresult[nres][k4]);
+ sprintf(gplotlabel+strlen(gplotlabel)," V%d=%f ",Tvqresult[nres][k4],Tqresult[nres][k4]);
}
+ strcpy(gplotlabel+strlen(gplotlabel),")");
fprintf(ficgp,"\n#\n");
- fprintf(ficgp,"\nset out \"%s_%d-%d-%d.svg\" ",subdirf2(optionfilefiname,"PE_"),jk,ng,nres);
+ fprintf(ficgp,"\nset out \"%s_%d-%d-%d.svg\" ",subdirf2(optionfilefiname,"PE_"),k1,ng,nres);
+ fprintf(ficgp,"\nset label \"%s\" at graph 0.98,0.5 center rotate font \"Helvetica,12\"\n",gplotlabel);
fprintf(ficgp,"\nset ter svg size 640, 480 ");
if (ng==1){
fprintf(ficgp,"\nset ylabel \"Value of the logit of the model\"\n"); /* exp(a12+b12*x) could be nice */
@@ -7236,7 +7500,7 @@ set ter svg size 640, 480\nunset log y\n
fprintf(ficgp,"+p%d*%d*x",i+j+2+nagesqr-1,Tinvresult[nres][Tvar[j]]);;
}else{ /* quantitative */
fprintf(ficgp,"+p%d*%f*x",i+j+2+nagesqr-1,Tqinvresult[nres][Tvar[j]]); /* Tqinvresult in decoderesult */
- /* fprintf(ficgp,"+p%d*%d*x",i+j+nagesqr-1,nbcode[Tvar[j-2]][codtabm(jk,Tvar[j-2])]); */
+ /* fprintf(ficgp,"+p%d*%d*x",i+j+nagesqr-1,nbcode[Tvar[j-2]][codtabm(k1,Tvar[j-2])]); */
}
ij++;
}
@@ -7245,10 +7509,10 @@ set ter svg size 640, 480\nunset log y\n
if(ijp <=cptcovprod) { /* Product */
if(DummyV[Tvard[ijp][1]]==0){/* Vn is dummy */
if(DummyV[Tvard[ijp][2]]==0){/* Vn and Vm are dummy */
- /* fprintf(ficgp,"+p%d*%d*%d",i+j+2+nagesqr-1,nbcode[Tvard[ijp][1]][codtabm(jk,j)],nbcode[Tvard[ijp][2]][codtabm(jk,j)]); */
+ /* fprintf(ficgp,"+p%d*%d*%d",i+j+2+nagesqr-1,nbcode[Tvard[ijp][1]][codtabm(k1,j)],nbcode[Tvard[ijp][2]][codtabm(k1,j)]); */
fprintf(ficgp,"+p%d*%d*%d",i+j+2+nagesqr-1,Tinvresult[nres][Tvard[ijp][1]],Tinvresult[nres][Tvard[ijp][2]]);
}else{ /* Vn is dummy and Vm is quanti */
- /* fprintf(ficgp,"+p%d*%d*%f",i+j+2+nagesqr-1,nbcode[Tvard[ijp][1]][codtabm(jk,j)],Tqinvresult[nres][Tvard[ijp][2]]); */
+ /* fprintf(ficgp,"+p%d*%d*%f",i+j+2+nagesqr-1,nbcode[Tvard[ijp][1]][codtabm(k1,j)],Tqinvresult[nres][Tvard[ijp][2]]); */
fprintf(ficgp,"+p%d*%d*%f",i+j+2+nagesqr-1,Tinvresult[nres][Tvard[ijp][1]],Tqinvresult[nres][Tvard[ijp][2]]);
}
}else{ /* Vn*Vm Vn is quanti */
@@ -7261,12 +7525,12 @@ set ter svg size 640, 480\nunset log y\n
ijp++;
}
} else{ /* simple covariate */
- /* fprintf(ficgp,"+p%d*%d",i+j+2+nagesqr-1,nbcode[Tvar[j]][codtabm(jk,j)]); /\* Valgrind bug nbcode *\/ */
+ /* fprintf(ficgp,"+p%d*%d",i+j+2+nagesqr-1,nbcode[Tvar[j]][codtabm(k1,j)]); /\* Valgrind bug nbcode *\/ */
if(Dummy[j]==0){
fprintf(ficgp,"+p%d*%d",i+j+2+nagesqr-1,Tinvresult[nres][Tvar[j]]); /* */
}else{ /* quantitative */
fprintf(ficgp,"+p%d*%f",i+j+2+nagesqr-1,Tqinvresult[nres][Tvar[j]]); /* */
- /* fprintf(ficgp,"+p%d*%d*x",i+j+nagesqr-1,nbcode[Tvar[j-2]][codtabm(jk,Tvar[j-2])]); */
+ /* fprintf(ficgp,"+p%d*%d*x",i+j+nagesqr-1,nbcode[Tvar[j-2]][codtabm(k1,Tvar[j-2])]); */
}
} /* end simple */
} /* end j */
@@ -7279,23 +7543,23 @@ set ter svg size 640, 480\nunset log y\n
if(ng != 1){
fprintf(ficgp,")/(1");
- for(k1=1; k1 <=nlstate; k1++){
+ for(cpt=1; cpt <=nlstate; cpt++){
if(nagesqr==0)
- fprintf(ficgp,"+exp(p%d+p%d*x",k3+(k1-1)*ncovmodel,k3+(k1-1)*ncovmodel+1);
+ fprintf(ficgp,"+exp(p%d+p%d*x",k3+(cpt-1)*ncovmodel,k3+(cpt-1)*ncovmodel+1);
else /* nagesqr =1 */
- fprintf(ficgp,"+exp(p%d+p%d*x+p%d*x*x",k3+(k1-1)*ncovmodel,k3+(k1-1)*ncovmodel+1,k3+(k1-1)*ncovmodel+1+nagesqr);
+ fprintf(ficgp,"+exp(p%d+p%d*x+p%d*x*x",k3+(cpt-1)*ncovmodel,k3+(cpt-1)*ncovmodel+1,k3+(cpt-1)*ncovmodel+1+nagesqr);
ij=1;
for(j=3; j <=ncovmodel-nagesqr; j++){
if((j-2)==Tage[ij]) { /* Bug valgrind */
if(ij <=cptcovage) { /* Bug valgrind */
- fprintf(ficgp,"+p%d*%d*x",k3+(k1-1)*ncovmodel+1+j-2+nagesqr,nbcode[Tvar[j-2]][codtabm(jk,j-2)]);
- /* fprintf(ficgp,"+p%d*%d*x",k3+(k1-1)*ncovmodel+1+j-2+nagesqr,nbcode[Tvar[j-2]][codtabm(jk,Tvar[j-2])]); */
+ fprintf(ficgp,"+p%d*%d*x",k3+(cpt-1)*ncovmodel+1+j-2+nagesqr,nbcode[Tvar[j-2]][codtabm(k1,j-2)]);
+ /* fprintf(ficgp,"+p%d*%d*x",k3+(cpt-1)*ncovmodel+1+j-2+nagesqr,nbcode[Tvar[j-2]][codtabm(k1,Tvar[j-2])]); */
ij++;
}
}
else
- fprintf(ficgp,"+p%d*%d",k3+(k1-1)*ncovmodel+1+j-2+nagesqr,nbcode[Tvar[j-2]][codtabm(jk,j-2)]);/* Valgrind bug nbcode */
+ fprintf(ficgp,"+p%d*%d",k3+(cpt-1)*ncovmodel+1+j-2+nagesqr,nbcode[Tvar[j-2]][codtabm(k1,j-2)]);/* Valgrind bug nbcode */
}
fprintf(ficgp,")");
}
@@ -7315,8 +7579,8 @@ set ter svg size 640, 480\nunset log y\n
i=i+ncovmodel;
} /* end k */
} /* end k2 */
- fprintf(ficgp,"\n set out\n");
- } /* end jk */
+ fprintf(ficgp,"\n set out; unset label;\n");
+ } /* end k1 */
} /* end ng */
/* avoid: */
fflush(ficgp);
@@ -7332,10 +7596,11 @@ set ter svg size 640, 480\nunset log y\n
int mobilavrange, mob;
int iage=0;
- double sum=0.;
+ double sum=0., sumr=0.;
double age;
- double *sumnewp, *sumnewm;
- double *agemingood, *agemaxgood; /* Currently identical for all covariates */
+ double *sumnewp, *sumnewm, *sumnewmr;
+ double *agemingood, *agemaxgood;
+ double *agemingoodr, *agemaxgoodr;
/* modcovmax=2*cptcoveff;/\* Max number of modalities. We suppose */
@@ -7343,19 +7608,22 @@ set ter svg size 640, 480\nunset log y\n
sumnewp = vector(1,ncovcombmax);
sumnewm = vector(1,ncovcombmax);
+ sumnewmr = vector(1,ncovcombmax);
agemingood = vector(1,ncovcombmax);
+ agemingoodr = vector(1,ncovcombmax);
agemaxgood = vector(1,ncovcombmax);
+ agemaxgoodr = vector(1,ncovcombmax);
for (cptcod=1;cptcod<=ncovcombmax;cptcod++){
- sumnewm[cptcod]=0.;
+ sumnewm[cptcod]=0.; sumnewmr[cptcod]=0.;
sumnewp[cptcod]=0.;
- agemingood[cptcod]=0;
- agemaxgood[cptcod]=0;
+ agemingood[cptcod]=0, agemingoodr[cptcod]=0;
+ agemaxgood[cptcod]=0, agemaxgoodr[cptcod]=0;
}
if (cptcovn<1) ncovcombmax=1; /* At least 1 pass */
- if(mobilav==1||mobilav ==3 ||mobilav==5 ||mobilav== 7){
- if(mobilav==1) mobilavrange=5; /* default */
+ if(mobilav==-1 || mobilav==1||mobilav ==3 ||mobilav==5 ||mobilav== 7){
+ if(mobilav==1 || mobilav==-1) mobilavrange=5; /* default */
else mobilavrange=mobilav;
for (age=bage; age<=fage; age++)
for (i=1; i<=nlstate;i++)
@@ -7367,77 +7635,143 @@ set ter svg size 640, 480\nunset log y\n
*/
for (mob=3;mob <=mobilavrange;mob=mob+2){
for (age=bage+(mob-1)/2; age<=fage-(mob-1)/2; age++){
- for (i=1; i<=nlstate;i++){
- for (cptcod=1;cptcod<=ncovcombmax;cptcod++){
+ for (cptcod=1;cptcod<=ncovcombmax;cptcod++){
+ sumnewm[cptcod]=0.;
+ for (i=1; i<=nlstate;i++){
mobaverage[(int)age][i][cptcod] =probs[(int)age][i][cptcod];
for (cpt=1;cpt<=(mob-1)/2;cpt++){
mobaverage[(int)age][i][cptcod] +=probs[(int)age-cpt][i][cptcod];
mobaverage[(int)age][i][cptcod] +=probs[(int)age+cpt][i][cptcod];
}
mobaverage[(int)age][i][cptcod]=mobaverage[(int)age][i][cptcod]/mob;
- }
- }
+ sumnewm[cptcod]+=mobaverage[(int)age][i][cptcod];
+ } /* end i */
+ if(sumnewm[cptcod] >1.e-3) mobaverage[(int)age][i][cptcod]=mobaverage[(int)age][i][cptcod]/sumnewm[cptcod]; /* Rescaling to sum one */
+ } /* end cptcod */
}/* end age */
}/* end mob */
- }else
+ }else{
+ printf("Error internal in movingaverage, mobilav=%d.\n",mobilav);
return -1;
- for (cptcod=1;cptcod<=ncovcombmax;cptcod++){
+ }
+
+ for (cptcod=1;cptcod<=ncovcombmax;cptcod++){ /* for each combination */
/* for (age=bage+(mob-1)/2; age<=fage-(mob-1)/2; age++){ */
if(invalidvarcomb[cptcod]){
printf("\nCombination (%d) ignored because no cases \n",cptcod);
continue;
}
- agemingood[cptcod]=fage-(mob-1)/2;
- for (age=fage-(mob-1)/2; age>=bage; age--){/* From oldest to youngest, finding the youngest wrong */
+ for (age=fage-(mob-1)/2; age>=bage+(mob-1)/2; age--){ /*looking for the youngest and oldest good age */
sumnewm[cptcod]=0.;
+ sumnewmr[cptcod]=0.;
for (i=1; i<=nlstate;i++){
sumnewm[cptcod]+=mobaverage[(int)age][i][cptcod];
+ sumnewmr[cptcod]+=probs[(int)age][i][cptcod];
+ }
+ if(fabs(sumnewmr[cptcod] - 1.) <= 1.e-3) { /* good without smoothing */
+ agemingoodr[cptcod]=age;
}
if(fabs(sumnewm[cptcod] - 1.) <= 1.e-3) { /* good */
- agemingood[cptcod]=age;
- }else{ /* bad */
- for (i=1; i<=nlstate;i++){
- mobaverage[(int)age][i][cptcod]=mobaverage[(int)agemingood[cptcod]][i][cptcod];
- } /* i */
- } /* end bad */
- }/* age */
- sum=0.;
- for (i=1; i<=nlstate;i++){
- sum+=mobaverage[(int)agemingood[cptcod]][i][cptcod];
- }
- if(fabs(sum - 1.) > 1.e-3) { /* bad */
- printf("For this combination of covariate cptcod=%d, we can't get a smoothed prevalence which sums to one at any descending age!\n",cptcod);
- /* for (i=1; i<=nlstate;i++){ */
- /* mobaverage[(int)age][i][cptcod]=mobaverage[(int)agemingood[cptcod]][i][cptcod]; */
- /* } /\* i *\/ */
- } /* end bad */
- /* else{ /\* We found some ages summing to one, we will smooth the oldest *\/ */
- /* From youngest, finding the oldest wrong */
- agemaxgood[cptcod]=bage+(mob-1)/2;
- for (age=bage+(mob-1)/2; age<=fage; age++){
+ agemingood[cptcod]=age;
+ }
+ } /* age */
+ for (age=bage+(mob-1)/2; age<=fage-(mob-1)/2; age++){ /*looking for the youngest and oldest good age */
sumnewm[cptcod]=0.;
+ sumnewmr[cptcod]=0.;
for (i=1; i<=nlstate;i++){
sumnewm[cptcod]+=mobaverage[(int)age][i][cptcod];
+ sumnewmr[cptcod]+=probs[(int)age][i][cptcod];
+ }
+ if(fabs(sumnewmr[cptcod] - 1.) <= 1.e-3) { /* good without smoothing */
+ agemaxgoodr[cptcod]=age;
}
if(fabs(sumnewm[cptcod] - 1.) <= 1.e-3) { /* good */
agemaxgood[cptcod]=age;
- }else{ /* bad */
- for (i=1; i<=nlstate;i++){
- mobaverage[(int)age][i][cptcod]=mobaverage[(int)agemaxgood[cptcod]][i][cptcod];
- } /* i */
+ }
+ } /* age */
+ /* Thus we have agemingood and agemaxgood as well as goodr for raw (preobs) */
+ /* but they will change */
+ for (age=fage-(mob-1)/2; age>=bage; age--){/* From oldest to youngest, filling up to the youngest */
+ sumnewm[cptcod]=0.;
+ sumnewmr[cptcod]=0.;
+ for (i=1; i<=nlstate;i++){
+ sumnewm[cptcod]+=mobaverage[(int)age][i][cptcod];
+ sumnewmr[cptcod]+=probs[(int)age][i][cptcod];
+ }
+ if(mobilav==-1){ /* Forcing raw ages if good else agemingood */
+ if(fabs(sumnewmr[cptcod] - 1.) <= 1.e-3) { /* good without smoothing */
+ agemaxgoodr[cptcod]=age; /* age min */
+ for (i=1; i<=nlstate;i++)
+ mobaverage[(int)age][i][cptcod]=probs[(int)age][i][cptcod];
+ }else{ /* bad we change the value with the values of good ages */
+ for (i=1; i<=nlstate;i++){
+ mobaverage[(int)age][i][cptcod]=mobaverage[(int)agemaxgoodr[cptcod]][i][cptcod];
+ } /* i */
+ } /* end bad */
+ }else{
+ if(fabs(sumnewm[cptcod] - 1.) <= 1.e-3) { /* good */
+ agemaxgood[cptcod]=age;
+ }else{ /* bad we change the value with the values of good ages */
+ for (i=1; i<=nlstate;i++){
+ mobaverage[(int)age][i][cptcod]=mobaverage[(int)agemaxgood[cptcod]][i][cptcod];
+ } /* i */
+ } /* end bad */
+ }/* end else */
+ sum=0.;sumr=0.;
+ for (i=1; i<=nlstate;i++){
+ sum+=mobaverage[(int)age][i][cptcod];
+ sumr+=probs[(int)age][i][cptcod];
+ }
+ if(fabs(sum - 1.) > 1.e-3) { /* bad */
+ printf("Moving average A1: For this combination of covariate cptcod=%d, we can't get a smoothed prevalence which sums to one (%f) at any descending age! age=%d, could you increase bage=%d\n",cptcod,sumr, (int)age, bage);
+ } /* end bad */
+ /* else{ /\* We found some ages summing to one, we will smooth the oldest *\/ */
+ if(fabs(sumr - 1.) > 1.e-3) { /* bad */
+ printf("Moving average A2: For this combination of covariate cptcod=%d, the raw prevalence doesn't sums to one (%f) even with smoothed values at young ages! age=%d, could you increase bage=%d\n",cptcod,sumr, (int)age, bage);
} /* end bad */
}/* age */
- sum=0.;
- for (i=1; i<=nlstate;i++){
- sum+=mobaverage[(int)agemaxgood[cptcod]][i][cptcod];
- }
- if(fabs(sum - 1.) > 1.e-3) { /* bad */
- printf("For this combination of covariate cptcod=%d, we can't get a smoothed prevalence which sums to one at any ascending age!\n",cptcod);
- /* for (i=1; i<=nlstate;i++){ */
- /* mobaverage[(int)age][i][cptcod]=mobaverage[(int)agemingood[cptcod]][i][cptcod]; */
- /* } /\* i *\/ */
- } /* end bad */
+
+ for (age=bage+(mob-1)/2; age<=fage; age++){/* From youngest, finding the oldest wrong */
+ sumnewm[cptcod]=0.;
+ sumnewmr[cptcod]=0.;
+ for (i=1; i<=nlstate;i++){
+ sumnewm[cptcod]+=mobaverage[(int)age][i][cptcod];
+ sumnewmr[cptcod]+=probs[(int)age][i][cptcod];
+ }
+ if(mobilav==-1){ /* Forcing raw ages if good else agemingood */
+ if(fabs(sumnewmr[cptcod] - 1.) <= 1.e-3) { /* good */
+ agemingoodr[cptcod]=age;
+ for (i=1; i<=nlstate;i++)
+ mobaverage[(int)age][i][cptcod]=probs[(int)age][i][cptcod];
+ }else{ /* bad we change the value with the values of good ages */
+ for (i=1; i<=nlstate;i++){
+ mobaverage[(int)age][i][cptcod]=mobaverage[(int)agemingoodr[cptcod]][i][cptcod];
+ } /* i */
+ } /* end bad */
+ }else{
+ if(fabs(sumnewm[cptcod] - 1.) <= 1.e-3) { /* good */
+ agemingood[cptcod]=age;
+ }else{ /* bad */
+ for (i=1; i<=nlstate;i++){
+ mobaverage[(int)age][i][cptcod]=mobaverage[(int)agemingood[cptcod]][i][cptcod];
+ } /* i */
+ } /* end bad */
+ }/* end else */
+ sum=0.;sumr=0.;
+ for (i=1; i<=nlstate;i++){
+ sum+=mobaverage[(int)age][i][cptcod];
+ sumr+=mobaverage[(int)age][i][cptcod];
+ }
+ if(fabs(sum - 1.) > 1.e-3) { /* bad */
+ printf("Moving average B1: For this combination of covariate cptcod=%d, we can't get a smoothed prevalence which sums to one (%f) at any descending age! age=%d, could you decrease fage=%d?\n",cptcod, sum, (int) age, fage);
+ } /* end bad */
+ /* else{ /\* We found some ages summing to one, we will smooth the oldest *\/ */
+ if(fabs(sumr - 1.) > 1.e-3) { /* bad */
+ printf("Moving average B2: For this combination of covariate cptcod=%d, the raw prevalence doesn't sums to one (%f) even with smoothed values at young ages! age=%d, could you increase fage=%d\n",cptcod,sumr, (int)age, fage);
+ } /* end bad */
+ }/* age */
+
for (age=bage; age<=fage; age++){
/* printf("%d %d ", cptcod, (int)age); */
@@ -7452,40 +7786,44 @@ set ter svg size 640, 480\nunset log y\n
}
/* printf("\n"); */
/* } */
+
/* brutal averaging */
- for (i=1; i<=nlstate;i++){
- for (age=1; age<=bage; age++){
- mobaverage[(int)age][i][cptcod]=mobaverage[(int)agemingood[cptcod]][i][cptcod];
- /* printf("age=%d i=%d cptcod=%d mobaverage=%.4f \n",(int)age,i, cptcod, mobaverage[(int)age][i][cptcod]); */
- }
- for (age=fage; age<=AGESUP; age++){
- mobaverage[(int)age][i][cptcod]=mobaverage[(int)agemaxgood[cptcod]][i][cptcod];
- /* printf("age=%d i=%d cptcod=%d mobaverage=%.4f \n",(int)age,i, cptcod, mobaverage[(int)age][i][cptcod]); */
- }
- } /* end i status */
- for (i=nlstate+1; i<=nlstate+ndeath;i++){
- for (age=1; age<=AGESUP; age++){
- /*printf("i=%d, age=%d, cptcod=%d\n",i, (int)age, cptcod);*/
- mobaverage[(int)age][i][cptcod]=0.;
- }
- }
+ /* for (i=1; i<=nlstate;i++){ */
+ /* for (age=1; age<=bage; age++){ */
+ /* mobaverage[(int)age][i][cptcod]=mobaverage[(int)agemingood[cptcod]][i][cptcod]; */
+ /* /\* printf("age=%d i=%d cptcod=%d mobaverage=%.4f \n",(int)age,i, cptcod, mobaverage[(int)age][i][cptcod]); *\/ */
+ /* } */
+ /* for (age=fage; age<=AGESUP; age++){ */
+ /* mobaverage[(int)age][i][cptcod]=mobaverage[(int)agemaxgood[cptcod]][i][cptcod]; */
+ /* /\* printf("age=%d i=%d cptcod=%d mobaverage=%.4f \n",(int)age,i, cptcod, mobaverage[(int)age][i][cptcod]); *\/ */
+ /* } */
+ /* } /\* end i status *\/ */
+ /* for (i=nlstate+1; i<=nlstate+ndeath;i++){ */
+ /* for (age=1; age<=AGESUP; age++){ */
+ /* /\*printf("i=%d, age=%d, cptcod=%d\n",i, (int)age, cptcod);*\/ */
+ /* mobaverage[(int)age][i][cptcod]=0.; */
+ /* } */
+ /* } */
}/* end cptcod */
- free_vector(sumnewm,1, ncovcombmax);
- free_vector(sumnewp,1, ncovcombmax);
+ free_vector(agemaxgoodr,1, ncovcombmax);
free_vector(agemaxgood,1, ncovcombmax);
free_vector(agemingood,1, ncovcombmax);
+ free_vector(agemingoodr,1, ncovcombmax);
+ free_vector(sumnewmr,1, ncovcombmax);
+ free_vector(sumnewm,1, ncovcombmax);
+ free_vector(sumnewp,1, ncovcombmax);
return 0;
}/* End movingaverage */
/************** Forecasting ******************/
- void prevforecast(char fileres[], double anproj1, double mproj1, double jproj1, double ageminpar, double agemax, double dateprev1, double dateprev2, int mobilav, double bage, double fage, int firstpass, int lastpass, double anproj2, double p[], int cptcoveff){
+void prevforecast(char fileres[], double anproj1, double mproj1, double jproj1, double ageminpar, double agemax, double dateprev1, double dateprev2, int mobilav, double bage, double fage, int firstpass, int lastpass, double anproj2, double p[], int cptcoveff){
/* proj1, year, month, day of starting projection
agemin, agemax range of age
dateprev1 dateprev2 range of dates during which prevalence is computed
anproj2 year of en of projection (same day and month as proj1).
*/
- int yearp, stepsize, hstepm, nhstepm, j, k, cptcod, i, h, i1, k4, nres=0;
+ int yearp, stepsize, hstepm, nhstepm, j, k, cptcod, i, h, i1, k4, nres=0;
double agec; /* generic age */
double agelim, ppij, yp,yp1,yp2,jprojmean,mprojmean,anprojmean;
double *popeffectif,*popcount;
@@ -7580,11 +7918,11 @@ set ter svg size 640, 480\nunset log y\n
for(j=1; j<=nlstate+ndeath;j++) {
ppij=0.;
for(i=1; i<=nlstate;i++) {
- if (mobilav==1)
+ /* if (mobilav>=1) */
ppij=ppij+p3mat[i][j][h]*mobaverage[(int)agec][i][k];
- else {
- ppij=ppij+p3mat[i][j][h]*probs[(int)(agec)][i][k];
- }
+ /* else { */ /* even if mobilav==-1 we use mobaverage */
+ /* ppij=ppij+p3mat[i][j][h]*probs[(int)(agec)][i][k]; */
+ /* } */
if (h*hstepm/YEARM*stepm== yearp) {
fprintf(ficresf," %.3f", p3mat[i][j][h]);
}
@@ -7596,6 +7934,8 @@ set ter svg size 640, 480\nunset log y\n
} /* end h */
free_ma3x(p3mat,1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);
} /* end agec */
+ /* diffyear=(int) anproj1+yearp-ageminpar-1; */
+ /*printf("Prevforecast %d+%d-%d=diffyear=%d\n",(int) anproj1, (int)yearp,(int)ageminpar,(int) anproj1-(int)ageminpar);*/
} /* end yearp */
} /* end k */
@@ -7606,134 +7946,143 @@ set ter svg size 640, 480\nunset log y\n
}
/* /\************** Back Forecasting ******************\/ */
-/* void prevbackforecast(char fileres[], double anback1, double mback1, double jback1, double ageminpar, double agemax, double dateprev1, double dateprev2, int mobilav, double bage, double fage, int firstpass, int lastpass, double anback2, double p[], int cptcoveff){ */
-/* /\* back1, year, month, day of starting backection */
-/* agemin, agemax range of age */
-/* dateprev1 dateprev2 range of dates during which prevalence is computed */
-/* anback2 year of en of backection (same day and month as back1). */
-/* *\/ */
-/* int yearp, stepsize, hstepm, nhstepm, j, k, cptcod, i, h, i1; */
-/* double agec; /\* generic age *\/ */
-/* double agelim, ppij, yp,yp1,yp2,jprojmean,mprojmean,anprojmean; */
-/* double *popeffectif,*popcount; */
-/* double ***p3mat; */
-/* /\* double ***mobaverage; *\/ */
-/* char fileresfb[FILENAMELENGTH]; */
-
-/* agelim=AGESUP; */
-/* /\* Compute observed prevalence between dateprev1 and dateprev2 by counting the number of people */
-/* in each health status at the date of interview (if between dateprev1 and dateprev2). */
-/* We still use firstpass and lastpass as another selection. */
-/* *\/ */
-/* /\* freqsummary(fileres, agemin, agemax, s, agev, nlstate, imx,Tvaraff,nbcode, ncodemax,mint,anint,strstart,\ *\/ */
-/* /\* firstpass, lastpass, stepm, weightopt, model); *\/ */
-/* prevalence(probs, ageminpar, agemax, s, agev, nlstate, imx, Tvar, nbcode, ncodemax, mint, anint, dateprev1, dateprev2, firstpass, lastpass); */
-
-/* strcpy(fileresfb,"FB_"); */
-/* strcat(fileresfb,fileresu); */
-/* if((ficresfb=fopen(fileresfb,"w"))==NULL) { */
-/* printf("Problem with back forecast resultfile: %s\n", fileresfb); */
-/* fprintf(ficlog,"Problem with back forecast resultfile: %s\n", fileresfb); */
-/* } */
-/* printf("Computing back forecasting: result on file '%s', please wait... \n", fileresfb); */
-/* fprintf(ficlog,"Computing back forecasting: result on file '%s', please wait... \n", fileresfb); */
-
-/* if (cptcoveff==0) ncodemax[cptcoveff]=1; */
-
-/* /\* if (mobilav!=0) { *\/ */
-/* /\* mobaverage= ma3x(1, AGESUP,1,NCOVMAX, 1,NCOVMAX); *\/ */
-/* /\* if (movingaverage(probs, ageminpar, fage, mobaverage,mobilav)!=0){ *\/ */
-/* /\* fprintf(ficlog," Error in movingaverage mobilav=%d\n",mobilav); *\/ */
-/* /\* printf(" Error in movingaverage mobilav=%d\n",mobilav); *\/ */
-/* /\* } *\/ */
-/* /\* } *\/ */
-
-/* stepsize=(int) (stepm+YEARM-1)/YEARM; */
-/* if (stepm<=12) stepsize=1; */
-/* if(estepm < stepm){ */
-/* printf ("Problem %d lower than %d\n",estepm, stepm); */
-/* } */
-/* else hstepm=estepm; */
-
-/* hstepm=hstepm/stepm; */
-/* yp1=modf(dateintmean,&yp);/\* extracts integral of datemean in yp and */
-/* fractional in yp1 *\/ */
-/* anprojmean=yp; */
-/* yp2=modf((yp1*12),&yp); */
-/* mprojmean=yp; */
-/* yp1=modf((yp2*30.5),&yp); */
-/* jprojmean=yp; */
-/* if(jprojmean==0) jprojmean=1; */
-/* if(mprojmean==0) jprojmean=1; */
-
-/* i1=cptcoveff; */
-/* if (cptcovn < 1){i1=1;} */
+void prevbackforecast(char fileres[], double ***prevacurrent, double anback1, double mback1, double jback1, double ageminpar, double agemax, double dateprev1, double dateprev2, int mobilav, double bage, double fage, int firstpass, int lastpass, double anback2, double p[], int cptcoveff){
+ /* back1, year, month, day of starting backection
+ agemin, agemax range of age
+ dateprev1 dateprev2 range of dates during which prevalence is computed
+ anback2 year of en of backection (same day and month as back1).
+ */
+ int yearp, stepsize, hstepm, nhstepm, j, k, cptcod, i, h, i1, k4, nres=0;
+ double agec; /* generic age */
+ double agelim, ppij, yp,yp1,yp2,jprojmean,mprojmean,anprojmean;
+ double *popeffectif,*popcount;
+ double ***p3mat;
+ /* double ***mobaverage; */
+ char fileresfb[FILENAMELENGTH];
+
+ agelim=AGESUP;
+ /* Compute observed prevalence between dateprev1 and dateprev2 by counting the number of people
+ in each health status at the date of interview (if between dateprev1 and dateprev2).
+ We still use firstpass and lastpass as another selection.
+ */
+ /* freqsummary(fileres, agemin, agemax, s, agev, nlstate, imx,Tvaraff,nbcode, ncodemax,mint,anint,strstart,\ */
+ /* firstpass, lastpass, stepm, weightopt, model); */
+
+ /*Do we need to compute prevalence again?*/
+
+ /* prevalence(probs, ageminpar, agemax, s, agev, nlstate, imx, Tvar, nbcode, ncodemax, mint, anint, dateprev1, dateprev2, firstpass, lastpass); */
-/* fprintf(ficresfb,"# Mean day of interviews %.lf/%.lf/%.lf (%.2f) between %.2f and %.2f \n",jprojmean,mprojmean,anprojmean,dateintmean,dateprev1,dateprev2); */
+ strcpy(fileresfb,"FB_");
+ strcat(fileresfb,fileresu);
+ if((ficresfb=fopen(fileresfb,"w"))==NULL) {
+ printf("Problem with back forecast resultfile: %s\n", fileresfb);
+ fprintf(ficlog,"Problem with back forecast resultfile: %s\n", fileresfb);
+ }
+ printf("\nComputing back forecasting: result on file '%s', please wait... \n", fileresfb);
+ fprintf(ficlog,"\nComputing back forecasting: result on file '%s', please wait... \n", fileresfb);
-/* fprintf(ficresfb,"#****** Routine prevbackforecast **\n"); */
-
-/* /\* if (h==(int)(YEARM*yearp)){ *\/ */
-/* for(cptcov=1, k=0;cptcov<=i1;cptcov++){ */
-/* for(cptcod=1;cptcod<=ncodemax[cptcoveff];cptcod++){ */
-/* k=k+1; */
-/* fprintf(ficresfb,"\n#****** hbijx=probability over h years, hp.jx is weighted by observed prev \n#"); */
-/* for(j=1;j<=cptcoveff;j++) { */
-/* fprintf(ficresfb," V%d (=) %d",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]); */
-/* } */
-/* fprintf(ficresfb," yearbproj age"); */
-/* for(j=1; j<=nlstate+ndeath;j++){ */
-/* for(i=1; i<=nlstate;i++) */
-/* fprintf(ficresfb," p%d%d",i,j); */
-/* fprintf(ficresfb," p.%d",j); */
-/* } */
-/* for (yearp=0; yearp>=(anback2-anback1);yearp -=stepsize) { */
-/* /\* for (yearp=0; yearp<=(anproj2-anproj1);yearp +=stepsize) { *\/ */
-/* fprintf(ficresfb,"\n"); */
-/* fprintf(ficresfb,"\n# Back Forecasting at date %.lf/%.lf/%.lf ",jback1,mback1,anback1+yearp); */
-/* for (agec=fage; agec>=(ageminpar-1); agec--){ */
-/* nhstepm=(int) rint((agelim-agec)*YEARM/stepm); */
-/* nhstepm = nhstepm/hstepm; */
-/* p3mat=ma3x(1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm); */
-/* oldm=oldms;savm=savms; */
-/* hbxij(p3mat,nhstepm,agec,hstepm,p,prevacurrent,nlstate,stepm,oldm,savm,oldm,savm, dnewm, doldm, dsavm, k); */
-/* for (h=0; h<=nhstepm; h++){ */
-/* if (h*hstepm/YEARM*stepm ==yearp) { */
-/* fprintf(ficresfb,"\n"); */
-/* for(j=1;j<=cptcoveff;j++) */
-/* fprintf(ficresfb,"%d %d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]); */
-/* fprintf(ficresfb,"%.f %.f ",anback1+yearp,agec+h*hstepm/YEARM*stepm); */
-/* } */
-/* for(j=1; j<=nlstate+ndeath;j++) { */
-/* ppij=0.; */
-/* for(i=1; i<=nlstate;i++) { */
-/* if (mobilav==1) */
-/* ppij=ppij+p3mat[i][j][h]*mobaverage[(int)agec][i][cptcod]; */
-/* else { */
-/* ppij=ppij+p3mat[i][j][h]*probs[(int)(agec)][i][cptcod]; */
-/* } */
-/* if (h*hstepm/YEARM*stepm== yearp) { */
-/* fprintf(ficresfb," %.3f", p3mat[i][j][h]); */
-/* } */
-/* } /\* end i *\/ */
-/* if (h*hstepm/YEARM*stepm==yearp) { */
-/* fprintf(ficresfb," %.3f", ppij); */
-/* } */
-/* }/\* end j *\/ */
-/* } /\* end h *\/ */
-/* free_ma3x(p3mat,1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm); */
-/* } /\* end agec *\/ */
-/* } /\* end yearp *\/ */
-/* } /\* end cptcod *\/ */
-/* } /\* end cptcov *\/ */
-
-/* /\* if (mobilav!=0) free_ma3x(mobaverage,1, AGESUP,1,NCOVMAX, 1,NCOVMAX); *\/ */
-
-/* fclose(ficresfb); */
-/* printf("End of Computing Back forecasting \n"); */
-/* fprintf(ficlog,"End of Computing Back forecasting\n"); */
+ if (cptcoveff==0) ncodemax[cptcoveff]=1;
+
+
+ stepsize=(int) (stepm+YEARM-1)/YEARM;
+ if (stepm<=12) stepsize=1;
+ if(estepm < stepm){
+ printf ("Problem %d lower than %d\n",estepm, stepm);
+ }
+ else hstepm=estepm;
+
+ hstepm=hstepm/stepm;
+ yp1=modf(dateintmean,&yp);/* extracts integral of datemean in yp and
+ fractional in yp1 */
+ anprojmean=yp;
+ yp2=modf((yp1*12),&yp);
+ mprojmean=yp;
+ yp1=modf((yp2*30.5),&yp);
+ jprojmean=yp;
+ if(jprojmean==0) jprojmean=1;
+ if(mprojmean==0) jprojmean=1;
+
+ i1=pow(2,cptcoveff);
+ if (cptcovn < 1){i1=1;}
+
+ fprintf(ficresfb,"# Mean day of interviews %.lf/%.lf/%.lf (%.2f) between %.2f and %.2f \n",jprojmean,mprojmean,anprojmean,dateintmean,dateprev1,dateprev2);
+
+ fprintf(ficresfb,"#****** Routine prevbackforecast **\n");
+
+ /* if (h==(int)(YEARM*yearp)){ */
+ /* for(cptcov=1, k=0;cptcov<=i1;cptcov++){ */
+ /* for(cptcod=1;cptcod<=ncodemax[cptcoveff];cptcod++){ */
+ /* k=k+1; */
+ for(nres=1; nres <= nresult; nres++) /* For each resultline */
+ for(k=1; k<=i1;k++){
+ if(i1 != 1 && TKresult[nres]!= k)
+ continue;
+ if(invalidvarcomb[k]){
+ printf("\nCombination (%d) projection ignored because no cases \n",k);
+ continue;
+ }
+ fprintf(ficresfb,"\n#****** hbijx=probability over h years, hp.jx is weighted by observed prev \n#");
+ for(j=1;j<=cptcoveff;j++) {
+ fprintf(ficresfb," V%d (=) %d",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
+ }
+ for (k4=1; k4<= nsq; k4++){ /* For each selected (single) quantitative value */
+ fprintf(ficresf," V%d=%f ",Tvqresult[nres][k4],Tqresult[nres][k4]);
+ }
+ fprintf(ficresfb," yearbproj age");
+ for(j=1; j<=nlstate+ndeath;j++){
+ for(i=1; i<=nlstate;i++)
+ fprintf(ficresfb," p%d%d",i,j);
+ fprintf(ficresfb," p.%d",j);
+ }
+ for (yearp=0; yearp>=(anback2-anback1);yearp -=stepsize) {
+ /* for (yearp=0; yearp<=(anproj2-anproj1);yearp +=stepsize) { */
+ fprintf(ficresfb,"\n");
+ fprintf(ficresfb,"\n# Back Forecasting at date %.lf/%.lf/%.lf ",jback1,mback1,anback1+yearp);
+ /* for (agec=fage; agec>=(ageminpar-1); agec--){ */
+ /* nhstepm=(int) rint((agelim-agec)*YEARM/stepm); */
+ for (agec=fage; agec>=fage-20; agec--){ /* testing up to 10 */
+ nhstepm=(int) rint((agelim-agec)*YEARM/stepm);
+ nhstepm = nhstepm/hstepm;
+ p3mat=ma3x(1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);
+ oldm=oldms;savm=savms;
+ hbxij(p3mat,nhstepm,agec,hstepm,p,prevacurrent,nlstate,stepm, k, nres);
+
+ for (h=0; h<=nhstepm; h++){
+ if (h*hstepm/YEARM*stepm ==yearp) {
+ fprintf(ficresfb,"\n");
+ for(j=1;j<=cptcoveff;j++)
+ fprintf(ficresfb,"%d %d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
+ fprintf(ficresfb,"%.f %.f ",anback1+yearp,agec+h*hstepm/YEARM*stepm);
+ }
+ for(j=1; j<=nlstate+ndeath;j++) {
+ ppij=0.;
+ for(i=1; i<=nlstate;i++) {
+ /* if (mobilav==1) */
+ ppij=ppij+p3mat[i][j][h]*mobaverage[(int)agec][i][k];
+ /* else { */
+ /* ppij=ppij+p3mat[i][j][h]*probs[(int)(agec)][i][k]; */
+ /* } */
+ if (h*hstepm/YEARM*stepm== yearp) {
+ fprintf(ficresfb," %.3f", p3mat[i][j][h]);
+ }
+ } /* end i */
+ if (h*hstepm/YEARM*stepm==yearp) {
+ fprintf(ficresfb," %.3f", ppij);
+ }
+ }/* end j */
+ } /* end h */
+ free_ma3x(p3mat,1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);
+ } /* end agec */
+ } /* end yearp */
+ } /* end k */
+
+ /* if (mobilav!=0) free_ma3x(mobaverage,1, AGESUP,1,NCOVMAX, 1,NCOVMAX); */
+
+ fclose(ficresfb);
+ printf("End of Computing Back forecasting \n");
+ fprintf(ficlog,"End of Computing Back forecasting\n");
-/* } */
+}
/************** Forecasting *****not tested NB*************/
/* void populforecast(char fileres[], double anpyram,double mpyram,double jpyram,double ageminpar, double agemax,double dateprev1, double dateprev2s, int mobilav, double agedeb, double fage, int popforecast, char popfile[], double anpyram1,double p[], int i2){ */
@@ -9108,18 +9457,18 @@ int calandcheckages(int imx, int maxwav,
s[m][i]=-1;
}
if((int)moisdc[i]==99 && (int)andc[i]==9999 && s[m][i]>nlstate){
- *nbwarn = *nbwarn + 1;
+ *nberr = *nberr + 1;
if(firstone == 0){
firstone=1;
- printf("Warning (#%d)! Date of death (month %2d and year %4d) of individual %ld on line %d was unknown but status is a death state %d at wave %d. If you don't know the vital status, please enter -2. If he/she is still alive but don't know the state, please code with '-1 or '.'. Here, we believe in a death.\nOther similar cases in log file\n", *nbwarn,(int)moisdc[i],(int)andc[i],num[i],i,s[m][i],m);
+ printf("Warning (#%d)! Date of death (month %2d and year %4d) of individual %ld on line %d was unknown but status is a death state %d at wave %d. If you don't know the vital status, please enter -2. If he/she is still alive but don't know the state, please code with '-1 or '.'. Here, we do not believe in a death, skipped.\nOther similar cases in log file\n", *nberr,(int)moisdc[i],(int)andc[i],num[i],i,s[m][i],m);
}
- fprintf(ficlog,"Warning (#%d)! Date of death (month %2d and year %4d) of individual %ld on line %d was unknown but status is a death state %d at wave %d. If you don't know the vital status, please enter -2. If he/she is still alive but don't know the state, please code with '-1 or '.'. Here, we believe in a death.\nOther similar cases in log file\n", *nbwarn,(int)moisdc[i],(int)andc[i],num[i],i,s[m][i],m);
- /* s[m][i]=-1; */ /* Keeping the death status */
+ fprintf(ficlog,"Warning (#%d)! Date of death (month %2d and year %4d) of individual %ld on line %d was unknown but status is a death state %d at wave %d. If you don't know the vital status, please enter -2. If he/she is still alive but don't know the state, please code with '-1 or '.'. Here, we do not believe in a death, skipped.\n", *nberr,(int)moisdc[i],(int)andc[i],num[i],i,s[m][i],m);
+ s[m][i]=-1; /* Droping the death status */
}
if((int)moisdc[i]==99 && (int)andc[i]!=9999 && s[m][i]>nlstate){
(*nberr)++;
printf("Error (#%d)! Month of death of individual %ld on line %d was unknown (%2d) (year of death is %4d) and status is a death state %d at wave %d. Please impute an arbitrary (or not) month and rerun. Currently this transition to death will be skipped (status is set to -2).\nOther similar cases in log file\n", *nberr, num[i],i,(int)moisdc[i],(int)andc[i],s[m][i],m);
- fprintf(ficlog,"Error (#%d)! Month of death of individual %ld on line %d was unknown (%2d) (year of death is %4d) and status is a death state %d at wave %d. Please impute an arbitrary (or not) month and rerun. Currently this transition to death will be skipped (status is set to -2).\nOther similar cases in log file\n", *nberr, num[i],i,(int)moisdc[i],(int)andc[i],s[m][i],m);
+ fprintf(ficlog,"Error (#%d)! Month of death of individual %ld on line %d was unknown (%2d) (year of death is %4d) and status is a death state %d at wave %d. Please impute an arbitrary (or not) month and rerun. Currently this transition to death will be skipped (status is set to -2).\n", *nberr, num[i],i,(int)moisdc[i],(int)andc[i],s[m][i],m);
s[m][i]=-2; /* We prefer to skip it (and to skip it in version 0.8a1 too */
}
}
@@ -9577,6 +9926,8 @@ int back_prevalence_limit(double *p, dou
}else{
/* bprevalim(bprlim, probs, nlstate, p, age, oldm, savm, dnewm, doldm, dsavm, ftolpl, ncvyearp, k); */
bprevalim(bprlim, probs, nlstate, p, age, ftolpl, ncvyearp, k,nres);
+ /* printf("TOTOT\n"); */
+ /* exit(1); */
}
fprintf(ficresplb,"%.0f ",age );
for(j=1;j<=cptcoveff;j++)
@@ -9722,7 +10073,7 @@ int hPijx(double *p, int bage, int fage)
fprintf(ficrespijb," V%d=%f ",Tvqresult[nres][j],Tqresult[nres][j]);
}
fprintf(ficrespijb,"******\n");
- if(invalidvarcomb[k]){
+ if(invalidvarcomb[k]){ /* Is it necessary here? */
fprintf(ficrespijb,"\n#Combination (%d) ignored because no cases \n",k);
continue;
}
@@ -9735,10 +10086,12 @@ int hPijx(double *p, int bage, int fage)
/* nhstepm=nhstepm*YEARM; aff par mois*/
- p3mat=ma3x(1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);
+ p3mat=ma3x(1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm); /* We can't have it at an upper level because of nhstepm */
+ /* and memory limitations if stepm is small */
+
/* oldm=oldms;savm=savms; */
/* hbxij(p3mat,nhstepm,agedeb,hstepm,p,nlstate,stepm,oldm,savm, k); */
- hbxij(p3mat,nhstepm,agedeb,hstepm,p,prevacurrent,nlstate,stepm, k);
+ hbxij(p3mat,nhstepm,agedeb,hstepm,p,prevacurrent,nlstate,stepm, k, nres);
/* hbxij(p3mat,nhstepm,agedeb,hstepm,p,prevacurrent,nlstate,stepm,oldm,savm, dnewm, doldm, dsavm, k); */
fprintf(ficrespijb,"# Cov Agex agex-h hbijx with i,j=");
for(i=1; i<=nlstate;i++)
@@ -10068,9 +10421,12 @@ int main(int argc, char *argv[])
break;
}
if((num_filled=sscanf(line,"model=1+age%[^.\n]", model)) !=EOF){
- if (num_filled == 0)
- model[0]='\0';
- else if (num_filled != 1){
+ if (num_filled == 0){
+ printf("ERROR %d: Model should be at minimum 'model=1+age.' WITHOUT space:'%s'\n",num_filled, line);
+ fprintf(ficlog,"ERROR %d: Model should be at minimum 'model=1+age.' WITHOUT space:'%s'\n",num_filled, line);
+ model[0]='\0';
+ goto end;
+ } else if (num_filled != 1){
printf("ERROR %d: Model should be at minimum 'model=1+age.' %s\n",num_filled, line);
fprintf(ficlog,"ERROR %d: Model should be at minimum 'model=1+age.' %s\n",num_filled, line);
model[0]='\0';
@@ -11236,8 +11592,8 @@ Please run with mle=-1 to get a correct
/*fscanf(ficpar,"backcast=%d starting-back-date=%lf/%lf/%lf final-back-date=%lf/%lf/%lf mobil_average=%d\n",&backcast,&jback1,&mback1,&anback1,&jback2,&mback2,&anback2,&mobilavproj);*/
if((num_filled=sscanf(line,"backcast=%d starting-back-date=%lf/%lf/%lf final-back-date=%lf/%lf/%lf mobil_average=%d\n",&backcast,&jback1,&mback1,&anback1,&jback2,&mback2,&anback2,&mobilavproj)) !=EOF){
if (num_filled != 8) {
- printf("Error: Not 8 (data)parameters in line but %d, for example:backcast=1 starting-back-date=1/1/1990 finloal-back-date=1/1/1970 mobil_average=1\n, your line=%s . Probably you are running an older format.\n",num_filled,line);
- fprintf(ficlog,"Error: Not 8 (data)parameters in line but %d, for example:backcast=1 starting-back-date=1/1/1990 finloal-back-date=1/1/1970 mobil_average=1\n, your line=%s . Probably you are running an older format.\n",num_filled,line);
+ printf("Error: Not 8 (data)parameters in line but %d, for example:backcast=1 starting-back-date=1/1/1990 final-back-date=1/1/1970 mobil_average=1\n, your line=%s . Probably you are running an older format.\n",num_filled,line);
+ fprintf(ficlog,"Error: Not 8 (data)parameters in line but %d, for example:backcast=1 starting-back-date=1/1/1990 final-back-date=1/1/1970 mobil_average=1\n, your line=%s . Probably you are running an older format.\n",num_filled,line);
goto end;
}
printf("backcast=%d starting-back-date=%.lf/%.lf/%.lf final-back-date=%.lf/%.lf/%.lf mobil_average=%d\n",backcast,jback1,mback1,anback1,jback2,mback2,anback2,mobilavproj);
@@ -11295,7 +11651,7 @@ Please run with mle=-1 to get a correct
This is probably because your parameter file doesn't \n contain the exact number of lines (or columns) corresponding to your model line.\n\
Please run with mle=-1 to get a correct covariance matrix.\n",ageminpar,agemaxpar);
}else{
- printinggnuplot(fileresu, optionfilefiname,ageminpar,agemaxpar,fage, prevfcast, backcast, pathc,p);
+ printinggnuplot(fileresu, optionfilefiname,ageminpar,agemaxpar,fage, prevfcast, backcast, pathc,p, (int)anproj1-(int)ageminpar);
}
printinghtml(fileresu,title,datafile, firstpass, lastpass, stepm, weightopt, \
model,imx,jmin,jmax,jmean,rfileres,popforecast,mobilav,prevfcast,mobilavproj,backcast, estepm, \
@@ -11357,8 +11713,14 @@ Please run with mle=-1 to get a correct
printf(" Error in movingaverage mobilav=%d\n",mobilav);
}
}
- /* /\* Prevalence for each covariates in probs[age][status][cov] *\/ */
- /* prevalence(probs, ageminpar, agemaxpar, s, agev, nlstate, imx, Tvar, nbcode, ncodemax, mint, anint, dateprev1, dateprev2, firstpass, lastpass); */
+ /* else if(mobilavproj==-1){ /\* Forcing raw observed prevalences *\/ */
+ /* for(i=1;i<=AGESUP;i++) */
+ /* for(j=1;j<=nlstate;j++) */
+ /* for(k=1;k<=ncovcombmax;k++) */
+ /* mobaverages[i][j][k]=probs[i][j][k]; */
+ /* /\* /\\* Prevalence for each covariates in probs[age][status][cov] *\\/ *\/ */
+ /* /\* prevalence(probs, ageminpar, agemaxpar, s, agev, nlstate, imx, Tvar, nbcode, ncodemax, mint, anint, dateprev1, dateprev2, firstpass, lastpass); *\/ */
+ /* } */
else if (mobilavproj !=0) {
printf("Movingaveraging projected observed prevalence\n");
fprintf(ficlog,"Movingaveraging projected observed prevalence\n");
@@ -11390,8 +11752,8 @@ Please run with mle=-1 to get a correct
fclose(ficrespijb);
free_matrix(bprlim,1,nlstate,1,nlstate); /*here or after loop ? */
- /* prevbackforecast(fileresu, anback1, mback1, jback1, agemin, agemax, dateprev1, dateprev2, mobilavproj,
- bage, fage, firstpass, lastpass, anback2, p, cptcoveff); */
+ prevbackforecast(fileresu, mobaverage, anback1, mback1, jback1, agemin, agemax, dateprev1, dateprev2, mobilavproj,
+ bage, fage, firstpass, lastpass, anback2, p, cptcoveff);
free_matrix(ddnewms, 1, nlstate+ndeath, 1, nlstate+ndeath);
free_matrix(ddsavms, 1, nlstate+ndeath, 1, nlstate+ndeath);
free_matrix(ddoldms, 1, nlstate+ndeath, 1, nlstate+ndeath);