--- imach/src/imach.c 2017/05/23 08:39:25 1.269
+++ imach/src/imach.c 2017/07/17 08:53:49 1.277
@@ -1,6 +1,30 @@
-/* $Id: imach.c,v 1.269 2017/05/23 08:39:25 brouard Exp $
+/* $Id: imach.c,v 1.277 2017/07/17 08:53:49 brouard Exp $
$State: Exp $
$Log: imach.c,v $
+ Revision 1.277 2017/07/17 08:53:49 brouard
+ Summary: BOM files can be read now
+
+ Revision 1.276 2017/06/30 15:48:31 brouard
+ Summary: Graphs improvements
+
+ Revision 1.275 2017/06/30 13:39:33 brouard
+ Summary: Saito's color
+
+ Revision 1.274 2017/06/29 09:47:08 brouard
+ Summary: Version 0.99r14
+
+ Revision 1.273 2017/06/27 11:06:02 brouard
+ Summary: More documentation on projections
+
+ Revision 1.272 2017/06/27 10:22:40 brouard
+ Summary: Color of backprojection changed from 6 to 5(yellow)
+
+ Revision 1.271 2017/06/27 10:17:50 brouard
+ Summary: Some bug with rint
+
+ Revision 1.270 2017/05/24 05:45:29 brouard
+ *** empty log message ***
+
Revision 1.269 2017/05/23 08:39:25 brouard
Summary: Code into subroutine, cleanings
@@ -1010,12 +1034,12 @@ typedef struct {
#define ODIRSEPARATOR '\\'
#endif
-/* $Id: imach.c,v 1.269 2017/05/23 08:39:25 brouard Exp $ */
+/* $Id: imach.c,v 1.277 2017/07/17 08:53:49 brouard Exp $ */
/* $State: Exp $ */
#include "version.h"
char version[]=__IMACH_VERSION__;
char copyright[]="February 2016,INED-EUROREVES-Institut de longevite-Japan Society for the Promotion of Science (Grant-in-Aid for Scientific Research 25293121), Intel Software 2015-2018";
-char fullversion[]="$Revision: 1.269 $ $Date: 2017/05/23 08:39:25 $";
+char fullversion[]="$Revision: 1.277 $ $Date: 2017/07/17 08:53:49 $";
char strstart[80];
char optionfilext[10], optionfilefiname[FILENAMELENGTH];
int erreur=0, nberr=0, nbwarn=0; /* Error number, number of errors number of warnings */
@@ -3240,7 +3264,7 @@ double ***hbxij(double ***po, int nhstep
newm=savm;
/* Covariates have to be included here again */
cov[1]=1.;
- agexact=age-((h-1)*hstepm + (d))*stepm/YEARM; /* age just before transition, d or d-1? */
+ agexact=age-( (h-1)*hstepm + (d) )*stepm/YEARM; /* age just before transition, d or d-1? */
/* agexact=age+((h-1)*hstepm + (d-1))*stepm/YEARM; /\* age just before transition *\/ */
cov[2]=agexact;
if(nagesqr==1)
@@ -3842,7 +3866,7 @@ void likelione(FILE *ficres,double p[],
else if(mle >=1)
fprintf(fichtm,"\n
File of contributions to the likelihood computed with optimized parameters mle = %d.",mle);
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
\
@@ -5464,7 +5488,7 @@ void concatwav(int wav[], int **dh, int
/* hstepm beeing the number of stepms, if hstepm=1 the length of hstepm is stepm.
nhstepm is the number of hstepm from age to agelim
nstepm is the number of stepm from age to agelin.
- Look at hpijx to understand the reason of that which relies in memory size
+ Look at hpijx to understand the reason which relies in memory size consideration
and note for a fixed period like estepm months */
/* We decided (b) to get a life expectancy respecting the most precise curvature of the
survival function given by stepm (the optimization length). Unfortunately it
@@ -6655,8 +6679,8 @@ void printinghtml(char fileresu[], char
int lastpass, int stepm, int weightopt, char model[],\
int imx,int jmin, int jmax, double jmeanint,char rfileres[],\
int popforecast, int mobilav, int prevfcast, int mobilavproj, int backcast, int estepm , \
- double jprev1, double mprev1,double anprev1, double dateprev1, \
- double jprev2, double mprev2,double anprev2, double dateprev2){
+ double jprev1, double mprev1,double anprev1, double dateprev1, double dateproj1, double dateback1, \
+ double jprev2, double mprev2,double anprev2, double dateprev2, double dateproj2, double dateback2){
int jj1, k1, i1, cpt, k4, nres;
fprintf(fichtm,"
- Result files (first order: no variance)\n \
@@ -6810,15 +6834,18 @@ divided by h: hPij
if(prevfcast==1){
/* Projection of prevalence up to period (stable) prevalence in each health state */
for(cpt=1; cpt<=nlstate;cpt++){
- fprintf(fichtm,"
\n- Projection of cross-sectional prevalence (estimated with cases observed from %.1f to %.1f and mobil_average=%d) up to period (stable) prevalence in state %d. Or probability to be in state %d being in an observed weighted state (from 1 to %d). %s_%d-%d-%d.svg
\
-", dateprev1, dateprev2, mobilavproj, cpt, cpt, nlstate, subdirf2(optionfilefiname,"PROJ_"),cpt,k1,nres,subdirf2(optionfilefiname,"PROJ_"),cpt,k1,nres,subdirf2(optionfilefiname,"PROJ_"),cpt,k1,nres);
+ fprintf(fichtm,"
\n- Projection of cross-sectional prevalence (estimated with cases observed from %.1f to %.1f and mobil_average=%d), from year %.1f up to year %.1f tending to period (stable) prevalence in state %d. Or probability to be in state %d being in an observed weighted state (from 1 to %d). %s_%d-%d-%d.svg
\
+", dateprev1, dateprev2, mobilavproj, dateproj1, dateproj2, cpt, cpt, nlstate, subdirf2(optionfilefiname,"PROJ_"),cpt,k1,nres,subdirf2(optionfilefiname,"PROJ_"),cpt,k1,nres,subdirf2(optionfilefiname,"PROJ_"),cpt,k1,nres);
}
}
if(backcast==1){
/* Back projection of prevalence up to stable (mixed) back-prevalence in each health state */
for(cpt=1; cpt<=nlstate;cpt++){
- fprintf(fichtm,"
\n- Back projection of cross-sectional prevalence (estimated with cases observed from %.1f to %.1f and mobil_average=%d) up to stable (mixed) back prevalence in state %d. Or probability to have been in an state %d, knowing that the person was in either state (1 or %d) with weights corresponding to observed prevalence at different ages. %s_%d-%d-%d.svg
\
-", dateprev1, dateprev2, mobilavproj, cpt, cpt, nlstate, subdirf2(optionfilefiname,"PROJB_"),cpt,k1,nres,subdirf2(optionfilefiname,"PROJB_"),cpt,k1,nres,subdirf2(optionfilefiname,"PROJB_"),cpt,k1,nres);
+ fprintf(fichtm,"
\n- Back projection of cross-sectional prevalence (estimated with cases observed from %.1f to %.1f and mobil_average=%d), \
+ from year %.1f up to year %.1f (probably close to stable [mixed] back prevalence in state %d (randomness in cross-sectional prevalence is not taken into \
+ account but can visually be appreciated). Or probability to have been in an state %d, knowing that the person was in either state (1 or %d) \
+with weights corresponding to observed prevalence at different ages. %s_%d-%d-%d.svg
\
+ ", dateprev1, dateprev2, mobilavproj, dateback1, dateback2, cpt, cpt, nlstate, subdirf2(optionfilefiname,"PROJB_"),cpt,k1,nres,subdirf2(optionfilefiname,"PROJB_"),cpt,k1,nres,subdirf2(optionfilefiname,"PROJB_"),cpt,k1,nres);
}
}
@@ -6924,7 +6951,7 @@ 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[], int offyear, int offbyear){
+void printinggnuplot(char fileresu[], char optionfilefiname[], double ageminpar, double agemaxpar, double bage, double fage , int prevfcast, int backcast, char pathc[], double p[], int offyear, int offbyear){
char dirfileres[132],optfileres[132];
char gplotcondition[132], gplotlabel[132];
@@ -6933,6 +6960,8 @@ void printinggnuplot(char fileresu[], ch
int ng=0;
int vpopbased;
int ioffset; /* variable offset for columns */
+ int iyearc=1; /* variable column for year of projection */
+ int iagec=1; /* variable column for age of projection */
int nres=0; /* Index of resultline */
int istart=1; /* For starting graphs in projections */
@@ -6946,6 +6975,20 @@ void printinggnuplot(char fileresu[], ch
/*#endif */
m=pow(2,cptcoveff);
+ /* diagram of the model */
+ fprintf(ficgp,"\n#Diagram of the model \n");
+ fprintf(ficgp,"\ndelta=0.03;delta2=0.07;unset arrow;\n");
+ fprintf(ficgp,"yoff=(%d > 2? 0:1);\n",nlstate);
+ fprintf(ficgp,"\n#Peripheral arrows\nset for [i=1:%d] for [j=1:%d] arrow i*10+j from cos(pi*((1-(%d/2)*2./%d)/2+(i-1)*2./%d))-(i!=j?(i-j)/abs(i-j)*delta:0), yoff +sin(pi*((1-(%d/2)*2./%d)/2+(i-1)*2./%d)) + (i!=j?(i-j)/abs(i-j)*delta:0) rto -0.95*(cos(pi*((1-(%d/2)*2./%d)/2+(i-1)*2./%d))+(i!=j?(i-j)/abs(i-j)*delta:0) - cos(pi*((1-(%d/2)*2./%d)/2+(j-1)*2./%d)) + (i!=j?(i-j)/abs(i-j)*delta2:0)), -0.95*(sin(pi*((1-(%d/2)*2./%d)/2+(i-1)*2./%d)) + (i!=j?(i-j)/abs(i-j)*delta:0) - sin(pi*((1-(%d/2)*2./%d)/2+(j-1)*2./%d))+( i!=j?(i-j)/abs(i-j)*delta2:0)) ls (i < j? 1:2)\n",nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate);
+
+ fprintf(ficgp,"\n#Centripete arrows (turning in other direction (1-i) instead of (i-1)) \nset for [i=1:%d] arrow (%d+1)*10+i from cos(pi*((1-(%d/2)*2./%d)/2+(1-i)*2./%d))-(i!=j?(i-j)/abs(i-j)*delta:0), yoff +sin(pi*((1-(%d/2)*2./%d)/2+(1-i)*2./%d)) + (i!=j?(i-j)/abs(i-j)*delta:0) rto -0.80*(cos(pi*((1-(%d/2)*2./%d)/2+(1-i)*2./%d))+(i!=j?(i-j)/abs(i-j)*delta:0) ), -0.80*(sin(pi*((1-(%d/2)*2./%d)/2+(1-i)*2./%d)) + (i!=j?(i-j)/abs(i-j)*delta:0) + yoff ) ls 4\n",nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate);
+ fprintf(ficgp,"\n#show arrow\nunset label\n");
+ fprintf(ficgp,"\n#States labels, starting from 2 (2-i) instead of (1-i), was (i-1)\nset for [i=1:%d] label i sprintf(\"State %%d\",i) center at cos(pi*((1-(%d/2)*2./%d)/2+(2-i)*2./%d)), yoff+sin(pi*((1-(%d/2)*2./%d)/2+(2-i)*2./%d)) font \"helvetica, 16\" tc rgbcolor \"blue\"\n",nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate);
+ fprintf(ficgp,"\nset label %d+1 sprintf(\"State %%d\",%d+1) center at 0.,0. font \"helvetica, 16\" tc rgbcolor \"red\"\n",nlstate,nlstate);
+ fprintf(ficgp,"\n#show label\nunset border;unset xtics; unset ytics;\n");
+ fprintf(ficgp,"\n\nset ter svg size 640, 480;set out \"%s_.svg\" \n",subdirf2(optionfilefiname,"D_"));
+ fprintf(ficgp,"unset log y; plot [-1.2:1.2][yoff-1.2:1.2] 1/0 not; set out;reset;\n");
+
/* Contribution to likelihood */
/* Plot the probability implied in the likelihood */
fprintf(ficgp,"\n# Contributions to the Likelihood, mle >=1. For mle=4 no interpolation, pure matrix products.\n#\n");
@@ -7015,7 +7058,8 @@ void printinggnuplot(char fileresu[], ch
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 label \"Alive state %d %s\" at graph 0.98,0.5 center rotate font \"Helvetica,12\"\n",cpt,gplotlabel);
+ /* 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 title \"Alive state %d %s\" 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*/
@@ -7037,7 +7081,7 @@ void printinggnuplot(char fileresu[], ch
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 );
+ fprintf(ficgp,"$%d)) t 'Observed prevalence in state %d' with line lt 3", 2+3*(cpt-1), cpt );
}else{
kl=0;
for (k=1; k<=cptcoveff; k++){ /* For each combination of covariate */
@@ -7095,20 +7139,21 @@ void printinggnuplot(char fileresu[], ch
if (i==cpt) fprintf(ficgp," %%lf (%%lf)");
else fprintf(ficgp," %%*lf (%%*lf)");
}
- fprintf(ficgp,"\" t\"Backward (stable) prevalence\" w l lt 0,\"%s\" every :::%d::%d u 1:($2==%d ? $3+1.96*$4 : 1/0) \"%%lf %%lf",subdirf2(fileresu,"VBL_"),nres-1,nres-1,nres);
+ fprintf(ficgp,"\" t\"Backward (stable) prevalence\" w l lt 6 dt 3,\"%s\" every :::%d::%d u 1:($2==%d ? $3+1.96*$4 : 1/0) \"%%lf %%lf",subdirf2(fileresu,"VBL_"),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,"VBL_"),nres-1,nres-1,nres);
+ fprintf(ficgp,"\" t\"95%% CI\" w l lt 4,\"%s\" every :::%d::%d u 1:($2==%d ? $3-1.96*$4 : 1/0) \"%%lf %%lf",subdirf2(fileresu,"VBL_"),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");
+ fprintf(ficgp,"\" t\"\" w l lt 4");
} /* end if backprojcast */
} /* end if backcast */
- fprintf(ficgp,"\nset out ;unset label;\n");
+ /* fprintf(ficgp,"\nset out ;unset label;\n"); */
+ fprintf(ficgp,"\nset out ;unset title;\n");
} /* nres */
} /* k1 */
} /* cpt */
@@ -7506,24 +7551,22 @@ set ter svg size 640, 480\nunset log y\n
/*# 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)):5 t 'pw.%d' with line lc variable ", \
+ fprintf(ficgp," $%d/(1.-$%d)):1 t 'pw.%d' with line lc variable ", \
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," (($5-$6) == %d ) ? $%d/(1.-$%d) : 1/0):5 with labels center not ", \
+ fprintf(ficgp," (($1-$2) == %d ) ? $%d/(1.-$%d) : 1/0):1 with labels center not ", \
offyear, \
ioffset+(cpt-1)*(nlstate+1)+1+(i-1), ioffset+1+(i-1)+(nlstate+1)*nlstate );
}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 */
- if(cptcoveff ==1){
- ioffset=4; /* Age is in 4 */
- }else{
- ioffset=6; /* Age is in 6 */
- /*# 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 */
- }
+ ioffset=2*cptcoveff+2; /* Age is in 4 or 6 or etc.*/
+ /*# 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 */
+ iyearc=ioffset-1;
+ iagec=ioffset;
fprintf(ficgp," u %d:(",ioffset);
kl=0;
strcpy(gplotcondition,"(");
@@ -7545,13 +7588,13 @@ 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):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,"%s ? $%d/(1.-$%d) : 1/0):%d t 'p.%d' with line lc variable", gplotcondition, \
+ ioffset+(cpt-1)*(nlstate+1)+1+(i-1), ioffset+1+(i-1)+(nlstate+1)*nlstate,iyearc, 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 );
+ fprintf(ficgp," u %d:(",iagec);
+ fprintf(ficgp,"%s && (($%d-$%d) == %d ) ? $%d/(1.-$%d) : 1/0):%d with labels center not ", gplotcondition, \
+ iyearc, iagec, offyear, \
+ ioffset+(cpt-1)*(nlstate+1)+1+(i-1), ioffset+1+(i-1)+(nlstate+1)*nlstate, iyearc );
/* '' 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, \
@@ -7621,24 +7664,22 @@ set ter svg size 640, 480\nunset log y\n
/*# 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)):5 t 'bw%d' with line lc variable ", \
+ fprintf(ficgp," $%d/(1.-$%d)):1 t 'bw%d' with line lc variable ", \
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," (($5-$6) == %d ) ? $%d : 1/0):5 with labels center not ", \
+ fprintf(ficgp," (($1-$2) == %d ) ? $%d : 1/0):1 with labels center not ", \
offbyear, \
ioffset+(cpt-1)*(nlstate+1)+1+(i-1) );
}else
fprintf(ficgp," $%d/(1.-$%d)) t 'b%d%d' with line ", \
ioffset+(cpt-1)*(nlstate+1)+1+(i-1), ioffset+1+(i-1)+(nlstate+1)*nlstate,cpt,i );
}else{ /* more than 2 covariates */
- if(cptcoveff ==1){
- ioffset=4; /* Age is in 4 */
- }else{
- ioffset=6; /* Age is in 6 */
- /*# 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 */
- }
+ ioffset=2*cptcoveff+2; /* Age is in 4 or 6 or etc.*/
+ /*# 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 */
+ iyearc=ioffset-1;
+ iagec=ioffset;
fprintf(ficgp," u %d:(",ioffset);
kl=0;
strcpy(gplotcondition,"(");
@@ -7660,14 +7701,14 @@ 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/0):5 t 'bw%d' with line lc variable", gplotcondition, \
- ioffset+(cpt-1)*(nlstate+1)+1+(i-1),cpt );
+ fprintf(ficgp,"%s ? $%d : 1/0):%d t 'bw%d' with line lc variable", gplotcondition, \
+ ioffset+(cpt-1)*(nlstate+1)+1+(i-1),iyearc,cpt );
fprintf(ficgp,",\\\n '' ");
- fprintf(ficgp," u %d:(",ioffset);
+ fprintf(ficgp," u %d:(",iagec);
/* fprintf(ficgp,"%s && (($5-$6) == %d ) ? $%d/(1.-$%d) : 1/0):5 with labels center not ", gplotcondition, \ */
- fprintf(ficgp,"%s && (($5-$6) == %d ) ? $%d : 1/0):5 with labels center not ", gplotcondition, \
- offbyear, \
- ioffset+(cpt-1)*(nlstate+1)+1+(i-1) );
+ fprintf(ficgp,"%s && (($%d-$%d) == %d ) ? $%d : 1/0):%d with labels center not ", gplotcondition, \
+ iyearc,iagec,offbyear, \
+ ioffset+(cpt-1)*(nlstate+1)+1+(i-1), iyearc );
/* '' 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, \ */
@@ -7726,7 +7767,7 @@ set ter svg size 640, 480\nunset log y\n
continue;
fprintf(ficgp,"\n\n# Combination of dummy k1=%d which is ",k1);
strcpy(gplotlabel,"(");
- sprintf(gplotlabel+strlen(gplotlabel)," Dummy combination %d ",k1);
+ /*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 */
@@ -7743,7 +7784,9 @@ set ter svg size 640, 480\nunset log y\n
strcpy(gplotlabel+strlen(gplotlabel),")");
fprintf(ficgp,"\n#\n");
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 key outside ");
+ /* fprintf(ficgp,"\nset label \"%s\" at graph 1.2,0.5 center rotate font \"Helvetica,12\"\n",gplotlabel); */
+ fprintf(ficgp,"\nset title \"%s\" 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 */
@@ -7863,12 +7906,12 @@ set ter svg size 640, 480\nunset log y\n
}
fprintf(ficgp,")");
if(ng ==2)
- fprintf(ficgp," t \"p%d%d\" ", k2,k);
+ fprintf(ficgp," w l lw 2 lt (%d*%d+%d)%%%d+1 dt %d t \"p%d%d\" ", nlstate+ndeath, k2, k, nlstate+ndeath, k2, k2,k);
else /* ng= 3 */
- fprintf(ficgp," t \"i%d%d\" ", k2,k);
+ fprintf(ficgp," w l lw 2 lt (%d*%d+%d)%%%d+1 dt %d t \"i%d%d\" ", nlstate+ndeath, k2, k, nlstate+ndeath, k2, k2,k);
}else{ /* end ng <> 1 */
if( k !=k2) /* logit p11 is hard to draw */
- fprintf(ficgp," t \"logit(p%d%d)\" ", k2,k);
+ fprintf(ficgp," w l lw 2 lt (%d*%d+%d)%%%d+1 dt %d t \"logit(p%d%d)\" ", nlstate+ndeath, k2, k, nlstate+ndeath, k2, k2,k);
}
if ((k+k2)!= (nlstate*2+ndeath) && ng != 1)
fprintf(ficgp,",");
@@ -7877,7 +7920,8 @@ set ter svg size 640, 480\nunset log y\n
i=i+ncovmodel;
} /* end k */
} /* end k2 */
- fprintf(ficgp,"\n set out; unset label;\n");
+ /* fprintf(ficgp,"\n set out; unset label;set key default;\n"); */
+ fprintf(ficgp,"\n set out; unset title;set key default;\n");
} /* end k1 */
} /* end ng */
/* avoid: */
@@ -8154,7 +8198,12 @@ set ter svg size 640, 480\nunset log y\n
if(estepm < stepm){
printf ("Problem %d lower than %d\n",estepm, stepm);
}
- else hstepm=estepm;
+ else{
+ hstepm=estepm;
+ }
+ if(estepm > stepm){ /* Yes every two year */
+ stepsize=2;
+ }
hstepm=hstepm/stepm;
yp1=modf(dateintmean,&yp);/* extracts integral of datemean in yp and
@@ -8199,7 +8248,8 @@ set ter svg size 640, 480\nunset log y\n
for (yearp=0; yearp<=(anproj2-anproj1);yearp +=stepsize) {
fprintf(ficresf,"\n");
fprintf(ficresf,"\n# Forecasting at date %.lf/%.lf/%.lf ",jproj1,mproj1,anproj1+yearp);
- for (agec=fage; agec>=(ageminpar-1); agec--){
+ /* for (agec=fage; agec>=(ageminpar-1); agec--){ */
+ for (agec=fage; agec>=(bage); agec--){
nhstepm=(int) rint((agelim-agec)*YEARM/stepm);
nhstepm = nhstepm/hstepm;
p3mat=ma3x(1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);
@@ -8287,7 +8337,12 @@ set ter svg size 640, 480\nunset log y\n
if(estepm < stepm){
printf ("Problem %d lower than %d\n",estepm, stepm);
}
- else hstepm=estepm;
+ else{
+ hstepm=estepm;
+ }
+ if(estepm >= stepm){ /* Yes every two year */
+ stepsize=2;
+ }
hstepm=hstepm/stepm;
yp1=modf(dateintmean,&yp);/* extracts integral of datemean in yp and
@@ -8334,13 +8389,15 @@ set ter svg size 640, 480\nunset log y\n
fprintf(ficresfb,"\n");
fprintf(ficresfb,"\n# Back Forecasting at date %.lf/%.lf/%.lf ",jback1,mback1,anback1+yearp);
/* printf("\n# Back Forecasting at date %.lf/%.lf/%.lf ",jback1,mback1,anback1+yearp); */
- for (agec=bage; agec<=agemax-1; agec++){ /* testing */
+ /* for (agec=bage; agec<=agemax-1; agec++){ /\* testing *\/ */
+ for (agec=bage; agec<=fage; agec++){ /* testing */
/* We compute bij at age agec over nhstepm, nhstepm decreases when agec increases because of agemax;*/
- nhstepm=(int) rint((agec-agelim)*YEARM/stepm);
+ nhstepm=(int) (agec-agelim) *YEARM/stepm;/* nhstepm=(int) rint((agec-agelim)*YEARM/stepm);*/
nhstepm = nhstepm/hstepm;
p3mat=ma3x(1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);
oldm=oldms;savm=savms;
/* computes hbxij at age agec over 1 to nhstepm */
+ /* printf("####prevbackforecast debug agec=%.2f nhstepm=%d\n",agec, nhstepm);fflush(stdout); */
hbxij(p3mat,nhstepm,agec,hstepm,p,prevacurrent,nlstate,stepm, k, nres);
/* hpxij(p3mat,nhstepm,agec,hstepm,p, nlstate,stepm,oldm,savm, k,nres); */
/* Then we print p3mat for h corresponding to the right agec+h*stepms=yearp */
@@ -10559,7 +10616,9 @@ int main(int argc, char *argv[])
int vpopbased=0;
int nres=0;
int endishere=0;
-
+ int noffset=0;
+ int ncurrv=0; /* Temporary variable */
+
char ca[32], cb[32];
/* FILE *fichtm; *//* Html File */
/* FILE *ficgp;*/ /*Gnuplot File */
@@ -10614,8 +10673,9 @@ int main(int argc, char *argv[])
double *epj, vepp;
- double dateprev1, dateprev2,jproj1=1,mproj1=1,anproj1=2000,jproj2=1,mproj2=1,anproj2=2000;
- double jback1=1,mback1=1,anback1=2000,jback2=1,mback2=1,anback2=2000;
+ double dateprev1, dateprev2;
+ double jproj1=1,mproj1=1,anproj1=2000,jproj2=1,mproj2=1,anproj2=2000, dateproj1=0, dateproj2=0;
+ double jback1=1,mback1=1,anback1=2000,jback2=1,mback2=1,anback2=2000, dateback1=0, dateback2=0;
double **ximort;
char *alph[]={"a","a","b","c","d","e"}, str[4]="1234";
@@ -10785,11 +10845,32 @@ int main(int argc, char *argv[])
/* Reads comments: lines beginning with '#' */
numlinepar=0;
-
- /* First parameter line */
+ /* Is it a BOM UTF-8 Windows file? */
+ /* First parameter line */
while(fgets(line, MAXLINE, ficpar)) {
+ noffset=0;
+ if( line[0] == (char)0xEF && line[1] == (char)0xBB) /* EF BB BF */
+ {
+ noffset=noffset+3;
+ printf("# File is an UTF8 Bom.\n"); // 0xBF
+ }
+ else if( line[0] == (char)0xFE && line[1] == (char)0xFF)
+ {
+ noffset=noffset+2;
+ printf("# File is an UTF16BE BOM file\n");
+ }
+ else if( line[0] == 0 && line[1] == 0)
+ {
+ if( line[2] == (char)0xFE && line[3] == (char)0xFF){
+ noffset=noffset+4;
+ printf("# File is an UTF16BE BOM file\n");
+ }
+ } else{
+ ;/*printf(" Not a BOM file\n");*/
+ }
+
/* If line starts with a # it is a comment */
- if (line[0] == '#') {
+ if (line[noffset] == '#') {
numlinepar++;
fputs(line,stdout);
fputs(line,ficparo);
@@ -11443,10 +11524,31 @@ Title=%s
Datafile=%s Firstpass=%d La
firstpass, lastpass, stepm, weightopt, model);
fprintf(fichtm,"\n");
- fprintf(fichtm,"
Total number of observations=%d
\n\
+ fprintf(fichtm,"Parameter line 2
- Tolerance for the convergence of the likelihood: ftol=%f \n
- Interval for the elementary matrix (in month): stepm=%d",\
+ ftol, stepm);
+ fprintf(fichtm,"\n
- Number of fixed dummy covariates: ncovcol=%d ", ncovcol);
+ ncurrv=1;
+ for(i=ncurrv; i <=ncovcol; i++) fprintf(fichtm,"V%d ", i);
+ fprintf(fichtm,"\n
- Number of fixed quantitative variables: nqv=%d ", nqv);
+ ncurrv=i;
+ for(i=ncurrv; i <=ncurrv-1+nqv; i++) fprintf(fichtm,"V%d ", i);
+ fprintf(fichtm,"\n
- Number of time varying (wave varying) covariates: ntv=%d ", ntv);
+ ncurrv=i;
+ for(i=ncurrv; i <=ncurrv-1+ntv; i++) fprintf(fichtm,"V%d ", i);
+ fprintf(fichtm,"\n
- Number of quantitative time varying covariates: nqtv=%d ", nqtv);
+ ncurrv=i;
+ for(i=ncurrv; i <=ncurrv-1+nqtv; i++) fprintf(fichtm,"V%d ", i);
+ fprintf(fichtm,"\n
- Weights column \n
Number of alive states: nlstate=%d
Number of death states (not really implemented): ndeath=%d \n - Number of waves: maxwav=%d \n
- Parameter for maximization (1), using parameter values (0), for design of parameters and variance-covariance matrix: mle=%d \n
- Does the weight column be taken into account (1), or not (0): weight=%d
\n", \
+ nlstate, ndeath, maxwav, mle, weightopt);
+
+ fprintf(fichtm," Diagram of states %s_.svg
\n\
+", subdirf2(optionfilefiname,"D_"),subdirf2(optionfilefiname,"D_"),subdirf2(optionfilefiname,"D_"));
+
+
+ fprintf(fichtm,"\nSome descriptive statistics
\n
Total number of observations=%d
\n\
Youngest age at first (selected) pass %.2f, oldest age %.2f
\n\
Interval (in months) between two waves: Min=%d Max=%d Mean=%.2lf
\n",\
- imx,agemin,agemax,jmin,jmax,jmean);
+ imx,agemin,agemax,jmin,jmax,jmean);
pmmij= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */
oldms= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */
newms= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */
@@ -12006,6 +12108,9 @@ Please run with mle=-1 to get a correct
fprintf(ficlog,"prevforecast=%d starting-proj-date=%.lf/%.lf/%.lf final-proj-date=%.lf/%.lf/%.lf mobil_average=%d\n",prevfcast,jproj1,mproj1,anproj1,jproj2,mproj2,anproj2,mobilavproj);
fprintf(ficres,"prevforecast=%d starting-proj-date=%.lf/%.lf/%.lf final-proj-date=%.lf/%.lf/%.lf mobil_average=%d\n",prevfcast,jproj1,mproj1,anproj1,jproj2,mproj2,anproj2,mobilavproj);
/* day and month of proj2 are not used but only year anproj2.*/
+ dateproj1=anproj1+(mproj1-1)/12.+(jproj1-1)/365.;
+ dateproj2=anproj2+(mproj2-1)/12.+(jproj2-1)/365.;
+
}
break;
case 12:
@@ -12021,6 +12126,8 @@ Please run with mle=-1 to get a correct
fprintf(ficlog,"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);
fprintf(ficres,"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);
/* day and month of proj2 are not used but only year anproj2.*/
+ dateback1=anback1+(mback1-1)/12.+(jback1-1)/365.;
+ dateback2=anback2+(mback2-1)/12.+(jback2-1)/365.;
}
break;
case 13:
@@ -12071,11 +12178,12 @@ 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, (int)anproj1-(int)agemin, (int)anback1-(int)agemax+1);
+ /* printinggnuplot(fileresu, optionfilefiname,ageminpar,agemaxpar,fage, prevfcast, backcast, pathc,p, (int)anproj1-(int)agemin, (int)anback1-(int)agemax+1); */
+ printinggnuplot(fileresu, optionfilefiname,ageminpar,agemaxpar,bage, fage, prevfcast, backcast, pathc,p, (int)anproj1-bage, (int)anback1-fage);
}
printinghtml(fileresu,title,datafile, firstpass, lastpass, stepm, weightopt, \
model,imx,jmin,jmax,jmean,rfileres,popforecast,mobilav,prevfcast,mobilavproj,backcast, estepm, \
- jprev1,mprev1,anprev1,dateprev1,jprev2,mprev2,anprev2,dateprev2);
+ jprev1,mprev1,anprev1,dateprev1, dateproj1, dateback1,jprev2,mprev2,anprev2,dateprev2,dateproj2, dateback2);
/*------------ free_vector -------------*/
/* chdir(path); */