|
|
| version 1.16, 2002/02/20 17:12:32 | version 1.18, 2002/02/20 17:17:09 |
|---|---|
| Line 1150 void lubksb(double **a, int n, int *indx | Line 1150 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 *Tvar, int **nbcode, int *ncodemax, int fprev1,int lprev1) | 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) |
| { /* 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; |
| double ***freq; /* Frequencies */ | double ***freq; /* Frequencies */ |
| double *pp; | double *pp; |
| double pos; | double pos, k2; |
| FILE *ficresp; | FILE *ficresp; |
| char fileresp[FILENAMELENGTH]; | char fileresp[FILENAMELENGTH]; |
| pp=vector(1,nlstate); | pp=vector(1,nlstate); |
| probs= ma3x(1,130 ,1,8, 1,8); | probs= ma3x(1,130 ,1,8, 1,8); |
| 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 1191 void freqsummary(char fileres[], int ag | Line 1191 void freqsummary(char fileres[], int ag |
| if (covar[Tvaraff[z1]][i]!= nbcode[Tvaraff[z1]][codtab[j1][z1]]) | if (covar[Tvaraff[z1]][i]!= nbcode[Tvaraff[z1]][codtab[j1][z1]]) |
| bool=0; | bool=0; |
| } | } |
| if (bool==1) { | if (bool==1) { |
| for(m=fprev1; m<=lprev1; m++){ | if (boolprev==1){ |
| for(m=fprev1; m<=lprev1; m++){ | |
| 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]] += weight[i]; | |
| freq[s[m][i]][s[m+1][i]][(int) agemax+3] += weight[i]; | |
| } | |
| } | |
| else { | |
| for(m=firstpass; m<=lastpass; m++){ | |
| k2=anint[m][i]+(mint[m][i]/12.); | |
| if ((k2>=dateprev1) && (k2<=dateprev2)) { | |
| if(agev[m][i]==0) agev[m][i]=agemax+1; | if(agev[m][i]==0) agev[m][i]=agemax+1; |
| if(agev[m][i]==1) agev[m][i]=agemax+2; | if(agev[m][i]==1) agev[m][i]=agemax+2; |
| 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]][(int) agemax+3] += weight[i]; |
| } | |
| } | |
| } | } |
| } | } |
| } | } |
| if (cptcovn>0) { | if (cptcovn>0) { |
| fprintf(ficresp, "\n#********** Variable "); | fprintf(ficresp, "\n#********** Variable "); |
| Line 1266 void freqsummary(char fileres[], int ag | Line 1279 void freqsummary(char fileres[], int ag |
| } /* End of Freq */ | } /* End of Freq */ |
| /************ Prevalence ********************/ | /************ Prevalence ********************/ |
| void prevalence(int agemin, int agemax, int **s, double **agev, int nlstate, int imx, int *Tvar, int **nbcode, int *ncodemax, int fprev1,int lprev1) | 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) |
| { /* 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; |
| double ***freq; /* Frequencies */ | double ***freq; /* Frequencies */ |
| double *pp; | double *pp; |
| double pos; | double pos, k2; |
| pp=vector(1,nlstate); | pp=vector(1,nlstate); |
| probs= ma3x(1,130 ,1,8, 1,8); | probs= ma3x(1,130 ,1,8, 1,8); |
| Line 1300 void prevalence(int agemin, int agemax, | Line 1313 void prevalence(int agemin, int agemax, |
| bool=0; | bool=0; |
| } | } |
| if (bool==1) { | if (bool==1) { |
| for(m=fprev1; m<=lprev1; m++){ | if (boolprev==1){ |
| if(agev[m][i]==0) agev[m][i]=agemax+1; | for(m=fprev1; m<=lprev1; m++){ |
| if(agev[m][i]==1) agev[m][i]=agemax+2; | if(agev[m][i]==0) agev[m][i]=agemax+1; |
| freq[s[m][i]][s[m+1][i]][(int)agev[m][i]] += weight[i]; | if(agev[m][i]==1) agev[m][i]=agemax+2; |
| freq[s[m][i]][s[m+1][i]][(int) agemax+3] += 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]; | |
| } | |
| } | |
| else { | |
| for(m=firstpass; m<=lastpass; m++){ | |
| k2=anint[m][i]+(mint[m][i]/12.); | |
| if ((k2>=dateprev1) && (k2<=dateprev2)) { | |
| 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]] += weight[i]; | |
| freq[s[m][i]][s[m+1][i]][(int) agemax+3] += weight[i]; | |
| } | |
| } | |
| } | } |
| } | } |
| } | } |
| for(i=(int)agemin; i <= (int)agemax+3; i++){ | for(i=(int)agemin; i <= (int)agemax+3; i++){ |
| for(jk=1; jk <=nlstate ; jk++){ | for(jk=1; jk <=nlstate ; jk++){ |
| for(m=-1, pp[jk]=0; m <=nlstate+ndeath ; m++) | for(m=-1, pp[jk]=0; m <=nlstate+ndeath ; m++) |
| pp[jk] += freq[jk][m][i]; | pp[jk] += freq[jk][m][i]; |
| } | } |
| for(jk=1; jk <=nlstate ; jk++){ | for(jk=1; jk <=nlstate ; jk++){ |
| for(m=-1, pos=0; m <=0 ; m++) | for(m=-1, pos=0; m <=0 ; m++) |
| pos += freq[jk][m][i]; | pos += freq[jk][m][i]; |
| } | } |
| Line 1333 void prevalence(int agemin, int agemax, | Line 1359 void prevalence(int agemin, int agemax, |
| } | } |
| } | } |
| } | } |
| } | } |
| } | } |
| Line 1870 int main() | Line 1896 int main() |
| int jnais,jdc,jint4,jint1,jint2,jint3,**outcome,**adl,*tab; | int jnais,jdc,jint4,jint1,jint2,jint3,**outcome,**adl,*tab; |
| int mobilav=0, fprev, lprev ,fprevfore=1, lprevfore=1,nforecast,popforecast=0; | int mobilav=0, fprev, lprev ,fprevfore=1, lprevfore=1,nforecast,popforecast=0; |
| int hstepm, nhstepm; | int hstepm, nhstepm; |
| int *popage; | int *popage,boolprev=0;/*boolprev=0 if date and zero if wave*/ |
| double bage, fage, age, agelim, agebase; | double bage, fage, age, agelim, agebase; |
| double ftolpl=FTOL; | double ftolpl=FTOL; |
| Line 1886 int main() | Line 1912 int main() |
| double *epj, vepp; | double *epj, vepp; |
| double kk1, kk2; | double kk1, kk2; |
| double *popeffectif,*popcount; | double *popeffectif,*popcount; |
| double dateprev1, dateprev2; | |
| char version[80]="Imach version 64b, May 2001, INED-EUROREVES "; | char version[80]="Imach version 64b, May 2001, INED-EUROREVES "; |
| char *alph[]={"a","a","b","c","d","e"}, str[4]; | char *alph[]={"a","a","b","c","d","e"}, str[4]; |
| Line 1895 int main() | Line 1922 int main() |
| #include <sys/time.h> | #include <sys/time.h> |
| #include <time.h> | #include <time.h> |
| char stra[80], strb[80], strc[80], strd[80],stre[80],modelsav[80]; | char stra[80], strb[80], strc[80], strd[80],stre[80],modelsav[80]; |
| char strfprev[10], strlprev[10]; | |
| char strfprevfore[10], strlprevfore[10]; | |
| /* long total_usecs; | /* long total_usecs; |
| struct timeval start_time, end_time; | struct timeval start_time, end_time; |
| Line 1957 while((c=getc(ficpar))=='#' && c!= EOF){ | Line 1986 while((c=getc(ficpar))=='#' && c!= EOF){ |
| } | } |
| ungetc(c,ficpar); | ungetc(c,ficpar); |
| fscanf(ficpar,"fprevalence=%d lprevalence=%d pop_based=%d\n",&fprev,&lprev,&popbased); | fscanf(ficpar,"fprevalence=%s lprevalence=%s pop_based=%d\n",strfprev,strlprev,&popbased); |
| fprintf(ficparo,"fprevalence=%d lprevalence=%d pop_based=%d\n",fprev,lprev,popbased); | fprintf(ficparo,"fprevalence=%s lprevalence=%s pop_based=%d\n",strfprev,strlprev,popbased); |
| /* printf("%s %s",strfprev,strlprev); | |
| exit(0);*/ | |
| while((c=getc(ficpar))=='#' && c!= EOF){ | while((c=getc(ficpar))=='#' && c!= EOF){ |
| ungetc(c,ficpar); | ungetc(c,ficpar); |
| fgets(line, MAXLINE, ficpar); | fgets(line, MAXLINE, ficpar); |
| Line 1968 while((c=getc(ficpar))=='#' && c!= EOF){ | Line 1999 while((c=getc(ficpar))=='#' && c!= EOF){ |
| } | } |
| ungetc(c,ficpar); | ungetc(c,ficpar); |
| fscanf(ficpar,"fprevalence=%d lprevalence=%d nforecast=%d mob_average=%d\n",&fprevfore,&lprevfore,&nforecast,&mobilav); | fscanf(ficpar,"fprevalence=%s lprevalence=%s nforecast=%d mob_average=%d\n",strfprevfore,strlprevfore,&nforecast,&mobilav); |
| fprintf(ficparo,"fprevalence=%d lprevalence=%d nforecast=%d mob_average=%d\n",fprevfore,lprevfore,nforecast,mobilav); | fprintf(ficparo,"fprevalence=%s lprevalence=%s nforecast=%d mob_average=%d\n",strfprevfore,strlprevfore,nforecast,mobilav); |
| while((c=getc(ficpar))=='#' && c!= EOF){ | while((c=getc(ficpar))=='#' && c!= EOF){ |
| Line 2290 printf("Total number of individuals= %d, | Line 2321 printf("Total number of individuals= %d, |
| free_imatrix(outcome,1,maxwav+1,1,n); | free_imatrix(outcome,1,maxwav+1,1,n); |
| free_vector(moisnais,1,n); | free_vector(moisnais,1,n); |
| free_vector(annais,1,n); | free_vector(annais,1,n); |
| free_matrix(mint,1,maxwav,1,n); | /* free_matrix(mint,1,maxwav,1,n); |
| free_matrix(anint,1,maxwav,1,n); | free_matrix(anint,1,maxwav,1,n);*/ |
| free_vector(moisdc,1,n); | free_vector(moisdc,1,n); |
| free_vector(andc,1,n); | free_vector(andc,1,n); |
| Line 2323 printf("Total number of individuals= %d, | Line 2354 printf("Total number of individuals= %d, |
| } | } |
| } | } |
| } | } |
| /*for(i=1; i <=m ;i++){ | |
| for(k=1; k <=cptcovn; k++){ | |
| printf("i=%d k=%d %d %d",i,k,codtab[i][k], cptcoveff); | |
| } | |
| printf("\n"); | |
| } | |
| scanf("%d",i);*/ | |
| /* Calculates basic frequencies. Computes observed prevalence at single age | /* Calculates basic frequencies. Computes observed prevalence at single age |
| and prints on file fileres'p'. */ | and prints on file fileres'p'. */ |
| freqsummary(fileres, agemin, agemax, s, agev, nlstate, imx,Tvar,nbcode, ncodemax, fprev, lprev); | |
| pmmij= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */ | if ((nbocc(strfprev,'/')==1) && (nbocc(strlprev,'/')==1)){ |
| boolprev=0; | |
| cutv(stra,strb,strfprev,'/'); | |
| dateprev1=(double)(atoi(strb)+atoi(stra)/12.); | |
| cutv(stra,strb,strlprev,'/'); | |
| dateprev2=(double)(atoi(strb)+atoi(stra)/12.); | |
| } | |
| else if ((nbocc(strfprev,'/')==0) &&(nbocc(strlprev,'/')==0)){ | |
| boolprev=1; | |
| fprev=atoi(strfprev); lprev=atoi(strlprev); | |
| } | |
| else { | |
| printf("Error in statement lprevalence or fprevalence\n"); | |
| goto end; | |
| } | |
| freqsummary(fileres, agemin, agemax, s, agev, nlstate, imx,Tvar,nbcode, ncodemax, fprev, lprev,mint,anint,boolprev,dateprev1,dateprev2); | |
| pmmij= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */ | |
| oldms= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */ | oldms= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */ |
| newms= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */ | newms= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */ |
| savms= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */ | savms= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */ |
| Line 2353 printf("Total number of individuals= %d, | Line 2393 printf("Total number of individuals= %d, |
| /*--------- results files --------------*/ | /*--------- 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=%d weight=%d\nmodel=%s\n", title, datafile, lastobs, firstpass,lastpass,ftol, stepm, ncov, nlstate, ndeath, maxwav, mle,weightopt,model); |
| fprintf(ficres,"fprevalence=%d lprevalence=%d pop_based=%d\n",fprev,lprev,popbased); | fprintf(ficres,"fprevalence=%s lprevalence=%s pop_based=%d\n",strfprev,strlprev,popbased); |
| fprintf(ficres,"fprevalence=%d lprevalence=%d nforecast=%d mob_average=%d\n",fprevfore,lprevfore,nforecast,mobilav); | fprintf(ficres,"fprevalence=%s lprevalence=%s nforecast=%d mob_average=%d\n",strfprevfore,strlprevfore,nforecast,mobilav); |
| jk=1; | jk=1; |
| fprintf(ficres,"# Parameters\n"); | fprintf(ficres,"# Parameters\n"); |
| Line 2396 printf("Total number of individuals= %d, | Line 2436 printf("Total number of individuals= %d, |
| fprintf(ficres,"\n"); | fprintf(ficres,"\n"); |
| } | } |
| } | } |
| } | } |
| k=1; | k=1; |
| fprintf(ficres,"# Covariance\n"); | fprintf(ficres,"# Covariance\n"); |
| Line 2652 Interval (in months) between two waves: | Line 2692 Interval (in months) between two waves: |
| - Variances of life expectancies by age and initial health status: <a href=\"v%s\">v%s</a><br> | - Variances of life expectancies by age and initial health status: <a href=\"v%s\">v%s</a><br> |
| - Health expectancies with their variances: <a href=\"t%s\">t%s</a> <br> | - Health expectancies with their variances: <a href=\"t%s\">t%s</a> <br> |
| - Standard deviation of stationary prevalences: <a href=\"vpl%s\">vpl%s</a> <br> | - Standard deviation of stationary prevalences: <a href=\"vpl%s\">vpl%s</a> <br> |
| - Prevalences forecasting: <a href=\"f%s\">f%s</a> <br> | - Prevalences and population forecasting: <a href=\"f%s\">f%s</a> <br> |
| <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); | <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); |
| fprintf(fichtm," <li>Graphs</li><p>"); | fprintf(fichtm," <li>Graphs</li><p>"); |
| Line 2800 fclose(fichtm); | Line 2840 fclose(fichtm); |
| } | } |
| printf("Computing forecasting: result on file '%s' \n", fileresf); | printf("Computing forecasting: result on file '%s' \n", fileresf); |
| prevalence(agemin, agemax, s, agev, nlstate, imx,Tvar,nbcode, ncodemax, fprevfore, lprevfore); | if ((nbocc(strfprevfore,'/')==1) && (nbocc(strlprevfore,'/')==1)){ |
| boolprev=0; | |
| cutv(stra,strb,strfprevfore,'/'); | |
| dateprev1=(double)(atoi(strb)+atoi(stra)/12.); | |
| cutv(stra,strb,strlprevfore,'/'); | |
| dateprev2=(double)(atoi(strb)+atoi(stra)/12.); | |
| } | |
| else if ((nbocc(strfprevfore,'/')==0) &&(nbocc(strlprevfore,'/')==0)){ | |
| boolprev=1; | |
| fprev=atoi(strfprevfore); lprev=atoi(strlprevfore); | |
| } | |
| else { | |
| printf("Error in statement lprevalence or fprevalence\n"); | |
| goto end; | |
| } | |
| free_matrix(agev,1,maxwav,1,imx); | prevalence(agemin, agemax, s, agev, nlstate, imx,Tvar,nbcode, ncodemax, fprevfore, lprevfore,mint,anint,boolprev,dateprev1,dateprev2); |
| free_matrix(mint,1,maxwav,1,n); | |
| free_matrix(anint,1,maxwav,1,n); | |
| free_matrix(agev,1,maxwav,1,imx); | |
| /* Mobile average */ | /* Mobile average */ |
| if (cptcoveff==0) ncodemax[cptcoveff]=1; | if (cptcoveff==0) ncodemax[cptcoveff]=1; |