int stepm;\r
/* Stepm, step in month: minimum step interpolation*/\r
\r
+int estepm;\r
+/* Estepm, step in month to interpolate survival function in order to approximate Life Expectancy*/\r
+\r
int m,nb;\r
int *num, firstpass=0, lastpass=4,*cod, *ncodemax, *Tage;\r
double **agev,*moisnais, *annais, *moisdc, *andc,**mint, **anint;\r
\r
/*********** Health Expectancies ****************/\r
\r
-void evsij(char fileres[], double ***eij, double x[], int nlstate, int stepm, int bage, int fage, double **oldm, double **savm, int ij)\r
+void evsij(char fileres[], double ***eij, double x[], int nlstate, int stepm, int bage, int fage, double **oldm, double **savm, int ij, int estepm)\r
{\r
/* Health expectancies */\r
- int i, j, nhstepm, hstepm, h, nstepm, k;\r
+ int i, j, nhstepm, hstepm, h, nstepm;\r
double age, agelim, hf;\r
double ***p3mat;\r
\r
fprintf(ficreseij," %1d-%1d",i,j);\r
fprintf(ficreseij,"\n");\r
\r
- k=1; /* For example stepm=6 months */\r
- hstepm=k*YEARM; /* (a) Every k years of age (in months), for example every k=2 years 24 m */\r
- hstepm=stepm; /* or (b) We decided to compute the life expectancy with the smallest unit */\r
+ if(estepm < stepm){\r
+ printf ("Problem %d lower than %d\n",estepm, stepm);\r
+ }\r
+ else hstepm=estepm; \r
+ /* We compute the life expectancy from trapezoids spaced every estepm months\r
+ * This is mainly to measure the difference between two models: for example\r
+ * if stepm=24 months pijx are given only every 2 years and by summing them\r
+ * we are calculating an estimate of the Life Expectancy assuming a linear \r
+ * progression inbetween and thus overestimating or underestimating according\r
+ * to the curvature of the survival function. If, for the same date, we \r
+ * estimate the model with stepm=1 month, we can keep estepm to 24 months\r
+ * to compare the new estimate of Life expectancy with the same linear \r
+ * hypothesis. A more precise result, taking into account a more precise\r
+ * curvature will be obtained if estepm is as small as stepm. */\r
+\r
+ /* For example we decided to compute the life expectancy with the smallest unit */\r
/* hstepm beeing the number of stepms, if hstepm=1 the length of hstepm is stepm. \r
nhstepm is the number of hstepm from age to agelim \r
nstepm is the number of stepm from age to agelin. \r
Look at hpijx to understand the reason of that which relies in memory size\r
- and note for a fixed period like k years */\r
+ and note for a fixed period like estepm months */\r
/* We decided (b) to get a life expectancy respecting the most precise curvature of the\r
survival function given by stepm (the optimization length). Unfortunately it\r
means that if the survival funtion is printed only each two years of age and if\r
you sum them up and add 1 year (area under the trapezoids) you won't get the same \r
results. So we changed our mind and took the option of the best precision.\r
*/\r
- hstepm=hstepm/stepm; /* Typically in stepm units, if k= 2 years, = 2/6 months = 4 */ \r
+ hstepm=hstepm/stepm; /* Typically in stepm units, if stepm=6 & estepm=24 , = 24/6 months = 4 */ \r
\r
agelim=AGESUP;\r
for (age=bage; age<=fage; age ++){ /* If stepm=6 months */\r
}\r
\r
/************ Variance ******************/\r
-void varevsij(char fileres[], double ***vareij, double **matcov, double x[], double delti[], int nlstate, int stepm, double bage, double fage, double **oldm, double **savm, double **prlim, double ftolpl, int ij)\r
+void varevsij(char fileres[], double ***vareij, double **matcov, double x[], double delti[], int nlstate, int stepm, double bage, double fage, double **oldm, double **savm, double **prlim, double ftolpl, int ij, int estepm)\r
{\r
/* Variance of health expectancies */\r
/* double **prevalim(double **prlim, int nlstate, double *xp, double age, double **oldm, double ** savm,double ftolpl);*/\r
double **newm;\r
double **dnewm,**doldm;\r
- int i, j, nhstepm, hstepm, h, nstepm, kk;\r
+ int i, j, nhstepm, hstepm, h, nstepm ;\r
int k, cptcode;\r
double *xp;\r
double **gp, **gm;\r
dnewm=matrix(1,nlstate,1,npar);\r
doldm=matrix(1,nlstate,1,nlstate);\r
\r
- kk=1; /* For example stepm=6 months */\r
- hstepm=kk*YEARM; /* (a) Every k years of age (in months), for example every k=2 years 24 m */\r
- hstepm=stepm; /* or (b) We decided to compute the life expectancy with the smallest unit */\r
+ if(estepm < stepm){\r
+ printf ("Problem %d lower than %d\n",estepm, stepm);\r
+ }\r
+ else hstepm=estepm; \r
+ /* For example we decided to compute the life expectancy with the smallest unit */\r
/* hstepm beeing the number of stepms, if hstepm=1 the length of hstepm is stepm. \r
nhstepm is the number of hstepm from age to agelim \r
nstepm is the number of stepm from age to agelin. \r
you sum them up and add 1 year (area under the trapezoids) you won't get the same \r
results. So we changed our mind and took the option of the best precision.\r
*/\r
- hstepm=hstepm/stepm; /* Typically in stepm units, if k= 2 years, = 2/6 months = 4 */ \r
+ hstepm=hstepm/stepm; /* Typically in stepm units, if stepm=6 & estepm=24 , = 24/6 months = 4 */ \r
agelim = AGESUP;\r
for (age=bage; age<=fage; age ++){ /* If stepm=6 months */\r
nstepm=(int) rint((agelim-age)*YEARM/stepm); /* Typically 20 years = 20*12/6=40 */ \r
int lastpass, int stepm, int weightopt, char model[],\\r
int imx,int jmin, int jmax, double jmeanint,char optionfile[], \\r
char optionfilehtm[],char rfileres[], char optionfilegnuplot[],\\r
- char version[], int popforecast ){\r
+ char version[], int popforecast, int estepm ){\r
int jj1, k1, i1, cpt;\r
FILE *fichtm;\r
/*char optionfilehtm[FILENAMELENGTH];*/\r
- Observed prevalence in each state: <a href=\"p%s\">p%s</a> <br>\n\r
- Stationary prevalence in each state: <a href=\"pl%s\">pl%s</a> <br>\n\r
- Transition probabilities: <a href=\"pij%s\">pij%s</a><br>\n\r
- - Life expectancies by age and initial health status: <a href=\"e%s\">e%s</a> <br>\n",version,title,datafile,firstpass,lastpass,stepm, weightopt,model,imx,jmin,jmax,jmean,fileres,fileres,optionfilegnuplot,optionfilegnuplot,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres);\r
+ - Life expectancies by age and initial health status (estepm=%2d months): <a href=\"e%s\">e%s</a> <br>\n",version,title,datafile,firstpass,lastpass,stepm, weightopt,model,imx,jmin,jmax,jmean,fileres,fileres,optionfilegnuplot,optionfilegnuplot,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,estepm);\r
\r
fprintf(fichtm,"\n\r
- Parameter file with estimated parameters and the covariance matrix: <a href=\"%s\">%s</a> <br>\n\r
- - Variances of life expectancies by age and initial health status: <a href=\"v%s\">v%s</a><br>\n\r
+ - Variances 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: <a href=\"t%s\">t%s</a> <br>\n\r
- - Standard deviation of stationary prevalences: <a href=\"vpl%s\">vpl%s</a> <br>\n",rfileres,rfileres,fileres,fileres,fileres,fileres,fileres,fileres);\r
+ - Standard deviation of stationary prevalences: <a href=\"vpl%s\">vpl%s</a> <br>\n",rfileres,rfileres, 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
fputs(line,ficparo);\r
}\r
ungetc(c,ficpar);\r
- \r
- fscanf(ficpar,"agemin=%lf agemax=%lf bage=%lf fage=%lf\n",&ageminpar,&agemaxpar, &bage, &fage);\r
- \r
+ estepm=0;\r
+ fscanf(ficpar,"agemin=%lf agemax=%lf bage=%lf fage=%lf estepm=%d\n",&ageminpar,&agemaxpar, &bage, &fage, &estepm);\r
+ if (estepm==0 || estepm < stepm) estepm=stepm;\r
if (fage <= 2) {\r
bage = ageminpar;\r
fage = agemaxpar;\r
}\r
\r
fprintf(ficres,"# agemin agemax for life expectancy, bage fage (if mle==0 ie no data nor Max likelihood).\n");\r
- fprintf(ficres,"agemin=%.0f agemax=%.0f bage=%.0f fage=%.0f\n",ageminpar,agemaxpar,bage,fage);\r
- fprintf(ficparo,"agemin=%.0f agemax=%.0f bage=%.0f fage=%.0f\n",ageminpar,agemaxpar,bage,fage);\r
+ fprintf(ficres,"agemin=%.0f agemax=%.0f bage=%.0f fage=%.0f estepm=%d\n",ageminpar,agemaxpar,bage,fage, estepm);\r
+ fprintf(ficparo,"agemin=%.0f agemax=%.0f bage=%.0f fage=%.0f estepm=%d\n",ageminpar,agemaxpar,bage,fage, estepm);\r
\r
while((c=getc(ficpar))=='#' && c!= EOF){\r
ungetc(c,ficpar);\r
\r
/*--------- index.htm --------*/\r
\r
- printinghtml(fileres,title,datafile, firstpass, lastpass, stepm, weightopt,model,imx,jmin,jmax,jmean,optionfile,optionfilehtm,rfileres,optionfilegnuplot,version,popforecast);\r
+ printinghtml(fileres,title,datafile, firstpass, lastpass, stepm, weightopt,model,imx,jmin,jmax,jmean,optionfile,optionfilehtm,rfileres,optionfilegnuplot,version,popforecast,estepm);\r
\r
\r
/*--------------- Prevalence limit --------------*/\r
\r
eij=ma3x(1,nlstate,1,nlstate,(int) bage, (int) fage);\r
oldm=oldms;savm=savms;\r
- evsij(fileres, eij, p, nlstate, stepm, (int) bage, (int)fage, oldm, savm, k); \r
+ evsij(fileres, eij, p, nlstate, stepm, (int) bage, (int)fage, oldm, savm, k, estepm); \r
vareij=ma3x(1,nlstate,1,nlstate,(int) bage, (int) fage);\r
oldm=oldms;savm=savms;\r
- varevsij(fileres, vareij, matcov, p, delti, nlstate, stepm, (int) bage, (int) fage, oldm, savm, prlim, ftolpl,k);\r
+ varevsij(fileres, vareij, matcov, p, delti, nlstate, stepm, (int) bage, (int) fage, oldm, savm, prlim, ftolpl,k, estepm);\r
\r
\r
\r