--- imach096d/src/imach.c 2002/02/22 18:08:30 1.23
+++ imach096d/src/imach.c 2002/03/10 13:43:02 1.31
@@ -1,5 +1,5 @@
-/* $Id: imach.c,v 1.23 2002/02/22 18:08:30 lievre Exp $
- Interpolate Markov Chain
+/* $Id: imach.c,v 1.31 2002/03/10 13:43:02 brouard Exp $
+ Interpolated Markov Chain
Short summary of the programme:
@@ -94,8 +94,8 @@ int **dh; /* dh[mi][i] is number of step
double jmean; /* Mean space between 2 waves */
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 *fic,*ficpar, *ficparo,*ficres, *ficrespl, *ficrespij, *ficrest,*ficresf,*ficrespop;
+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;
@@ -1185,7 +1185,7 @@ void freqsummary(char fileres[], int ag
double pos, k2, dateintsum=0,k2cpt=0;
FILE *ficresp;
char fileresp[FILENAMELENGTH];
-
+
pp=vector(1,nlstate);
probs= ma3x(1,AGESUP,1,NCOVMAX, 1,NCOVMAX);
strcpy(fileresp,"p");
@@ -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]]);
@@ -1304,7 +1307,7 @@ void freqsummary(char fileres[], int ag
}
/************ Prevalence ********************/
-void prevalence(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 calagedate)
+void prevalence(int agemin, float agemax, int **s, double **agev, int nlstate, int imx, int *Tvar, int **nbcode, int *ncodemax,double **mint,double **anint, double dateprev1,double dateprev2, double calagedate)
{ /* Some frequencies */
int i, m, jk, k1, i1, j1, bool, z1,z2,j;
@@ -1329,14 +1332,14 @@ void prevalence(int agemin, int agemax,
for (jk=-1; jk<=nlstate+ndeath; jk++)
for(m=agemin; m <= agemax+3; m++)
freq[i][jk][m]=0;
-
+
for (i=1; i<=imx; i++) {
bool=1;
if (cptcovn>0) {
for (z1=1; z1<=cptcoveff; z1++)
if (covar[Tvaraff[z1]][i]!= nbcode[Tvaraff[z1]][codtab[j1][z1]])
bool=0;
- }
+ }
if (bool==1) {
for(m=firstpass; m<=lastpass; m++){
k2=anint[m][i]+(mint[m][i]/12.);
@@ -1344,12 +1347,11 @@ void prevalence(int agemin, int agemax,
if(agev[m][i]==0) agev[m][i]=agemax+1;
if(agev[m][i]==1) agev[m][i]=agemax+2;
freq[s[m][i]][s[m+1][i]][(int)(agev[m][i]+1-((int)calagedate %12)/12.)] += weight[i];
- freq[s[m][i]][s[m+1][i]][(int)(agemax+3+1)] += weight[i];
+ /* freq[s[m][i]][s[m+1][i]][(int)(agemax+3+1)] += weight[i]; */
}
}
}
}
-
for(i=(int)agemin; i <= (int)agemax+3; i++){
for(jk=1; jk <=nlstate ; jk++){
for(m=-1, pp[jk]=0; m <=nlstate+ndeath ; m++)
@@ -1441,7 +1443,7 @@ void concatwav(int wav[], int **dh, int
if (j >= jmax) jmax=j;
if (j <= jmin) jmin=j;
sum=sum+j;
- /* if (j<10) printf("j=%d num=%d ",j,i); */
+ /*if (j<0) printf("j=%d num=%d \n",j,i); */
}
}
else{
@@ -1449,7 +1451,7 @@ void concatwav(int wav[], int **dh, int
k=k+1;
if (j >= jmax) jmax=j;
else if (j <= jmin)jmin=j;
- /* if (j<10) printf("j=%d jmin=%d num=%d ",j,jmin,i); */
+ /* if (j<10) printf("j=%d jmin=%d num=%d ",j,jmin,i); */
sum=sum+j;
}
jk= j/stepm;
@@ -1525,7 +1527,7 @@ void tricode(int *Tvar, int **nbcode, in
void evsij(char fileres[], double ***eij, double x[], int nlstate, int stepm, int bage, int fage, double **oldm, double **savm, int ij)
{
/* Health expectancies */
- int i, j, nhstepm, hstepm, h;
+ int i, j, nhstepm, hstepm, h, nstepm, k;
double age, agelim,hf;
double ***p3mat;
@@ -1536,34 +1538,44 @@ void evsij(char fileres[], double ***eij
fprintf(ficreseij," %1d-%1d",i,j);
fprintf(ficreseij,"\n");
- hstepm=1*YEARM; /* Every j years of age (in month) */
- hstepm=hstepm/stepm; /* Typically in stepm units, if j= 2 years, = 2/6 months = 4 */
+ 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=1; /* or (b) 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 */
+ /* We decided (b) to get a life expectancy respecting the most precise curvature of the
+ survival function given par 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 */
agelim=AGESUP;
for (age=bage; age<=fage; age ++){ /* If stepm=6 months */
/* nhstepm age range expressed in number of stepm */
- nhstepm=(int) rint((agelim-age)*YEARM/stepm);
- /* Typically if 20 years = 20*12/6=40 stepm */
+ nstepm=(int) rint((agelim-age)*YEARM/stepm);
+ /* Typically if 20 years nstepm = 20*12/6=40 stepm */
if (stepm >= YEARM) hstepm=1;
- nhstepm = nhstepm/hstepm;/* Expressed in hstepm, typically 40/4=10 */
+ nhstepm = nstepm/hstepm;/* Expressed in hstepm, typically nhstepm=40/4=10 */
p3mat=ma3x(1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);
/* Computed by stepm unit matrices, product of hstepm matrices, stored
in an array of nhstepm length: nhstepm=10, hstepm=4, stepm=6 months */
hpxij(p3mat,nhstepm,age,hstepm,x,nlstate,stepm,oldm, savm, ij);
-
-
+ hf=hstepm/YEARM; /* Duration of hstepm expressed in year unit. */
for(i=1; i<=nlstate;i++)
for(j=1; j<=nlstate;j++)
- for (h=0, eij[i][j][(int)age]=0; h<=nhstepm; h++){
- eij[i][j][(int)age] +=p3mat[i][j][h];
+ for (h=0, eij[i][j][(int)age]=0; h<=nhstepm-1; h++){
+ eij[i][j][(int)age] += (p3mat[i][j][h]+p3mat[i][j][h+1])/2.0*hf;
+ /* if((int)age==70)printf("i=%2d,j=%2d,h=%2d,age=%3d,%9.4f,%9.4f,%9.4f\n",i,j,h,(int)age,p3mat[i][j][h],hf,eij[i][j][(int)age]);*/
}
-
- hf=1;
- if (stepm >= YEARM) hf=stepm/YEARM;
- fprintf(ficreseij,"%.0f",age );
+ fprintf(ficreseij,"%3.0f",age );
for(i=1; i<=nlstate;i++)
for(j=1; j<=nlstate;j++){
- fprintf(ficreseij," %.4f", hf*eij[i][j][(int)age]);
+ fprintf(ficreseij," %9.4f", eij[i][j][(int)age]);
}
fprintf(ficreseij,"\n");
free_ma3x(p3mat,1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);
@@ -1620,7 +1632,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 +1644,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 +1696,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,144 +1888,663 @@ if (i== 4) fprintf(ficresprob,"%.3e %.3e
}
free_vector(xp,1,npar);
fclose(ficresprob);
- exit(0);
-}
-
-/***********************************************/
-/**************** Main Program *****************/
-/***********************************************/
-
-int main(int argc, char *argv[])
-{
-
- int i,j, k, n=MAXN,iter,m,size,cptcode, cptcod;
- double agedeb, agefin,hf;
- double agemin=1.e20, agemax=-1.e20;
-
- double fret;
- double **xi,tmp,delta;
-
- double dum; /* Dummy variable */
- double ***p3mat;
- int *indx;
- char line[MAXLINE], linepar[MAXLINE];
- char title[MAXLINE];
- char optionfile[FILENAMELENGTH], datafile[FILENAMELENGTH], filerespl[FILENAMELENGTH], optionfilehtm[FILENAMELENGTH];
- char optionfilext[10], optionfilefiname[FILENAMELENGTH], optionfilegnuplot[FILENAMELENGTH], plotcmd[FILENAMELENGTH];
-
- char fileres[FILENAMELENGTH], filerespij[FILENAMELENGTH], filereso[FILENAMELENGTH], fileresf[FILENAMELENGTH];
- char filerest[FILENAMELENGTH];
- char fileregp[FILENAMELENGTH];
- char popfile[FILENAMELENGTH];
- char path[80],pathc[80],pathcd[80],pathtot[80],model[20];
- int firstobs=1, lastobs=10;
- int sdeb, sfin; /* Status at beginning and end */
- int c, h , cpt,l;
- int ju,jl, mi;
- int i1,j1, k1,k2,k3,jk,aa,bb, stepsize, ij;
- int jnais,jdc,jint4,jint1,jint2,jint3,**outcome,**adl,*tab;
- int mobilav=0,popforecast=0;
- int hstepm, nhstepm;
- int *popage;/*boolprev=0 if date and zero if wave*/
- double jprev1, mprev1,anprev1,jprev2, mprev2,anprev2;
+}
- double bage, fage, age, agelim, agebase;
- double ftolpl=FTOL;
- double **prlim;
- double *severity;
- double ***param; /* Matrix of parameters */
- double *p;
- double **matcov; /* Matrix of covariance */
- double ***delti3; /* Scale */
- double *delti; /* Scale */
- double ***eij, ***vareij;
- double **varpl; /* Variances of prevalence limits by age */
- double *epj, vepp;
- double kk1, kk2;
- double *popeffectif,*popcount;
- double dateprev1, dateprev2,jproj1,mproj1,anproj1,jproj2,mproj2,anproj2,jprojmean,mprojmean,anprojmean, calagedate;
- double yp,yp1,yp2;
+/******************* 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[],char rfileres[] ){
+ int jj1, k1, i1, cpt;
+ FILE *fichtm;
+ /*char optionfilehtm[FILENAMELENGTH];*/
- char version[80]="Imach version 0.7, February 2002, INED-EUROREVES ";
- char *alph[]={"a","a","b","c","d","e"}, str[4];
+ 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.71a
+Title=%s
Datafile=%s Firstpass=%d Lastpass=%d Stepm=%d Weight=%d Model=%s
- char z[1]="c", occ;
-#include
-#include
- char stra[80], strb[80], strc[80], strd[80],stre[80],modelsav[80];
+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 forecasting: f%s
+ - Population forecasting (if popforecast=1): pop%s
+
",title,datafile,firstpass,lastpass,stepm, weightopt,model,imx,jmin,jmax,jmean,fileres,fileres,rfileres,rfileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres);
- /* long total_usecs;
- struct timeval start_time, end_time;
-
- gettimeofday(&start_time, (struct timezone*)0); */ /* at first time */
+fprintf(fichtm," - Graphs
");
+ m=cptcoveff;
+ if (cptcovn < 1) {m=1;ncodemax[1]=1;}
- printf("\n%s",version);
- if(argc <=1){
- printf("\nEnter the parameter file name: ");
- scanf("%s",pathtot);
- }
- else{
- strcpy(pathtot,argv[1]);
- }
- /*if(getcwd(pathcd, 80)!= NULL)printf ("Error pathcd\n");*/
- /*cygwin_split_path(pathtot,path,optionfile);
- printf("pathtot=%s, path=%s, optionfile=%s\n",pathtot,path,optionfile);*/
- /* cutv(path,optionfile,pathtot,'\\');*/
+ 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);
+}
- split(pathtot,path,optionfile,optionfilext,optionfilefiname);
- printf("pathtot=%s, path=%s, optionfile=%s optionfilext=%s optionfilefiname=%s\n",pathtot,path,optionfile,optionfilext,optionfilefiname);
- chdir(path);
- replace(pathc,path);
+/******************* Gnuplot file **************/
+void printinggnuplot(char fileres[],char optionfilefiname[],char optionfile[],char optionfilegnuplot[], double agemin, double agemaxpar, double fage , char pathc[], double p[]){
-/*-------- arguments in the command line --------*/
+ int m,cpt,k1,i,k,j,jk,k2,k3,ij,l;
- strcpy(fileres,"r");
- strcat(fileres, optionfilefiname);
- strcat(fileres,".txt"); /* Other files have txt extension */
+ strcpy(optionfilegnuplot,optionfilefiname);
+ strcat(optionfilegnuplot,".plt");
+ if((ficgp=fopen(optionfilegnuplot,"w"))==NULL) {
+ printf("Problem with file %s",optionfilegnuplot);
+ }
- /*---------arguments file --------*/
+#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 ++) {
- if((ficpar=fopen(optionfile,"r"))==NULL) {
- printf("Problem with optionfile %s\n",optionfile);
- goto end;
- }
+#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
- strcpy(filereso,"o");
- strcat(filereso,fileres);
- if((ficparo=fopen(filereso,"w"))==NULL) {
- printf("Problem with Output resultfile: %s\n", filereso);goto end;
+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*/
- /* Reads comments: lines beginning with '#' */
- while((c=getc(ficpar))=='#' && c!= EOF){
- ungetc(c,ficpar);
- fgets(line, MAXLINE, ficpar);
- puts(line);
- fputs(line,ficparo);
+ 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);
}
- ungetc(c,ficpar);
+
+ /*3eme*/
- fscanf(ficpar,"title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\nftol=%lf 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);
- printf("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);
- fprintf(ficparo,"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);
-while((c=getc(ficpar))=='#' && c!= EOF){
- ungetc(c,ficpar);
- fgets(line, MAXLINE, ficpar);
- puts(line);
- fputs(line,ficparo);
- }
- ungetc(c,ficpar);
-
-
- covar=matrix(0,NCOVMAX,1,n);
- cptcovn=0;
- if (strlen(model)>1) cptcovn=nbocc(model,'+')+1;
+ 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=(agemin-((int)calagedate %12)/12.); agedeb--){
+ nhstepm=(int) rint((agelim-agedeb)*YEARM/stepm);
+ nhstepm = nhstepm/hstepm;
+
+ p3mat=ma3x(1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);
+ oldm=oldms;savm=savms;
+ hpxij(p3mat,nhstepm,agedeb,hstepm,p,nlstate,stepm,oldm,savm, k);
+
+ for (h=0; h<=nhstepm; h++){
+ if (h==(int) (calagedate+YEARM*cpt)) {
+ fprintf(ficresf,"\n %.f ",agedeb+h*hstepm/YEARM*stepm);
+ }
+ for(j=1; j<=nlstate+ndeath;j++) {
+ kk1=0.;kk2=0;
+ for(i=1; i<=nlstate;i++) {
+ if (mobilav==1)
+ kk1=kk1+p3mat[i][j][h]*mobaverage[(int)agedeb+1][i][cptcod];
+ else {
+ kk1=kk1+p3mat[i][j][h]*probs[(int)(agedeb+1)][i][cptcod];
+ }
+
+ }
+ if (h==(int)(calagedate+12*cpt)){
+ fprintf(ficresf," %.3f", kk1);
+
+ }
+ }
+ }
+ free_ma3x(p3mat,1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);
+ }
+ }
+ }
+ }
+
+ if (mobilav==1) free_ma3x(mobaverage,1, AGESUP,1,NCOVMAX, 1,NCOVMAX);
+
+ fclose(ficresf);
+}
+/************** Forecasting ******************/
+populforecast(char fileres[], double anpyram,double mpyram,double jpyram,double agemin, double agemax,double dateprev1, double dateprev2, int mobilav, double agedeb, double fage, int popforecast, char popfile[], double anpyram1,double p[], int i2){
+
+ int cpt, stepsize, hstepm, nhstepm, j,k,c, cptcod, i,h;
+ int *popage;
+ double calagedate, agelim, kk1, kk2, yp,yp1,yp2,jprojmean,mprojmean,anprojmean;
+ double *popeffectif,*popcount;
+ double ***p3mat,***tabpop,***tabpopprev;
+ char filerespop[FILENAMELENGTH];
+
+ tabpop= ma3x(1, AGESUP,1,NCOVMAX, 1,NCOVMAX);
+ tabpopprev= ma3x(1, AGESUP,1,NCOVMAX, 1,NCOVMAX);
+ agelim=AGESUP;
+ calagedate=(anpyram+mpyram/12.+jpyram/365.-dateintmean)*YEARM;
+
+ prevalence(agemin, agemax, s, agev, nlstate, imx,Tvar,nbcode, ncodemax,mint,anint,dateprev1,dateprev2, calagedate);
+
+
+ strcpy(filerespop,"pop");
+ strcat(filerespop,fileres);
+ if((ficrespop=fopen(filerespop,"w"))==NULL) {
+ printf("Problem with forecast resultfile: %s\n", filerespop);
+ }
+ printf("Computing forecasting: result on file '%s' \n", filerespop);
+
+ if (cptcoveff==0) ncodemax[cptcoveff]=1;
+
+ if (mobilav==1) {
+ mobaverage= ma3x(1, AGESUP,1,NCOVMAX, 1,NCOVMAX);
+ movingaverage(agedeb, fage, agemin, mobaverage);
+ }
+
+ stepsize=(int) (stepm+YEARM-1)/YEARM;
+ if (stepm<=12) stepsize=1;
+
+ agelim=AGESUP;
+
+ hstepm=1;
+ hstepm=hstepm/stepm;
+
+ if (popforecast==1) {
+ if((ficpop=fopen(popfile,"r"))==NULL) {
+ printf("Problem with population file : %s\n",popfile);exit(0);
+ }
+ popage=ivector(0,AGESUP);
+ popeffectif=vector(0,AGESUP);
+ popcount=vector(0,AGESUP);
+
+ i=1;
+ while ((c=fscanf(ficpop,"%d %lf\n",&popage[i],&popcount[i])) != EOF) i=i+1;
+
+ imx=i;
+ for (i=1; i=(agemin-((int)calagedate %12)/12.); agedeb--){
+ nhstepm=(int) rint((agelim-agedeb)*YEARM/stepm);
+ nhstepm = nhstepm/hstepm;
+
+ p3mat=ma3x(1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);
+ oldm=oldms;savm=savms;
+ hpxij(p3mat,nhstepm,agedeb,hstepm,p,nlstate,stepm,oldm,savm, k);
+
+ for (h=0; h<=nhstepm; h++){
+ if (h==(int) (calagedate+YEARM*cpt)) {
+ fprintf(ficrespop,"\n %3.f ",agedeb+h*hstepm/YEARM*stepm);
+ }
+ for(j=1; j<=nlstate+ndeath;j++) {
+ kk1=0.;kk2=0;
+ for(i=1; i<=nlstate;i++) {
+ if (mobilav==1)
+ kk1=kk1+p3mat[i][j][h]*mobaverage[(int)agedeb+1][i][cptcod];
+ else {
+ kk1=kk1+p3mat[i][j][h]*probs[(int)(agedeb+1)][i][cptcod];
+ }
+ }
+ if (h==(int)(calagedate+12*cpt)){
+ tabpop[(int)(agedeb)][j][cptcod]=kk1;
+ /*fprintf(ficrespop," %.3f", kk1);
+ if (popforecast==1) fprintf(ficrespop," [%.f]", kk1*popeffectif[(int)agedeb+1]);*/
+ }
+ }
+ for(i=1; i<=nlstate;i++){
+ kk1=0.;
+ for(j=1; j<=nlstate;j++){
+ kk1= kk1+tabpop[(int)(agedeb)][j][cptcod];
+ }
+ tabpopprev[(int)(agedeb)][i][cptcod]=tabpop[(int)(agedeb)][i][cptcod]/kk1*popeffectif[(int)(agedeb+(calagedate+12*cpt)*hstepm/YEARM*stepm-1)];
+ }
+
+ if (h==(int)(calagedate+12*cpt)) for(j=1; j<=nlstate;j++)
+ fprintf(ficrespop," %15.2f",tabpopprev[(int)(agedeb+1)][j][cptcod]);
+ }
+ free_ma3x(p3mat,1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);
+ }
+ }
+
+ /******/
+
+ for (cpt=1; cpt<=(anpyram1-anpyram);cpt++) {
+ fprintf(ficrespop,"\n\n# Forecasting at date %.lf/%.lf/%.lf ",jpyram,mpyram,anpyram+cpt);
+ for (agedeb=(fage-((int)calagedate %12/12.)); agedeb>=(agemin-((int)calagedate %12)/12.); agedeb--){
+ nhstepm=(int) rint((agelim-agedeb)*YEARM/stepm);
+ nhstepm = nhstepm/hstepm;
+
+ p3mat=ma3x(1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);
+ oldm=oldms;savm=savms;
+ hpxij(p3mat,nhstepm,agedeb,hstepm,p,nlstate,stepm,oldm,savm, k);
+ for (h=0; h<=nhstepm; h++){
+ if (h==(int) (calagedate+YEARM*cpt)) {
+ fprintf(ficresf,"\n %3.f ",agedeb+h*hstepm/YEARM*stepm);
+ }
+ for(j=1; j<=nlstate+ndeath;j++) {
+ kk1=0.;kk2=0;
+ for(i=1; i<=nlstate;i++) {
+ kk1=kk1+p3mat[i][j][h]*tabpopprev[(int)agedeb+1][i][cptcod];
+ }
+ if (h==(int)(calagedate+12*cpt)) fprintf(ficresf," %15.2f", kk1);
+ }
+ }
+ free_ma3x(p3mat,1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);
+ }
+ }
+ }
+ }
+
+ if (mobilav==1) free_ma3x(mobaverage,1, AGESUP,1,NCOVMAX, 1,NCOVMAX);
+
+ if (popforecast==1) {
+ free_ivector(popage,0,AGESUP);
+ free_vector(popeffectif,0,AGESUP);
+ free_vector(popcount,0,AGESUP);
+ }
+ free_ma3x(tabpop,1, AGESUP,1,NCOVMAX, 1,NCOVMAX);
+ free_ma3x(tabpopprev,1, AGESUP,1,NCOVMAX, 1,NCOVMAX);
+ fclose(ficrespop);
+}
+
+/***********************************************/
+/**************** Main Program *****************/
+/***********************************************/
+
+int main(int argc, char *argv[])
+{
+
+ int i,j, k, n=MAXN,iter,m,size,cptcode, cptcod;
+ double agedeb, agefin,hf;
+ double agemin=1.e20, agemaxpar=-1.e20, agemax=-1.e20;
+
+ double fret;
+ double **xi,tmp,delta;
+
+ double dum; /* Dummy variable */
+ double ***p3mat;
+ int *indx;
+ char line[MAXLINE], linepar[MAXLINE];
+ char title[MAXLINE];
+ char optionfile[FILENAMELENGTH], datafile[FILENAMELENGTH], filerespl[FILENAMELENGTH];
+ char optionfilext[10], optionfilefiname[FILENAMELENGTH], optionfilehtm[FILENAMELENGTH], optionfilegnuplot[FILENAMELENGTH], plotcmd[FILENAMELENGTH];
+
+ char fileres[FILENAMELENGTH], filerespij[FILENAMELENGTH], filereso[FILENAMELENGTH], rfileres[FILENAMELENGTH];
+
+ char filerest[FILENAMELENGTH];
+ char fileregp[FILENAMELENGTH];
+ char popfile[FILENAMELENGTH];
+ char path[80],pathc[80],pathcd[80],pathtot[80],model[20];
+ int firstobs=1, lastobs=10;
+ int sdeb, sfin; /* Status at beginning and end */
+ int c, h , cpt,l;
+ int ju,jl, mi;
+ int i1,j1, k1,k2,k3,jk,aa,bb, stepsize, ij;
+ int jnais,jdc,jint4,jint1,jint2,jint3,**outcome,**adl,*tab;
+ int mobilav=0,popforecast=0;
+ int hstepm, nhstepm;
+ double jprev1, mprev1,anprev1,jprev2, mprev2,anprev2,jpyram, mpyram,anpyram,jpyram1, mpyram1,anpyram1;
+
+ double bage, fage, age, agelim, agebase;
+ double ftolpl=FTOL;
+ double **prlim;
+ double *severity;
+ double ***param; /* Matrix of parameters */
+ double *p;
+ double **matcov; /* Matrix of covariance */
+ double ***delti3; /* Scale */
+ double *delti; /* Scale */
+ double ***eij, ***vareij;
+ double **varpl; /* Variances of prevalence limits by age */
+ double *epj, vepp;
+ double kk1, kk2;
+ double dateprev1, dateprev2,jproj1,mproj1,anproj1,jproj2,mproj2,anproj2;
+
+
+ char version[80]="Imach version 0.71a, March 2002, INED-EUROREVES ";
+ char *alph[]={"a","a","b","c","d","e"}, str[4];
+
+
+ char z[1]="c", occ;
+#include
+#include
+ char stra[80], strb[80], strc[80], strd[80],stre[80],modelsav[80];
+
+ /* long total_usecs;
+ struct timeval start_time, end_time;
+
+ gettimeofday(&start_time, (struct timezone*)0); */ /* at first time */
+
+
+ printf("\n%s",version);
+ if(argc <=1){
+ printf("\nEnter the parameter file name: ");
+ scanf("%s",pathtot);
+ }
+ else{
+ strcpy(pathtot,argv[1]);
+ }
+ /*if(getcwd(pathcd, 80)!= NULL)printf ("Error pathcd\n");*/
+ /*cygwin_split_path(pathtot,path,optionfile);
+ printf("pathtot=%s, path=%s, optionfile=%s\n",pathtot,path,optionfile);*/
+ /* cutv(path,optionfile,pathtot,'\\');*/
+
+ split(pathtot,path,optionfile,optionfilext,optionfilefiname);
+ printf("pathtot=%s, path=%s, optionfile=%s optionfilext=%s optionfilefiname=%s\n",pathtot,path,optionfile,optionfilext,optionfilefiname);
+ chdir(path);
+ replace(pathc,path);
+
+/*-------- arguments in the command line --------*/
+
+ strcpy(fileres,"r");
+ strcat(fileres, optionfilefiname);
+ strcat(fileres,".txt"); /* Other files have txt extension */
+
+ /*---------arguments file --------*/
+
+ if((ficpar=fopen(optionfile,"r"))==NULL) {
+ printf("Problem with optionfile %s\n",optionfile);
+ goto end;
+ }
+
+ strcpy(filereso,"o");
+ strcat(filereso,fileres);
+ if((ficparo=fopen(filereso,"w"))==NULL) {
+ printf("Problem with Output resultfile: %s\n", filereso);goto end;
+ }
+
+ /* Reads comments: lines beginning with '#' */
+ while((c=getc(ficpar))=='#' && c!= EOF){
+ ungetc(c,ficpar);
+ fgets(line, MAXLINE, ficpar);
+ puts(line);
+ fputs(line,ficparo);
+ }
+ ungetc(c,ficpar);
+
+ fscanf(ficpar,"title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\nftol=%lf 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);
+ printf("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);
+ fprintf(ficparo,"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);
+while((c=getc(ficpar))=='#' && c!= EOF){
+ ungetc(c,ficpar);
+ fgets(line, MAXLINE, ficpar);
+ puts(line);
+ fputs(line,ficparo);
+ }
+ ungetc(c,ficpar);
+
+
+ covar=matrix(0,NCOVMAX,1,n);
+ cptcovn=0;
+ if (strlen(model)>1) cptcovn=nbocc(model,'+')+1;
+
+ ncovmodel=2+cptcovn;
+ nvar=ncovmodel-1; /* Suppressing age as a basic covariate */
/* Read guess parameters */
/* Reads comments: lines beginning with '#' */
@@ -2103,12 +2634,17 @@ while((c=getc(ficpar))=='#' && c!= EOF){
printf("\n");
- /*-------- data file ----------*/
- if((ficres =fopen(fileres,"w"))==NULL) {
- printf("Problem with resultfile: %s\n", fileres);goto end;
+ /*-------- Rewriting paramater file ----------*/
+ strcpy(rfileres,"r"); /* "Rparameterfile */
+ strcat(rfileres,optionfilefiname); /* Parameter file first name*/
+ strcat(rfileres,"."); /* */
+ strcat(rfileres,optionfilext); /* Other files have txt extension */
+ if((ficres =fopen(rfileres,"w"))==NULL) {
+ printf("Problem writing new parameter file: %s\n", fileres);goto end;
}
fprintf(ficres,"#%s\n",version);
+ /*-------- data file ----------*/
if((fic=fopen(datafile,"r"))==NULL) {
printf("Problem with datafile: %s\n", datafile);goto end;
}
@@ -2381,7 +2917,7 @@ printf("Total number of individuals= %d,
}
/*--------- results files --------------*/
- 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);
+ 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= 0 weight=%d\nmodel=%s\n", title, datafile, lastobs, firstpass,lastpass,ftol, stepm, ncov, nlstate, ndeath, maxwav, weightopt,model);
jk=1;
@@ -2410,287 +2946,72 @@ printf("Total number of individuals= %d,
}
fprintf(ficres,"# Scales\n");
printf("# Scales\n");
- for(i=1,jk=1; i <=nlstate; i++){
- for(j=1; j <=nlstate+ndeath; j++){
- if (j!=i) {
- fprintf(ficres,"%1d%1d",i,j);
- printf("%1d%1d",i,j);
- for(k=1; k<=ncovmodel;k++){
- printf(" %.5e",delti[jk]);
- fprintf(ficres," %.5e",delti[jk]);
- jk++;
- }
- printf("\n");
- fprintf(ficres,"\n");
- }
- }
- }
-
- k=1;
- fprintf(ficres,"# Covariance\n");
- printf("# Covariance\n");
- for(i=1;i<=npar;i++){
- /* if (k>nlstate) k=1;
- i1=(i-1)/(ncovmodel*nlstate)+1;
- fprintf(ficres,"%s%d%d",alph[k],i1,tab[i]);
- printf("%s%d%d",alph[k],i1,tab[i]);*/
- fprintf(ficres,"%3d",i);
- printf("%3d",i);
- for(j=1; j<=i;j++){
- fprintf(ficres," %.5e",matcov[i][j]);
- printf(" %.5e",matcov[i][j]);
- }
- fprintf(ficres,"\n");
- printf("\n");
- k++;
- }
-
- while((c=getc(ficpar))=='#' && c!= EOF){
- ungetc(c,ficpar);
- fgets(line, MAXLINE, ficpar);
- puts(line);
- fputs(line,ficparo);
- }
- ungetc(c,ficpar);
-
- fscanf(ficpar,"agemin=%lf agemax=%lf bage=%lf fage=%lf\n",&agemin,&agemax, &bage, &fage);
-
- if (fage <= 2) {
- bage = agemin;
- fage = agemax;
- }
-
- 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",agemin,agemax,bage,fage);
- fprintf(ficparo,"agemin=%.0f agemax=%.0f bage=%.0f fage=%.0f\n",agemin,agemax,bage,fage);
-
- while((c=getc(ficpar))=='#' && c!= EOF){
- ungetc(c,ficpar);
- fgets(line, MAXLINE, ficpar);
- puts(line);
- fputs(line,ficparo);
- }
- ungetc(c,ficpar);
-
- fscanf(ficpar,"begin-prev-date=%lf/%lf/%lf end-prev-date=%lf/%lf/%lf mob_average=%d\n",&jprev1, &mprev1,&anprev1,&jprev2, &mprev2,&anprev2,&mobilav);
- fprintf(ficparo,"begin-prev-date=%.lf/%.lf/%.lf end-prev-date=%.lf/%.lf/%.lf mob_average=%d\n",jprev1, mprev1,anprev1,jprev2, mprev2,anprev2,mobilav);
- fprintf(ficres,"begin-prev-date=%.lf/%.lf/%.lf end-prev-date=%.lf/%.lf/%.lf mob_average=%d\n",jprev1, mprev1,anprev1,jprev2, mprev2,anprev2,mobilav);
-
- while((c=getc(ficpar))=='#' && c!= EOF){
- ungetc(c,ficpar);
- fgets(line, MAXLINE, ficpar);
- puts(line);
- fputs(line,ficparo);
- }
- ungetc(c,ficpar);
-
-
- dateprev1=anprev1+mprev1/12.+jprev1/365.;
- dateprev2=anprev2+mprev2/12.+jprev2/365.;
-
- fscanf(ficpar,"pop_based=%d\n",&popbased);
- fprintf(ficparo,"pop_based=%d\n",popbased);
- fprintf(ficres,"pop_based=%d\n",popbased);
-
- while((c=getc(ficpar))=='#' && c!= EOF){
- ungetc(c,ficpar);
- fgets(line, MAXLINE, ficpar);
- puts(line);
- fputs(line,ficparo);
- }
- ungetc(c,ficpar);
- fscanf(ficpar,"popforecast=%d popfile=%s starting-proj-date=%lf/%lf/%lf final-proj-date=%lf/%lf/%lf\n",&popforecast,popfile,&jproj1,&mproj1,&anproj1,&jproj2,&mproj2,&anproj2);
-fprintf(ficparo,"popforecast=%d popfile=%s starting-proj-date=%.lf/%.lf/%.lf final-proj-date=%.lf/%.lf/%.lf\n",popforecast,popfile,jproj1,mproj1,anproj1,jproj2,mproj2,anproj2);
-fprintf(ficres,"popforecast=%d popfile=%s starting-proj-date=%.lf/%.lf/%.lf final-proj-date=%.lf/%.lf/%.lf\n",popforecast,popfile,jproj1,mproj1,anproj1,jproj2,mproj2,anproj2);
-
- freqsummary(fileres, agemin, agemax, s, agev, nlstate, imx,Tvar,nbcode, ncodemax,mint,anint,dateprev1,dateprev2);
-
-
- /*------------ gnuplot -------------*/
- /*chdir(pathcd);*/
- strcpy(optionfilegnuplot,optionfilefiname);
- strcat(optionfilegnuplot,".plt");
- if((ficgp=fopen(optionfilegnuplot,"w"))==NULL) {
- printf("Problem with file %s",optionfilegnuplot);goto end;
- }
-#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; cptnlstate) k=1;
+ i1=(i-1)/(ncovmodel*nlstate)+1;
+ fprintf(ficres,"%s%d%d",alph[k],i1,tab[i]);
+ printf("%s%d%d",alph[k],i1,tab[i]);*/
+ fprintf(ficres,"%3d",i);
+ printf("%3d",i);
+ for(j=1; j<=i;j++){
+ fprintf(ficres," %.5e",matcov[i][j]);
+ printf(" %.5e",matcov[i][j]);
+ }
+ fprintf(ficres,"\n");
+ printf("\n");
+ k++;
+ }
+
+ while((c=getc(ficpar))=='#' && c!= EOF){
+ ungetc(c,ficpar);
+ fgets(line, MAXLINE, ficpar);
+ puts(line);
+ fputs(line,ficparo);
+ }
+ ungetc(c,ficpar);
+
+ fscanf(ficpar,"agemin=%lf agemax=%lf bage=%lf fage=%lf\n",&agemin,&agemaxpar, &bage, &fage);
+
+ if (fage <= 2) {
+ bage = agemin;
+ 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",agemin,agemaxpar,bage,fage);
+ fprintf(ficparo,"agemin=%.0f agemax=%.0f bage=%.0f fage=%.0f\n",agemin,agemaxpar,bage,fage);
+
+ while((c=getc(ficpar))=='#' && c!= EOF){
+ ungetc(c,ficpar);
+ fgets(line, MAXLINE, ficpar);
+ puts(line);
+ fputs(line,ficparo);
}
-
- fclose(ficgp);
- /* end gnuplot */
-
-chdir(path);
-
- free_ivector(wav,1,imx);
- free_imatrix(dh,1,lastpass-firstpass+1,1,imx);
- free_imatrix(mw,1,lastpass-firstpass+1,1,imx);
- free_ivector(num,1,n);
- free_vector(agedc,1,n);
- /*free_matrix(covar,1,NCOVMAX,1,n);*/
- fclose(ficparo);
- fclose(ficres);
- /* }*/
-
- /*________fin mle=1_________*/
-
-
+ ungetc(c,ficpar);
- /* No more information from the sample is required now */
- /* Reads comments: lines beginning with '#' */
+ fscanf(ficpar,"begin-prev-date=%lf/%lf/%lf end-prev-date=%lf/%lf/%lf\n",&jprev1, &mprev1,&anprev1,&jprev2, &mprev2,&anprev2);
+ fprintf(ficparo,"begin-prev-date=%.lf/%.lf/%.lf end-prev-date=%.lf/%.lf/%.lf\n",jprev1, mprev1,anprev1,jprev2, mprev2,anprev2);
+ fprintf(ficres,"begin-prev-date=%.lf/%.lf/%.lf end-prev-date=%.lf/%.lf/%.lf\n",jprev1, mprev1,anprev1,jprev2, mprev2,anprev2);
+
while((c=getc(ficpar))=='#' && c!= EOF){
ungetc(c,ficpar);
fgets(line, MAXLINE, ficpar);
@@ -2698,74 +3019,62 @@ chdir(path);
fputs(line,ficparo);
}
ungetc(c,ficpar);
-
- fscanf(ficpar,"agemin=%lf agemax=%lf bage=%lf fage=%lf\n",&agemin,&agemax, &bage, &fage);
- printf("agemin=%.0f agemax=%.0f bage=%.0f fage=%.0f\n",agemin,agemax, bage, fage);
- fprintf(ficparo,"agemin=%.0f agemax=%.0f bage=%.0f fage=%.0f\n",agemin,agemax,bage,fage);
-/*--------- index.htm --------*/
+
- strcpy(optionfilehtm,optionfile);
- strcat(optionfilehtm,".htm");
- if((fichtm=fopen(optionfilehtm,"w"))==NULL) {
- printf("Problem with %s \n",optionfilehtm);goto end;
+ dateprev1=anprev1+mprev1/12.+jprev1/365.;
+ dateprev2=anprev2+mprev2/12.+jprev2/365.;
+
+ fscanf(ficpar,"pop_based=%d\n",&popbased);
+ fprintf(ficparo,"pop_based=%d\n",popbased);
+ fprintf(ficres,"pop_based=%d\n",popbased);
+
+ while((c=getc(ficpar))=='#' && c!= EOF){
+ ungetc(c,ficpar);
+ fgets(line, MAXLINE, ficpar);
+ puts(line);
+ fputs(line,ficparo);
}
+ ungetc(c,ficpar);
- fprintf(fichtm," 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);
+ fscanf(ficpar,"starting-proj-date=%lf/%lf/%lf final-proj-date=%lf/%lf/%lf mov_average=%d\n",&jproj1,&mproj1,&anproj1,&jproj2,&mproj2,&anproj2,&mobilav);
+fprintf(ficparo,"starting-proj-date=%.lf/%.lf/%.lf final-proj-date=%.lf/%.lf/%.lf mov_average=%d\n",jproj1,mproj1,anproj1,jproj2,mproj2,anproj2,mobilav);
+fprintf(ficres,"starting-proj-date=%.lf/%.lf/%.lf final-proj-date=%.lf/%.lf/%.lf mov_average=%d\n",jproj1,mproj1,anproj1,jproj2,mproj2,anproj2,mobilav);
- fprintf(fichtm," - Graphs
");
- m=cptcoveff;
- if (cptcovn < 1) {m=1;ncodemax[1]=1;}
+while((c=getc(ficpar))=='#' && c!= EOF){
+ ungetc(c,ficpar);
+ fgets(line, MAXLINE, ficpar);
+ puts(line);
+ fputs(line,ficparo);
+ }
+ ungetc(c,ficpar);
- 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");
- }
- }
-fclose(fichtm);
+ fscanf(ficpar,"popforecast=%d popfile=%s popfiledate=%lf/%lf/%lf last-popfiledate=%lf/%lf/%lf\n",&popforecast,popfile,&jpyram,&mpyram,&anpyram,&jpyram1,&mpyram1,&anpyram1);
+ fprintf(ficparo,"popforecast=%d popfile=%s popfiledate=%.lf/%.lf/%.lf last-popfiledate=%.lf/%.lf/%.lf\n",popforecast,popfile,jpyram,mpyram,anpyram,jpyram1,mpyram1,anpyram1);
+ fprintf(ficres,"popforecast=%d popfile=%s popfiledate=%.lf/%.lf/%.lf last-popfiledate=%.lf/%.lf/%.lf\n",popforecast,popfile,jpyram,mpyram,anpyram,jpyram1,mpyram1,anpyram1);
+
+ freqsummary(fileres, agemin, agemax, s, agev, nlstate, imx,Tvar,nbcode, ncodemax,mint,anint,dateprev1,dateprev2,jprev1, mprev1,anprev1,jprev2, mprev2,anprev2);
+
+/*------------ gnuplot -------------*/
+ printinggnuplot(fileres,optionfilefiname,optionfile,optionfilegnuplot, agemin,agemaxpar,fage, pathc,p);
+
+/*------------ free_vector -------------*/
+ chdir(path);
+
+ free_ivector(wav,1,imx);
+ free_imatrix(dh,1,lastpass-firstpass+1,1,imx);
+ free_imatrix(mw,1,lastpass-firstpass+1,1,imx);
+ free_ivector(num,1,n);
+ free_vector(agedc,1,n);
+ /*free_matrix(covar,1,NCOVMAX,1,n);*/
+ fclose(ficparo);
+ fclose(ficres);
+
+/*--------- index.htm --------*/
+
+ printinghtml(fileres,title,datafile, firstpass, lastpass, stepm, weightopt,model,imx,jmin,jmax,jmean,optionfile,optionfilehtm,rfileres);
+
/*--------------- Prevalence limit --------------*/
strcpy(filerespl,"pl");
@@ -2787,7 +3096,7 @@ fclose(fichtm);
oldm=oldms; newm=newms; savm=savms; /* Keeps fixed addresses to free */
k=0;
agebase=agemin;
- agelim=agemax;
+ agelim=agemaxpar;
ftolpl=1.e-10;
i1=cptcoveff;
if (cptcovn < 1){i1=1;}
@@ -2864,152 +3173,19 @@ fclose(fichtm);
fclose(ficrespij);
- if(stepm == 1) {
- /*---------- Forecasting ------------------*/
- calagedate=(anproj1+mproj1/12.+jproj1/365.-dateintmean)*YEARM;
-
- /*printf("calage= %f", calagedate);*/
-
- prevalence(agemin, agemax, s, agev, nlstate, imx,Tvar,nbcode, ncodemax,mint,anint,dateprev1,dateprev2, calagedate);
-
-
- strcpy(fileresf,"f");
- strcat(fileresf,fileres);
- if((ficresf=fopen(fileresf,"w"))==NULL) {
- printf("Problem with forecast resultfile: %s\n", fileresf);goto end;
- }
- printf("Computing forecasting: result on file '%s' \n", fileresf);
-
- free_matrix(mint,1,maxwav,1,n);
- free_matrix(anint,1,maxwav,1,n);
- free_matrix(agev,1,maxwav,1,imx);
- /* Mobile average */
-
- if (cptcoveff==0) ncodemax[cptcoveff]=1;
-
- if (mobilav==1) {
- mobaverage= ma3x(1, AGESUP,1,NCOVMAX, 1,NCOVMAX);
- for (agedeb=bage+3; agedeb<=fage-2; agedeb++)
- for (i=1; i<=nlstate;i++)
- for (cptcod=1;cptcod<=ncodemax[cptcov];cptcod++)
- mobaverage[(int)agedeb][i][cptcod]=0.;
-
- for (agedeb=bage+4; agedeb<=fage; agedeb++){
- for (i=1; i<=nlstate;i++){
- for (cptcod=1;cptcod<=ncodemax[cptcoveff];cptcod++){
- for (cpt=0;cpt<=4;cpt++){
- mobaverage[(int)agedeb-2][i][cptcod]=mobaverage[(int)agedeb-2][i][cptcod]+probs[(int)agedeb-cpt][i][cptcod];
- }
- mobaverage[(int)agedeb-2][i][cptcod]=mobaverage[(int)agedeb-2][i][cptcod]/5;
- }
- }
- }
- }
-
- stepsize=(int) (stepm+YEARM-1)/YEARM;
- if (stepm<=12) stepsize=1;
-
- agelim=AGESUP;
- /*hstepm=stepsize*YEARM; *//* Every year of age */
- hstepm=1;
- hstepm=hstepm/stepm; /* Typically 2 years, = 2 years/6 months = 4 */
- yp1=modf(dateintmean,&yp);
- anprojmean=yp;
- yp2=modf((yp1*12),&yp);
- mprojmean=yp;
- yp1=modf((yp2*30.5),&yp);
- jprojmean=yp;
- if(jprojmean==0) jprojmean=1;
- if(mprojmean==0) jprojmean=1;
-
- fprintf(ficresf,"# Estimated date of observed prevalence: %.lf/%.lf/%.lf ",jprojmean,mprojmean,anprojmean);
-
- if (popforecast==1) {
- if((ficpop=fopen(popfile,"r"))==NULL) {
- printf("Problem with population file : %s\n",popfile);goto end;
- }
- popage=ivector(0,AGESUP);
- popeffectif=vector(0,AGESUP);
- popcount=vector(0,AGESUP);
-
- i=1;
- while ((c=fscanf(ficpop,"%d %lf\n",&popage[i],&popcount[i])) != EOF)
- {
- i=i+1;
- }
- imx=i;
-
- for (i=1; i=(bage-((int)calagedate %12)/12.); agedeb--){ /* If stepm=6 months */
- nhstepm=(int) rint((agelim-agedeb)*YEARM/stepm);
- nhstepm = nhstepm/hstepm;
- /*printf("agedeb=%.lf stepm=%d hstepm=%d nhstepm=%d \n",agedeb,stepm,hstepm,nhstepm);*/
-
- p3mat=ma3x(1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);
- oldm=oldms;savm=savms;
- hpxij(p3mat,nhstepm,agedeb,hstepm,p,nlstate,stepm,oldm,savm, k);
-
- for (h=0; h<=nhstepm; h++){
- if (h==(int) (calagedate+YEARM*cpt)) {
- fprintf(ficresf,"\n %.f ",agedeb+h*hstepm/YEARM*stepm);
- }
- for(j=1; j<=nlstate+ndeath;j++) {
- kk1=0.;kk2=0;
- for(i=1; i<=nlstate;i++) {
- if (mobilav==1)
- kk1=kk1+p3mat[i][j][h]*mobaverage[(int)agedeb+1][i][cptcod];
- else {
- kk1=kk1+p3mat[i][j][h]*probs[(int)(agedeb+1)][i][cptcod];
- /* fprintf(ficresf," p3=%.3f p=%.3f ", p3mat[i][j][h], probs[(int)(agedeb)+1][i][cptcod]);*/
- }
- if (popforecast==1) kk2=kk1*popeffectif[(int)agedeb];
- }
-
- if (h==(int)(calagedate+12*cpt)){
- fprintf(ficresf," %.3f", kk1);
-
- if (popforecast==1) fprintf(ficresf," [%.f]", kk2);
- }
- }
- }
- /* free_ma3x(p3mat,1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);*/
- }
- }
- }
- }
- /* if (mobilav==1) free_ma3x(mobaverage,1, AGESUP,1,NCOVMAX, 1,NCOVMAX);
- if (popforecast==1) {
- free_ivector(popage,0,AGESUP);
- free_vector(popeffectif,0,AGESUP);
- free_vector(popcount,0,AGESUP);
- }
- free_imatrix(s,1,maxwav+1,1,n);
- free_vector(weight,1,n);*/
- fclose(ficresf);
- }/* End forecasting */
+ /*---------- Forecasting ------------------*/
+ if((stepm == 1) && (model==".")){
+ prevforecast(fileres, anproj1,mproj1,jproj1, agemin,agemax, dateprev1, dateprev2,mobilav, agedeb, fage, popforecast, popfile, anproj2,p, i1);
+if (popforecast==1) populforecast(fileres, anpyram,mpyram,jpyram, agemin,agemax, dateprev1, dateprev2,mobilav, agedeb, fage, popforecast, popfile, anpyram1,p, i1);
+ free_matrix(mint,1,maxwav,1,n);
+ free_matrix(anint,1,maxwav,1,n); free_imatrix(s,1,maxwav+1,1,n);
+ free_vector(weight,1,n);}
else{
erreur=108;
printf("Error %d!! You can only forecast the prevalences if the optimization\n has been performed with stepm = 1 (month) instead of %d\n", erreur, stepm);
}
+
/*---------- Health expectancies and variances ------------*/
@@ -3059,12 +3235,14 @@ fclose(fichtm);
evsij(fileres, eij, p, nlstate, stepm, (int) bage, (int)fage, oldm, savm, k);
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);
+
+
+
fprintf(ficrest,"#Total LEs with variances: e.. (std) ");
for (i=1;i<=nlstate;i++) fprintf(ficrest,"e.%d (std) ",i);
fprintf(ficrest,"\n");
-
+
hf=1;
if (stepm >= YEARM) hf=stepm/YEARM;
epj=vector(1,nlstate+1);
@@ -3093,20 +3271,16 @@ fclose(fichtm);
}
}
}
-
-
-
- fclose(ficreseij);
- fclose(ficresvij);
+ fclose(ficreseij);
+ fclose(ficresvij);
fclose(ficrest);
fclose(ficpar);
free_vector(epj,1,nlstate+1);
- /* scanf("%d ",i); */
-
+
/*------- Variance limit prevalence------*/
-strcpy(fileresvpl,"vpl");
+ strcpy(fileresvpl,"vpl");
strcat(fileresvpl,fileres);
if((ficresvpl=fopen(fileresvpl,"w"))==NULL) {
printf("Problem with variance prev lim resultfile: %s\n", fileresvpl);
@@ -3114,19 +3288,19 @@ strcpy(fileresvpl,"vpl");
}
printf("Computing Variance-covariance of Prevalence limit: file '%s' \n", fileresvpl);
- k=0;
- for(cptcov=1;cptcov<=i1;cptcov++){
- for(cptcod=1;cptcod<=ncodemax[cptcov];cptcod++){
- k=k+1;
- fprintf(ficresvpl,"\n#****** ");
- for(j=1;j<=cptcoveff;j++)
- fprintf(ficresvpl,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtab[k][j]]);
- fprintf(ficresvpl,"******\n");
-
- varpl=matrix(1,nlstate,(int) bage, (int) fage);
- oldm=oldms;savm=savms;
+ k=0;
+ for(cptcov=1;cptcov<=i1;cptcov++){
+ for(cptcod=1;cptcod<=ncodemax[cptcov];cptcod++){
+ k=k+1;
+ fprintf(ficresvpl,"\n#****** ");
+ for(j=1;j<=cptcoveff;j++)
+ fprintf(ficresvpl,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtab[k][j]]);
+ fprintf(ficresvpl,"******\n");
+
+ varpl=matrix(1,nlstate,(int) bage, (int) fage);
+ oldm=oldms;savm=savms;
varprevlim(fileres, varpl, matcov, p, delti, nlstate, stepm, (int) bage, (int) fage, oldm, savm, prlim, ftolpl,k);
- }
+ }
}
fclose(ficresvpl);
@@ -3145,7 +3319,7 @@ strcpy(fileresvpl,"vpl");
free_matrix(matcov,1,npar,1,npar);
free_vector(delti,1,npar);
-
+ free_matrix(agev,1,maxwav,1,imx);
free_ma3x(param,1,nlstate,1, nlstate+ndeath-1,1,ncovmodel);
if(erreur >0)