} \r
\r
/************ Frequencies ********************/\r
-void freqsummary(char fileres[], int agemin, int agemax, int **s, double **agev, int nlstate, int imx, int *Tvar, int **nbcode, int *ncodemax, int fprev1,int lprev1,double **mint,double **anint)\r
+void freqsummary(char fileres[], int agemin, int agemax, int **s, double **agev, int nlstate, int imx, int *Tvar, int **nbcode, int *ncodemax, int fprev1,int lprev1,double **mint,double **anint, int boolprev, double dateprev1,double dateprev2)\r
{ /* Some frequencies */\r
\r
- int i, m, jk, k1, k2,i1, j1, bool, z1,z2,j;\r
+ int i, m, jk, k1,i1, j1, bool, z1,z2,j;\r
double ***freq; /* Frequencies */\r
double *pp;\r
- double pos;\r
+ double pos, k2;\r
FILE *ficresp;\r
char fileresp[FILENAMELENGTH];\r
\r
if (covar[Tvaraff[z1]][i]!= nbcode[Tvaraff[z1]][codtab[j1][z1]]) \r
bool=0;\r
}\r
- if (bool==1) {\r
- for(m=fprev1; m<=lprev1; m++){\r
+ if (bool==1) {\r
+ if (boolprev==1){\r
+ for(m=fprev1; m<=lprev1; m++){\r
+ if(agev[m][i]==0) agev[m][i]=agemax+1;\r
+ if(agev[m][i]==1) agev[m][i]=agemax+2;\r
+ freq[s[m][i]][s[m+1][i]][(int)agev[m][i]] += weight[i];\r
+ freq[s[m][i]][s[m+1][i]][(int) agemax+3] += weight[i];\r
+ }\r
+ }\r
+ else {\r
+ for(m=firstpass; m<=lastpass; m++){\r
k2=anint[m][i]+(mint[m][i]/12.);\r
- if ((k2>=1984) && (k2<=1988.5)) {\r
+ if ((k2>=dateprev1) && (k2<=dateprev2)) {\r
if(agev[m][i]==0) agev[m][i]=agemax+1;\r
if(agev[m][i]==1) agev[m][i]=agemax+2;\r
freq[s[m][i]][s[m+1][i]][(int)agev[m][i]] += weight[i];\r
freq[s[m][i]][s[m+1][i]][(int) agemax+3] += weight[i];\r
}\r
}\r
+ }\r
}\r
}\r
if (cptcovn>0) {\r
} /* End of Freq */\r
\r
/************ Prevalence ********************/\r
-void prevalence(int agemin, int agemax, int **s, double **agev, int nlstate, int imx, int *Tvar, int **nbcode, int *ncodemax, int fprev1,int lprev1)\r
+void prevalence(int agemin, int agemax, int **s, double **agev, int nlstate, int imx, int *Tvar, int **nbcode, int *ncodemax, int fprev1,int lprev1, double **mint,double **anint,int boolprev, double dateprev1, double dateprev2)\r
{ /* Some frequencies */\r
\r
int i, m, jk, k1, i1, j1, bool, z1,z2,j;\r
double ***freq; /* Frequencies */\r
double *pp;\r
- double pos;\r
+ double pos, k2;\r
\r
pp=vector(1,nlstate);\r
probs= ma3x(1,130 ,1,8, 1,8);\r
bool=0;\r
}\r
if (bool==1) {\r
- for(m=fprev1; m<=lprev1; m++){\r
- if(agev[m][i]==0) agev[m][i]=agemax+1;\r
- if(agev[m][i]==1) agev[m][i]=agemax+2;\r
- freq[s[m][i]][s[m+1][i]][(int)agev[m][i]] += weight[i];\r
- freq[s[m][i]][s[m+1][i]][(int) agemax+3] += weight[i];\r
+ if (boolprev==1){\r
+ for(m=fprev1; m<=lprev1; m++){\r
+ if(agev[m][i]==0) agev[m][i]=agemax+1;\r
+ if(agev[m][i]==1) agev[m][i]=agemax+2;\r
+ freq[s[m][i]][s[m+1][i]][(int)agev[m][i]] += weight[i];\r
+ freq[s[m][i]][s[m+1][i]][(int) agemax+3] += weight[i];\r
+ }\r
+ }\r
+ else {\r
+ for(m=firstpass; m<=lastpass; m++){\r
+ k2=anint[m][i]+(mint[m][i]/12.);\r
+ if ((k2>=dateprev1) && (k2<=dateprev2)) {\r
+ if(agev[m][i]==0) agev[m][i]=agemax+1;\r
+ if(agev[m][i]==1) agev[m][i]=agemax+2;\r
+ freq[s[m][i]][s[m+1][i]][(int)agev[m][i]] += weight[i];\r
+ freq[s[m][i]][s[m+1][i]][(int) agemax+3] += weight[i];\r
+ }\r
+ }\r
}\r
}\r
}\r
- for(i=(int)agemin; i <= (int)agemax+3; i++){ \r
- for(jk=1; jk <=nlstate ; jk++){\r
- for(m=-1, pp[jk]=0; m <=nlstate+ndeath ; m++)\r
- pp[jk] += freq[jk][m][i]; \r
- }\r
- for(jk=1; jk <=nlstate ; jk++){\r
- for(m=-1, pos=0; m <=0 ; m++)\r
+ for(i=(int)agemin; i <= (int)agemax+3; i++){ \r
+ for(jk=1; jk <=nlstate ; jk++){\r
+ for(m=-1, pp[jk]=0; m <=nlstate+ndeath ; m++)\r
+ pp[jk] += freq[jk][m][i]; \r
+ }\r
+ for(jk=1; jk <=nlstate ; jk++){\r
+ for(m=-1, pos=0; m <=0 ; m++)\r
pos += freq[jk][m][i];\r
}\r
\r
}\r
}\r
\r
- }\r
+ }\r
}\r
}\r
\r
int jnais,jdc,jint4,jint1,jint2,jint3,**outcome,**adl,*tab; \r
int mobilav=0, fprev, lprev ,fprevfore=1, lprevfore=1,nforecast,popforecast=0;\r
int hstepm, nhstepm;\r
- int *popage;\r
+ int *popage,boolprev=0;/*boolprev=0 if date and zero if wave*/\r
\r
double bage, fage, age, agelim, agebase;\r
double ftolpl=FTOL;\r
double *epj, vepp;\r
double kk1, kk2;\r
double *popeffectif,*popcount;\r
+ double dateprev1, dateprev2;\r
\r
char version[80]="Imach version 64b, May 2001, INED-EUROREVES ";\r
char *alph[]={"a","a","b","c","d","e"}, str[4];\r
#include <sys/time.h>\r
#include <time.h>\r
char stra[80], strb[80], strc[80], strd[80],stre[80],modelsav[80];\r
+ char strfprev[10], strlprev[10];\r
+ char strfprevfore[10], strlprevfore[10];\r
/* long total_usecs;\r
struct timeval start_time, end_time;\r
\r
}\r
ungetc(c,ficpar);\r
\r
- fscanf(ficpar,"fprevalence=%d lprevalence=%d pop_based=%d\n",&fprev,&lprev,&popbased);\r
- fprintf(ficparo,"fprevalence=%d lprevalence=%d pop_based=%d\n",fprev,lprev,popbased);\r
+ fscanf(ficpar,"fprevalence=%s lprevalence=%s pop_based=%d\n",strfprev,strlprev,&popbased);\r
+ fprintf(ficparo,"fprevalence=%s lprevalence=%s pop_based=%d\n",strfprev,strlprev,popbased);\r
\r
+ /* printf("%s %s",strfprev,strlprev);\r
+ exit(0);*/\r
while((c=getc(ficpar))=='#' && c!= EOF){\r
ungetc(c,ficpar);\r
fgets(line, MAXLINE, ficpar);\r
}\r
ungetc(c,ficpar);\r
\r
- fscanf(ficpar,"fprevalence=%d lprevalence=%d nforecast=%d mob_average=%d\n",&fprevfore,&lprevfore,&nforecast,&mobilav);\r
- fprintf(ficparo,"fprevalence=%d lprevalence=%d nforecast=%d mob_average=%d\n",fprevfore,lprevfore,nforecast,mobilav);\r
+ fscanf(ficpar,"fprevalence=%s lprevalence=%s nforecast=%d mob_average=%d\n",strfprevfore,strlprevfore,&nforecast,&mobilav);\r
+ fprintf(ficparo,"fprevalence=%s lprevalence=%s nforecast=%d mob_average=%d\n",strfprevfore,strlprevfore,nforecast,mobilav);\r
\r
\r
while((c=getc(ficpar))=='#' && c!= EOF){\r
\r
/* Calculates basic frequencies. Computes observed prevalence at single age\r
and prints on file fileres'p'. */\r
- freqsummary(fileres, agemin, agemax, s, agev, nlstate, imx,Tvar,nbcode, ncodemax, fprev, lprev,mint,anint);\r
- \r
- free_matrix(mint,1,maxwav,1,n);\r
- free_matrix(anint,1,maxwav,1,n);\r
+\r
+ if ((nbocc(strfprev,'/')==1) && (nbocc(strlprev,'/')==1)){\r
+ boolprev=0;\r
+ cutv(stra,strb,strfprev,'/');\r
+ dateprev1=(double)(atoi(strb)+atoi(stra)/12.);\r
+ cutv(stra,strb,strlprev,'/');\r
+ dateprev2=(double)(atoi(strb)+atoi(stra)/12.);\r
+ }\r
+ \r
+ else if ((nbocc(strfprev,'/')==0) &&(nbocc(strlprev,'/')==0)){\r
+ boolprev=1;\r
+ fprev=atoi(strfprev); lprev=atoi(strlprev);\r
+ }\r
+ else {\r
+ printf("Error in statement lprevalence or fprevalence\n");\r
+ goto end;\r
+ }\r
+ \r
+ freqsummary(fileres, agemin, agemax, s, agev, nlstate, imx,Tvar,nbcode, ncodemax, fprev, lprev,mint,anint,boolprev,dateprev1,dateprev2); \r
\r
pmmij= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */\r
oldms= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */\r
\r
/*--------- results files --------------*/\r
fprintf(ficres,"title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\nftol=%e stepm=%d ncov=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d\nmodel=%s\n", title, datafile, lastobs, firstpass,lastpass,ftol, stepm, ncov, nlstate, ndeath, maxwav, mle,weightopt,model);\r
- fprintf(ficres,"fprevalence=%d lprevalence=%d pop_based=%d\n",fprev,lprev,popbased); \r
- fprintf(ficres,"fprevalence=%d lprevalence=%d nforecast=%d mob_average=%d\n",fprevfore,lprevfore,nforecast,mobilav);\r
+ fprintf(ficres,"fprevalence=%s lprevalence=%s pop_based=%d\n",strfprev,strlprev,popbased); \r
+ fprintf(ficres,"fprevalence=%s lprevalence=%s nforecast=%d mob_average=%d\n",strfprevfore,strlprevfore,nforecast,mobilav);\r
\r
jk=1;\r
fprintf(ficres,"# Parameters\n");\r
fprintf(ficres,"\n");\r
}\r
}\r
- }\r
+ }\r
\r
k=1;\r
fprintf(ficres,"# Covariance\n");\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 forecasting: <a href=\"f%s\">f%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
printf("Computing forecasting: result on file '%s' \n", fileresf);\r
\r
- prevalence(agemin, agemax, s, agev, nlstate, imx,Tvar,nbcode, ncodemax, fprevfore, lprevfore);\r
+ if ((nbocc(strfprevfore,'/')==1) && (nbocc(strlprevfore,'/')==1)){\r
+ boolprev=0;\r
+ cutv(stra,strb,strfprevfore,'/');\r
+ dateprev1=(double)(atoi(strb)+atoi(stra)/12.);\r
+ cutv(stra,strb,strlprevfore,'/');\r
+ dateprev2=(double)(atoi(strb)+atoi(stra)/12.);\r
+ }\r
+ \r
+ else if ((nbocc(strfprevfore,'/')==0) &&(nbocc(strlprevfore,'/')==0)){\r
+ boolprev=1;\r
+ fprev=atoi(strfprevfore); lprev=atoi(strlprevfore);\r
+ }\r
+ else {\r
+ printf("Error in statement lprevalence or fprevalence\n");\r
+ goto end;\r
+ }\r
\r
- free_matrix(agev,1,maxwav,1,imx);\r
+ prevalence(agemin, agemax, s, agev, nlstate, imx,Tvar,nbcode, ncodemax, fprevfore, lprevfore,mint,anint,boolprev,dateprev1,dateprev2);\r
+ \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
/* Mobile average */\r
\r
if (cptcoveff==0) ncodemax[cptcoveff]=1;\r