double **oldm, **newm, **savm; /* Working pointers to matrices */\r
double **oldms, **newms, **savms; /* Fixed working pointers to matrices */\r
FILE *fic,*ficpar, *ficparo,*ficres, *ficrespl, *ficrespij, *ficrest,*ficresf;\r
-FILE *ficgp, *fichtm,*ficresprob,*ficpop;\r
+FILE *ficgp,*ficresprob,*ficpop;\r
FILE *ficreseij;\r
char filerese[FILENAMELENGTH];\r
FILE *ficresvij;\r
static double maxarg1,maxarg2;\r
#define FMAX(a,b) (maxarg1=(a),maxarg2=(b),(maxarg1)>(maxarg2)? (maxarg1):(maxarg2))\r
#define FMIN(a,b) (maxarg1=(a),maxarg2=(b),(maxarg1)<(maxarg2)? (maxarg1):(maxarg2))\r
- \r
+ \r
#define SIGN(a,b) ((b)>0.0 ? fabs(a) : -fabs(a))\r
#define rint(a) floor(a+0.5)\r
\r
exit(0);\r
}\r
\r
+/******************* Printing html file ***********/\r
+void printinghtml(char fileres[], char title[], char datafile[], int firstpass, int lastpass, int stepm, int weightopt, char model[],int imx,int jmin, int jmax, double jmeanint,char optionfile[],char optionfilehtm[] ){\r
+ int jj1, k1, i1, cpt;\r
+ FILE *fichtm;\r
+ /*char optionfilehtm[FILENAMELENGTH];*/\r
+\r
+ strcpy(optionfilehtm,optionfile);\r
+ strcat(optionfilehtm,".htm");\r
+ if((fichtm=fopen(optionfilehtm,"w"))==NULL) {\r
+ printf("Problem with %s \n",optionfilehtm), exit(0);\r
+ }\r
+\r
+ fprintf(fichtm,"<body><ul> <font size=\"6\">Imach, Version 0.7 </font> <hr size=\"2\" color=\"#EC5E5E\"> \r
+Title=%s <br>Datafile=%s Firstpass=%d Lastpass=%d Stepm=%d Weight=%d Model=%s<br>\r
+\r
+Total number of observations=%d <br>\r
+Interval (in months) between two waves: Min=%d Max=%d Mean=%.2lf<br>\r
+<hr size=\"2\" color=\"#EC5E5E\"> \r
+<li>Outputs files<br><br>\n\r
+ - Observed prevalence in each state: <a href=\"p%s\">p%s</a> <br>\n\r
+- Estimated parameters and the covariance matrix: <a href=\"%s\">%s</a> <br>\r
+ - Stationary prevalence in each state: <a href=\"pl%s\">pl%s</a> <br>\r
+ - Transition probabilities: <a href=\"pij%s\">pij%s</a><br>\r
+ - Copy of the parameter file: <a href=\"o%s\">o%s</a><br>\r
+ - Life expectancies by age and initial health status: <a href=\"e%s\">e%s</a> <br>\r
+ - Variances of life expectancies by age and initial health status: <a href=\"v%s\">v%s</a><br>\r
+ - Health expectancies with their variances: <a href=\"t%s\">t%s</a> <br>\r
+ - Standard deviation of stationary prevalences: <a href=\"vpl%s\">vpl%s</a> <br>\r
+ - Prevalences and population forecasting: <a href=\"f%s\">f%s</a> <br>\r
+ <br>",title,datafile,firstpass,lastpass,stepm, weightopt,model,imx,jmin,jmax,jmean,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres);\r
+ \r
+fprintf(fichtm," <li>Graphs</li><p>");\r
+\r
+ m=cptcoveff;\r
+ if (cptcovn < 1) {m=1;ncodemax[1]=1;}\r
+\r
+ jj1=0;\r
+ for(k1=1; k1<=m;k1++){\r
+ for(i1=1; i1<=ncodemax[k1];i1++){\r
+ jj1++;\r
+ if (cptcovn > 0) {\r
+ fprintf(fichtm,"<hr size=\"2\" color=\"#EC5E5E\">************ Results for covariates");\r
+ for (cpt=1; cpt<=cptcoveff;cpt++) \r
+ fprintf(fichtm," V%d=%d ",Tvaraff[cpt],nbcode[Tvaraff[cpt]][codtab[jj1][cpt]]);\r
+ fprintf(fichtm," ************\n<hr size=\"2\" color=\"#EC5E5E\">");\r
+ }\r
+ fprintf(fichtm,"<br>- Probabilities: pe%s%d.gif<br>\r
+<img src=\"pe%s%d.gif\">",strtok(optionfile, "."),jj1,strtok(optionfile, "."),jj1); \r
+ for(cpt=1; cpt<nlstate;cpt++){\r
+ fprintf(fichtm,"<br>- Prevalence of disability : p%s%d%d.gif<br>\r
+<img src=\"p%s%d%d.gif\">",strtok(optionfile, "."),cpt,jj1,strtok(optionfile, "."),cpt,jj1);\r
+ }\r
+ for(cpt=1; cpt<=nlstate;cpt++) {\r
+ fprintf(fichtm,"<br>- Observed and stationary prevalence (with confident\r
+interval) in state (%d): v%s%d%d.gif <br>\r
+<img src=\"v%s%d%d.gif\">",cpt,strtok(optionfile, "."),cpt,jj1,strtok(optionfile, "."),cpt,jj1); \r
+ }\r
+ for(cpt=1; cpt<=nlstate;cpt++) {\r
+ fprintf(fichtm,"\n<br>- Health life expectancies by age and initial health state (%d): exp%s%d%d.gif <br>\r
+<img src=\"exp%s%d%d.gif\">",cpt,strtok(optionfile, "."),cpt,jj1,strtok(optionfile, "."),cpt,jj1);\r
+ }\r
+ fprintf(fichtm,"\n<br>- Total life expectancy by age and\r
+health expectancies in states (1) and (2): e%s%d.gif<br>\r
+<img src=\"e%s%d.gif\">",strtok(optionfile, "."),jj1,strtok(optionfile, "."),jj1);\r
+fprintf(fichtm,"\n</body>");\r
+ }\r
+ }\r
+fclose(fichtm);\r
+}\r
+\r
+/******************* Gnuplot file **************/\r
+void printinggnuplot(char fileres[],char optionfilefiname[],char optionfile[],char optionfilegnuplot[], double agemin, double agemax, double fage , char pathc[], double p[]){\r
+\r
+ int m,cpt,k1,i,k,j,jk,k2,k3,ij,l;\r
+\r
+ strcpy(optionfilegnuplot,optionfilefiname);\r
+ strcat(optionfilegnuplot,".plt");\r
+ if((ficgp=fopen(optionfilegnuplot,"w"))==NULL) {\r
+ printf("Problem with file %s",optionfilegnuplot);\r
+ }\r
+\r
+#ifdef windows\r
+ fprintf(ficgp,"cd \"%s\" \n",pathc);\r
+#endif\r
+m=pow(2,cptcoveff);\r
+ \r
+ /* 1eme*/\r
+ for (cpt=1; cpt<= nlstate ; cpt ++) {\r
+ for (k1=1; k1<= m ; k1 ++) {\r
+\r
+#ifdef windows\r
+ fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability\" \nset ter gif small size 400,300\nplot [%.f:%.f] \"vpl%s\" every :::%d::%d u 1:2 \"\%%lf",agemin,fage,fileres,k1-1,k1-1);\r
+#endif\r
+#ifdef unix\r
+fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability\" \nplot [%.f:%.f] \"vpl%s\" u 1:2 \"\%%lf",agemin,fage,fileres);\r
+#endif\r
+\r
+for (i=1; i<= nlstate ; i ++) {\r
+ if (i==cpt) fprintf(ficgp," \%%lf (\%%lf)");\r
+ else fprintf(ficgp," \%%*lf (\%%*lf)");\r
+}\r
+ fprintf(ficgp,"\" t\"Stationary prevalence\" w l 0,\"vpl%s\" every :::%d::%d u 1:($2+2*$3) \"\%%lf",fileres,k1-1,k1-1);\r
+ for (i=1; i<= nlstate ; i ++) {\r
+ if (i==cpt) fprintf(ficgp," \%%lf (\%%lf)");\r
+ else fprintf(ficgp," \%%*lf (\%%*lf)");\r
+} \r
+ fprintf(ficgp,"\" t\"95\%% CI\" w l 1,\"vpl%s\" every :::%d::%d u 1:($2-2*$3) \"\%%lf",fileres,k1-1,k1-1); \r
+ for (i=1; i<= nlstate ; i ++) {\r
+ if (i==cpt) fprintf(ficgp," \%%lf (\%%lf)");\r
+ else fprintf(ficgp," \%%*lf (\%%*lf)");\r
+} \r
+ fprintf(ficgp,"\" t\"\" w l 1,\"p%s\" every :::%d::%d u 1:($%d) t\"Observed prevalence \" w l 2",fileres,k1-1,k1-1,2+4*(cpt-1));\r
+#ifdef unix\r
+fprintf(ficgp,"\nset ter gif small size 400,300");\r
+#endif\r
+fprintf(ficgp,"\nset out \"v%s%d%d.gif\" \nreplot\n\n",strtok(optionfile, "."),cpt,k1);\r
+ }\r
+ }\r
+ /*2 eme*/\r
+\r
+ for (k1=1; k1<= m ; k1 ++) { \r
+ fprintf(ficgp,"set ylabel \"Years\" \nset ter gif small size 400,300\nplot [%.f:%.f] ",agemin,fage);\r
+ \r
+ for (i=1; i<= nlstate+1 ; i ++) {\r
+ k=2*i;\r
+ fprintf(ficgp,"\"t%s\" every :::%d::%d u 1:2 \"\%%lf",fileres,k1-1,k1-1);\r
+ for (j=1; j<= nlstate+1 ; j ++) {\r
+ if (j==i) fprintf(ficgp," \%%lf (\%%lf)");\r
+ else fprintf(ficgp," \%%*lf (\%%*lf)");\r
+} \r
+ if (i== 1) fprintf(ficgp,"\" t\"TLE\" w l ,");\r
+ else fprintf(ficgp,"\" t\"LE in state (%d)\" w l ,",i-1);\r
+ fprintf(ficgp,"\"t%s\" every :::%d::%d u 1:($2-$3*2) \"\%%lf",fileres,k1-1,k1-1);\r
+ for (j=1; j<= nlstate+1 ; j ++) {\r
+ if (j==i) fprintf(ficgp," \%%lf (\%%lf)");\r
+ else fprintf(ficgp," \%%*lf (\%%*lf)");\r
+} \r
+ fprintf(ficgp,"\" t\"\" w l 0,");\r
+ fprintf(ficgp,"\"t%s\" every :::%d::%d u 1:($2+$3*2) \"\%%lf",fileres,k1-1,k1-1);\r
+ for (j=1; j<= nlstate+1 ; j ++) {\r
+ if (j==i) fprintf(ficgp," \%%lf (\%%lf)");\r
+ else fprintf(ficgp," \%%*lf (\%%*lf)");\r
+} \r
+ if (i== (nlstate+1)) fprintf(ficgp,"\" t\"\" w l 0");\r
+ else fprintf(ficgp,"\" t\"\" w l 0,");\r
+ }\r
+ fprintf(ficgp,"\nset out \"e%s%d.gif\" \nreplot\n\n",strtok(optionfile, "."),k1);\r
+ }\r
+ \r
+ /*3eme*/\r
+\r
+ for (k1=1; k1<= m ; k1 ++) { \r
+ for (cpt=1; cpt<= nlstate ; cpt ++) {\r
+ k=2+nlstate*(cpt-1);\r
+ fprintf(ficgp,"set ter gif small size 400,300\nplot [%.f:%.f] \"e%s\" every :::%d::%d u 1:%d t \"e%d1\" w l",agemin,fage,fileres,k1-1,k1-1,k,cpt);\r
+ for (i=1; i< nlstate ; i ++) {\r
+ fprintf(ficgp,",\"e%s\" every :::%d::%d u 1:%d t \"e%d%d\" w l",fileres,k1-1,k1-1,k+i,cpt,i+1);\r
+ } \r
+ fprintf(ficgp,"\nset out \"exp%s%d%d.gif\" \nreplot\n\n",strtok(optionfile, "."),cpt,k1);\r
+ }\r
+ }\r
+ \r
+ /* CV preval stat */\r
+ for (k1=1; k1<= m ; k1 ++) { \r
+ for (cpt=1; cpt<nlstate ; cpt ++) {\r
+ k=3;\r
+ fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability\" \nset ter gif small size 400,300\nplot [%.f:%.f] \"pij%s\" u ($1==%d ? ($3):1/0):($%d/($%d",agemin,agemax,fileres,k1,k+cpt+1,k+1);\r
+\r
+ for (i=1; i< nlstate ; i ++)\r
+ fprintf(ficgp,"+$%d",k+i+1);\r
+ fprintf(ficgp,")) t\"prev(%d,%d)\" w l",cpt,cpt+1);\r
+ \r
+ l=3+(nlstate+ndeath)*cpt;\r
+ fprintf(ficgp,",\"pij%s\" u ($1==%d ? ($3):1/0):($%d/($%d",fileres,k1,l+cpt+1,l+1);\r
+ for (i=1; i< nlstate ; i ++) {\r
+ l=3+(nlstate+ndeath)*cpt;\r
+ fprintf(ficgp,"+$%d",l+i+1);\r
+ }\r
+ fprintf(ficgp,")) t\"prev(%d,%d)\" w l\n",cpt+1,cpt+1); \r
+ fprintf(ficgp,"set out \"p%s%d%d.gif\" \nreplot\n\n",strtok(optionfile, "."),cpt,k1);\r
+ } \r
+ } \r
+ \r
+ /* proba elementaires */\r
+ for(i=1,jk=1; i <=nlstate; i++){\r
+ for(k=1; k <=(nlstate+ndeath); k++){\r
+ if (k != i) {\r
+ for(j=1; j <=ncovmodel; j++){\r
+ \r
+ fprintf(ficgp,"p%d=%f ",jk,p[jk]);\r
+ jk++; \r
+ fprintf(ficgp,"\n");\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ for(jk=1; jk <=m; jk++) {\r
+ fprintf(ficgp,"\nset ter gif small size 400,300\nset log y\nplot [%.f:%.f] ",agemin,agemax);\r
+ i=1;\r
+ for(k2=1; k2<=nlstate; k2++) {\r
+ k3=i;\r
+ for(k=1; k<=(nlstate+ndeath); k++) {\r
+ if (k != k2){\r
+ fprintf(ficgp," exp(p%d+p%d*x",i,i+1);\r
+ij=1;\r
+ for(j=3; j <=ncovmodel; j++) {\r
+ if(((j-2)==Tage[ij]) &&(ij <=cptcovage)) {\r
+ fprintf(ficgp,"+p%d*%d*x",i+j-1,nbcode[Tvar[j-2]][codtab[jk][Tvar[j-2]]]);\r
+ ij++;\r
+ }\r
+ else\r
+ fprintf(ficgp,"+p%d*%d",i+j-1,nbcode[Tvar[j-2]][codtab[jk][j-2]]);\r
+ }\r
+ fprintf(ficgp,")/(1");\r
+ \r
+ for(k1=1; k1 <=nlstate; k1++){ \r
+ fprintf(ficgp,"+exp(p%d+p%d*x",k3+(k1-1)*ncovmodel,k3+(k1-1)*ncovmodel+1);\r
+ij=1;\r
+ for(j=3; j <=ncovmodel; j++){\r
+ if(((j-2)==Tage[ij]) &&(ij <=cptcovage)) {\r
+ fprintf(ficgp,"+p%d*%d*x",k3+(k1-1)*ncovmodel+1+j-2,nbcode[Tvar[j-2]][codtab[jk][Tvar[j-2]]]);\r
+ ij++;\r
+ }\r
+ else\r
+ fprintf(ficgp,"+p%d*%d",k3+(k1-1)*ncovmodel+1+j-2,nbcode[Tvar[j-2]][codtab[jk][j-2]]);\r
+ }\r
+ fprintf(ficgp,")");\r
+ }\r
+ fprintf(ficgp,") t \"p%d%d\" ", k2,k);\r
+ if ((k+k2)!= (nlstate*2+ndeath)) fprintf(ficgp,",");\r
+ i=i+ncovmodel;\r
+ }\r
+ }\r
+ }\r
+ fprintf(ficgp,"\nset out \"pe%s%d.gif\" \nreplot\n\n",strtok(optionfile, "."),jk); \r
+ }\r
+ \r
+ fclose(ficgp);\r
+} /* end gnuplot */\r
+\r
+\r
+/*************** Moving average **************/\r
+void movingaverage(double agedeb, double fage,double agemin, double ***mobaverage){\r
+\r
+ int i, cpt, cptcod;\r
+ for (agedeb=agemin; agedeb<=fage; agedeb++)\r
+ for (i=1; i<=nlstate;i++)\r
+ for (cptcod=1;cptcod<=ncodemax[cptcov];cptcod++)\r
+ mobaverage[(int)agedeb][i][cptcod]=0.;\r
+ \r
+ for (agedeb=agemin+4; agedeb<=fage; agedeb++){\r
+ for (i=1; i<=nlstate;i++){\r
+ for (cptcod=1;cptcod<=ncodemax[cptcoveff];cptcod++){\r
+ for (cpt=0;cpt<=4;cpt++){\r
+ mobaverage[(int)agedeb-2][i][cptcod]=mobaverage[(int)agedeb-2][i][cptcod]+probs[(int)agedeb-cpt][i][cptcod];\r
+ }\r
+ mobaverage[(int)agedeb-2][i][cptcod]=mobaverage[(int)agedeb-2][i][cptcod]/5;\r
+ }\r
+ }\r
+ }\r
+ \r
+}\r
+\r
/***********************************************/\r
/**************** Main Program *****************/\r
/***********************************************/\r
int *indx;\r
char line[MAXLINE], linepar[MAXLINE];\r
char title[MAXLINE];\r
- char optionfile[FILENAMELENGTH], datafile[FILENAMELENGTH], filerespl[FILENAMELENGTH], optionfilehtm[FILENAMELENGTH];\r
- char optionfilext[10], optionfilefiname[FILENAMELENGTH], optionfilegnuplot[FILENAMELENGTH], plotcmd[FILENAMELENGTH];\r
+ char optionfile[FILENAMELENGTH], datafile[FILENAMELENGTH], filerespl[FILENAMELENGTH];\r
+ char optionfilext[10], optionfilefiname[FILENAMELENGTH], optionfilehtm[FILENAMELENGTH], optionfilegnuplot[FILENAMELENGTH], plotcmd[FILENAMELENGTH];\r
\r
char fileres[FILENAMELENGTH], filerespij[FILENAMELENGTH], filereso[FILENAMELENGTH], fileresf[FILENAMELENGTH];\r
\r
}\r
ungetc(c,ficpar);\r
\r
- fscanf(ficpar,"begin-prev-date=%lf/%lf/%lf end-prev-date=%lf/%lf/%lf mob_average=%d\n",&jprev1, &mprev1,&anprev1,&jprev2, &mprev2,&anprev2,&mobilav);\r
- fprintf(ficparo,"begin-prev-date=%.lf/%.lf/%.lf end-prev-date=%.lf/%.lf/%.lf mob_average=%d\n",jprev1, mprev1,anprev1,jprev2, mprev2,anprev2,mobilav);\r
- fprintf(ficres,"begin-prev-date=%.lf/%.lf/%.lf end-prev-date=%.lf/%.lf/%.lf mob_average=%d\n",jprev1, mprev1,anprev1,jprev2, mprev2,anprev2,mobilav);\r
+ fscanf(ficpar,"begin-prev-date=%lf/%lf/%lf end-prev-date=%lf/%lf/%lf\n",&jprev1, &mprev1,&anprev1,&jprev2, &mprev2,&anprev2);\r
+ fprintf(ficparo,"begin-prev-date=%.lf/%.lf/%.lf end-prev-date=%.lf/%.lf/%.lf\n",jprev1, mprev1,anprev1,jprev2, mprev2,anprev2);\r
+ fprintf(ficres,"begin-prev-date=%.lf/%.lf/%.lf end-prev-date=%.lf/%.lf/%.lf\n",jprev1, mprev1,anprev1,jprev2, mprev2,anprev2);\r
\r
while((c=getc(ficpar))=='#' && c!= EOF){\r
ungetc(c,ficpar);\r
fputs(line,ficparo);\r
}\r
ungetc(c,ficpar);\r
- fscanf(ficpar,"popforecast=%d popfile=%s starting-proj-date=%lf/%lf/%lf final-proj-date=%lf/%lf/%lf\n",&popforecast,popfile,&jproj1,&mproj1,&anproj1,&jproj2,&mproj2,&anproj2);\r
-fprintf(ficparo,"popforecast=%d popfile=%s starting-proj-date=%.lf/%.lf/%.lf final-proj-date=%.lf/%.lf/%.lf\n",popforecast,popfile,jproj1,mproj1,anproj1,jproj2,mproj2,anproj2);\r
-fprintf(ficres,"popforecast=%d popfile=%s starting-proj-date=%.lf/%.lf/%.lf final-proj-date=%.lf/%.lf/%.lf\n",popforecast,popfile,jproj1,mproj1,anproj1,jproj2,mproj2,anproj2);\r
+ fscanf(ficpar,"popforecast=%d popfile=%s starting-proj-date=%lf/%lf/%lf final-proj-date=%lf/%lf/%lf mob_average=%d\n",&popforecast,popfile,&jproj1,&mproj1,&anproj1,&jproj2,&mproj2,&anproj2,&mobilav);\r
+fprintf(ficparo,"popforecast=%d popfile=%s starting-proj-date=%.lf/%.lf/%.lf final-proj-date=%.lf/%.lf/%.lf mob_average=%d\n",popforecast,popfile,jproj1,mproj1,anproj1,jproj2,mproj2,anproj2,mobilav);\r
+fprintf(ficres,"popforecast=%d popfile=%s starting-proj-date=%.lf/%.lf/%.lf final-proj-date=%.lf/%.lf/%.lf mob_average=%d\n",popforecast,popfile,jproj1,mproj1,anproj1,jproj2,mproj2,anproj2,mobilav);\r
\r
freqsummary(fileres, agemin, agemax, s, agev, nlstate, imx,Tvar,nbcode, ncodemax,mint,anint,dateprev1,dateprev2);\r
\r
- \r
- /*------------ gnuplot -------------*/\r
- /*chdir(pathcd);*/\r
- strcpy(optionfilegnuplot,optionfilefiname);\r
- strcat(optionfilegnuplot,".plt");\r
- if((ficgp=fopen(optionfilegnuplot,"w"))==NULL) {\r
- printf("Problem with file %s",optionfilegnuplot);goto end;\r
- }\r
-#ifdef windows\r
- fprintf(ficgp,"cd \"%s\" \n",pathc);\r
-#endif\r
-m=pow(2,cptcoveff);\r
- \r
- /* 1eme*/\r
- for (cpt=1; cpt<= nlstate ; cpt ++) {\r
- for (k1=1; k1<= m ; k1 ++) {\r
-\r
-#ifdef windows\r
- fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability\" \nset ter gif small size 400,300\nplot [%.f:%.f] \"vpl%s\" every :::%d::%d u 1:2 \"\%%lf",agemin,fage,fileres,k1-1,k1-1);\r
-#endif\r
-#ifdef unix\r
-fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability\" \nplot [%.f:%.f] \"vpl%s\" u 1:2 \"\%%lf",agemin,fage,fileres);\r
-#endif\r
-\r
-for (i=1; i<= nlstate ; i ++) {\r
- if (i==cpt) fprintf(ficgp," \%%lf (\%%lf)");\r
- else fprintf(ficgp," \%%*lf (\%%*lf)");\r
-}\r
- fprintf(ficgp,"\" t\"Stationary prevalence\" w l 0,\"vpl%s\" every :::%d::%d u 1:($2+2*$3) \"\%%lf",fileres,k1-1,k1-1);\r
- for (i=1; i<= nlstate ; i ++) {\r
- if (i==cpt) fprintf(ficgp," \%%lf (\%%lf)");\r
- else fprintf(ficgp," \%%*lf (\%%*lf)");\r
-} \r
- fprintf(ficgp,"\" t\"95\%% CI\" w l 1,\"vpl%s\" every :::%d::%d u 1:($2-2*$3) \"\%%lf",fileres,k1-1,k1-1); \r
- for (i=1; i<= nlstate ; i ++) {\r
- if (i==cpt) fprintf(ficgp," \%%lf (\%%lf)");\r
- else fprintf(ficgp," \%%*lf (\%%*lf)");\r
-} \r
- fprintf(ficgp,"\" t\"\" w l 1,\"p%s\" every :::%d::%d u 1:($%d) t\"Observed prevalence \" w l 2",fileres,k1-1,k1-1,2+4*(cpt-1));\r
-#ifdef unix\r
-fprintf(ficgp,"\nset ter gif small size 400,300");\r
-#endif\r
-fprintf(ficgp,"\nset out \"v%s%d%d.gif\" \nreplot\n\n",strtok(optionfile, "."),cpt,k1);\r
- }\r
- }\r
- /*2 eme*/\r
-\r
- for (k1=1; k1<= m ; k1 ++) { \r
- fprintf(ficgp,"set ylabel \"Years\" \nset ter gif small size 400,300\nplot [%.f:%.f] ",agemin,fage);\r
- \r
- for (i=1; i<= nlstate+1 ; i ++) {\r
- k=2*i;\r
- fprintf(ficgp,"\"t%s\" every :::%d::%d u 1:2 \"\%%lf",fileres,k1-1,k1-1);\r
- for (j=1; j<= nlstate+1 ; j ++) {\r
- if (j==i) fprintf(ficgp," \%%lf (\%%lf)");\r
- else fprintf(ficgp," \%%*lf (\%%*lf)");\r
-} \r
- if (i== 1) fprintf(ficgp,"\" t\"TLE\" w l ,");\r
- else fprintf(ficgp,"\" t\"LE in state (%d)\" w l ,",i-1);\r
- fprintf(ficgp,"\"t%s\" every :::%d::%d u 1:($2-$3*2) \"\%%lf",fileres,k1-1,k1-1);\r
- for (j=1; j<= nlstate+1 ; j ++) {\r
- if (j==i) fprintf(ficgp," \%%lf (\%%lf)");\r
- else fprintf(ficgp," \%%*lf (\%%*lf)");\r
-} \r
- fprintf(ficgp,"\" t\"\" w l 0,");\r
- fprintf(ficgp,"\"t%s\" every :::%d::%d u 1:($2+$3*2) \"\%%lf",fileres,k1-1,k1-1);\r
- for (j=1; j<= nlstate+1 ; j ++) {\r
- if (j==i) fprintf(ficgp," \%%lf (\%%lf)");\r
- else fprintf(ficgp," \%%*lf (\%%*lf)");\r
-} \r
- if (i== (nlstate+1)) fprintf(ficgp,"\" t\"\" w l 0");\r
- else fprintf(ficgp,"\" t\"\" w l 0,");\r
- }\r
- fprintf(ficgp,"\nset out \"e%s%d.gif\" \nreplot\n\n",strtok(optionfile, "."),k1);\r
- }\r
+/*------------ gnuplot -------------*/\r
+ printinggnuplot(fileres,optionfilefiname,optionfile,optionfilegnuplot, agemin,agemax,fage, pathc,p);\r
\r
- /*3eme*/\r
-\r
- for (k1=1; k1<= m ; k1 ++) { \r
- for (cpt=1; cpt<= nlstate ; cpt ++) {\r
- k=2+nlstate*(cpt-1);\r
- fprintf(ficgp,"set ter gif small size 400,300\nplot [%.f:%.f] \"e%s\" every :::%d::%d u 1:%d t \"e%d1\" w l",agemin,fage,fileres,k1-1,k1-1,k,cpt);\r
- for (i=1; i< nlstate ; i ++) {\r
- fprintf(ficgp,",\"e%s\" every :::%d::%d u 1:%d t \"e%d%d\" w l",fileres,k1-1,k1-1,k+i,cpt,i+1);\r
- } \r
- fprintf(ficgp,"\nset out \"exp%s%d%d.gif\" \nreplot\n\n",strtok(optionfile, "."),cpt,k1);\r
- }\r
- }\r
+/*------------ free_vector -------------*/\r
+ chdir(path);\r
+ \r
+ free_ivector(wav,1,imx);\r
+ free_imatrix(dh,1,lastpass-firstpass+1,1,imx);\r
+ free_imatrix(mw,1,lastpass-firstpass+1,1,imx); \r
+ free_ivector(num,1,n);\r
+ free_vector(agedc,1,n);\r
+ /*free_matrix(covar,1,NCOVMAX,1,n);*/\r
+ fclose(ficparo);\r
+ fclose(ficres);\r
\r
- /* CV preval stat */\r
- for (k1=1; k1<= m ; k1 ++) { \r
- for (cpt=1; cpt<nlstate ; cpt ++) {\r
- k=3;\r
- fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability\" \nset ter gif small size 400,300\nplot [%.f:%.f] \"pij%s\" u ($1==%d ? ($3):1/0):($%d/($%d",agemin,agemax,fileres,k1,k+cpt+1,k+1);\r
- for (i=1; i< nlstate ; i ++)\r
- fprintf(ficgp,"+$%d",k+i+1);\r
- fprintf(ficgp,")) t\"prev(%d,%d)\" w l",cpt,cpt+1);\r
- \r
- l=3+(nlstate+ndeath)*cpt;\r
- fprintf(ficgp,",\"pij%s\" u ($1==%d ? ($3):1/0):($%d/($%d",fileres,k1,l+cpt+1,l+1);\r
- for (i=1; i< nlstate ; i ++) {\r
- l=3+(nlstate+ndeath)*cpt;\r
- fprintf(ficgp,"+$%d",l+i+1);\r
- }\r
- fprintf(ficgp,")) t\"prev(%d,%d)\" w l\n",cpt+1,cpt+1); \r
- fprintf(ficgp,"set out \"p%s%d%d.gif\" \nreplot\n\n",strtok(optionfile, "."),cpt,k1);\r
- } \r
- } \r
-\r
- /* proba elementaires */\r
- for(i=1,jk=1; i <=nlstate; i++){\r
- for(k=1; k <=(nlstate+ndeath); k++){\r
- if (k != i) {\r
- for(j=1; j <=ncovmodel; j++){\r
- /*fprintf(ficgp,"%s%1d%1d=%f ",alph[j],i,k,p[jk]);*/\r
- /*fprintf(ficgp,"%s",alph[1]);*/\r
- fprintf(ficgp,"p%d=%f ",jk,p[jk]);\r
- jk++; \r
- fprintf(ficgp,"\n");\r
- }\r
- }\r
- }\r
- }\r
-\r
- for(jk=1; jk <=m; jk++) {\r
- fprintf(ficgp,"\nset ter gif small size 400,300\nset log y\nplot [%.f:%.f] ",agemin,agemax);\r
- i=1;\r
- for(k2=1; k2<=nlstate; k2++) {\r
- k3=i;\r
- for(k=1; k<=(nlstate+ndeath); k++) {\r
- if (k != k2){\r
- fprintf(ficgp," exp(p%d+p%d*x",i,i+1);\r
-ij=1;\r
- for(j=3; j <=ncovmodel; j++) {\r
- if(((j-2)==Tage[ij]) &&(ij <=cptcovage)) {\r
- fprintf(ficgp,"+p%d*%d*x",i+j-1,nbcode[Tvar[j-2]][codtab[jk][Tvar[j-2]]]);\r
- ij++;\r
- }\r
- else\r
- fprintf(ficgp,"+p%d*%d",i+j-1,nbcode[Tvar[j-2]][codtab[jk][j-2]]);\r
- }\r
- fprintf(ficgp,")/(1");\r
- \r
- for(k1=1; k1 <=nlstate; k1++){ \r
- fprintf(ficgp,"+exp(p%d+p%d*x",k3+(k1-1)*ncovmodel,k3+(k1-1)*ncovmodel+1);\r
-ij=1;\r
- for(j=3; j <=ncovmodel; j++){\r
- if(((j-2)==Tage[ij]) &&(ij <=cptcovage)) {\r
- fprintf(ficgp,"+p%d*%d*x",k3+(k1-1)*ncovmodel+1+j-2,nbcode[Tvar[j-2]][codtab[jk][Tvar[j-2]]]);\r
- ij++;\r
- }\r
- else\r
- fprintf(ficgp,"+p%d*%d",k3+(k1-1)*ncovmodel+1+j-2,nbcode[Tvar[j-2]][codtab[jk][j-2]]);\r
- }\r
- fprintf(ficgp,")");\r
- }\r
- fprintf(ficgp,") t \"p%d%d\" ", k2,k);\r
- if ((k+k2)!= (nlstate*2+ndeath)) fprintf(ficgp,",");\r
- i=i+ncovmodel;\r
- }\r
- }\r
- }\r
- fprintf(ficgp,"\nset out \"pe%s%d.gif\" \nreplot\n\n",strtok(optionfile, "."),jk); \r
- }\r
- \r
- fclose(ficgp);\r
- /* end gnuplot */\r
- \r
-chdir(path);\r
- \r
- free_ivector(wav,1,imx);\r
- free_imatrix(dh,1,lastpass-firstpass+1,1,imx);\r
- free_imatrix(mw,1,lastpass-firstpass+1,1,imx); \r
- free_ivector(num,1,n);\r
- free_vector(agedc,1,n);\r
- /*free_matrix(covar,1,NCOVMAX,1,n);*/\r
- fclose(ficparo);\r
- fclose(ficres);\r
- /* }*/\r
- \r
- /*________fin mle=1_________*/\r
- \r
-\r
- \r
- /* No more information from the sample is required now */\r
/* Reads comments: lines beginning with '#' */\r
while((c=getc(ficpar))=='#' && c!= EOF){\r
ungetc(c,ficpar);\r
fprintf(ficparo,"agemin=%.0f agemax=%.0f bage=%.0f fage=%.0f\n",agemin,agemax,bage,fage);\r
/*--------- index.htm --------*/\r
\r
- strcpy(optionfilehtm,optionfile);\r
- strcat(optionfilehtm,".htm");\r
- if((fichtm=fopen(optionfilehtm,"w"))==NULL) {\r
- printf("Problem with %s \n",optionfilehtm);goto end;\r
- }\r
-\r
- fprintf(fichtm,"<body><ul> <font size=\"6\">Imach, Version 0.7 </font> <hr size=\"2\" color=\"#EC5E5E\"> \r
-Titre=%s <br>Datafile=%s Firstpass=%d Lastpass=%d Stepm=%d Weight=%d Model=%s<br>\r
-Total number of observations=%d <br>\r
-Interval (in months) between two waves: Min=%d Max=%d Mean=%.2lf<br>\r
-<hr size=\"2\" color=\"#EC5E5E\"> \r
-<li>Outputs files<br><br>\n\r
- - Observed prevalence in each state: <a href=\"p%s\">p%s</a> <br>\n\r
-- Estimated parameters and the covariance matrix: <a href=\"%s\">%s</a> <br>\r
- - Stationary prevalence in each state: <a href=\"pl%s\">pl%s</a> <br>\r
- - Transition probabilities: <a href=\"pij%s\">pij%s</a><br>\r
- - Copy of the parameter file: <a href=\"o%s\">o%s</a><br>\r
- - Life expectancies by age and initial health status: <a href=\"e%s\">e%s</a> <br>\r
- - Variances of life expectancies by age and initial health status: <a href=\"v%s\">v%s</a><br>\r
- - Health expectancies with their variances: <a href=\"t%s\">t%s</a> <br>\r
- - Standard deviation of stationary prevalences: <a href=\"vpl%s\">vpl%s</a> <br>\r
- - Prevalences and population forecasting: <a href=\"f%s\">f%s</a> <br>\r
-<br>",title,datafile,firstpass,lastpass,stepm, weightopt,model,imx,jmin,jmax,jmean,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres);\r
-\r
- fprintf(fichtm," <li>Graphs</li><p>");\r
-\r
- m=cptcoveff;\r
- if (cptcovn < 1) {m=1;ncodemax[1]=1;}\r
-\r
- j1=0;\r
- for(k1=1; k1<=m;k1++){\r
- for(i1=1; i1<=ncodemax[k1];i1++){\r
- j1++;\r
- if (cptcovn > 0) {\r
- fprintf(fichtm,"<hr size=\"2\" color=\"#EC5E5E\">************ Results for covariates");\r
- for (cpt=1; cpt<=cptcoveff;cpt++) \r
- fprintf(fichtm," V%d=%d ",Tvaraff[cpt],nbcode[Tvaraff[cpt]][codtab[j1][cpt]]);\r
- fprintf(fichtm," ************\n<hr size=\"2\" color=\"#EC5E5E\">");\r
- }\r
- fprintf(fichtm,"<br>- Probabilities: pe%s%d.gif<br>\r
-<img src=\"pe%s%d.gif\">",strtok(optionfile, "."),j1,strtok(optionfile, "."),j1); \r
- for(cpt=1; cpt<nlstate;cpt++){\r
- fprintf(fichtm,"<br>- Prevalence of disability : p%s%d%d.gif<br>\r
-<img src=\"p%s%d%d.gif\">",strtok(optionfile, "."),cpt,j1,strtok(optionfile, "."),cpt,j1);\r
- }\r
- for(cpt=1; cpt<=nlstate;cpt++) {\r
- fprintf(fichtm,"<br>- Observed and stationary prevalence (with confident\r
-interval) in state (%d): v%s%d%d.gif <br>\r
-<img src=\"v%s%d%d.gif\">",cpt,strtok(optionfile, "."),cpt,j1,strtok(optionfile, "."),cpt,j1); \r
- }\r
- for(cpt=1; cpt<=nlstate;cpt++) {\r
- fprintf(fichtm,"\n<br>- Health life expectancies by age and initial health state (%d): exp%s%d%d.gif <br>\r
-<img src=\"exp%s%d%d.gif\">",cpt,strtok(optionfile, "."),cpt,j1,strtok(optionfile, "."),cpt,j1);\r
- }\r
- fprintf(fichtm,"\n<br>- Total life expectancy by age and\r
-health expectancies in states (1) and (2): e%s%d.gif<br>\r
-<img src=\"e%s%d.gif\">",strtok(optionfile, "."),j1,strtok(optionfile, "."),j1);\r
-fprintf(fichtm,"\n</body>");\r
- }\r
- }\r
-fclose(fichtm);\r
+ printinghtml(fileres,title,datafile, firstpass, lastpass, stepm, weightopt,model,imx,jmin,jmax,jmean,optionfile,optionfilehtm);\r
\r
+ \r
/*--------------- Prevalence limit --------------*/\r
\r
strcpy(filerespl,"pl");\r
free_matrix(mint,1,maxwav,1,n);\r
free_matrix(anint,1,maxwav,1,n);\r
free_matrix(agev,1,maxwav,1,imx);\r
+\r
/* Mobile average */\r
\r
if (cptcoveff==0) ncodemax[cptcoveff]=1;\r
\r
if (mobilav==1) {\r
mobaverage= ma3x(1, AGESUP,1,NCOVMAX, 1,NCOVMAX);\r
- for (agedeb=bage+3; agedeb<=fage-2; agedeb++)\r
- for (i=1; i<=nlstate;i++)\r
- for (cptcod=1;cptcod<=ncodemax[cptcov];cptcod++)\r
- mobaverage[(int)agedeb][i][cptcod]=0.;\r
- \r
- for (agedeb=bage+4; agedeb<=fage; agedeb++){\r
- for (i=1; i<=nlstate;i++){\r
- for (cptcod=1;cptcod<=ncodemax[cptcoveff];cptcod++){\r
- for (cpt=0;cpt<=4;cpt++){\r
- mobaverage[(int)agedeb-2][i][cptcod]=mobaverage[(int)agedeb-2][i][cptcod]+probs[(int)agedeb-cpt][i][cptcod];\r
- }\r
- mobaverage[(int)agedeb-2][i][cptcod]=mobaverage[(int)agedeb-2][i][cptcod]/5;\r
- }\r
- }\r
- } \r
+ movingaverage(agedeb, fage, agemin, mobaverage);\r
}\r
\r
stepsize=(int) (stepm+YEARM-1)/YEARM;\r
fprintf(ficresf,"# StartingAge FinalAge");\r
for(j=1; j<=nlstate+ndeath;j++) fprintf(ficresf," P.%d",j);\r
if (popforecast==1) fprintf(ficresf," [Population]");\r
- \r
- for (cpt=0; cpt<4;cpt++) { \r
+ \r
+ for (cpt=0; cpt<=(anproj2-anproj1);cpt++) { \r
fprintf(ficresf,"\n");\r
fprintf(ficresf,"\n# Forecasting at date %.lf/%.lf/%.lf ",jproj1,mproj1,anproj1+cpt); \r
\r
- for (agedeb=(fage-((int)calagedate %12/12.)); agedeb>=(bage-((int)calagedate %12)/12.); agedeb--){ /* If stepm=6 months */\r
+ for (agedeb=(fage-((int)calagedate %12/12.)); agedeb>=(agemin-((int)calagedate %12)/12.); agedeb--){ \r
nhstepm=(int) rint((agelim-agedeb)*YEARM/stepm); \r
nhstepm = nhstepm/hstepm; \r
- /*printf("agedeb=%.lf stepm=%d hstepm=%d nhstepm=%d \n",agedeb,stepm,hstepm,nhstepm);*/\r
-\r
+ \r
p3mat=ma3x(1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);\r
oldm=oldms;savm=savms;\r
hpxij(p3mat,nhstepm,agedeb,hstepm,p,nlstate,stepm,oldm,savm, k); \r
kk1=kk1+p3mat[i][j][h]*mobaverage[(int)agedeb+1][i][cptcod];\r
else {\r
kk1=kk1+p3mat[i][j][h]*probs[(int)(agedeb+1)][i][cptcod];\r
- /* fprintf(ficresf," p3=%.3f p=%.3f ", p3mat[i][j][h], probs[(int)(agedeb)+1][i][cptcod]);*/\r
+ \r
}\r
\r
if (popforecast==1) kk2=kk1*popeffectif[(int)agedeb];\r
}\r
}\r
}\r
- /* free_ma3x(p3mat,1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);*/\r
- }\r
- }\r
+ free_ma3x(p3mat,1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);\r
+ }\r
+ }\r
}\r
}\r
- /* if (mobilav==1) free_ma3x(mobaverage,1, AGESUP,1,NCOVMAX, 1,NCOVMAX);\r
+ if (mobilav==1) free_ma3x(mobaverage,1, AGESUP,1,NCOVMAX, 1,NCOVMAX);\r
+\r
if (popforecast==1) {\r
free_ivector(popage,0,AGESUP);\r
free_vector(popeffectif,0,AGESUP);\r
free_vector(popcount,0,AGESUP);\r
}\r
free_imatrix(s,1,maxwav+1,1,n);\r
- free_vector(weight,1,n);*/\r
+ free_vector(weight,1,n);\r
fclose(ficresf);\r
}/* End forecasting */\r
else{\r
erreur=108;\r
printf("Error %d!! You can only forecast the prevalences if the optimization\n has been performed with stepm = 1 (month) instead of %d\n", erreur, stepm);\r
+\r
}\r
\r
+ \r
/*---------- Health expectancies and variances ------------*/\r
\r
strcpy(filerest,"t");\r