--- imach/src/imach.c 2015/11/17 14:31:57 1.208 +++ imach/src/imach.c 2015/12/11 18:22:17 1.213 @@ -1,6 +1,30 @@ -/* $Id: imach.c,v 1.208 2015/11/17 14:31:57 brouard Exp $ +/* $Id: imach.c,v 1.213 2015/12/11 18:22:17 brouard Exp $ $State: Exp $ $Log: imach.c,v $ + Revision 1.213 2015/12/11 18:22:17 brouard + Summary: 0.98r4 + + Revision 1.212 2015/11/21 12:47:24 brouard + Summary: minor typo + + Revision 1.211 2015/11/21 12:41:11 brouard + Summary: 0.98r3 with some graph of projected cross-sectional + + Author: Nicolas Brouard + + Revision 1.210 2015/11/18 17:41:20 brouard + Summary: Start working on projected prevalences + + Revision 1.209 2015/11/17 22:12:03 brouard + Summary: Adding ftolpl parameter + Author: N Brouard + + We had difficulties to get smoothed confidence intervals. It was due + to the period prevalence which wasn't computed accurately. The inner + parameter ftolpl is now an outer parameter of the .imach parameter + file after estepm. If ftolpl is small 1.e-4 and estepm too, + computation are long. + Revision 1.208 2015/11/17 14:31:57 brouard Summary: temporary @@ -744,6 +768,8 @@ typedef struct { #define NDEATHMAX 8 /**< Maximum number of dead states (for func) */ #define NCOVMAX 20 /**< Maximum number of covariates, including generated covariates V1*V2 */ #define codtabm(h,k) (1 & (h-1) >> (k-1))+1 +/*#define decodtabm(h,k,cptcoveff)= (h <= (1<> (k-1)) & 1) +1 : -1)*/ +#define decodtabm(h,k,cptcoveff) (((h-1) >> (k-1)) & 1) +1 #define MAXN 20000 #define YEARM 12. /**< Number of months per year */ #define AGESUP 130 @@ -760,12 +786,12 @@ typedef struct { #define ODIRSEPARATOR '\\' #endif -/* $Id: imach.c,v 1.208 2015/11/17 14:31:57 brouard Exp $ */ +/* $Id: imach.c,v 1.213 2015/12/11 18:22:17 brouard Exp $ */ /* $State: Exp $ */ #include "version.h" char version[]=__IMACH_VERSION__; char copyright[]="October 2015,INED-EUROREVES-Institut de longevite-Japan Society for the Promotion of Science (Grant-in-Aid for Scientific Research 25293121), Intel Software 2015"; -char fullversion[]="$Revision: 1.208 $ $Date: 2015/11/17 14:31:57 $"; +char fullversion[]="$Revision: 1.213 $ $Date: 2015/12/11 18:22:17 $"; char strstart[80]; char optionfilext[10], optionfilefiname[FILENAMELENGTH]; int erreur=0, nberr=0, nbwarn=0; /* Error number, number of errors number of warnings */ @@ -801,7 +827,7 @@ double **matprod2(); /* test */ double **oldm, **newm, **savm; /* Working pointers to matrices */ double **oldms, **newms, **savms; /* Fixed working pointers to matrices */ /*FILE *fic ; */ /* Used in readdata only */ -FILE *ficpar, *ficparo,*ficres, *ficresp, *ficrespl, *ficrespij, *ficrest,*ficresf,*ficrespop; +FILE *ficpar, *ficparo,*ficres, *ficresp, *ficresphtm, *ficrespl, *ficrespij, *ficrest,*ficresf,*ficrespop; FILE *ficlog, *ficrespow; int globpr=0; /* Global variable for printing or not */ double fretone; /* Only one call to likelihood */ @@ -1363,7 +1389,30 @@ char *subdirf3(char fileres[], char *pre strcat(tmpout,fileres); return tmpout; } + +/*************** function subdirfext ***********/ +char *subdirfext(char fileres[], char *preop, char *postop) +{ + + strcpy(tmpout,preop); + strcat(tmpout,fileres); + strcat(tmpout,postop); + return tmpout; +} +/*************** function subdirfext3 ***********/ +char *subdirfext3(char fileres[], char *preop, char *postop) +{ + + /* Caution optionfilefiname is hidden */ + strcpy(tmpout,optionfilefiname); + strcat(tmpout,"/"); + strcat(tmpout,preop); + strcat(tmpout,fileres); + strcat(tmpout,postop); + return tmpout; +} + char *asc_diff_time(long time_sec, char ascdiff[]) { long sec_left, days, hours, minutes; @@ -1988,13 +2037,17 @@ double **prevalim(double **prlim, int nl /* If we start from prlim again, prlim tends to a constant matrix */ int i, ii,j,k; - double min, max, maxmin, maxmax,sumnew=0.; + double *min, *max, *meandiff, maxmax,sumnew=0.; /* double **matprod2(); */ /* test */ double **out, cov[NCOVMAX+1], **pmij(); double **newm; - double agefin, delaymax=100. ; /* 100 Max number of years to converge */ + double agefin, delaymax=200. ; /* 100 Max number of years to converge */ int ncvloop=0; + min=vector(1,nlstate); + max=vector(1,nlstate); + meandiff=vector(1,nlstate); + for (ii=1;ii<=nlstate+ndeath;ii++) for (j=1;j<=nlstate+ndeath;j++){ oldm[ii][j]=(ii==j ? 1.0 : 0.0); @@ -2032,57 +2085,45 @@ double **prevalim(double **prlim, int nl savm=oldm; oldm=newm; - maxmax=0.; - for(j=1;j<=nlstate;j++){ - min=1.; - max=0.; - for(i=1; i<=nlstate; i++) { - sumnew=0; - for(k=1; k<=ndeath; k++) sumnew+=newm[i][nlstate+k]; + + for(j=1; j<=nlstate; j++){ + max[j]=0.; + min[j]=1.; + } + for(i=1;i<=nlstate;i++){ + sumnew=0; + for(k=1; k<=ndeath; k++) sumnew+=newm[i][nlstate+k]; + for(j=1; j<=nlstate; j++){ prlim[i][j]= newm[i][j]/(1-sumnew); - max=FMAX(max,prlim[i][j]); - min=FMIN(min,prlim[i][j]); - /* printf(" age= %d prevalim i=%d, j=%d, prmlim[%d][%d]=%f, agefin=%d max=%f min=%f\n", (int)age, i, j, i, j, prlim[i][j],(int)agefin, max, min); */ - } - maxmin=(max-min)/(max+min)*2; - maxmax=FMAX(maxmax,maxmin); - /* for(i=1; i<=nlstate; i++) { */ - /* sumnew=0.; */ - /* sumnew+=prlim[i][j]; */ - /* } */ - /* prmimj = sumnew/(float)nlstate; /\* Means of various prevalence limits. */ + max[j]=FMAX(max[j],prlim[i][j]); + min[j]=FMIN(min[j],prlim[i][j]); + } + } + + maxmax=0.; + for(j=1; j<=nlstate; j++){ + meandiff[j]=(max[j]-min[j])/(max[j]+min[j])*2.; /* mean difference for each column */ + maxmax=FMAX(maxmax,meandiff[j]); + /* printf(" age= %d meandiff[%d]=%f, agefin=%d max[%d]=%f min[%d]=%f maxmax=%f\n", (int)age, j, meandiff[j],(int)agefin, j, max[j], j, min[j],maxmax); */ } /* j loop */ *ncvyear= (int)age- (int)agefin; /* printf("maxmax=%lf maxmin=%lf ncvloop=%d, age=%d, agefin=%d ncvyear=%d \n", maxmax, maxmin, ncvloop, (int)age, (int)agefin, *ncvyear); */ if(maxmax < ftolpl){ - /* printf("maxmax=%lf maxmin=%lf ncvloop=%ld, age=%d, agefin=%d ncvyear=%d \n", maxmax, maxmin, ncvloop, (int)age, (int)agefin, *ncvyear); */ + /* printf("maxmax=%lf ncvloop=%ld, age=%d, agefin=%d ncvyear=%d \n", maxmax, ncvloop, (int)age, (int)agefin, *ncvyear); */ + free_vector(min,1,nlstate); + free_vector(max,1,nlstate); + free_vector(meandiff,1,nlstate); return prlim; } } /* age loop */ /* After some age loop it doesn't converge */ - printf("Warning: the stable prevalence at age %d did not converge with the required precision %g > ftolpl=%g within %.0f years. \n\ + printf("Warning: the stable prevalence at age %d did not converge with the required precision (%g > ftolpl=%g) within %.0f years. Try to lower 'ftolpl'. \n\ Earliest age to start was %d-%d=%d, ncvloop=%d, ncvyear=%d\n", (int)age, maxmax, ftolpl, delaymax, (int)age, (int)delaymax, (int)agefin, ncvloop, *ncvyear); - /* printf(" age= %d newm\n",(int)age); */ - /* for(i=1; i<=nlstate+ndeath; i++) { */ - /* for(j=1;j<=nlstate+ndeath;j++){ */ - /* printf(" %lf", newm[i][j]); */ - /* } */ - /* printf("\n"); */ - /* } */ - /* printf("\n"); */ - /* printf("prlim\n"); */ - /* for(i=1; i<=nlstate; i++) { */ - /* sumnew=0; */ - /* for(k=1; k<=ndeath; k++) sumnew+=newm[i][nlstate+k]; */ - /* for(j=1;j<=nlstate;j++){ */ - /* prlim[i][j]= newm[i][j]/(1-sumnew); */ - /* printf(" %lf", prlim[i][j]); */ - /* } */ - /* printf("\n"); */ - /* } */ - /* printf("\n"); */ - /* Try to lower 'ftol', for example from 1.e-8 to 6.e-9.\n", ftolpl, (int)age, (int)delaymax, (int)agefin, ncvloop, (int)age-(int)agefin); */ + free_vector(min,1,nlstate); + free_vector(max,1,nlstate); + free_vector(meandiff,1,nlstate); + return prlim; /* should not reach here */ } @@ -2717,7 +2758,7 @@ void likelione(FILE *ficres,double p[], for (k=1; k<= nlstate ; k++) { - fprintf(fichtm,"
- Probability p%dj by origin %d and destination j %s-p%dj.png
\ + fprintf(fichtm,"
- Probability p%dj by origin %d and destination j. Dot's sizes are related to corresponding weight: %s-p%dj.png
\ ",k,k,subdirf2(optionfilefiname,"ILK_"),k,subdirf2(optionfilefiname,"ILK_"),k,subdirf2(optionfilefiname,"ILK_"),k); } fprintf(fichtm,"
- The function drawn is -2Log(L) in Log scale: by state of origin %s-ori.png
\ @@ -3181,17 +3222,26 @@ void freqsummary(char fileres[], int ia double ***freq; /* Frequencies */ double *pp, **prop; double pos,posprop, k2, dateintsum=0,k2cpt=0; - char fileresp[FILENAMELENGTH]; + char fileresp[FILENAMELENGTH], fileresphtm[FILENAMELENGTH]; pp=vector(1,nlstate); prop=matrix(1,nlstate,iagemin,iagemax+3); strcpy(fileresp,"P_"); strcat(fileresp,fileresu); + /*strcat(fileresphtm,fileresu);*/ if((ficresp=fopen(fileresp,"w"))==NULL) { printf("Problem with prevalence resultfile: %s\n", fileresp); fprintf(ficlog,"Problem with prevalence resultfile: %s\n", fileresp); exit(0); } + printf("Problem with prevalence resultfile: %s\n", fileresp); + strcpy(fileresphtm,subdirfext(optionfilefiname,"PHTM_",".htm")); + if((ficresphtm=fopen(fileresphtm,"w"))==NULL) { + printf("Problem with prevalence HTM resultfile '%s' with errno='%s'\n",fileresphtm,strerror(errno)); + fprintf(ficlog,"Problem with prevalence HTM resultfile '%s' with errno='%s'\n",fileresphtm,strerror(errno)); + fflush(ficlog); + exit(70); + } freq= ma3x(-5,nlstate+ndeath,-5,nlstate+ndeath,iagemin,iagemax+3); j1=0; @@ -3219,7 +3269,7 @@ void freqsummary(char fileres[], int ia k2cpt=0; for (i=1; i<=imx; i++) { bool=1; - if (cptcovn>0) { /* Filter is here: Must be looked at for model=V1+V2+V3+V4 */ + if (cptcovn>0) { /* Filter is here: Must be looked at for model=V1+V2+V3+V4 */ for (z1=1; z1<=cptcoveff; z1++) if (covar[Tvaraff[z1]][i]!= nbcode[Tvaraff[z1]][codtabm(j1,z1)]){ /* Tests if the value of each of the covariates of i is equal to filter j1 */ @@ -3229,7 +3279,7 @@ void freqsummary(char fileres[], int ia j1,z1,nbcode[Tvaraff[z1]][codtabm(j1,z1)],j1);*/ /* For j1=7 in V1+V2+V3+V4 = 0 1 1 0 and codtabm(7,3)=1 and nbcde[3][?]=1*/ } - } + } /* cptcovn > 0 */ if (bool==1){ for(m=firstpass; m<=lastpass; m++){ @@ -3237,36 +3287,48 @@ void freqsummary(char fileres[], int ia /*if ((k2>=dateprev1) && (k2<=dateprev2)) {*/ if(agev[m][i]==0) agev[m][i]=iagemax+1; 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 (m1) && (agev[m][i]< (iagemax+3))) { + if ((agev[m][i]>1) && (agev[m][i]< (iagemax+3)) && (anint[m][i]!=9999) && (mint[m][i]!=99)) { dateintsum=dateintsum+k2; k2cpt++; + /* printf("i=%ld dateintmean = %lf dateintsum=%lf k2cpt=%lf k2=%lf\n",i, dateintsum/k2cpt, dateintsum,k2cpt, k2); */ } /*}*/ - } - } - } /* end i */ + } /* end m */ + } /* end bool */ + } /* end i = 1 to imx */ /* fprintf(ficresp, "#Count between %.lf/%.lf/%.lf and %.lf/%.lf/%.lf\n",jprev1, mprev1,anprev1,jprev2, mprev2,anprev2);*/ pstamp(ficresp); if (cptcovn>0) { fprintf(ficresp, "\n#********** Variable "); - for (z1=1; z1<=cptcoveff; z1++) fprintf(ficresp, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtabm(j1,z1)]); - fprintf(ficresp, "**********\n#"); + fprintf(ficresphtm, "\n

********** Variable "); + for (z1=1; z1<=cptcoveff; z1++){ + fprintf(ficresp, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtabm(j1,z1)]); + fprintf(ficresphtm, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtabm(j1,z1)]); + } + fprintf(ficresp, "**********\n#"); + fprintf(ficresphtm, "**********

\n#"); fprintf(ficlog, "\n#********** Variable "); for (z1=1; z1<=cptcoveff; z1++) fprintf(ficlog, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtabm(j1,z1)]); fprintf(ficlog, "**********\n#"); } - for(i=1; i<=nlstate;i++) + fprintf(ficresphtm,""); + for(i=1; i<=nlstate;i++) { fprintf(ficresp, " Age Prev(%d) N(%d) N",i,i); + fprintf(ficresphtm, "",i,i); + } fprintf(ficresp, "\n"); + fprintf(ficresphtm, "\n"); for(i=iagemin; i <= iagemax+3; i++){ + fprintf(ficresphtm,""); if(i==iagemax+3){ fprintf(ficlog,"Total"); }else{ @@ -3316,11 +3378,14 @@ void freqsummary(char fileres[], int ia if( i <= iagemax){ if(pos>=1.e-5){ fprintf(ficresp," %d %.5f %.0f %.0f",i,prop[jk][i]/posprop, prop[jk][i],posprop); + fprintf(ficresphtm,"",i,prop[jk][i]/posprop, prop[jk][i],posprop); /*probs[i][jk][j1]= pp[jk]/pos;*/ /*printf("\ni=%d jk=%d j1=%d %.5f %.0f %.0f %f",i,jk,j1,pp[jk]/pos, pp[jk],pos,probs[i][jk][j1]);*/ } - else + else{ fprintf(ficresp," %d NaNq %.0f %.0f",i,prop[jk][i],posprop); + fprintf(ficresphtm,"",i, prop[jk][i],posprop); + } } } @@ -3331,17 +3396,21 @@ void freqsummary(char fileres[], int ia printf(" %d%d=%.0f",jk,m,freq[jk][m][i]); fprintf(ficlog," %d%d=%.0f",jk,m,freq[jk][m][i]); } - if(i <= iagemax) + if(i <= iagemax){ fprintf(ficresp,"\n"); + fprintf(ficresphtm,"\n"); + } if(first==1) printf("Others in log...\n"); fprintf(ficlog,"\n"); - } + } /* end loop i */ + fprintf(ficresphtm,"
AgePrev(%d)N(%d)N
%d%.5f%.0f%.0f%dNaNq%.0f%.0f
\n"); /*}*/ - } + } /* end j1 */ dateintmean=dateintsum/k2cpt; fclose(ficresp); + fclose(ficresphtm); free_ma3x(freq,-5,nlstate+ndeath,-5,nlstate+ndeath, iagemin, iagemax+3); free_vector(pp,1,nlstate); free_matrix(prop,1,nlstate,iagemin, iagemax+3); @@ -4025,7 +4094,7 @@ void cvevsij(double ***eij, double x[], } /************ Variance ******************/ - void varevsij(char optionfilefiname[], double ***vareij, double **matcov, double x[], double delti[], int nlstate, int stepm, double bage, double fage, double **oldm, double **savm, double **prlim, double ftolpl, int *ncvyear, int ij, int estepm, int cptcov, int cptcod, int popbased, int mobilav, char strstart[]) + void varevsij(char optionfilefiname[], double ***vareij, double **matcov, double x[], double delti[], int nlstate, int stepm, double bage, double fage, double **oldm, double **savm, double **prlim, double ftolpl, int *ncvyearp, int ij, int estepm, int cptcov, int cptcod, int popbased, int mobilav, char strstart[]) { /* Variance of health expectancies */ /* double **prevalim(double **prlim, int nlstate, double *xp, double age, double **oldm, double ** savm,double ftolpl);*/ @@ -4128,7 +4197,7 @@ void cvevsij(double ***eij, double x[], /* 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 agelim. - Look at function hpijx to understand why (it is linked to memory size questions) + Look at function hpijx to understand why because of memory size limitations, we decided (b) to get a life expectancy respecting the most precise curvature of the survival function given by stepm (the optimization length). Unfortunately it means that if the survival funtion is printed every two years of age and if @@ -4150,8 +4219,8 @@ void cvevsij(double ***eij, double x[], for(i=1; i<=npar; i++){ /* Computes gradient x + delta*/ 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,ncvyear,ij); + + prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyearp,ij); if (popbased==1) { if(mobilav ==0){ @@ -4163,13 +4232,14 @@ void cvevsij(double ***eij, double x[], } } + hpxij(p3mat,nhstepm,age,hstepm,xp,nlstate,stepm,oldm,savm, ij); /* Returns p3mat[i][j][h] for h=1 to nhstepm */ for(j=1; j<= nlstate; j++){ for(h=0; h<=nhstepm; h++){ for(i=1, gp[h][j]=0.;i<=nlstate;i++) gp[h][j] += prlim[i][i]*p3mat[i][j][h]; } } - /* This for computing probability of death (h=1 means + /* Next for computing probability of death (h=1 means computed over hstepm matrices product = hstepm*stepm months) as a weighted average of prlim. */ @@ -4181,8 +4251,8 @@ void cvevsij(double ***eij, double x[], for(i=1; i<=npar; i++) /* Computes gradient x - delta */ 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,ncvyear, ij); + + prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyearp, ij); if (popbased==1) { if(mobilav ==0){ @@ -4194,6 +4264,8 @@ void cvevsij(double ***eij, double x[], } } + hpxij(p3mat,nhstepm,age,hstepm,xp,nlstate,stepm,oldm,savm, ij); + for(j=1; j<= nlstate; j++){ /* Sum of wi * eij = e.j */ for(h=0; h<=nhstepm; h++){ for(i=1, gm[h][j]=0.;i<=nlstate;i++) @@ -4256,8 +4328,8 @@ void cvevsij(double ***eij, double x[], varppt[j][i]=doldmp[j][i]; /* end ppptj */ /* x centered again */ - hpxij(p3mat,nhstepm,age,hstepm,x,nlstate,stepm,oldm,savm, ij); - prevalim(prlim,nlstate,x,age,oldm,savm,ftolpl,ncvyear,ij); + + prevalim(prlim,nlstate,x,age,oldm,savm,ftolpl,ncvyearp,ij); if (popbased==1) { if(mobilav ==0){ @@ -4273,6 +4345,7 @@ void cvevsij(double ***eij, double x[], computed over hstepm (estepm) matrices product = hstepm*stepm months) as a weighted average of prlim. */ + hpxij(p3mat,nhstepm,age,hstepm,x,nlstate,stepm,oldm,savm, ij); for(j=nlstate+1;j<=nlstate+ndeath;j++){ for(i=1,gmp[j]=0.;i<= nlstate; i++) gmp[j] += prlim[i][i]*p3mat[i][j][1]; @@ -4335,7 +4408,7 @@ void cvevsij(double ***eij, double x[], } /* end varevsij */ /************ Variance of prevlim ******************/ - void varprevlim(char fileres[], double **varpl, double **matcov, double x[], double delti[], int nlstate, int stepm, double bage, double fage, double **oldm, double **savm, double **prlim, double ftolpl, int *ncvyear, int ij, char strstart[]) + void varprevlim(char fileres[], double **varpl, double **matcov, double x[], double delti[], int nlstate, int stepm, double bage, double fage, double **oldm, double **savm, double **prlim, double ftolpl, int *ncvyearp, int ij, char strstart[]) { /* Variance of prevalence limit for each state ij using current parameters x[] and estimates of neighbourhood give by delti*/ /* double **prevalim(double **prlim, int nlstate, double *xp, double age, double **oldm, double **savm,double ftolpl);*/ @@ -4367,7 +4440,6 @@ void cvevsij(double ***eij, double x[], nhstepm=(int) rint((agelim-age)*YEARM/stepm); /* Typically 20 years = 20*12/6=40 */ if (stepm >= YEARM) hstepm=1; nhstepm = nhstepm/hstepm; /* Typically 40/4=10 */ - p3mat=ma3x(1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm); gradg=matrix(1,npar,1,nlstate); mgp=matrix(1,npar,1,nlstate); mgm=matrix(1,npar,1,nlstate); @@ -4378,21 +4450,27 @@ void cvevsij(double ***eij, double x[], for(i=1; i<=npar; i++){ /* Computes gradient */ xp[i] = x[i] + (i==theta ?delti[theta]:0); } - hpxij(p3mat,nhstepm,age,hstepm,xp,nlstate,stepm,oldm,savm, ij); /* Missing or not useful because 1 year */ - prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyear,ij); + if((int)age==79 ||(int)age== 80 ||(int)age== 81 ) + prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyearp,ij); + else + prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyearp,ij); for(i=1;i<=nlstate;i++){ gp[i] = prlim[i][i]; mgp[theta][i] = prlim[i][i]; } for(i=1; i<=npar; i++) /* Computes gradient */ xp[i] = x[i] - (i==theta ?delti[theta]:0); - prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyear,ij); + if((int)age==79 ||(int)age== 80 ||(int)age== 81 ) + prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyearp,ij); + else + prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyearp,ij); for(i=1;i<=nlstate;i++){ gm[i] = prlim[i][i]; mgm[theta][i] = prlim[i][i]; } for(i=1;i<=nlstate;i++) gradg[theta][i]= (gp[i]-gm[i])/2./delti[theta]; + /* gradg[theta][2]= -gradg[theta][1]; */ /* For testing if nlstate=2 */ } /* End theta */ trgradg =matrix(1,nlstate,1,npar); @@ -4400,28 +4478,28 @@ void cvevsij(double ***eij, double x[], for(j=1; j<=nlstate;j++) for(theta=1; theta <=npar; theta++) trgradg[j][theta]=gradg[theta][j]; - if((int)age==68 ||(int)age== 69 ){ - printf("\nmgm mgp %d ",(int)age); - for(j=1; j<=nlstate;j++){ - printf("%d ",j); - for(theta=1; theta <=npar; theta++) - printf("%d %lf %lf",theta,mgm[theta][j],mgp[theta][j]); - printf("\n "); - } - } - if((int)age==68 ||(int)age== 69 ){ - printf("\n gradg %d ",(int)age); - for(j=1; j<=nlstate;j++){ - printf("%d ",j); - for(theta=1; theta <=npar; theta++) - printf("%d %lf ",theta,gradg[theta][j]); - printf("\n "); - } - } + /* if((int)age==79 ||(int)age== 80 ||(int)age== 81 ){ */ + /* printf("\nmgm mgp %d ",(int)age); */ + /* for(j=1; j<=nlstate;j++){ */ + /* printf(" %d ",j); */ + /* for(theta=1; theta <=npar; theta++) */ + /* printf(" %d %lf %lf",theta,mgm[theta][j],mgp[theta][j]); */ + /* printf("\n "); */ + /* } */ + /* } */ + /* if((int)age==79 ||(int)age== 80 ||(int)age== 81 ){ */ + /* printf("\n gradg %d ",(int)age); */ + /* for(j=1; j<=nlstate;j++){ */ + /* printf("%d ",j); */ + /* for(theta=1; theta <=npar; theta++) */ + /* printf("%d %lf ",theta,gradg[theta][j]); */ + /* printf("\n "); */ + /* } */ + /* } */ for(i=1;i<=nlstate;i++) varpl[i][(int)age] =0.; - if((int)age==68 ||(int)age== 69 ){ + if((int)age==79 ||(int)age== 80 ||(int)age== 81){ matprod2(dnewm,trgradg,1,nlstate,1,npar,1,npar,matcov); matprod2(doldm,dnewm,1,nlstate,1,npar,1,nlstate,gradg); }else{ @@ -4789,17 +4867,18 @@ To be simple, these graphs help to under void printinghtml(char fileresu[], char title[], char datafile[], int firstpass, \ int lastpass, int stepm, int weightopt, char model[],\ int imx,int jmin, int jmax, double jmeanint,char rfileres[],\ - int popforecast, int estepm ,\ - double jprev1, double mprev1,double anprev1, \ - double jprev2, double mprev2,double anprev2){ + int popforecast, int prevfcast, int estepm , \ + double jprev1, double mprev1,double anprev1, double dateprev1, \ + double jprev2, double mprev2,double anprev2, double dateprev2){ int jj1, k1, i1, cpt; fprintf(fichtm,""); fprintf(fichtm,"