version 1.73, 2003/04/08 14:06:50
|
version 1.74, 2003/05/02 18:51:41
|
Line 48
|
Line 48
|
It is copyrighted identically to a GNU software product, ie programme and |
It is copyrighted identically to a GNU software product, ie programme and |
software can be distributed freely for non commercial use. Latest version |
software can be distributed freely for non commercial use. Latest version |
can be accessed at http://euroreves.ined.fr/imach . |
can be accessed at http://euroreves.ined.fr/imach . |
|
|
|
Help to debug: LD_PRELOAD=/usr/local/lib/libnjamd.so ./imach foo.imach |
|
or better on gdb : set env LD_PRELOAD=/usr/local/lib/libnjamd.so |
|
|
**********************************************************************/ |
**********************************************************************/ |
|
/* |
|
main |
|
read parameterfile |
|
read datafile |
|
concatwav |
|
if (mle >= 1) |
|
mlikeli |
|
print results files |
|
if mle==1 |
|
computes hessian |
|
read end of parameter file: agemin, agemax, bage, fage, estepm |
|
begin-prev-date,... |
|
open gnuplot file |
|
open html file |
|
stable prevalence |
|
for age prevalim() |
|
h Pij x |
|
variance of p varprob |
|
forecasting if prevfcast==1 prevforecast call prevalence() |
|
health expectancies |
|
Variance-covariance of DFLE |
|
prevalence() |
|
movingaverage() |
|
varevsij() |
|
if popbased==1 varevsij(,popbased) |
|
total life expectancies |
|
Variance of stable prevalence |
|
end |
|
*/ |
|
|
|
|
|
|
|
|
#include <math.h> |
#include <math.h> |
#include <stdio.h> |
#include <stdio.h> |
Line 83
|
Line 119
|
#define ODIRSEPARATOR '\\' |
#define ODIRSEPARATOR '\\' |
#endif |
#endif |
|
|
char version[80]="Imach version 0.94, February 2003, INED-EUROREVES "; |
char version[80]="Imach version 0.95, February 2003, INED-EUROREVES "; |
int erreur; /* Error number */ |
int erreur; /* Error number */ |
int nvar; |
int nvar; |
int cptcovn=0, cptcovage=0, cptcoveff=0,cptcov; |
int cptcovn=0, cptcovage=0, cptcoveff=0,cptcov; |
Line 188 static int split( char *path, char *dirc
|
Line 224 static int split( char *path, char *dirc
|
if ( ss == NULL ) { /* no directory, so use current */ |
if ( ss == NULL ) { /* no directory, so use current */ |
/*if(strrchr(path, ODIRSEPARATOR )==NULL) |
/*if(strrchr(path, ODIRSEPARATOR )==NULL) |
printf("Warning you should use %s as a separator\n",DIRSEPARATOR);*/ |
printf("Warning you should use %s as a separator\n",DIRSEPARATOR);*/ |
#if defined(__bsd__) /* get current working directory */ |
/* get current working directory */ |
extern char *getwd( ); |
/* extern char* getcwd ( char *buf , int len);*/ |
|
|
if ( getwd( dirc ) == NULL ) { |
|
#else |
|
extern char *getcwd( ); |
|
|
|
if ( getcwd( dirc, FILENAME_MAX ) == NULL ) { |
if ( getcwd( dirc, FILENAME_MAX ) == NULL ) { |
#endif |
|
return( GLOCK_ERROR_GETCWD ); |
return( GLOCK_ERROR_GETCWD ); |
} |
} |
strcpy( name, path ); /* we've got it */ |
strcpy( name, path ); /* we've got it */ |
Line 365 double **matrix(long nrl, long nrh, long
|
Line 395 double **matrix(long nrl, long nrh, long
|
|
|
for (i=nrl+1; i<=nrh; i++) m[i]=m[i-1]+ncol; |
for (i=nrl+1; i<=nrh; i++) m[i]=m[i-1]+ncol; |
return m; |
return m; |
|
/* print *(*(m+1)+70) ou print m[1][70]; print m+1 or print &(m[1]) |
|
*/ |
} |
} |
|
|
/*************************free matrix ************************/ |
/*************************free matrix ************************/ |
Line 404 double ***ma3x(long nrl, long nrh, long
|
Line 436 double ***ma3x(long nrl, long nrh, long
|
for (j=ncl+1; j<=nch; j++) |
for (j=ncl+1; j<=nch; j++) |
m[i][j]=m[i][j-1]+nlay; |
m[i][j]=m[i][j-1]+nlay; |
} |
} |
return m; |
return m; |
|
/* gdb: p *(m+1) <=> p m[1] and p (m+1) <=> p (m+1) <=> p &(m[1]) |
|
&(m[i][j][k]) <=> *((*(m+i) + j)+k) |
|
*/ |
} |
} |
|
|
/*************************free ma3x ************************/ |
/*************************free ma3x ************************/ |
Line 1150 double func( double *x)
|
Line 1185 double func( double *x)
|
void mlikeli(FILE *ficres,double p[], int npar, int ncovmodel, int nlstate, double ftol, double (*func)(double [])) |
void mlikeli(FILE *ficres,double p[], int npar, int ncovmodel, int nlstate, double ftol, double (*func)(double [])) |
{ |
{ |
int i,j, iter; |
int i,j, iter; |
double **xi,*delti; |
double **xi; |
double fret; |
double fret; |
xi=matrix(1,npar,1,npar); |
xi=matrix(1,npar,1,npar); |
for (i=1;i<=npar;i++) |
for (i=1;i<=npar;i++) |
Line 1423 void lubksb(double **a, int n, int *indx
|
Line 1458 void lubksb(double **a, int n, int *indx
|
} |
} |
|
|
/************ Frequencies ********************/ |
/************ Frequencies ********************/ |
void freqsummary(char fileres[], int agemin, int agemax, int **s, double **agev, int nlstate, int imx, int *Tvaraff, int **nbcode, int *ncodemax,double **mint,double **anint, double dateprev1,double dateprev2,double jprev1, double mprev1,double anprev1,double jprev2, double mprev2,double anprev2) |
void freqsummary(char fileres[], int iagemin, int iagemax, int **s, double **agev, int nlstate, int imx, int *Tvaraff, 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 */ |
{ /* Some frequencies */ |
|
|
int i, m, jk, k1,i1, j1, bool, z1,z2,j; |
int i, m, jk, k1,i1, j1, bool, z1,z2,j; |
Line 1435 void freqsummary(char fileres[], int ag
|
Line 1470 void freqsummary(char fileres[], int ag
|
char fileresp[FILENAMELENGTH]; |
char fileresp[FILENAMELENGTH]; |
|
|
pp=vector(1,nlstate); |
pp=vector(1,nlstate); |
prop=matrix(1,nlstate,agemin,agemax+3); |
prop=matrix(1,nlstate,iagemin,iagemax+3); |
probs= ma3x(1,AGESUP,1,NCOVMAX, 1,NCOVMAX); |
|
strcpy(fileresp,"p"); |
strcpy(fileresp,"p"); |
strcat(fileresp,fileres); |
strcat(fileresp,fileres); |
if((ficresp=fopen(fileresp,"w"))==NULL) { |
if((ficresp=fopen(fileresp,"w"))==NULL) { |
Line 1444 void freqsummary(char fileres[], int ag
|
Line 1478 void freqsummary(char fileres[], int ag
|
fprintf(ficlog,"Problem with prevalence resultfile: %s\n", fileresp); |
fprintf(ficlog,"Problem with prevalence resultfile: %s\n", fileresp); |
exit(0); |
exit(0); |
} |
} |
freq= ma3x(-1,nlstate+ndeath,-1,nlstate+ndeath,agemin,agemax+3); |
freq= ma3x(-1,nlstate+ndeath,-1,nlstate+ndeath,iagemin,iagemax+3); |
j1=0; |
j1=0; |
|
|
j=cptcoveff; |
j=cptcoveff; |
Line 1459 void freqsummary(char fileres[], int ag
|
Line 1493 void freqsummary(char fileres[], int ag
|
scanf("%d", i);*/ |
scanf("%d", i);*/ |
for (i=-1; i<=nlstate+ndeath; i++) |
for (i=-1; i<=nlstate+ndeath; i++) |
for (jk=-1; jk<=nlstate+ndeath; jk++) |
for (jk=-1; jk<=nlstate+ndeath; jk++) |
for(m=agemin; m <= agemax+3; m++) |
for(m=iagemin; m <= iagemax+3; m++) |
freq[i][jk][m]=0; |
freq[i][jk][m]=0; |
|
|
for (i=1; i<=nlstate; i++) |
for (i=1; i<=nlstate; i++) |
for(m=agemin; m <= agemax+3; m++) |
for(m=iagemin; m <= iagemax+3; m++) |
prop[i][m]=0; |
prop[i][m]=0; |
|
|
dateintsum=0; |
dateintsum=0; |
Line 1479 void freqsummary(char fileres[], int ag
|
Line 1513 void freqsummary(char fileres[], int ag
|
for(m=firstpass; m<=lastpass; m++){ |
for(m=firstpass; m<=lastpass; m++){ |
k2=anint[m][i]+(mint[m][i]/12.); |
k2=anint[m][i]+(mint[m][i]/12.); |
if ((k2>=dateprev1) && (k2<=dateprev2)) { |
if ((k2>=dateprev1) && (k2<=dateprev2)) { |
if(agev[m][i]==0) agev[m][i]=agemax+1; |
if(agev[m][i]==0) agev[m][i]=iagemax+1; |
if(agev[m][i]==1) agev[m][i]=agemax+2; |
if(agev[m][i]==1) agev[m][i]=iagemax+2; |
if (s[m][i]>0 && s[m][i]<=nlstate) prop[s[m][i]][(int)agev[m][i]] += weight[i]; |
if (s[m][i]>0 && s[m][i]<=nlstate) prop[s[m][i]][(int)agev[m][i]] += weight[i]; |
if (m<lastpass) { |
if (m<lastpass) { |
freq[s[m][i]][s[m+1][i]][(int)agev[m][i]] += weight[i]; |
freq[s[m][i]][s[m+1][i]][(int)agev[m][i]] += weight[i]; |
freq[s[m][i]][s[m+1][i]][(int) agemax+3] += weight[i]; |
freq[s[m][i]][s[m+1][i]][iagemax+3] += weight[i]; |
} |
} |
|
|
if ((agev[m][i]>1) && (agev[m][i]< (agemax+3))) { |
if ((agev[m][i]>1) && (agev[m][i]< (iagemax+3))) { |
dateintsum=dateintsum+k2; |
dateintsum=dateintsum+k2; |
k2cpt++; |
k2cpt++; |
} |
} |
Line 1507 void freqsummary(char fileres[], int ag
|
Line 1541 void freqsummary(char fileres[], int ag
|
fprintf(ficresp, " Age Prev(%d) N(%d) N",i,i); |
fprintf(ficresp, " Age Prev(%d) N(%d) N",i,i); |
fprintf(ficresp, "\n"); |
fprintf(ficresp, "\n"); |
|
|
for(i=(int)agemin; i <= (int)agemax+3; i++){ |
for(i=iagemin; i <= iagemax+3; i++){ |
if(i==(int)agemax+3){ |
if(i==iagemax+3){ |
fprintf(ficlog,"Total"); |
fprintf(ficlog,"Total"); |
}else{ |
}else{ |
if(first==1){ |
if(first==1){ |
Line 1554 void freqsummary(char fileres[], int ag
|
Line 1588 void freqsummary(char fileres[], int ag
|
printf(" %d.=%.0f prev[%d]=NaNQ%%",jk,pp[jk],jk); |
printf(" %d.=%.0f prev[%d]=NaNQ%%",jk,pp[jk],jk); |
fprintf(ficlog," %d.=%.0f prev[%d]=NaNQ%%",jk,pp[jk],jk); |
fprintf(ficlog," %d.=%.0f prev[%d]=NaNQ%%",jk,pp[jk],jk); |
} |
} |
if( i <= (int) agemax){ |
if( i <= iagemax){ |
if(pos>=1.e-5){ |
if(pos>=1.e-5){ |
fprintf(ficresp," %d %.5f %.0f %.0f",i,prop[jk][i]/posprop, prop[jk][i],posprop); |
fprintf(ficresp," %d %.5f %.0f %.0f",i,prop[jk][i]/posprop, prop[jk][i],posprop); |
probs[i][jk][j1]= pp[jk]/pos; |
probs[i][jk][j1]= pp[jk]/pos; |
Line 1572 void freqsummary(char fileres[], int ag
|
Line 1606 void freqsummary(char fileres[], int ag
|
printf(" %d%d=%.0f",jk,m,freq[jk][m][i]); |
printf(" %d%d=%.0f",jk,m,freq[jk][m][i]); |
fprintf(ficlog," %d%d=%.0f",jk,m,freq[jk][m][i]); |
fprintf(ficlog," %d%d=%.0f",jk,m,freq[jk][m][i]); |
} |
} |
if(i <= (int) agemax) |
if(i <= iagemax) |
fprintf(ficresp,"\n"); |
fprintf(ficresp,"\n"); |
if(first==1) |
if(first==1) |
printf("Others in log...\n"); |
printf("Others in log...\n"); |
Line 1583 void freqsummary(char fileres[], int ag
|
Line 1617 void freqsummary(char fileres[], int ag
|
dateintmean=dateintsum/k2cpt; |
dateintmean=dateintsum/k2cpt; |
|
|
fclose(ficresp); |
fclose(ficresp); |
free_ma3x(freq,-1,nlstate+ndeath,-1,nlstate+ndeath,(int) agemin,(int) agemax+3); |
free_ma3x(freq,-1,nlstate+ndeath,-1,nlstate+ndeath, iagemin, iagemax+3); |
free_vector(pp,1,nlstate); |
free_vector(pp,1,nlstate); |
free_matrix(prop,1,nlstate,(int) agemin,(int) agemax+3); |
free_matrix(prop,1,nlstate,iagemin, iagemax+3); |
/* End of Freq */ |
/* End of Freq */ |
} |
} |
|
|
/************ Prevalence ********************/ |
/************ Prevalence ********************/ |
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, int firstpass, int lastpass) |
void prevalence(double agemin, double agemax, int **s, double **agev, int nlstate, int imx, int *Tvar, int **nbcode, int *ncodemax,double **mint,double **anint, double dateprev1,double dateprev2, int firstpass, int lastpass) |
{ |
{ |
/* Compute observed prevalence between dateprev1 and dateprev2 by counting the number of people |
/* Compute observed prevalence between dateprev1 and dateprev2 by counting the number of people |
in each health status at the date of interview (if between dateprev1 and dateprev2). |
in each health status at the date of interview (if between dateprev1 and dateprev2). |
Line 1602 void prevalence(int agemin, float agemax
|
Line 1636 void prevalence(int agemin, float agemax
|
double *pp, **prop; |
double *pp, **prop; |
double pos,posprop; |
double pos,posprop; |
double y2; /* in fractional years */ |
double y2; /* in fractional years */ |
|
int iagemin, iagemax; |
|
|
pp=vector(1,nlstate); |
iagemin= (int) agemin; |
prop=matrix(1,nlstate,agemin,agemax+3); |
iagemax= (int) agemax; |
freq=ma3x(-1,nlstate+ndeath,-1,nlstate+ndeath,agemin,agemax+3); |
/*pp=vector(1,nlstate);*/ |
|
prop=matrix(1,nlstate,iagemin,iagemax+3); |
|
/* freq=ma3x(-1,nlstate+ndeath,-1,nlstate+ndeath,iagemin,iagemax+3);*/ |
j1=0; |
j1=0; |
|
|
j=cptcoveff; |
j=cptcoveff; |
Line 1616 void prevalence(int agemin, float agemax
|
Line 1653 void prevalence(int agemin, float agemax
|
j1++; |
j1++; |
|
|
for (i=1; i<=nlstate; i++) |
for (i=1; i<=nlstate; i++) |
for(m=agemin; m <= agemax+3; m++) |
for(m=iagemin; m <= iagemax+3; m++) |
prop[i][m]=0; |
prop[i][m]=0.0; |
|
|
for (i=1; i<=imx; i++) { /* Each individual */ |
for (i=1; i<=imx; i++) { /* Each individual */ |
bool=1; |
bool=1; |
Line 1630 void prevalence(int agemin, float agemax
|
Line 1667 void prevalence(int agemin, float agemax
|
for(m=firstpass; m<=lastpass; m++){/* Other selection (we can limit to certain interviews*/ |
for(m=firstpass; m<=lastpass; m++){/* Other selection (we can limit to certain interviews*/ |
y2=anint[m][i]+(mint[m][i]/12.); /* Fractional date in year */ |
y2=anint[m][i]+(mint[m][i]/12.); /* Fractional date in year */ |
if ((y2>=dateprev1) && (y2<=dateprev2)) { /* Here is the main selection (fractional years) */ |
if ((y2>=dateprev1) && (y2<=dateprev2)) { /* Here is the main selection (fractional years) */ |
if(agev[m][i]==0) agev[m][i]=agemax+1; |
if(agev[m][i]==0) agev[m][i]=iagemax+1; |
if(agev[m][i]==1) agev[m][i]=agemax+2; |
if(agev[m][i]==1) agev[m][i]=iagemax+2; |
if (s[m][i]>0 && s[m][i]<=nlstate) { |
if((int)agev[m][i] <iagemin || (int)agev[m][i] >iagemax+3) printf("Error on individual =%d agev[m][i]=%f m=%d\n",i, agev[m][i],m); |
prop[s[m][i]][(int)agev[m][i]] += weight[i]; |
if (s[m][i]>0 && s[m][i]<=nlstate) { |
prop[s[m][i]][(int)(agemax+3)] += weight[i]; |
/*if(i>4620) printf(" i=%d m=%d s[m][i]=%d (int)agev[m][i]=%d weight[i]=%f prop=%f\n",i,m,s[m][i],(int)agev[m][m],weight[i],prop[s[m][i]][(int)agev[m][i]]);*/ |
} |
prop[s[m][i]][(int)agev[m][i]] += weight[i]; |
|
prop[s[m][i]][iagemax+3] += weight[i]; |
|
} |
} |
} |
} /* end selection of waves */ |
} /* end selection of waves */ |
} |
} |
} |
} |
for(i=(int)agemin; i <= (int)agemax+3; i++){ |
for(i=iagemin; i <= iagemax+3; i++){ |
|
|
for(jk=1,posprop=0; jk <=nlstate ; jk++) { |
for(jk=1,posprop=0; jk <=nlstate ; jk++) { |
posprop += prop[jk][i]; |
posprop += prop[jk][i]; |
} |
} |
|
|
for(jk=1; jk <=nlstate ; jk++){ |
for(jk=1; jk <=nlstate ; jk++){ |
if( i <= (int) agemax){ |
if( i <= iagemax){ |
if(posprop>=1.e-5){ |
if(posprop>=1.e-5){ |
probs[i][jk][j1]= prop[jk][i]/posprop; |
probs[i][jk][j1]= prop[jk][i]/posprop; |
} |
} |
} |
} |
}/* end jk */ |
}/* end jk */ |
}/* end i */ |
}/* end i */ |
} /* end i1 */ |
} /* end i1 */ |
} /* end k1 */ |
} /* end k1 */ |
|
|
|
|
free_ma3x(freq,-1,nlstate+ndeath,-1,nlstate+ndeath,(int) agemin,(int) agemax+3); |
/* free_ma3x(freq,-1,nlstate+ndeath,-1,nlstate+ndeath, iagemin, iagemax+3);*/ |
free_vector(pp,1,nlstate); |
/*free_vector(pp,1,nlstate);*/ |
free_matrix(prop,1,nlstate,(int) agemin,(int) agemax+3); |
free_matrix(prop,1,nlstate, iagemin,iagemax+3); |
} /* End of Freq */ |
} /* End of prevalence */ |
|
|
/************* Waves Concatenation ***************/ |
/************* Waves Concatenation ***************/ |
|
|
Line 1853 void evsij(char fileres[], double ***eij
|
Line 1891 void evsij(char fileres[], double ***eij
|
double ***gradg, ***trgradg; |
double ***gradg, ***trgradg; |
int theta; |
int theta; |
|
|
varhe=ma3x(1,nlstate*2,1,nlstate*2,(int) bage, (int) fage); |
varhe=ma3x(1,nlstate*nlstate,1,nlstate*nlstate,(int) bage, (int) fage); |
xp=vector(1,npar); |
xp=vector(1,npar); |
dnewm=matrix(1,nlstate*2,1,npar); |
dnewm=matrix(1,nlstate*nlstate,1,npar); |
doldm=matrix(1,nlstate*2,1,nlstate*2); |
doldm=matrix(1,nlstate*nlstate,1,nlstate*nlstate); |
|
|
fprintf(ficreseij,"# Health expectancies\n"); |
fprintf(ficreseij,"# Health expectancies\n"); |
fprintf(ficreseij,"# Age"); |
fprintf(ficreseij,"# Age"); |
Line 1902 void evsij(char fileres[], double ***eij
|
Line 1940 void evsij(char fileres[], double ***eij
|
/* if (stepm >= YEARM) hstepm=1;*/ |
/* if (stepm >= YEARM) hstepm=1;*/ |
nhstepm = nstepm/hstepm;/* Expressed in hstepm, typically nhstepm=40/4=10 */ |
nhstepm = nstepm/hstepm;/* Expressed in hstepm, typically nhstepm=40/4=10 */ |
p3mat=ma3x(1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm); |
p3mat=ma3x(1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm); |
gradg=ma3x(0,nhstepm,1,npar,1,nlstate*2); |
gradg=ma3x(0,nhstepm,1,npar,1,nlstate*nlstate); |
gp=matrix(0,nhstepm,1,nlstate*2); |
gp=matrix(0,nhstepm,1,nlstate*nlstate); |
gm=matrix(0,nhstepm,1,nlstate*2); |
gm=matrix(0,nhstepm,1,nlstate*nlstate); |
|
|
/* Computed by stepm unit matrices, product of hstepm matrices, stored |
/* Computed by stepm unit matrices, product of hstepm matrices, stored |
in an array of nhstepm length: nhstepm=10, hstepm=4, stepm=6 months */ |
in an array of nhstepm length: nhstepm=10, hstepm=4, stepm=6 months */ |
Line 1945 void evsij(char fileres[], double ***eij
|
Line 1983 void evsij(char fileres[], double ***eij
|
} |
} |
} |
} |
} |
} |
for(j=1; j<= nlstate*2; j++) |
for(j=1; j<= nlstate*nlstate; j++) |
for(h=0; h<=nhstepm-1; h++){ |
for(h=0; h<=nhstepm-1; h++){ |
gradg[h][theta][j]= (gp[h][j]-gm[h][j])/2./delti[theta]; |
gradg[h][theta][j]= (gp[h][j]-gm[h][j])/2./delti[theta]; |
} |
} |
Line 1953 void evsij(char fileres[], double ***eij
|
Line 1991 void evsij(char fileres[], double ***eij
|
|
|
/* End theta */ |
/* End theta */ |
|
|
trgradg =ma3x(0,nhstepm,1,nlstate*2,1,npar); |
trgradg =ma3x(0,nhstepm,1,nlstate*nlstate,1,npar); |
|
|
for(h=0; h<=nhstepm-1; h++) |
for(h=0; h<=nhstepm-1; h++) |
for(j=1; j<=nlstate*2;j++) |
for(j=1; j<=nlstate*nlstate;j++) |
for(theta=1; theta <=npar; theta++) |
for(theta=1; theta <=npar; theta++) |
trgradg[h][j][theta]=gradg[h][theta][j]; |
trgradg[h][j][theta]=gradg[h][theta][j]; |
|
|
|
|
for(i=1;i<=nlstate*2;i++) |
for(i=1;i<=nlstate*nlstate;i++) |
for(j=1;j<=nlstate*2;j++) |
for(j=1;j<=nlstate*nlstate;j++) |
varhe[i][j][(int)age] =0.; |
varhe[i][j][(int)age] =0.; |
|
|
printf("%d|",(int)age);fflush(stdout); |
printf("%d|",(int)age);fflush(stdout); |
fprintf(ficlog,"%d|",(int)age);fflush(ficlog); |
fprintf(ficlog,"%d|",(int)age);fflush(ficlog); |
for(h=0;h<=nhstepm-1;h++){ |
for(h=0;h<=nhstepm-1;h++){ |
for(k=0;k<=nhstepm-1;k++){ |
for(k=0;k<=nhstepm-1;k++){ |
matprod2(dnewm,trgradg[h],1,nlstate*2,1,npar,1,npar,matcov); |
matprod2(dnewm,trgradg[h],1,nlstate*nlstate,1,npar,1,npar,matcov); |
matprod2(doldm,dnewm,1,nlstate*2,1,npar,1,nlstate*2,gradg[k]); |
matprod2(doldm,dnewm,1,nlstate*nlstate,1,npar,1,nlstate*nlstate,gradg[k]); |
for(i=1;i<=nlstate*2;i++) |
for(i=1;i<=nlstate*nlstate;i++) |
for(j=1;j<=nlstate*2;j++) |
for(j=1;j<=nlstate*nlstate;j++) |
varhe[i][j][(int)age] += doldm[i][j]*hf*hf; |
varhe[i][j][(int)age] += doldm[i][j]*hf*hf; |
} |
} |
} |
} |
Line 1995 void evsij(char fileres[], double ***eij
|
Line 2033 void evsij(char fileres[], double ***eij
|
} |
} |
fprintf(ficreseij,"\n"); |
fprintf(ficreseij,"\n"); |
|
|
free_matrix(gm,0,nhstepm,1,nlstate*2); |
free_matrix(gm,0,nhstepm,1,nlstate*nlstate); |
free_matrix(gp,0,nhstepm,1,nlstate*2); |
free_matrix(gp,0,nhstepm,1,nlstate*nlstate); |
free_ma3x(gradg,0,nhstepm,1,npar,1,nlstate*2); |
free_ma3x(gradg,0,nhstepm,1,npar,1,nlstate*nlstate); |
free_ma3x(trgradg,0,nhstepm,1,nlstate*2,1,npar); |
free_ma3x(trgradg,0,nhstepm,1,nlstate*nlstate,1,npar); |
free_ma3x(p3mat,1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm); |
free_ma3x(p3mat,1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm); |
} |
} |
printf("\n"); |
printf("\n"); |
fprintf(ficlog,"\n"); |
fprintf(ficlog,"\n"); |
|
|
free_vector(xp,1,npar); |
free_vector(xp,1,npar); |
free_matrix(dnewm,1,nlstate*2,1,npar); |
free_matrix(dnewm,1,nlstate*nlstate,1,npar); |
free_matrix(doldm,1,nlstate*2,1,nlstate*2); |
free_matrix(doldm,1,nlstate*nlstate,1,nlstate*nlstate); |
free_ma3x(varhe,1,nlstate*2,1,nlstate*2,(int) bage, (int)fage); |
free_ma3x(varhe,1,nlstate*nlstate,1,nlstate*nlstate,(int) bage, (int)fage); |
} |
} |
|
|
/************ Variance ******************/ |
/************ Variance ******************/ |
Line 2542 void varprob(char optionfilefiname[], do
|
Line 2580 void varprob(char optionfilefiname[], do
|
|
|
for(theta=1; theta <=npar; theta++){ |
for(theta=1; theta <=npar; theta++){ |
for(i=1; i<=npar; i++) |
for(i=1; i<=npar; i++) |
xp[i] = x[i] + (i==theta ?delti[theta]:0); |
xp[i] = x[i] + (i==theta ?delti[theta]:(double)0); |
|
|
pmij(pmmij,cov,ncovmodel,xp,nlstate); |
pmij(pmmij,cov,ncovmodel,xp,nlstate); |
|
|
Line 2555 void varprob(char optionfilefiname[], do
|
Line 2593 void varprob(char optionfilefiname[], do
|
} |
} |
|
|
for(i=1; i<=npar; i++) |
for(i=1; i<=npar; i++) |
xp[i] = x[i] - (i==theta ?delti[theta]:0); |
xp[i] = x[i] - (i==theta ?delti[theta]:(double)0); |
|
|
pmij(pmmij,cov,ncovmodel,xp,nlstate); |
pmij(pmmij,cov,ncovmodel,xp,nlstate); |
k=0; |
k=0; |
Line 2567 void varprob(char optionfilefiname[], do
|
Line 2605 void varprob(char optionfilefiname[], do
|
} |
} |
|
|
for(i=1; i<= (nlstate)*(nlstate+ndeath); i++) |
for(i=1; i<= (nlstate)*(nlstate+ndeath); i++) |
gradg[theta][i]=(gp[i]-gm[i])/2./delti[theta]; |
gradg[theta][i]=(gp[i]-gm[i])/(double)2./delti[theta]; |
} |
} |
|
|
for(j=1; j<=(nlstate)*(nlstate+ndeath);j++) |
for(j=1; j<=(nlstate)*(nlstate+ndeath);j++) |
Line 3077 prevforecast(char fileres[], double anpr
|
Line 3115 prevforecast(char fileres[], double anpr
|
|
|
stepsize=(int) (stepm+YEARM-1)/YEARM; |
stepsize=(int) (stepm+YEARM-1)/YEARM; |
if (stepm<=12) stepsize=1; |
if (stepm<=12) stepsize=1; |
|
if(estepm < stepm){ |
hstepm=1; |
printf ("Problem %d lower than %d\n",estepm, stepm); |
|
} |
|
else hstepm=estepm; |
|
|
hstepm=hstepm/stepm; |
hstepm=hstepm/stepm; |
yp1=modf(dateintmean,&yp);/* extracts integral of datemean in yp and |
yp1=modf(dateintmean,&yp);/* extracts integral of datemean in yp and |
fractional in yp1 */ |
fractional in yp1 */ |
Line 3111 prevforecast(char fileres[], double anpr
|
Line 3152 prevforecast(char fileres[], double anpr
|
fprintf(ficresf," p%d%d",i,j); |
fprintf(ficresf," p%d%d",i,j); |
fprintf(ficresf," p.%d",j); |
fprintf(ficresf," p.%d",j); |
} |
} |
for (yearp=0; yearp<=(anproj2-anproj1);yearp++) { |
for (yearp=0; yearp<=(anproj2-anproj1);yearp +=stepsize) { |
fprintf(ficresf,"\n"); |
fprintf(ficresf,"\n"); |
fprintf(ficresf,"\n# Forecasting at date %.lf/%.lf/%.lf ",jproj1,mproj1,anproj1+yearp); |
fprintf(ficresf,"\n# Forecasting at date %.lf/%.lf/%.lf ",jproj1,mproj1,anproj1+yearp); |
|
|
Line 3323 populforecast(char fileres[], double anp
|
Line 3364 populforecast(char fileres[], double anp
|
int main(int argc, char *argv[]) |
int main(int argc, char *argv[]) |
{ |
{ |
int movingaverage(double ***probs, double bage,double fage, double ***mobaverage, int mobilav); |
int movingaverage(double ***probs, double bage,double fage, double ***mobaverage, int mobilav); |
int i,j, k, n=MAXN,iter,m,size,cptcode, cptcod; |
int i,j, k, n=MAXN,iter,m,size=100,cptcode, cptcod; |
double agedeb, agefin,hf; |
double agedeb, agefin,hf; |
double ageminpar=1.e20,agemin=1.e20, agemaxpar=-1.e20, agemax=-1.e20; |
double ageminpar=1.e20,agemin=1.e20, agemaxpar=-1.e20, agemax=-1.e20; |
|
|
Line 3345 int main(int argc, char *argv[])
|
Line 3386 int main(int argc, char *argv[])
|
int mobilavproj=0 , prevfcast=0 ; /* moving average of prev, If prevfcast=1 prevalence projection */ |
int mobilavproj=0 , prevfcast=0 ; /* moving average of prev, If prevfcast=1 prevalence projection */ |
int mobilav=0,popforecast=0; |
int mobilav=0,popforecast=0; |
int hstepm, nhstepm; |
int hstepm, nhstepm; |
double jprev1, mprev1,anprev1,jprev2, mprev2,anprev2,jpyram, mpyram,anpyram,jpyram1, mpyram1,anpyram1; |
double jprev1=1, mprev1=1,anprev1=2000,jprev2=1, mprev2=1,anprev2=2000; |
|
double jpyram=1, mpyram=1,anpyram=2000,jpyram1=1, mpyram1=1,anpyram1=2000; |
|
|
double bage, fage, age, agelim, agebase; |
double bage, fage, age, agelim, agebase; |
double ftolpl=FTOL; |
double ftolpl=FTOL; |
Line 3360 int main(int argc, char *argv[])
|
Line 3402 int main(int argc, char *argv[])
|
double **varpl; /* Variances of prevalence limits by age */ |
double **varpl; /* Variances of prevalence limits by age */ |
double *epj, vepp; |
double *epj, vepp; |
double kk1, kk2; |
double kk1, kk2; |
double dateprev1, dateprev2,jproj1,mproj1,anproj1,jproj2,mproj2,anproj2; |
double dateprev1, dateprev2,jproj1=1,mproj1=1,anproj1=2000,jproj2=1,mproj2=1,anproj2=2000; |
|
|
char *alph[]={"a","a","b","c","d","e"}, str[4]; |
char *alph[]={"a","a","b","c","d","e"}, str[4]; |
|
|
Line 3507 int main(int argc, char *argv[])
|
Line 3549 int main(int argc, char *argv[])
|
ungetc(c,ficpar); |
ungetc(c,ficpar); |
|
|
delti3= ma3x(1,nlstate,1,nlstate+ndeath-1,1,ncovmodel); |
delti3= ma3x(1,nlstate,1,nlstate+ndeath-1,1,ncovmodel); |
delti=vector(1,npar); /* Scale of each paramater (output from hesscov) */ |
/* delti=vector(1,npar); *//* Scale of each paramater (output from hesscov) */ |
for(i=1; i <=nlstate; i++){ |
for(i=1; i <=nlstate; i++){ |
for(j=1; j <=nlstate+ndeath-1; j++){ |
for(j=1; j <=nlstate+ndeath-1; j++){ |
fscanf(ficpar,"%1d%1d",&i1,&j1); |
fscanf(ficpar,"%1d%1d",&i1,&j1); |
Line 3524 int main(int argc, char *argv[])
|
Line 3566 int main(int argc, char *argv[])
|
} |
} |
} |
} |
delti=delti3[1][1]; |
delti=delti3[1][1]; |
|
|
|
|
|
/* free_ma3x(delti3,1,nlstate,1,nlstate+ndeath-1,1,ncovmodel); */ /* Hasn't to to freed here otherwise delti is no more allocated */ |
|
|
/* Reads comments: lines beginning with '#' */ |
/* Reads comments: lines beginning with '#' */ |
while((c=getc(ficpar))=='#' && c!= EOF){ |
while((c=getc(ficpar))=='#' && c!= EOF){ |
Line 4038 int main(int argc, char *argv[])
|
Line 4083 int main(int argc, char *argv[])
|
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(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); |
fprintf(ficres,"popforecast=%d popfile=%s popfiledate=%.lf/%.lf/%.lf last-popfiledate=%.lf/%.lf/%.lf\n",popforecast,popfile,jpyram,mpyram,anpyram,jpyram1,mpyram1,anpyram1); |
|
|
|
probs= ma3x(1,AGESUP,1,NCOVMAX, 1,NCOVMAX); |
freqsummary(fileres, agemin, agemax, s, agev, nlstate, imx,Tvaraff,nbcode, ncodemax,mint,anint,dateprev1,dateprev2,jprev1, mprev1,anprev1,jprev2, mprev2,anprev2); |
freqsummary(fileres, agemin, agemax, s, agev, nlstate, imx,Tvaraff,nbcode, ncodemax,mint,anint,dateprev1,dateprev2,jprev1, mprev1,anprev1,jprev2, mprev2,anprev2); |
|
|
/*------------ gnuplot -------------*/ |
/*------------ gnuplot -------------*/ |
Line 4071 Interval (in months) between two waves:
|
Line 4117 Interval (in months) between two waves:
|
- Copy of the parameter file: <a href=\"o%s\">o%s</a><br>\n |
- Copy of the parameter file: <a href=\"o%s\">o%s</a><br>\n |
- Log file of the run: <a href=\"%s\">%s</a><br>\n |
- Log file of the run: <a href=\"%s\">%s</a><br>\n |
- Gnuplot file name: <a href=\"%s\">%s</a></ul>\n",version,title,datafile,firstpass,lastpass,stepm, weightopt,model,imx,jmin,jmax,jmean,fileres,fileres,filelog,filelog,optionfilegnuplot,optionfilegnuplot); |
- Gnuplot file name: <a href=\"%s\">%s</a></ul>\n",version,title,datafile,firstpass,lastpass,stepm, weightopt,model,imx,jmin,jmax,jmean,fileres,fileres,filelog,filelog,optionfilegnuplot,optionfilegnuplot); |
fclose(fichtm); |
fclose(fichtm); |
|
|
printinghtml(fileres,title,datafile, firstpass, lastpass, stepm, weightopt,model,imx,jmin,jmax,jmean,rfileres,popforecast,estepm,jprev1,mprev1,anprev1,jprev2,mprev2,anprev2); |
printinghtml(fileres,title,datafile, firstpass, lastpass, stepm, weightopt,model,imx,jmin,jmax,jmean,rfileres,popforecast,estepm,jprev1,mprev1,anprev1,jprev2,mprev2,anprev2); |
|
|
Line 4197 Interval (in months) between two waves:
|
Line 4243 Interval (in months) between two waves:
|
} |
} |
} |
} |
|
|
varprob(optionfilefiname, matcov, p, delti, nlstate, (int) bage, (int) fage,k,Tvar,nbcode, ncodemax); |
varprob(optionfilefiname, matcov, p, delti, nlstate, bage, fage,k,Tvar,nbcode, ncodemax); |
|
|
fclose(ficrespij); |
fclose(ficrespij); |
|
|
Line 4205 Interval (in months) between two waves:
|
Line 4251 Interval (in months) between two waves:
|
/*---------- Forecasting ------------------*/ |
/*---------- Forecasting ------------------*/ |
/*if((stepm == 1) && (strcmp(model,".")==0)){*/ |
/*if((stepm == 1) && (strcmp(model,".")==0)){*/ |
if(prevfcast==1){ |
if(prevfcast==1){ |
if(stepm ==1){ |
/* if(stepm ==1){*/ |
prevforecast(fileres, anproj1, mproj1, jproj1, agemin, agemax, dateprev1, dateprev2, mobilavproj, bage, fage, firstpass, lastpass, anproj2, p, cptcoveff); |
prevforecast(fileres, anproj1, mproj1, jproj1, agemin, agemax, dateprev1, dateprev2, mobilavproj, bage, fage, firstpass, lastpass, anproj2, p, cptcoveff); |
if (popforecast==1) populforecast(fileres, anpyram,mpyram,jpyram, agemin,agemax, dateprev1, dateprev2,mobilav, agedeb, fage, popforecast, popfile, anpyram1,p, i1); |
/* (popforecast==1) populforecast(fileres, anpyram,mpyram,jpyram, agemin,agemax, dateprev1, dateprev2,mobilav, agedeb, fage, popforecast, popfile, anpyram1,p, i1);*/ |
} |
/* } */ |
else{ |
/* else{ */ |
erreur=108; |
/* erreur=108; */ |
printf("Warning %d!! You can only forecast the prevalences if the optimization\n has been performed with stepm = 1 (month) instead of %d or model=. instead of '%s'\n", erreur, stepm, model); |
/* printf("Warning %d!! You can only forecast the prevalences if the optimization\n has been performed with stepm = 1 (month) instead of %d or model=. instead of '%s'\n", erreur, stepm, model); */ |
fprintf(ficlog,"Warning %d!! You can only forecast the prevalences if the optimization\n has been performed with stepm = 1 (month) instead of %d or model=. instead of '%s'\n", erreur, stepm, model); |
/* fprintf(ficlog,"Warning %d!! You can only forecast the prevalences if the optimization\n has been performed with stepm = 1 (month) instead of %d or model=. instead of '%s'\n", erreur, stepm, model); */ |
} |
/* } */ |
} |
} |
|
|
|
|
Line 4247 Interval (in months) between two waves:
|
Line 4293 Interval (in months) between two waves:
|
printf("Computing Variance-covariance of DFLEs: file '%s' \n", fileresv); |
printf("Computing Variance-covariance of DFLEs: file '%s' \n", fileresv); |
fprintf(ficlog,"Computing Variance-covariance of DFLEs: file '%s' \n", fileresv); |
fprintf(ficlog,"Computing Variance-covariance of DFLEs: file '%s' \n", fileresv); |
|
|
prevalence(ageminpar, agemax, s, agev, nlstate, imx, Tvar, nbcode, ncodemax, mint, anint, dateprev1, dateprev2, firstpass, lastpass); |
/* Computes prevalence between agemin (i.e minimal age computed) and no more ageminpar */ |
|
prevalence(agemin, agemax, s, agev, nlstate, imx, Tvar, nbcode, ncodemax, mint, anint, dateprev1, dateprev2, firstpass, lastpass); |
|
/* printf("ageminpar=%f, agemax=%f, s[lastpass][imx]=%d, agev[lastpass][imx]=%f, nlstate=%d, imx=%d, mint[lastpass][imx]=%f, anint[lastpass][imx]=%f,dateprev1=%f, dateprev2=%f, firstpass=%d, lastpass=%d\n",\ |
|
ageminpar, agemax, s[lastpass][imx], agev[lastpass][imx], nlstate, imx, mint[lastpass][imx],anint[lastpass][imx], dateprev1, dateprev2, firstpass, lastpass); |
|
*/ |
|
|
if (mobilav!=0) { |
if (mobilav!=0) { |
mobaverage= ma3x(1, AGESUP,1,NCOVMAX, 1,NCOVMAX); |
mobaverage= ma3x(1, AGESUP,1,NCOVMAX, 1,NCOVMAX); |
Line 4374 Interval (in months) between two waves:
|
Line 4424 Interval (in months) between two waves:
|
|
|
free_matrix(covar,0,NCOVMAX,1,n); |
free_matrix(covar,0,NCOVMAX,1,n); |
free_matrix(matcov,1,npar,1,npar); |
free_matrix(matcov,1,npar,1,npar); |
free_vector(delti,1,npar); |
/*free_vector(delti,1,npar);*/ |
|
free_ma3x(delti3,1,nlstate,1, nlstate+ndeath-1,1,ncovmodel); |
free_matrix(agev,1,maxwav,1,imx); |
free_matrix(agev,1,maxwav,1,imx); |
free_ma3x(param,1,nlstate,1, nlstate+ndeath-1,1,ncovmodel); |
free_ma3x(param,1,nlstate,1, nlstate+ndeath-1,1,ncovmodel); |
if (mobilav!=0) free_ma3x(mobaverage,1, AGESUP,1,NCOVMAX, 1,NCOVMAX); |
if (mobilav!=0) free_ma3x(mobaverage,1, AGESUP,1,NCOVMAX, 1,NCOVMAX); |
|
free_ma3x(probs,1,AGESUP,1,NCOVMAX, 1,NCOVMAX); |
|
|
free_ivector(ncodemax,1,8); |
free_ivector(ncodemax,1,8); |
free_ivector(Tvar,1,15); |
free_ivector(Tvar,1,15); |
free_ivector(Tprod,1,15); |
free_ivector(Tprod,1,15); |
Line 4385 Interval (in months) between two waves:
|
Line 4438 Interval (in months) between two waves:
|
free_ivector(Tage,1,15); |
free_ivector(Tage,1,15); |
free_ivector(Tcode,1,100); |
free_ivector(Tcode,1,100); |
|
|
fprintf(fichtm,"\n</body>"); |
/* fclose(fichtm);*/ |
fclose(fichtm); |
/* fclose(ficgp);*/ /* ALready done */ |
fclose(ficgp); |
|
|
|
|
|
if(erreur >0){ |
if(erreur >0){ |