--- imach096d/src/imach.c 2002/02/22 17:54:20 1.22
+++ imach096d/src/imach.c 2002/02/27 15:42:00 1.26
@@ -1,5 +1,5 @@
-/* $Id: imach.c,v 1.22 2002/02/22 17:54:20 brouard Exp $
- Interpolate Markov Chain
+/* $Id: imach.c,v 1.26 2002/02/27 15:42:00 lievre Exp $
+ Interpolated Markov Chain
Short summary of the programme:
@@ -95,7 +95,7 @@ double jmean; /* Mean space between 2 wa
double **oldm, **newm, **savm; /* Working pointers to matrices */
double **oldms, **newms, **savms; /* Fixed working pointers to matrices */
FILE *fic,*ficpar, *ficparo,*ficres, *ficrespl, *ficrespij, *ficrest,*ficresf;
-FILE *ficgp, *fichtm,*ficresprob,*ficpop;
+FILE *ficgp,*ficresprob,*ficpop;
FILE *ficreseij;
char filerese[FILENAMELENGTH];
FILE *ficresvij;
@@ -123,7 +123,7 @@ FILE *ficreseij;
static double maxarg1,maxarg2;
#define FMAX(a,b) (maxarg1=(a),maxarg2=(b),(maxarg1)>(maxarg2)? (maxarg1):(maxarg2))
#define FMIN(a,b) (maxarg1=(a),maxarg2=(b),(maxarg1)<(maxarg2)? (maxarg1):(maxarg2))
-
+
#define SIGN(a,b) ((b)>0.0 ? fabs(a) : -fabs(a))
#define rint(a) floor(a+0.5)
@@ -1176,7 +1176,7 @@ void lubksb(double **a, int n, int *indx
}
/************ Frequencies ********************/
-void freqsummary(char fileres[], int agemin, int agemax, int **s, double **agev, int nlstate, int imx, int *Tvar, int **nbcode, int *ncodemax,double **mint,double **anint, double dateprev1,double dateprev2)
+void freqsummary(char fileres[], int agemin, int agemax, int **s, double **agev, int nlstate, int imx, int *Tvar, int **nbcode, int *ncodemax,double **mint,double **anint, double dateprev1,double dateprev2,double jprev1, double mprev1,double anprev1,double jprev2, double mprev2,double anprev2)
{ /* Some frequencies */
int i, m, jk, k1,i1, j1, bool, z1,z2,j;
@@ -1236,6 +1236,9 @@ void freqsummary(char fileres[], int ag
}
}
}
+
+ fprintf(ficresp, "#Count between %.lf/%.lf/%.lf and %.lf/%.lf/%.lf\n",jprev1, mprev1,anprev1,jprev2, mprev2,anprev2);
+
if (cptcovn>0) {
fprintf(ficresp, "\n#********** Variable ");
for (z1=1; z1<=cptcoveff; z1++) fprintf(ficresp, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtab[j1][z1]]);
@@ -1620,7 +1623,7 @@ void varevsij(char fileres[], double ***
for(i=1; i<=nlstate;i++)
prlim[i][i]=probs[(int)age][i][ij];
}
-
+
for(j=1; j<= nlstate; j++){
for(h=0; h<=nhstepm; h++){
for(i=1, gp[h][j]=0.;i<=nlstate;i++)
@@ -1632,7 +1635,7 @@ void varevsij(char fileres[], double ***
xp[i] = x[i] - (i==theta ?delti[theta]:0);
hpxij(p3mat,nhstepm,age,hstepm,xp,nlstate,stepm,oldm,savm, ij);
prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ij);
-
+
if (popbased==1) {
for(i=1; i<=nlstate;i++)
prlim[i][i]=probs[(int)age][i][ij];
@@ -1684,7 +1687,7 @@ void varevsij(char fileres[], double ***
free_ma3x(trgradg,0,nhstepm,1,nlstate,1,npar);
free_ma3x(p3mat,1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);
} /* End age */
-
+
free_vector(xp,1,npar);
free_matrix(doldm,1,nlstate,1,npar);
free_matrix(dnewm,1,nlstate,1,nlstate);
@@ -1876,7 +1879,271 @@ if (i== 4) fprintf(ficresprob,"%.3e %.3e
}
free_vector(xp,1,npar);
fclose(ficresprob);
- exit(0);
+
+}
+
+/******************* Printing html file ***********/
+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[] ){
+ int jj1, k1, i1, cpt;
+ FILE *fichtm;
+ /*char optionfilehtm[FILENAMELENGTH];*/
+
+ strcpy(optionfilehtm,optionfile);
+ strcat(optionfilehtm,".htm");
+ if((fichtm=fopen(optionfilehtm,"w"))==NULL) {
+ printf("Problem with %s \n",optionfilehtm), exit(0);
+ }
+
+ fprintf(fichtm,"
Imach, Version 0.7
+Title=%s
Datafile=%s Firstpass=%d Lastpass=%d Stepm=%d Weight=%d Model=%s
+
+Total number of observations=%d
+Interval (in months) between two waves: Min=%d Max=%d Mean=%.2lf
+
+- Outputs files
\n
+ - Observed prevalence in each state: p%s
\n
+- Estimated parameters and the covariance matrix: %s
+ - Stationary prevalence in each state: pl%s
+ - Transition probabilities: pij%s
+ - Copy of the parameter file: o%s
+ - Life expectancies by age and initial health status: e%s
+ - Variances of life expectancies by age and initial health status: v%s
+ - Health expectancies with their variances: t%s
+ - Standard deviation of stationary prevalences: vpl%s
+ - Prevalences and population forecasting: f%s
+
",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);
+
+fprintf(fichtm," - Graphs
");
+
+ m=cptcoveff;
+ if (cptcovn < 1) {m=1;ncodemax[1]=1;}
+
+ jj1=0;
+ for(k1=1; k1<=m;k1++){
+ for(i1=1; i1<=ncodemax[k1];i1++){
+ jj1++;
+ if (cptcovn > 0) {
+ fprintf(fichtm,"
************ Results for covariates");
+ for (cpt=1; cpt<=cptcoveff;cpt++)
+ fprintf(fichtm," V%d=%d ",Tvaraff[cpt],nbcode[Tvaraff[cpt]][codtab[jj1][cpt]]);
+ fprintf(fichtm," ************\n
");
+ }
+ fprintf(fichtm,"
- Probabilities: pe%s%d.gif
+",strtok(optionfile, "."),jj1,strtok(optionfile, "."),jj1);
+ for(cpt=1; cpt- Prevalence of disability : p%s%d%d.gif
+",strtok(optionfile, "."),cpt,jj1,strtok(optionfile, "."),cpt,jj1);
+ }
+ for(cpt=1; cpt<=nlstate;cpt++) {
+ fprintf(fichtm,"
- Observed and stationary prevalence (with confident
+interval) in state (%d): v%s%d%d.gif
+",cpt,strtok(optionfile, "."),cpt,jj1,strtok(optionfile, "."),cpt,jj1);
+ }
+ for(cpt=1; cpt<=nlstate;cpt++) {
+ fprintf(fichtm,"\n
- Health life expectancies by age and initial health state (%d): exp%s%d%d.gif
+",cpt,strtok(optionfile, "."),cpt,jj1,strtok(optionfile, "."),cpt,jj1);
+ }
+ fprintf(fichtm,"\n
- Total life expectancy by age and
+health expectancies in states (1) and (2): e%s%d.gif
+",strtok(optionfile, "."),jj1,strtok(optionfile, "."),jj1);
+fprintf(fichtm,"\n");
+ }
+ }
+fclose(fichtm);
+}
+
+/******************* Gnuplot file **************/
+void printinggnuplot(char fileres[],char optionfilefiname[],char optionfile[],char optionfilegnuplot[], double agemin, double agemax, double fage , char pathc[], double p[]){
+
+ int m,cpt,k1,i,k,j,jk,k2,k3,ij,l;
+
+ strcpy(optionfilegnuplot,optionfilefiname);
+ strcat(optionfilegnuplot,".plt");
+ if((ficgp=fopen(optionfilegnuplot,"w"))==NULL) {
+ printf("Problem with file %s",optionfilegnuplot);
+ }
+
+#ifdef windows
+ fprintf(ficgp,"cd \"%s\" \n",pathc);
+#endif
+m=pow(2,cptcoveff);
+
+ /* 1eme*/
+ for (cpt=1; cpt<= nlstate ; cpt ++) {
+ for (k1=1; k1<= m ; k1 ++) {
+
+#ifdef windows
+ 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);
+#endif
+#ifdef unix
+fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability\" \nplot [%.f:%.f] \"vpl%s\" u 1:2 \"\%%lf",agemin,fage,fileres);
+#endif
+
+for (i=1; i<= nlstate ; i ++) {
+ if (i==cpt) fprintf(ficgp," \%%lf (\%%lf)");
+ else fprintf(ficgp," \%%*lf (\%%*lf)");
+}
+ fprintf(ficgp,"\" t\"Stationary prevalence\" w l 0,\"vpl%s\" every :::%d::%d u 1:($2+2*$3) \"\%%lf",fileres,k1-1,k1-1);
+ 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 1,\"vpl%s\" every :::%d::%d u 1:($2-2*$3) \"\%%lf",fileres,k1-1,k1-1);
+ for (i=1; i<= nlstate ; i ++) {
+ if (i==cpt) fprintf(ficgp," \%%lf (\%%lf)");
+ else fprintf(ficgp," \%%*lf (\%%*lf)");
+}
+ 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));
+#ifdef unix
+fprintf(ficgp,"\nset ter gif small size 400,300");
+#endif
+fprintf(ficgp,"\nset out \"v%s%d%d.gif\" \nreplot\n\n",strtok(optionfile, "."),cpt,k1);
+ }
+ }
+ /*2 eme*/
+
+ for (k1=1; k1<= m ; k1 ++) {
+ fprintf(ficgp,"set ylabel \"Years\" \nset ter gif small size 400,300\nplot [%.f:%.f] ",agemin,fage);
+
+ for (i=1; i<= nlstate+1 ; i ++) {
+ k=2*i;
+ fprintf(ficgp,"\"t%s\" every :::%d::%d u 1:2 \"\%%lf",fileres,k1-1,k1-1);
+ 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 ,");
+ else fprintf(ficgp,"\" t\"LE in state (%d)\" w l ,",i-1);
+ fprintf(ficgp,"\"t%s\" every :::%d::%d u 1:($2-$3*2) \"\%%lf",fileres,k1-1,k1-1);
+ for (j=1; j<= nlstate+1 ; j ++) {
+ if (j==i) fprintf(ficgp," \%%lf (\%%lf)");
+ else fprintf(ficgp," \%%*lf (\%%*lf)");
+}
+ fprintf(ficgp,"\" t\"\" w l 0,");
+ fprintf(ficgp,"\"t%s\" every :::%d::%d u 1:($2+$3*2) \"\%%lf",fileres,k1-1,k1-1);
+ for (j=1; j<= nlstate+1 ; j ++) {
+ if (j==i) fprintf(ficgp," \%%lf (\%%lf)");
+ else fprintf(ficgp," \%%*lf (\%%*lf)");
+}
+ if (i== (nlstate+1)) fprintf(ficgp,"\" t\"\" w l 0");
+ else fprintf(ficgp,"\" t\"\" w l 0,");
+ }
+ fprintf(ficgp,"\nset out \"e%s%d.gif\" \nreplot\n\n",strtok(optionfile, "."),k1);
+ }
+
+ /*3eme*/
+
+ for (k1=1; k1<= m ; k1 ++) {
+ for (cpt=1; cpt<= nlstate ; cpt ++) {
+ k=2+nlstate*(cpt-1);
+ 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);
+ for (i=1; i< nlstate ; i ++) {
+ 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);
+ }
+ fprintf(ficgp,"\nset out \"exp%s%d%d.gif\" \nreplot\n\n",strtok(optionfile, "."),cpt,k1);
+ }
+ }
+
+ /* CV preval stat */
+ for (k1=1; k1<= m ; k1 ++) {
+ for (cpt=1; cpt Imach, Version 0.7
-Titre=%s
Datafile=%s Firstpass=%d Lastpass=%d Stepm=%d Weight=%d Model=%s
-Total number of observations=%d
-Interval (in months) between two waves: Min=%d Max=%d Mean=%.2lf
-
-- Outputs files
\n
- - Observed prevalence in each state: p%s
\n
-- Estimated parameters and the covariance matrix: %s
- - Stationary prevalence in each state: pl%s
- - Transition probabilities: pij%s
- - Copy of the parameter file: o%s
- - Life expectancies by age and initial health status: e%s
- - Variances of life expectancies by age and initial health status: v%s
- - Health expectancies with their variances: t%s
- - Standard deviation of stationary prevalences: vpl%s
- - Prevalences and population forecasting: f%s
-
",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);
-
- fprintf(fichtm," - Graphs
");
-
- m=cptcoveff;
- if (cptcovn < 1) {m=1;ncodemax[1]=1;}
-
- j1=0;
- for(k1=1; k1<=m;k1++){
- for(i1=1; i1<=ncodemax[k1];i1++){
- j1++;
- if (cptcovn > 0) {
- fprintf(fichtm,"
************ Results for covariates");
- for (cpt=1; cpt<=cptcoveff;cpt++)
- fprintf(fichtm," V%d=%d ",Tvaraff[cpt],nbcode[Tvaraff[cpt]][codtab[j1][cpt]]);
- fprintf(fichtm," ************\n
");
- }
- fprintf(fichtm,"
- Probabilities: pe%s%d.gif
-",strtok(optionfile, "."),j1,strtok(optionfile, "."),j1);
- for(cpt=1; cpt- Prevalence of disability : p%s%d%d.gif
-",strtok(optionfile, "."),cpt,j1,strtok(optionfile, "."),cpt,j1);
- }
- for(cpt=1; cpt<=nlstate;cpt++) {
- fprintf(fichtm,"
- Observed and stationary prevalence (with confident
-interval) in state (%d): v%s%d%d.gif
-",cpt,strtok(optionfile, "."),cpt,j1,strtok(optionfile, "."),cpt,j1);
- }
- for(cpt=1; cpt<=nlstate;cpt++) {
- fprintf(fichtm,"\n
- Health life expectancies by age and initial health state (%d): exp%s%d%d.gif
-",cpt,strtok(optionfile, "."),cpt,j1,strtok(optionfile, "."),cpt,j1);
- }
- fprintf(fichtm,"\n
- Total life expectancy by age and
-health expectancies in states (1) and (2): e%s%d.gif
-",strtok(optionfile, "."),j1,strtok(optionfile, "."),j1);
-fprintf(fichtm,"\n