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,*ficrespop;\r
-FILE *ficgp,*ficresprob,*ficpop;\r
+FILE *ficgp,*ficresprob,*ficpop, *ficresprobcov, *ficresprobcor;\r
FILE *ficreseij;\r
char filerese[FILENAMELENGTH];\r
FILE *ficresvij;\r
}\r
}\r
}\r
- \r
- \r
-\r
for(j=1; j<= nlstate*2; j++)\r
for(h=0; h<=nhstepm-1; h++){\r
gradg[h][theta][j]= (gp[h][j]-gm[h][j])/2./delti[theta];\r
}\r
-\r
} \r
\r
/* End theta */\r
for(h=0; h<=nhstepm-1; h++)\r
for(j=1; j<=nlstate*2;j++)\r
for(theta=1; theta <=npar; theta++)\r
- trgradg[h][j][theta]=gradg[h][theta][j];\r
-\r
+ trgradg[h][j][theta]=gradg[h][theta][j];\r
+ \r
\r
for(i=1;i<=nlstate*2;i++)\r
for(j=1;j<=nlstate*2;j++)\r
varhe[i][j][(int)age] =0.;\r
\r
printf("%d|",(int)age);fflush(stdout);\r
- for(h=0;h<=nhstepm-1;h++){\r
+ for(h=0;h<=nhstepm-1;h++){\r
for(k=0;k<=nhstepm-1;k++){\r
matprod2(dnewm,trgradg[h],1,nlstate*2,1,npar,1,npar,matcov);\r
matprod2(doldm,dnewm,1,nlstate*2,1,npar,1,nlstate*2,gradg[k]);\r
void varprob(char fileres[], double **matcov, double x[], double delti[], int nlstate, double bage, double fage, int ij, int *Tvar, int **nbcode, int *ncodemax)\r
{\r
int i, j, i1, k1, j1, z1;\r
- int k=0, cptcode;\r
+ int k=0,l, cptcode;\r
double **dnewm,**doldm;\r
double *xp;\r
double *gp, *gm;\r
double age,agelim, cov[NCOVMAX];\r
int theta;\r
char fileresprob[FILENAMELENGTH];\r
+ char fileresprobcov[FILENAMELENGTH];\r
+ char fileresprobcor[FILENAMELENGTH];\r
\r
strcpy(fileresprob,"prob"); \r
strcat(fileresprob,fileres);\r
if((ficresprob=fopen(fileresprob,"w"))==NULL) {\r
printf("Problem with resultfile: %s\n", fileresprob);\r
}\r
+ strcpy(fileresprobcov,"probcov"); \r
+ strcat(fileresprobcov,fileres);\r
+ if((ficresprobcov=fopen(fileresprobcov,"w"))==NULL) {\r
+ printf("Problem with resultfile: %s\n", fileresprobcov);\r
+ }\r
+ strcpy(fileresprobcor,"probcor"); \r
+ strcat(fileresprobcor,fileres);\r
+ if((ficresprobcor=fopen(fileresprobcor,"w"))==NULL) {\r
+ printf("Problem with resultfile: %s\n", fileresprobcor);\r
+ }\r
printf("Computing standard deviation of one-step probabilities: result on file '%s' \n",fileresprob);\r
+ printf("Computing matrix of variance covariance of one-step probabilities: result on file '%s' \n",fileresprobcov);\r
+ printf("and correlation matrix of one-step probabilities: result on file '%s' \n",fileresprobcor);\r
\r
-fprintf(ficresprob,"#One-step probabilities and standard deviation in parentheses\n");\r
+ fprintf(ficresprob,"#One-step probabilities and stand. devi in ()\n");\r
fprintf(ficresprob,"# Age");\r
+ fprintf(ficresprobcov,"#One-step probabilities and covariance matrix\n");\r
+ fprintf(ficresprobcov,"# Age");\r
+ fprintf(ficresprobcor,"#One-step probabilities and correlation matrix\n");\r
+ fprintf(ficresprobcov,"# Age");\r
for(i=1; i<=nlstate;i++)\r
- for(j=1; j<=(nlstate+ndeath);j++)\r
+ for(j=1; j<=(nlstate+ndeath);j++){\r
fprintf(ficresprob," p%1d-%1d (SE)",i,j);\r
-\r
-\r
+ fprintf(ficresprobcov," p%1d-%1d ",i,j);\r
+ fprintf(ficresprobcor," p%1d-%1d ",i,j);\r
+ } \r
fprintf(ficresprob,"\n");\r
-\r
-\r
+ fprintf(ficresprobcov,"\n");\r
+ fprintf(ficresprobcor,"\n");\r
xp=vector(1,npar);\r
dnewm=matrix(1,(nlstate+ndeath)*(nlstate+ndeath),1,npar);\r
doldm=matrix(1,(nlstate+ndeath)*(nlstate+ndeath),1,(nlstate+ndeath)*(nlstate+ndeath));\r
\r
if (cptcovn>0) {\r
fprintf(ficresprob, "\n#********** Variable "); \r
+ fprintf(ficresprobcov, "\n#********** Variable "); \r
+ fprintf(ficresprobcor, "\n#********** Variable "); \r
for (z1=1; z1<=cptcoveff; z1++) fprintf(ficresprob, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtab[j1][z1]]);\r
fprintf(ficresprob, "**********\n#");\r
+ for (z1=1; z1<=cptcoveff; z1++) fprintf(ficresprobcov, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtab[j1][z1]]);\r
+ fprintf(ficresprobcov, "**********\n#");\r
+ for (z1=1; z1<=cptcoveff; z1++) fprintf(ficresprobcor, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtab[j1][z1]]);\r
+ fprintf(ficresprobcor, "**********\n#");\r
}\r
\r
for (age=bage; age<=fage; age ++){ \r
cov[2]=age;\r
for (k=1; k<=cptcovn;k++) {\r
cov[2+k]=nbcode[Tvar[k]][codtab[j1][Tvar[k]]];\r
- \r
}\r
for (k=1; k<=cptcovage;k++) cov[2+Tage[k]]=cov[2+Tage[k]]*cov[2];\r
for (k=1; k<=cptcovprod;k++)\r
}\r
}\r
\r
- /*printf("\n%d ",(int)age);\r
+ /*printf("\n%d ",(int)age);\r
for (i=1; i<=(nlstate+ndeath)*(nlstate+ndeath-1);i++){\r
printf("%e [%e ;%e] ",gm[i],gm[i]-2*sqrt(doldm[i][i]),gm[i]+2*sqrt(doldm[i][i]));\r
}*/\r
\r
fprintf(ficresprob,"\n%d ",(int)age);\r
+ fprintf(ficresprobcov,"\n%d ",(int)age);\r
+ fprintf(ficresprobcor,"\n%d ",(int)age);\r
\r
for (i=1; i<=(nlstate+ndeath)*(nlstate+ndeath-1);i++)\r
- fprintf(ficresprob,"%.3e (%.3e) ",gm[i],sqrt(doldm[i][i]));\r
- \r
+ fprintf(ficresprob,"%12.3e (%12.3e) ",gm[i],sqrt(doldm[i][j]));\r
+ for (i=1; i<=(nlstate)*(nlstate+ndeath);i++){\r
+ fprintf(ficresprobcov,"%12.3e ",gm[i]);\r
+ fprintf(ficresprobcor,"%12.3e ",gm[i]);\r
+ }\r
+ i=0;\r
+ for (k=1; k<=(nlstate);k++){\r
+ for (l=1; l<=(nlstate+ndeath);l++){ \r
+ i=i++;\r
+ fprintf(ficresprobcov,"\n%d %d-%d",(int)age,k,l);\r
+ fprintf(ficresprobcor,"\n%d %d-%d",(int)age,k,l);\r
+ for (j=1; j<=i;j++){\r
+ fprintf(ficresprobcov," %12.3e",doldm[i][j]);\r
+ fprintf(ficresprobcor," %12.3e",doldm[i][j]/sqrt(doldm[i][i])/sqrt(doldm[j][j]));\r
+ }\r
+ }\r
+ }\r
}\r
}\r
free_vector(gp,1,(nlstate+ndeath)*(nlstate+ndeath));\r
}\r
free_vector(xp,1,npar);\r
fclose(ficresprob);\r
- \r
+ fclose(ficresprobcov);\r
+ fclose(ficresprobcor);\r
}\r
\r
\r
fprintf(fichtm,"\n<li> Result files (second order: variances)<br>\n\r
- Parameter file with estimated parameters and covariance matrix: <a href=\"%s\">%s</a> <br>\n\r
- Variance of one-step probabilities: <a href=\"prob%s\">prob%s</a> <br>\n\r
+ - Variance-covariance of one-step probabilities: <a href=\"probcov%s\">probcov%s</a> <br>\n\r
+ - Correlation matrix of one-step probabilities: <a href=\"probcor%s\">probcor%s</a> <br>\n\r
- Variances and covariances of life expectancies by age and initial health status (estepm=%d months): <a href=\"v%s\">v%s</a><br>\n \r
- Health expectancies with their variances (no covariance): <a href=\"t%s\">t%s</a> <br>\n\r
- - Standard deviation of stable prevalences: <a href=\"vpl%s\">vpl%s</a> <br>\n",rfileres,rfileres,fileres,fileres, estepm, fileres,fileres,fileres,fileres,fileres,fileres);\r
+ - Standard deviation of stable prevalences: <a href=\"vpl%s\">vpl%s</a> <br>\n",rfileres,rfileres,fileres,fileres,fileres,fileres,fileres,fileres, estepm, fileres,fileres,fileres,fileres,fileres,fileres);\r
\r
if(popforecast==1) fprintf(fichtm,"\n\r
- Prevalences forecasting: <a href=\"f%s\">f%s</a> <br>\n\r
int m,cpt,k1,i,k,j,jk,k2,k3,ij,l;\r
int ng;\r
strcpy(optionfilegnuplot,optionfilefiname);\r
- strcat(optionfilegnuplot,".gp.txt");\r
+ strcat(optionfilegnuplot,".gp");\r
if((ficgp=fopen(optionfilegnuplot,"w"))==NULL) {\r
printf("Problem with file %s",optionfilegnuplot);\r
}\r
for(k=1; k<=(nlstate+ndeath); k++) {\r
if (k != k2){\r
if(ng==2)\r
- fprintf(ficgp," %f*exp(p%d+p%d*x",stepm/YEARM,i,i+1);\r
+ fprintf(ficgp," %f*exp(p%d+p%d*x",YEARM/stepm,i,i+1);\r
else\r
fprintf(ficgp," exp(p%d+p%d*x",i,i+1);\r
ij=1;\r
double dateprev1, dateprev2,jproj1,mproj1,anproj1,jproj2,mproj2,anproj2;\r
\r
\r
- char version[80]="Imach version 0.8f, May 2002, INED-EUROREVES ";\r
+ char version[80]="Imach version 0.8g, May 2002, INED-EUROREVES ";\r
char *alph[]={"a","a","b","c","d","e"}, str[4];\r
\r
\r