--- imach096d/src/imach.c 2002/03/26 17:08:39 1.35
+++ imach096d/src/imach.c 2002/03/29 15:27:27 1.36
@@ -1,4 +1,4 @@
-/* $Id: imach.c,v 1.35 2002/03/26 17:08:39 lievre Exp $
+/* $Id: imach.c,v 1.36 2002/03/29 15:27:27 brouard Exp $
Interpolated Markov Chain
Short summary of the programme:
@@ -136,6 +136,9 @@ int imx;
int stepm;
/* Stepm, step in month: minimum step interpolation*/
+int estepm;
+/* Estepm, step in month to interpolate survival function in order to approximate Life Expectancy*/
+
int m,nb;
int *num, firstpass=0, lastpass=4,*cod, *ncodemax, *Tage;
double **agev,*moisnais, *annais, *moisdc, *andc,**mint, **anint;
@@ -1528,10 +1531,10 @@ void tricode(int *Tvar, int **nbcode, in
/*********** Health Expectancies ****************/
-void evsij(char fileres[], double ***eij, double x[], int nlstate, int stepm, int bage, int fage, double **oldm, double **savm, int ij)
+void evsij(char fileres[], double ***eij, double x[], int nlstate, int stepm, int bage, int fage, double **oldm, double **savm, int ij, int estepm)
{
/* Health expectancies */
- int i, j, nhstepm, hstepm, h, nstepm, k;
+ int i, j, nhstepm, hstepm, h, nstepm;
double age, agelim, hf;
double ***p3mat;
@@ -1542,21 +1545,34 @@ void evsij(char fileres[], double ***eij
fprintf(ficreseij," %1d-%1d",i,j);
fprintf(ficreseij,"\n");
- k=1; /* For example stepm=6 months */
- hstepm=k*YEARM; /* (a) Every k years of age (in months), for example every k=2 years 24 m */
- hstepm=stepm; /* or (b) We decided to compute the life expectancy with the smallest unit */
+ if(estepm < stepm){
+ printf ("Problem %d lower than %d\n",estepm, stepm);
+ }
+ else hstepm=estepm;
+ /* We compute the life expectancy from trapezoids spaced every estepm months
+ * This is mainly to measure the difference between two models: for example
+ * if stepm=24 months pijx are given only every 2 years and by summing them
+ * we are calculating an estimate of the Life Expectancy assuming a linear
+ * progression inbetween and thus overestimating or underestimating according
+ * to the curvature of the survival function. If, for the same date, we
+ * estimate the model with stepm=1 month, we can keep estepm to 24 months
+ * to compare the new estimate of Life expectancy with the same linear
+ * hypothesis. A more precise result, taking into account a more precise
+ * curvature will be obtained if estepm is as small as stepm. */
+
+ /* For example we decided to compute the life expectancy with the smallest unit */
/* 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
- and note for a fixed period like k years */
+ 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
means that if the survival funtion is printed only each two years of age and if
you sum them up and add 1 year (area under the trapezoids) you won't get the same
results. So we changed our mind and took the option of the best precision.
*/
- hstepm=hstepm/stepm; /* Typically in stepm units, if k= 2 years, = 2/6 months = 4 */
+ hstepm=hstepm/stepm; /* Typically in stepm units, if stepm=6 & estepm=24 , = 24/6 months = 4 */
agelim=AGESUP;
for (age=bage; age<=fage; age ++){ /* If stepm=6 months */
@@ -1587,13 +1603,13 @@ void evsij(char fileres[], double ***eij
}
/************ Variance ******************/
-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)
+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)
{
/* Variance of health expectancies */
/* double **prevalim(double **prlim, int nlstate, double *xp, double age, double **oldm, double ** savm,double ftolpl);*/
double **newm;
double **dnewm,**doldm;
- int i, j, nhstepm, hstepm, h, nstepm, kk;
+ int i, j, nhstepm, hstepm, h, nstepm ;
int k, cptcode;
double *xp;
double **gp, **gm;
@@ -1613,9 +1629,11 @@ void varevsij(char fileres[], double ***
dnewm=matrix(1,nlstate,1,npar);
doldm=matrix(1,nlstate,1,nlstate);
- kk=1; /* For example stepm=6 months */
- hstepm=kk*YEARM; /* (a) Every k years of age (in months), for example every k=2 years 24 m */
- hstepm=stepm; /* or (b) We decided to compute the life expectancy with the smallest unit */
+ if(estepm < stepm){
+ printf ("Problem %d lower than %d\n",estepm, stepm);
+ }
+ else hstepm=estepm;
+ /* For example we decided to compute the life expectancy with the smallest unit */
/* 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.
@@ -1627,7 +1645,7 @@ void varevsij(char fileres[], double ***
you sum them up and add 1 year (area under the trapezoids) you won't get the same
results. So we changed our mind and took the option of the best precision.
*/
- hstepm=hstepm/stepm; /* Typically in stepm units, if k= 2 years, = 2/6 months = 4 */
+ hstepm=hstepm/stepm; /* Typically in stepm units, if stepm=6 & estepm=24 , = 24/6 months = 4 */
agelim = AGESUP;
for (age=bage; age<=fage; age ++){ /* If stepm=6 months */
nstepm=(int) rint((agelim-age)*YEARM/stepm); /* Typically 20 years = 20*12/6=40 */
@@ -1913,7 +1931,7 @@ void printinghtml(char fileres[], char t
int lastpass, int stepm, int weightopt, char model[],\
int imx,int jmin, int jmax, double jmeanint,char optionfile[], \
char optionfilehtm[],char rfileres[], char optionfilegnuplot[],\
- char version[], int popforecast ){
+ char version[], int popforecast, int estepm ){
int jj1, k1, i1, cpt;
FILE *fichtm;
/*char optionfilehtm[FILENAMELENGTH];*/
@@ -1936,13 +1954,13 @@ Interval (in months) between two waves:
- Observed prevalence in each state: p%s
\n
- Stationary prevalence in each state: pl%s
\n
- Transition probabilities: pij%s
\n
- - Life expectancies by age and initial health status: e%s
\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);
+ - Life expectancies by age and initial health status (estepm=%2d months): e%s
\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);
fprintf(fichtm,"\n
- Parameter file with estimated parameters and the covariance matrix: %s
\n
- - Variances of life expectancies by age and initial health status: v%s
\n
+ - Variances of life expectancies by age and initial health status (estepm=%d months): v%s
\n
- Health expectancies with their variances: t%s
\n
- - Standard deviation of stationary prevalences: vpl%s
\n",rfileres,rfileres,fileres,fileres,fileres,fileres,fileres,fileres);
+ - Standard deviation of stationary prevalences: vpl%s
\n",rfileres,rfileres, estepm, fileres,fileres,fileres,fileres,fileres,fileres);
if(popforecast==1) fprintf(fichtm,"\n
- Prevalences forecasting: f%s
\n
@@ -3021,17 +3039,17 @@ printf("Total number of individuals= %d,
fputs(line,ficparo);
}
ungetc(c,ficpar);
-
- fscanf(ficpar,"agemin=%lf agemax=%lf bage=%lf fage=%lf\n",&ageminpar,&agemaxpar, &bage, &fage);
-
+ estepm=0;
+ fscanf(ficpar,"agemin=%lf agemax=%lf bage=%lf fage=%lf estepm=%d\n",&ageminpar,&agemaxpar, &bage, &fage, &estepm);
+ if (estepm==0 || estepm < stepm) estepm=stepm;
if (fage <= 2) {
bage = ageminpar;
fage = agemaxpar;
}
fprintf(ficres,"# agemin agemax for life expectancy, bage fage (if mle==0 ie no data nor Max likelihood).\n");
- fprintf(ficres,"agemin=%.0f agemax=%.0f bage=%.0f fage=%.0f\n",ageminpar,agemaxpar,bage,fage);
- fprintf(ficparo,"agemin=%.0f agemax=%.0f bage=%.0f fage=%.0f\n",ageminpar,agemaxpar,bage,fage);
+ fprintf(ficres,"agemin=%.0f agemax=%.0f bage=%.0f fage=%.0f estepm=%d\n",ageminpar,agemaxpar,bage,fage, estepm);
+ fprintf(ficparo,"agemin=%.0f agemax=%.0f bage=%.0f fage=%.0f estepm=%d\n",ageminpar,agemaxpar,bage,fage, estepm);
while((c=getc(ficpar))=='#' && c!= EOF){
ungetc(c,ficpar);
@@ -3105,7 +3123,7 @@ while((c=getc(ficpar))=='#' && c!= EOF){
/*--------- index.htm --------*/
- printinghtml(fileres,title,datafile, firstpass, lastpass, stepm, weightopt,model,imx,jmin,jmax,jmean,optionfile,optionfilehtm,rfileres,optionfilegnuplot,version,popforecast);
+ printinghtml(fileres,title,datafile, firstpass, lastpass, stepm, weightopt,model,imx,jmin,jmax,jmean,optionfile,optionfilehtm,rfileres,optionfilegnuplot,version,popforecast,estepm);
/*--------------- Prevalence limit --------------*/
@@ -3265,10 +3283,10 @@ while((c=getc(ficpar))=='#' && c!= EOF){
eij=ma3x(1,nlstate,1,nlstate,(int) bage, (int) fage);
oldm=oldms;savm=savms;
- evsij(fileres, eij, p, nlstate, stepm, (int) bage, (int)fage, oldm, savm, k);
+ evsij(fileres, eij, p, nlstate, stepm, (int) bage, (int)fage, oldm, savm, k, estepm);
vareij=ma3x(1,nlstate,1,nlstate,(int) bage, (int) fage);
oldm=oldms;savm=savms;
- varevsij(fileres, vareij, matcov, p, delti, nlstate, stepm, (int) bage, (int) fage, oldm, savm, prlim, ftolpl,k);
+ varevsij(fileres, vareij, matcov, p, delti, nlstate, stepm, (int) bage, (int) fage, oldm, savm, prlim, ftolpl,k, estepm);