|
|
| version 1.204, 2015/10/01 16:20:26 | version 1.208, 2015/11/17 14:31:57 |
|---|---|
| Line 1 | Line 1 |
| /* $Id$ | /* $Id$ |
| $State$ | $State$ |
| $Log$ | $Log$ |
| Revision 1.208 2015/11/17 14:31:57 brouard | |
| Summary: temporary | |
| Revision 1.207 2015/10/27 17:36:57 brouard | |
| *** empty log message *** | |
| Revision 1.206 2015/10/24 07:14:11 brouard | |
| *** empty log message *** | |
| Revision 1.205 2015/10/23 15:50:53 brouard | |
| Summary: 0.98r3 some clarification for graphs on likelihood contributions | |
| Revision 1.204 2015/10/01 16:20:26 brouard | Revision 1.204 2015/10/01 16:20:26 brouard |
| Summary: Some new graphs of contribution to likelihood | Summary: Some new graphs of contribution to likelihood |
| Line 943 static int split( char *path, char *dirc | Line 955 static int split( char *path, char *dirc |
| } | } |
| /* got dirc from getcwd*/ | /* got dirc from getcwd*/ |
| printf(" DIRC = %s \n",dirc); | printf(" DIRC = %s \n",dirc); |
| } else { /* strip direcotry from path */ | } else { /* strip directory from path */ |
| ss++; /* after this, the filename */ | ss++; /* after this, the filename */ |
| l2 = strlen( ss ); /* length of filename */ | l2 = strlen( ss ); /* length of filename */ |
| if ( l2 == 0 ) return( GLOCK_ERROR_NOPATH ); | if ( l2 == 0 ) return( GLOCK_ERROR_NOPATH ); |
| Line 1957 double **prevalim(double **prlim, int nl | Line 1969 double **prevalim(double **prlim, int nl |
| { | { |
| /* Computes the prevalence limit in each live state at age x by left multiplying the unit | /* Computes the prevalence limit in each live state at age x by left multiplying the unit |
| matrix by transitions matrix until convergence is reached with precision ftolpl */ | matrix by transitions matrix until convergence is reached with precision ftolpl */ |
| /* Wx= Wx-1 Px-1= Wx-2 Px-2 Px-1 = Wx-n Px-n ... Px-2 Px-1 I */ | |
| /* Wx is row vector: population in state 1, population in state 2, population dead */ | |
| /* or prevalence in state 1, prevalence in state 2, 0 */ | |
| /* newm is the matrix after multiplications, its rows are identical at a factor */ | |
| /* Initial matrix pimij */ | |
| /* {0.85204250825084937, 0.13044499163996345, 0.017512500109187184, */ | |
| /* 0.090851990222114765, 0.88271245433047185, 0.026435555447413338, */ | |
| /* 0, 0 , 1} */ | |
| /* | |
| * and after some iteration: */ | |
| /* {0.45504275246439968, 0.42731458730878791, 0.11764266022681241, */ | |
| /* 0.45201005341706885, 0.42865420071559901, 0.11933574586733192, */ | |
| /* 0, 0 , 1} */ | |
| /* And prevalence by suppressing the deaths are close to identical rows in prlim: */ | |
| /* {0.51571254859325999, 0.4842874514067399, */ | |
| /* 0.51326036147820708, 0.48673963852179264} */ | |
| /* If we start from prlim again, prlim tends to a constant matrix */ | |
| int i, ii,j,k; | int i, ii,j,k; |
| double min, max, maxmin, maxmax,sumnew=0.; | double min, max, maxmin, maxmax,sumnew=0.; |
| /* double **matprod2(); */ /* test */ | /* double **matprod2(); */ /* test */ |
| double **out, cov[NCOVMAX+1], **pmij(); | double **out, cov[NCOVMAX+1], **pmij(); |
| double **newm; | double **newm; |
| double agefin, delaymax=100 ; /* Max number of years to converge */ | double agefin, delaymax=100. ; /* 100 Max number of years to converge */ |
| int ncvloop=0; | int ncvloop=0; |
| for (ii=1;ii<=nlstate+ndeath;ii++) | for (ii=1;ii<=nlstate+ndeath;ii++) |
| Line 2017 double **prevalim(double **prlim, int nl | Line 2046 double **prevalim(double **prlim, int nl |
| } | } |
| maxmin=(max-min)/(max+min)*2; | maxmin=(max-min)/(max+min)*2; |
| maxmax=FMAX(maxmax,maxmin); | 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. */ | |
| } /* j loop */ | } /* j loop */ |
| *ncvyear= (int)age- (int)agefin; | *ncvyear= (int)age- (int)agefin; |
| /* 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 maxmin=%lf ncvloop=%d, age=%d, agefin=%d ncvyear=%d \n", maxmax, maxmin, ncvloop, (int)age, (int)agefin, *ncvyear); */ |
| if(maxmax < ftolpl){ | 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 maxmin=%lf ncvloop=%ld, age=%d, agefin=%d ncvyear=%d \n", maxmax, maxmin, ncvloop, (int)age, (int)agefin, *ncvyear); */ |
| return prlim; | return prlim; |
| } | } |
| } /* age loop */ | } /* age loop */ |
| printf("Warning: the stable prevalence at age %d did not converge with the required precision %g > ftolpl=%g. \n\ | /* After some age loop it doesn't converge */ |
| Earliest age to start was %d-%d=%d, ncvloop=%d, ncvyear=%d\n", (int)age, maxmax, ftolpl, (int)age, (int)delaymax, (int)agefin, ncvloop, *ncvyear); | printf("Warning: the stable prevalence at age %d did not converge with the required precision %g > ftolpl=%g within %.0f years. \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); */ | 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); */ | |
| return prlim; /* should not reach here */ | return prlim; /* should not reach here */ |
| } | } |
| Line 2603 double funcone( double *x) | Line 2658 double funcone( double *x) |
| ll[s[mw[mi][i]][i]] += 2*weight[i]*lli; | ll[s[mw[mi][i]][i]] += 2*weight[i]*lli; |
| /*printf("i=%6d s1=%1d s2=%1d mi=%1d mw=%1d dh=%3d prob=%10.6f w=%6.4f out=%10.6f sav=%10.6f\n",i,s1,s2,mi,mw[mi][i],dh[mi][i],exp(lli),weight[i],out[s1][s2],savm[s1][s2]); */ | /*printf("i=%6d s1=%1d s2=%1d mi=%1d mw=%1d dh=%3d prob=%10.6f w=%6.4f out=%10.6f sav=%10.6f\n",i,s1,s2,mi,mw[mi][i],dh[mi][i],exp(lli),weight[i],out[s1][s2],savm[s1][s2]); */ |
| if(globpr){ | if(globpr){ |
| fprintf(ficresilk,"%9ld %6.1f %6d %2d %2d %2d %2d %3d %11.6f %8.4f\ | fprintf(ficresilk,"%9ld %6.1f %6d %2d %2d %2d %2d %3d %11.6f %8.4f %8.3f\ |
| %11.6f %11.6f %11.6f ", \ | %11.6f %11.6f %11.6f ", \ |
| num[i], agexact, i,s1,s2,mi,mw[mi][i],dh[mi][i],exp(lli),weight[i], | num[i], agexact, i,s1,s2,mi,mw[mi][i],dh[mi][i],exp(lli),weight[i],weight[i]*gipmx/gsw, |
| 2*weight[i]*lli,out[s1][s2],savm[s1][s2]); | 2*weight[i]*lli,out[s1][s2],savm[s1][s2]); |
| for(k=1,llt=0.,l=0.; k<=nlstate; k++){ | for(k=1,llt=0.,l=0.; k<=nlstate; k++){ |
| llt +=ll[k]*gipmx/gsw; | llt +=ll[k]*gipmx/gsw; |
| Line 2643 void likelione(FILE *ficres,double p[], | Line 2698 void likelione(FILE *ficres,double p[], |
| printf("Problem with resultfile: %s\n", fileresilk); | printf("Problem with resultfile: %s\n", fileresilk); |
| fprintf(ficlog,"Problem with resultfile: %s\n", fileresilk); | fprintf(ficlog,"Problem with resultfile: %s\n", fileresilk); |
| } | } |
| fprintf(ficresilk, "#individual(line's_record) s1 s2 wave# effective_wave# number_of_matrices_product pij weight -2ln(pij)*weight 0pij_x 0pij_(x-stepm) cumulating_loglikeli_by_health_state(reweighted=-2ll*weightXnumber_of_contribs/sum_of_weights) and_total\n"); | fprintf(ficresilk, "#individual(line's_record) count age s1 s2 wave# effective_wave# number_of_matrices_product pij weight weight/gpw -2ln(pij)*weight 0pij_x 0pij_(x-stepm) cumulating_loglikeli_by_health_state(reweighted=-2ll*weightXnumber_of_contribs/sum_of_weights) and_total\n"); |
| fprintf(ficresilk, "#num_i age i s1 s2 mi mw dh likeli weight 2wlli out sav "); | fprintf(ficresilk, "#num_i age i s1 s2 mi mw dh likeli weight %%weight 2wlli out sav "); |
| /* i,s1,s2,mi,mw[mi][i],dh[mi][i],exp(lli),weight[i],2*weight[i]*lli,out[s1][s2],savm[s1][s2]); */ | /* i,s1,s2,mi,mw[mi][i],dh[mi][i],exp(lli),weight[i],2*weight[i]*lli,out[s1][s2],savm[s1][s2]); */ |
| for(k=1; k<=nlstate; k++) | for(k=1; k<=nlstate; k++) |
| fprintf(ficresilk," -2*gipw/gsw*weight*ll[%d]++",k); | fprintf(ficresilk," -2*gipw/gsw*weight*ll[%d]++",k); |
| Line 2654 void likelione(FILE *ficres,double p[], | Line 2709 void likelione(FILE *ficres,double p[], |
| *fretone=(*funcone)(p); | *fretone=(*funcone)(p); |
| if(*globpri !=0){ | if(*globpri !=0){ |
| fclose(ficresilk); | fclose(ficresilk); |
| fprintf(fichtm,"\n<br>File of contributions to the likelihood computed with initial parameters and mle >= 1. You should at least run with mle >= 1 and starting values corresponding to the optimized parameters in order to visualize the real contribution of each individual/wave: <a href=\"%s\">%s</a><br>\n",subdirf(fileresilk),subdirf(fileresilk)); | if (mle ==0) |
| fprintf(fichtm,"<br>- The function drawn is -2Log(L) in Log scale: by state of origin <a href=\"%s-ori.png\">%s-ori.png</a><br> \ | fprintf(fichtm,"\n<br>File of contributions to the likelihood computed with initial parameters and mle = %d.",mle); |
| <img src=\"%s-ori.png\">",subdirf2(optionfilefiname,"ILK_"),subdirf2(optionfilefiname,"ILK_"),subdirf2(optionfilefiname,"ILK_")); | else if(mle >=1) |
| fprintf(fichtm,"<br>- and by state of destination <a href=\"%s-dest.png\">%s-dest.png</a><br> \ | fprintf(fichtm,"\n<br>File of contributions to the likelihood computed with optimized parameters mle = %d.",mle); |
| <img src=\"%s-dest.png\">",subdirf2(optionfilefiname,"ILK_"),subdirf2(optionfilefiname,"ILK_"),subdirf2(optionfilefiname,"ILK_")); | fprintf(fichtm," You should at least run with mle >= 1 to get starting values corresponding to the optimized parameters in order to visualize the real contribution of each individual/wave: <a href=\"%s\">%s</a><br>\n",subdirf(fileresilk),subdirf(fileresilk)); |
| fflush(fichtm); | |
| for (k=1; k<= nlstate ; k++) { | for (k=1; k<= nlstate ; k++) { |
| fprintf(fichtm,"<br>- Probability p%dj by origin %d and destination j <a href=\"%s-p%dj.png\">%s-p%dj.png</a><br> \ | fprintf(fichtm,"<br>- Probability p%dj by origin %d and destination j <a href=\"%s-p%dj.png\">%s-p%dj.png</a><br> \ |
| <img src=\"%s-p%dj.png\">",k,k,subdirf2(optionfilefiname,"ILK_"),k,subdirf2(optionfilefiname,"ILK_"),k,subdirf2(optionfilefiname,"ILK_"),k); | <img src=\"%s-p%dj.png\">",k,k,subdirf2(optionfilefiname,"ILK_"),k,subdirf2(optionfilefiname,"ILK_"),k,subdirf2(optionfilefiname,"ILK_"),k); |
| } | } |
| } | fprintf(fichtm,"<br>- The function drawn is -2Log(L) in Log scale: by state of origin <a href=\"%s-ori.png\">%s-ori.png</a><br> \ |
| <img src=\"%s-ori.png\">",subdirf2(optionfilefiname,"ILK_"),subdirf2(optionfilefiname,"ILK_"),subdirf2(optionfilefiname,"ILK_")); | |
| fprintf(fichtm,"<br>- and by state of destination <a href=\"%s-dest.png\">%s-dest.png</a><br> \ | |
| <img src=\"%s-dest.png\">",subdirf2(optionfilefiname,"ILK_"),subdirf2(optionfilefiname,"ILK_"),subdirf2(optionfilefiname,"ILK_")); | |
| fflush(fichtm); | |
| } | |
| return; | return; |
| } | } |
| Line 2930 double hessij( double x[], double **hess | Line 2989 double hessij( double x[], double **hess |
| double p2[MAXPARM+1]; | double p2[MAXPARM+1]; |
| int k, kmax=1; | int k, kmax=1; |
| double v1, v2, cv12, lc1, lc2; | double v1, v2, cv12, lc1, lc2; |
| int firstime=0; | |
| fx=func(x); | fx=func(x); |
| for (k=1; k<=kmax; k=k+10) { | for (k=1; k<=kmax; k=k+10) { |
| Line 2951 double hessij( double x[], double **hess | Line 3012 double hessij( double x[], double **hess |
| k4=func(p2)-fx; | k4=func(p2)-fx; |
| res=(k1-k2-k3+k4)/4.0/delti[thetai]/k/delti[thetaj]/k/2.; /* Because of L not 2*L */ | res=(k1-k2-k3+k4)/4.0/delti[thetai]/k/delti[thetaj]/k/2.; /* Because of L not 2*L */ |
| if(k1*k2*k3*k4 <0.){ | if(k1*k2*k3*k4 <0.){ |
| firstime=1; | |
| kmax=kmax+10; | kmax=kmax+10; |
| if(kmax >=10){ | } |
| if(kmax >=10 || firstime ==1){ | |
| printf("Warning: directions %d-%d, you are not estimating the Hessian at the exact maximum likelihood; increase ftol=%.2e\n",thetai,thetaj, ftol); | printf("Warning: directions %d-%d, you are not estimating the Hessian at the exact maximum likelihood; increase ftol=%.2e\n",thetai,thetaj, ftol); |
| fprintf(ficlog,"Warning: directions %d-%d, you are not estimating the Hessian at the exact maximum likelihood; increase ftol=%.2e\n",thetai,thetaj, ftol); | fprintf(ficlog,"Warning: directions %d-%d, you are not estimating the Hessian at the exact maximum likelihood; increase ftol=%.2e\n",thetai,thetaj, ftol); |
| printf("%d %d k=%d, k1=%.12e k2=%.12e k3=%.12e k4=%.12e delti*k=%.12e deltj*k=%.12e, xi-de*k=%.12e xj-de*k=%.12e res=%.12e k1234=%.12e,k1-2=%.12e,k3-4=%.12e\n",thetai,thetaj,k,k1,k2,k3,k4,delti[thetai]/k,delti[thetaj]/k,x[thetai]-delti[thetai]/k,x[thetaj]-delti[thetaj]/k, res,k1-k2-k3+k4,k1-k2,k3-k4); | printf("%d %d k=%d, k1=%.12e k2=%.12e k3=%.12e k4=%.12e delti*k=%.12e deltj*k=%.12e, xi-de*k=%.12e xj-de*k=%.12e res=%.12e k1234=%.12e,k1-2=%.12e,k3-4=%.12e\n",thetai,thetaj,k,k1,k2,k3,k4,delti[thetai]/k,delti[thetaj]/k,x[thetai]-delti[thetai]/k,x[thetaj]-delti[thetaj]/k, res,k1-k2-k3+k4,k1-k2,k3-k4); |
| fprintf(ficlog,"%d %d k=%d, k1=%.12e k2=%.12e k3=%.12e k4=%.12e delti*k=%.12e deltj*k=%.12e, xi-de*k=%.12e xj-de*k=%.12e res=%.12e k1234=%.12e,k1-2=%.12e,k3-4=%.12e\n",thetai,thetaj,k,k1,k2,k3,k4,delti[thetai]/k,delti[thetaj]/k,x[thetai]-delti[thetai]/k,x[thetaj]-delti[thetaj]/k, res,k1-k2-k3+k4,k1-k2,k3-k4); | fprintf(ficlog,"%d %d k=%d, k1=%.12e k2=%.12e k3=%.12e k4=%.12e delti*k=%.12e deltj*k=%.12e, xi-de*k=%.12e xj-de*k=%.12e res=%.12e k1234=%.12e,k1-2=%.12e,k3-4=%.12e\n",thetai,thetaj,k,k1,k2,k3,k4,delti[thetai]/k,delti[thetaj]/k,x[thetai]-delti[thetai]/k,x[thetaj]-delti[thetaj]/k, res,k1-k2-k3+k4,k1-k2,k3-k4); |
| } | |
| } | } |
| #ifdef DEBUGHESSIJ | #ifdef DEBUGHESSIJ |
| v1=hess[thetai][thetai]; | v1=hess[thetai][thetai]; |
| Line 4017 void cvevsij(double ***eij, double x[], | Line 4079 void cvevsij(double ***eij, double x[], |
| fprintf(ficlog,"Problem with resultfile: %s\n", fileresprobmorprev); | fprintf(ficlog,"Problem with resultfile: %s\n", fileresprobmorprev); |
| } | } |
| printf("Computing total mortality p.j=w1*p1j+w2*p2j+..: result on file '%s' \n",fileresprobmorprev); | printf("Computing total mortality p.j=w1*p1j+w2*p2j+..: result on file '%s' \n",fileresprobmorprev); |
| fprintf(ficlog,"Computing total mortality p.j=w1*p1j+w2*p2j+..: result on file '%s' \n",fileresprobmorprev); | fprintf(ficlog,"Computing total mortality p.j=w1*p1j+w2*p2j+..: result on file '%s' \n",fileresprobmorprev); |
| pstamp(ficresprobmorprev); | pstamp(ficresprobmorprev); |
| fprintf(ficresprobmorprev,"# probabilities of dying before estepm=%d months for people of exact age and weighted probabilities w1*p1j+w2*p2j+... stand dev in()\n",estepm); | fprintf(ficresprobmorprev,"# probabilities of dying before estepm=%d months for people of exact age and weighted probabilities w1*p1j+w2*p2j+... stand dev in()\n",estepm); |
| Line 4028 void cvevsij(double ***eij, double x[], | Line 4089 void cvevsij(double ***eij, double x[], |
| fprintf(ficresprobmorprev," w%1d p%-d%-d",i,i,j); | fprintf(ficresprobmorprev," w%1d p%-d%-d",i,i,j); |
| } | } |
| fprintf(ficresprobmorprev,"\n"); | fprintf(ficresprobmorprev,"\n"); |
| fprintf(ficgp,"\n# Routine varevsij"); | fprintf(ficgp,"\n# Routine varevsij"); |
| fprintf(ficgp,"\nunset title \n"); | fprintf(ficgp,"\nunset title \n"); |
| /* fprintf(fichtm, "#Local time at start: %s", strstart);*/ | /* fprintf(fichtm, "#Local time at start: %s", strstart);*/ |
| Line 4065 void cvevsij(double ***eij, double x[], | Line 4127 void cvevsij(double ***eij, double x[], |
| /* For example we decided to compute the life expectancy with the smallest unit */ | /* For example 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. | /* 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 | nhstepm is the number of hstepm from age to agelim |
| nstepm is the number of stepm from age to agelin. | 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 (it is linked to memory size questions) |
| /* We decided (b) to get a life expectancy respecting the most precise curvature of the | 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 | 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 | means that if the survival funtion is printed every two years of age and if |
| you sum them up and add 1 year (area under the trapezoids) you won't get the same | you sum them up and add 1 year (area under the trapezoids) you won't get the same |
| Line 4275 void cvevsij(double ***eij, double x[], | Line 4337 void cvevsij(double ***eij, double x[], |
| /************ Variance of prevlim ******************/ | /************ 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 *ncvyear, int ij, char strstart[]) |
| { | { |
| /* Variance of prevalence limit */ | /* 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);*/ | /* double **prevalim(double **prlim, int nlstate, double *xp, double age, double **oldm, double **savm,double ftolpl);*/ |
| double **dnewm,**doldm; | double **dnewm,**doldm; |
| Line 4283 void cvevsij(double ***eij, double x[], | Line 4345 void cvevsij(double ***eij, double x[], |
| double *xp; | double *xp; |
| double *gp, *gm; | double *gp, *gm; |
| double **gradg, **trgradg; | double **gradg, **trgradg; |
| double **mgm, **mgp; | |
| double age,agelim; | double age,agelim; |
| int theta; | int theta; |
| Line 4304 void cvevsij(double ***eij, double x[], | Line 4367 void cvevsij(double ***eij, double x[], |
| nhstepm=(int) rint((agelim-age)*YEARM/stepm); /* Typically 20 years = 20*12/6=40 */ | nhstepm=(int) rint((agelim-age)*YEARM/stepm); /* Typically 20 years = 20*12/6=40 */ |
| if (stepm >= YEARM) hstepm=1; | if (stepm >= YEARM) hstepm=1; |
| nhstepm = nhstepm/hstepm; /* Typically 40/4=10 */ | nhstepm = nhstepm/hstepm; /* Typically 40/4=10 */ |
| p3mat=ma3x(1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm); | |
| gradg=matrix(1,npar,1,nlstate); | gradg=matrix(1,npar,1,nlstate); |
| mgp=matrix(1,npar,1,nlstate); | |
| mgm=matrix(1,npar,1,nlstate); | |
| gp=vector(1,nlstate); | gp=vector(1,nlstate); |
| gm=vector(1,nlstate); | gm=vector(1,nlstate); |
| Line 4312 void cvevsij(double ***eij, double x[], | Line 4378 void cvevsij(double ***eij, double x[], |
| for(i=1; i<=npar; i++){ /* Computes gradient */ | for(i=1; i<=npar; i++){ /* Computes gradient */ |
| xp[i] = x[i] + (i==theta ?delti[theta]:0); | 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); | prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyear,ij); |
| for(i=1;i<=nlstate;i++) | for(i=1;i<=nlstate;i++){ |
| gp[i] = prlim[i][i]; | gp[i] = prlim[i][i]; |
| mgp[theta][i] = prlim[i][i]; | |
| } | |
| for(i=1; i<=npar; i++) /* Computes gradient */ | for(i=1; i<=npar; i++) /* Computes gradient */ |
| xp[i] = x[i] - (i==theta ?delti[theta]:0); | xp[i] = x[i] - (i==theta ?delti[theta]:0); |
| prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyear,ij); | prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyear,ij); |
| for(i=1;i<=nlstate;i++) | for(i=1;i<=nlstate;i++){ |
| gm[i] = prlim[i][i]; | gm[i] = prlim[i][i]; |
| mgm[theta][i] = prlim[i][i]; | |
| } | |
| for(i=1;i<=nlstate;i++) | for(i=1;i<=nlstate;i++) |
| gradg[theta][i]= (gp[i]-gm[i])/2./delti[theta]; | gradg[theta][i]= (gp[i]-gm[i])/2./delti[theta]; |
| } /* End theta */ | } /* End theta */ |
| Line 4331 void cvevsij(double ***eij, double x[], | Line 4400 void cvevsij(double ***eij, double x[], |
| for(j=1; j<=nlstate;j++) | for(j=1; j<=nlstate;j++) |
| for(theta=1; theta <=npar; theta++) | for(theta=1; theta <=npar; theta++) |
| trgradg[j][theta]=gradg[theta][j]; | 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 "); | |
| } | |
| } | |
| for(i=1;i<=nlstate;i++) | for(i=1;i<=nlstate;i++) |
| varpl[i][(int)age] =0.; | varpl[i][(int)age] =0.; |
| if((int)age==68 ||(int)age== 69 ){ | |
| matprod2(dnewm,trgradg,1,nlstate,1,npar,1,npar,matcov); | |
| matprod2(doldm,dnewm,1,nlstate,1,npar,1,nlstate,gradg); | |
| }else{ | |
| matprod2(dnewm,trgradg,1,nlstate,1,npar,1,npar,matcov); | matprod2(dnewm,trgradg,1,nlstate,1,npar,1,npar,matcov); |
| matprod2(doldm,dnewm,1,nlstate,1,npar,1,nlstate,gradg); | matprod2(doldm,dnewm,1,nlstate,1,npar,1,nlstate,gradg); |
| } | |
| for(i=1;i<=nlstate;i++) | for(i=1;i<=nlstate;i++) |
| varpl[i][(int)age] = doldm[i][i]; /* Covariances are useless */ | varpl[i][(int)age] = doldm[i][i]; /* Covariances are useless */ |
| Line 4345 void cvevsij(double ***eij, double x[], | Line 4437 void cvevsij(double ***eij, double x[], |
| fprintf(ficresvpl,"\n"); | fprintf(ficresvpl,"\n"); |
| free_vector(gp,1,nlstate); | free_vector(gp,1,nlstate); |
| free_vector(gm,1,nlstate); | free_vector(gm,1,nlstate); |
| free_matrix(mgm,1,npar,1,nlstate); | |
| free_matrix(mgp,1,npar,1,nlstate); | |
| free_matrix(gradg,1,npar,1,nlstate); | free_matrix(gradg,1,npar,1,nlstate); |
| free_matrix(trgradg,1,nlstate,1,npar); | free_matrix(trgradg,1,nlstate,1,npar); |
| } /* End age */ | } /* End age */ |
| Line 4756 divided by h: hPij/h : <a href=\"%s_%d-3 | Line 4850 divided by h: hPij/h : <a href=\"%s_%d-3 |
| } | } |
| /* State specific survival functions (period) */ | /* State specific survival functions (period) */ |
| for(cpt=1; cpt<=nlstate;cpt++){ | for(cpt=1; cpt<=nlstate;cpt++){ |
| fprintf(fichtm,"<br>\n- Survival functions from state %d in any different live states and total.\ | fprintf(fichtm,"<br>\n- Survival functions from state %d in each live state and total.\ |
| Or probability to survive in various states (1 to %d) being in state %d at different ages.\ | Or probability to survive in various states (1 to %d) being in state %d at different ages.\ |
| <a href=\"%s%d_%d.svg\">%s%d_%d.svg</a><br> <img src=\"%s_%d-%d.svg\">", cpt, nlstate, cpt, subdirf2(optionfilefiname,"LIJT_"),cpt,jj1,subdirf2(optionfilefiname,"LIJT_"),cpt,jj1,subdirf2(optionfilefiname,"LIJT_"),cpt,jj1); | <a href=\"%s%d_%d.svg\">%s%d_%d.svg</a><br> <img src=\"%s_%d-%d.svg\">", cpt, nlstate, cpt, subdirf2(optionfilefiname,"LIJT_"),cpt,jj1,subdirf2(optionfilefiname,"LIJT_"),cpt,jj1,subdirf2(optionfilefiname,"LIJT_"),cpt,jj1); |
| } | } |
| Line 4766 divided by h: hPij/h : <a href=\"%s_%d-3 | Line 4860 divided by h: hPij/h : <a href=\"%s_%d-3 |
| <img src=\"%s_%d-%d.svg\">", cpt, cpt, nlstate, subdirf2(optionfilefiname,"P_"),cpt,jj1,subdirf2(optionfilefiname,"P_"),cpt,jj1,subdirf2(optionfilefiname,"P_"),cpt,jj1); | <img src=\"%s_%d-%d.svg\">", cpt, cpt, nlstate, subdirf2(optionfilefiname,"P_"),cpt,jj1,subdirf2(optionfilefiname,"P_"),cpt,jj1,subdirf2(optionfilefiname,"P_"),cpt,jj1); |
| } | } |
| for(cpt=1; cpt<=nlstate;cpt++) { | for(cpt=1; cpt<=nlstate;cpt++) { |
| fprintf(fichtm,"\n<br>- Life expectancy by health state (%d) at initial age and its decomposition into health expectancies in each alive state (1 to %d) (or area under each survival functions): <a href=\"%s%d%d.svg\">%s%d%d.svg</a> <br> \ | fprintf(fichtm,"\n<br>- Life expectancy by health state (%d) at initial age and its decomposition into health expectancies in each alive state (1 to %d) (or area under each survival functions): <a href=\"%s_%d%d.svg\">%s_%d%d.svg</a> <br> \ |
| <img src=\"%s_%d%d.svg\">",cpt,nlstate,subdirf2(optionfilefiname,"EXP_"),cpt,jj1,subdirf2(optionfilefiname,"EXP_"),cpt,jj1,subdirf2(optionfilefiname,"EXP_"),cpt,jj1); | <img src=\"%s_%d%d.svg\">",cpt,nlstate,subdirf2(optionfilefiname,"EXP_"),cpt,jj1,subdirf2(optionfilefiname,"EXP_"),cpt,jj1,subdirf2(optionfilefiname,"EXP_"),cpt,jj1); |
| } | } |
| /* } /\* end i1 *\/ */ | /* } /\* end i1 *\/ */ |
| Line 4836 See page 'Matrix of variance-covariance | Line 4930 See page 'Matrix of variance-covariance |
| } | } |
| for(cpt=1; cpt<=nlstate;cpt++) { | for(cpt=1; cpt<=nlstate;cpt++) { |
| fprintf(fichtm,"<br>- Observed (cross-sectional) and period (incidence based) \ | fprintf(fichtm,"<br>- Observed (cross-sectional) and period (incidence based) \ |
| prevalence (with 95%% confidence interval) in state (%d): %s%d_%d.svg <br>\ | prevalence (with 95%% confidence interval) in state (%d): <a href=\"%s_%d%d.svg\"> %s_%d-%d.svg <br>\ |
| <img src=\"%s_%d-%d.svg\">",cpt,subdirf2(optionfilefiname,"V_"),cpt,jj1,subdirf2(optionfilefiname,"V_"),cpt,jj1); | <img src=\"%s_%d-%d.svg\">",cpt,subdirf2(optionfilefiname,"V_"),cpt,jj1,subdirf2(optionfilefiname,"V_"),cpt,jj1,subdirf2(optionfilefiname,"V_"),cpt,jj1); |
| } | } |
| fprintf(fichtm,"\n<br>- Total life expectancy by age and \ | fprintf(fichtm,"\n<br>- Total life expectancy by age and \ |
| health expectancies in states (1) and (2). If popbased=1 the smooth (due to the model) \ | health expectancies in states (1) and (2). If popbased=1 the smooth (due to the model) \ |
| true period expectancies (those weighted with period prevalences are also\ | true period expectancies (those weighted with period prevalences are also\ |
| drawn in addition to the population based expectancies computed using\ | drawn in addition to the population based expectancies computed using\ |
| observed and cahotic prevalences: %s_%d.svg<br>\ | observed and cahotic prevalences: <a href=\"%s_%d.svg\">%s_%d.svg<br>\ |
| <img src=\"%s_%d.svg\">",subdirf2(optionfilefiname,"E_"),jj1,subdirf2(optionfilefiname,"E_"),jj1); | <img src=\"%s_%d.svg\">",subdirf2(optionfilefiname,"E_"),jj1,subdirf2(optionfilefiname,"E_"),jj1,subdirf2(optionfilefiname,"E_"),jj1); |
| /* } /\* end i1 *\/ */ | /* } /\* end i1 *\/ */ |
| }/* End k1 */ | }/* End k1 */ |
| fprintf(fichtm,"</ul>"); | fprintf(fichtm,"</ul>"); |
| Line 4873 void printinggnuplot(char fileresu[], ch | Line 4967 void printinggnuplot(char fileresu[], ch |
| fprintf(ficgp,"\n# Contributions to the Likelihood, mle >=1. For mle=4 no interpolation, pure matrix products.\n#\n"); | fprintf(ficgp,"\n# Contributions to the Likelihood, mle >=1. For mle=4 no interpolation, pure matrix products.\n#\n"); |
| fprintf(ficgp,"\n set log y; unset log x;set xlabel \"Age\"; set ylabel \"Likelihood (-2Log(L))\";"); | fprintf(ficgp,"\n set log y; unset log x;set xlabel \"Age\"; set ylabel \"Likelihood (-2Log(L))\";"); |
| /* fprintf(ficgp,"\nset ter svg size 640, 480"); */ /* Too big for svg */ | /* fprintf(ficgp,"\nset ter svg size 640, 480"); */ /* Too big for svg */ |
| fprintf(ficgp,"\nset ter png size 640, 480"); | fprintf(ficgp,"\nset ter pngcairo size 640, 480"); |
| /* nice for mle=4 plot by number of matrix products. | /* nice for mle=4 plot by number of matrix products. |
| replot "rrtest1/toto.txt" u 2:($4 == 1 && $5==2 ? $9 : 1/0):5 t "p12" with point lc 1 */ | replot "rrtest1/toto.txt" u 2:($4 == 1 && $5==2 ? $9 : 1/0):5 t "p12" with point lc 1 */ |
| /* replot exp(p1+p2*x)/(1+exp(p1+p2*x)+exp(p3+p4*x)+exp(p5+p6*x)) t "p12(x)" */ | /* replot exp(p1+p2*x)/(1+exp(p1+p2*x)+exp(p3+p4*x)+exp(p5+p6*x)) t "p12(x)" */ |
| /* fprintf(ficgp,"\nset out \"%s.svg\";",subdirf2(optionfilefiname,"ILK_")); */ | /* fprintf(ficgp,"\nset out \"%s.svg\";",subdirf2(optionfilefiname,"ILK_")); */ |
| fprintf(ficgp,"\nset out \"%s-dest.png\";",subdirf2(optionfilefiname,"ILK_")); | fprintf(ficgp,"\nset out \"%s-dest.png\";",subdirf2(optionfilefiname,"ILK_")); |
| fprintf(ficgp,"\nset log y;plot \"%s\" u 2:(-$11):5 t \"All sample, transitions colored by destination\" with dots lc variable; set out;\n",subdirf(fileresilk)); | fprintf(ficgp,"\nset log y;plot \"%s\" u 2:(-$12):5 t \"All sample, transitions colored by destination\" with dots lc variable; set out;\n",subdirf(fileresilk)); |
| fprintf(ficgp,"\nset out \"%s-ori.png\";",subdirf2(optionfilefiname,"ILK_")); | fprintf(ficgp,"\nset out \"%s-ori.png\";",subdirf2(optionfilefiname,"ILK_")); |
| fprintf(ficgp,"\nset log y;plot \"%s\" u 2:(-$11):4 t \"All sample, transitions colored by origin\" with dots lc variable; set out;\n\n",subdirf(fileresilk)); | fprintf(ficgp,"\nset log y;plot \"%s\" u 2:(-$12):4 t \"All sample, transitions colored by origin\" with dots lc variable; set out;\n\n",subdirf(fileresilk)); |
| for (i=1; i<= nlstate ; i ++) { | for (i=1; i<= nlstate ; i ++) { |
| fprintf(ficgp,"\nset out \"%s-p%dj.png\";set ylabel \"Probability for each individual/wave\";",subdirf2(optionfilefiname,"ILK_"),i); | fprintf(ficgp,"\nset out \"%s-p%dj.png\";set ylabel \"Probability for each individual/wave\";",subdirf2(optionfilefiname,"ILK_"),i); |
| fprintf(ficgp,"unset log;\n plot \"%s\"",subdirf(fileresilk)); | fprintf(ficgp,"unset log;\n# plot weighted, mean weight should have point size of 0.5\n plot \"%s\"",subdirf(fileresilk)); |
| fprintf(ficgp," u 2:($4 == %d && $5==%d ? $9 : 1/0):5 t \"p%d%d\" with points lc variable \\\n",i,1,i,1); | fprintf(ficgp," u 2:($4 == %d && $5==%d ? $9 : 1/0):($11/4.):5 t \"p%d%d\" with points pointtype 7 ps variable lc variable \\\n",i,1,i,1); |
| for (j=2; j<= nlstate+ndeath ; j ++) { | for (j=2; j<= nlstate+ndeath ; j ++) { |
| fprintf(ficgp,", \"\" u 2:($4 == %d && $5==%d ? $9 : 1/0):5 t \"p%d%d\" with points lc variable ",i,j,i,j); | fprintf(ficgp,",\\\n \"\" u 2:($4 == %d && $5==%d ? $9 : 1/0):($11/4.):5 t \"p%d%d\" with points pointtype 7 ps variable lc variable ",i,j,i,j); |
| } | } |
| fprintf(ficgp,";\nset out; unset ylabel;\n"); | fprintf(ficgp,";\nset out; unset ylabel;\n"); |
| } | } |
| Line 6742 int main(int argc, char *argv[]) | Line 6836 int main(int argc, char *argv[]) |
| printf("\nIMaCh version %s, %s\n%s",version, copyright, fullversion); | printf("\nIMaCh version %s, %s\n%s",version, copyright, fullversion); |
| if(argc <=1){ | if(argc <=1){ |
| printf("\nEnter the parameter file name: "); | printf("\nEnter the parameter file name: "); |
| fgets(pathr,FILENAMELENGTH,stdin); | if(!fgets(pathr,FILENAMELENGTH,stdin)){ |
| printf("ERROR Empty parameter file name\n"); | |
| goto end; | |
| } | |
| i=strlen(pathr); | i=strlen(pathr); |
| if(pathr[i-1]=='\n') | if(pathr[i-1]=='\n') |
| pathr[i-1]='\0'; | pathr[i-1]='\0'; |
| i=strlen(pathr); | i=strlen(pathr); |
| if(pathr[i-1]==' ') /* This may happen when dragging on oS/X! */ | if(i >= 1 && pathr[i-1]==' ') {/* This may happen when dragging on oS/X! */ |
| pathr[i-1]='\0'; | pathr[i-1]='\0'; |
| for (tok = pathr; tok != NULL; ){ | } |
| i=strlen(pathr); | |
| if( i==0 ){ | |
| printf("ERROR Empty parameter file name\n"); | |
| goto end; | |
| } | |
| for (tok = pathr; tok != NULL; ){ | |
| printf("Pathr |%s|\n",pathr); | printf("Pathr |%s|\n",pathr); |
| while ((val = strsep(&tok, "\"" )) != NULL && *val == '\0'); | while ((val = strsep(&tok, "\"" )) != NULL && *val == '\0'); |
| printf("val= |%s| pathr=%s\n",val,pathr); | printf("val= |%s| pathr=%s\n",val,pathr); |
| Line 7645 Please run with mle=-1 to get a correct | Line 7748 Please run with mle=-1 to get a correct |
| free_matrix(ximort,1,NDIM,1,NDIM); | free_matrix(ximort,1,NDIM,1,NDIM); |
| #endif | #endif |
| } /* Endof if mle==-3 mortality only */ | } /* Endof if mle==-3 mortality only */ |
| /* Standard maximisation */ | /* Standard */ |
| else{ /* For mle !=- 3 */ | else{ /* For mle !=- 3, could be 0 or 1 or 4 etc. */ |
| globpr=0;/* debug */ | globpr=0;/* Computes sum of likelihood for globpr=1 and funcone */ |
| /* Computes likelihood for initial parameters */ | /* Computes likelihood for initial parameters, uses funcone to compute gpimx and gsw */ |
| likelione(ficres, p, npar, nlstate, &globpr, &ipmx, &sw, &fretone, funcone); /* Prints the contributions to the likelihood */ | likelione(ficres, p, npar, nlstate, &globpr, &ipmx, &sw, &fretone, funcone); /* Prints the contributions to the likelihood */ |
| printf("First Likeli=%12.6f ipmx=%ld sw=%12.6f",fretone,ipmx,sw); | printf("First Likeli=%12.6f ipmx=%ld sw=%12.6f",fretone,ipmx,sw); |
| for (k=1; k<=npar;k++) | for (k=1; k<=npar;k++) |
| printf(" %d %8.5f",k,p[k]); | printf(" %d %8.5f",k,p[k]); |
| printf("\n"); | printf("\n"); |
| globpr=1; /* again, to print the contributions */ | if(mle>=1){ /* Could be 1 or 2, Real Maximization */ |
| /* mlikeli uses func not funcone */ | |
| mlikeli(ficres,p, npar, ncovmodel, nlstate, ftol, func); | |
| } | |
| if(mle==0) {/* No optimization, will print the likelihoods for the datafile */ | |
| globpr=0;/* Computes sum of likelihood for globpr=1 and funcone */ | |
| /* Computes likelihood for initial parameters, uses funcone to compute gpimx and gsw */ | |
| likelione(ficres, p, npar, nlstate, &globpr, &ipmx, &sw, &fretone, funcone); /* Prints the contributions to the likelihood */ | |
| } | |
| globpr=1; /* again, to print the individual contributions using computed gpimx and gsw */ | |
| likelione(ficres, p, npar, nlstate, &globpr, &ipmx, &sw, &fretone, funcone); /* Prints the contributions to the likelihood */ | likelione(ficres, p, npar, nlstate, &globpr, &ipmx, &sw, &fretone, funcone); /* Prints the contributions to the likelihood */ |
| printf("Second Likeli=%12.6f ipmx=%ld sw=%12.6f",fretone,ipmx,sw); | printf("Second Likeli=%12.6f ipmx=%ld sw=%12.6f",fretone,ipmx,sw); |
| for (k=1; k<=npar;k++) | for (k=1; k<=npar;k++) |
| printf(" %d %8.5f",k,p[k]); | printf(" %d %8.5f",k,p[k]); |
| printf("\n"); | printf("\n"); |
| if(mle>=1){ /* Could be 1 or 2, Real Maximisation */ | |
| mlikeli(ficres,p, npar, ncovmodel, nlstate, ftol, func); | |
| } | |
| /*--------- results files --------------*/ | /*--------- results files --------------*/ |
| fprintf(ficres,"title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\nftol=%e stepm=%d ncovcol=%d nlstate=%d ndeath=%d maxwav=%d mle= 0 weight=%d\nmodel=1+age+%s.\n", title, datafile, lastobs, firstpass,lastpass,ftol, stepm, ncovcol, nlstate, ndeath, maxwav, weightopt,model); | fprintf(ficres,"title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\nftol=%e stepm=%d ncovcol=%d nlstate=%d ndeath=%d maxwav=%d mle= 0 weight=%d\nmodel=1+age+%s.\n", title, datafile, lastobs, firstpass,lastpass,ftol, stepm, ncovcol, nlstate, ndeath, maxwav, weightopt,model); |
| Line 7992 Please run with mle=-1 to get a correct | Line 8101 Please run with mle=-1 to get a correct |
| printf("Problem with Health Exp. resultfile: %s\n", filerese); exit(0); | printf("Problem with Health Exp. resultfile: %s\n", filerese); exit(0); |
| fprintf(ficlog,"Problem with Health Exp. resultfile: %s\n", filerese); exit(0); | fprintf(ficlog,"Problem with Health Exp. resultfile: %s\n", filerese); exit(0); |
| } | } |
| printf("Computing Health Expectancies: result on file '%s' \n", filerese); | printf("Computing Health Expectancies: result on file '%s' ...", filerese);fflush(stdout); |
| fprintf(ficlog,"Computing Health Expectancies: result on file '%s' \n", filerese); | fprintf(ficlog,"Computing Health Expectancies: result on file '%s' ...", filerese);fflush(ficlog); |
| /*for(cptcov=1,k=0;cptcov<=i1;cptcov++){ | /*for(cptcov=1,k=0;cptcov<=i1;cptcov++){ |
| for(cptcod=1;cptcod<=ncodemax[cptcov];cptcod++){*/ | for(cptcod=1;cptcod<=ncodemax[cptcov];cptcod++){*/ |
| Line 8012 Please run with mle=-1 to get a correct | Line 8121 Please run with mle=-1 to get a correct |
| /*}*/ | /*}*/ |
| } | } |
| fclose(ficreseij); | fclose(ficreseij); |
| printf("done evsij\n");fflush(stdout); | |
| fprintf(ficlog,"done evsij\n");fflush(ficlog); | |
| /*---------- Health expectancies and variances ------------*/ | /*---------- Health expectancies and variances ------------*/ |
| Line 8023 Please run with mle=-1 to get a correct | Line 8133 Please run with mle=-1 to get a correct |
| printf("Problem with total LE resultfile: %s\n", filerest);goto end; | printf("Problem with total LE resultfile: %s\n", filerest);goto end; |
| fprintf(ficlog,"Problem with total LE resultfile: %s\n", filerest);goto end; | fprintf(ficlog,"Problem with total LE resultfile: %s\n", filerest);goto end; |
| } | } |
| printf("Computing Total Life expectancies with their standard errors: file '%s' \n", filerest); | printf("Computing Total Life expectancies with their standard errors: file '%s' ...\n", filerest); fflush(stdout); |
| fprintf(ficlog,"Computing Total Life expectancies with their standard errors: file '%s' \n", filerest); | fprintf(ficlog,"Computing Total Life expectancies with their standard errors: file '%s' ...\n", filerest); fflush(ficlog); |
| strcpy(fileresstde,"STDE_"); | strcpy(fileresstde,"STDE_"); |
| Line 8033 Please run with mle=-1 to get a correct | Line 8143 Please run with mle=-1 to get a correct |
| printf("Problem with Health Exp. and std errors resultfile: %s\n", fileresstde); exit(0); | printf("Problem with Health Exp. and std errors resultfile: %s\n", fileresstde); exit(0); |
| fprintf(ficlog,"Problem with Health Exp. and std errors resultfile: %s\n", fileresstde); exit(0); | fprintf(ficlog,"Problem with Health Exp. and std errors resultfile: %s\n", fileresstde); exit(0); |
| } | } |
| printf("Computing Health Expectancies and standard errors: result on file '%s' \n", fileresstde); | printf(" Computing Health Expectancies and standard errors: result on file '%s' \n", fileresstde); |
| fprintf(ficlog,"Computing Health Expectancies and standard errors: result on file '%s' \n", fileresstde); | fprintf(ficlog," Computing Health Expectancies and standard errors: result on file '%s' \n", fileresstde); |
| strcpy(filerescve,"CVE_"); | strcpy(filerescve,"CVE_"); |
| strcat(filerescve,fileresu); | strcat(filerescve,fileresu); |
| Line 8042 Please run with mle=-1 to get a correct | Line 8152 Please run with mle=-1 to get a correct |
| printf("Problem with Covar. Health Exp. resultfile: %s\n", filerescve); exit(0); | printf("Problem with Covar. Health Exp. resultfile: %s\n", filerescve); exit(0); |
| fprintf(ficlog,"Problem with Covar. Health Exp. resultfile: %s\n", filerescve); exit(0); | fprintf(ficlog,"Problem with Covar. Health Exp. resultfile: %s\n", filerescve); exit(0); |
| } | } |
| printf("Computing Covar. of Health Expectancies: result on file '%s' \n", filerescve); | printf(" Computing Covar. of Health Expectancies: result on file '%s' \n", filerescve); |
| fprintf(ficlog,"Computing Covar. of Health Expectancies: result on file '%s' \n", filerescve); | fprintf(ficlog," Computing Covar. of Health Expectancies: result on file '%s' \n", filerescve); |
| strcpy(fileresv,"V_"); | strcpy(fileresv,"V_"); |
| strcat(fileresv,fileresu); | strcat(fileresv,fileresu); |
| Line 8051 Please run with mle=-1 to get a correct | Line 8161 Please run with mle=-1 to get a correct |
| printf("Problem with variance resultfile: %s\n", fileresv);exit(0); | printf("Problem with variance resultfile: %s\n", fileresv);exit(0); |
| fprintf(ficlog,"Problem with variance resultfile: %s\n", fileresv);exit(0); | fprintf(ficlog,"Problem with variance resultfile: %s\n", fileresv);exit(0); |
| } | } |
| printf("Computing Variance-covariance of DFLEs: file '%s' \n", fileresv); | printf(" Computing Variance-covariance of DFLEs: file '%s' ... ", fileresv);fflush(stdout); |
| fprintf(ficlog,"Computing Variance-covariance of DFLEs: file '%s' \n", fileresv); | fprintf(ficlog," Computing Variance-covariance of DFLEs: file '%s' ... ", fileresv);fflush(ficlog); |
| /*for(cptcov=1,k=0;cptcov<=i1;cptcov++){ | /*for(cptcov=1,k=0;cptcov<=i1;cptcov++){ |
| for(cptcod=1;cptcod<=ncodemax[cptcov];cptcod++){*/ | for(cptcod=1;cptcod<=ncodemax[cptcov];cptcod++){*/ |
| for (k=1; k <= (int) pow(2,cptcoveff); k++){ | for (k=1; k <= (int) pow(2,cptcoveff); k++){ |
| fprintf(ficrest,"\n#****** "); | fprintf(ficrest,"\n#****** "); |
| for(j=1;j<=cptcoveff;j++) | for(j=1;j<=cptcoveff;j++) |
| fprintf(ficrest,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]); | fprintf(ficrest,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]); |
| fprintf(ficrest,"******\n"); | fprintf(ficrest,"******\n"); |
| fprintf(ficresstdeij,"\n#****** "); | fprintf(ficresstdeij,"\n#****** "); |
| fprintf(ficrescveij,"\n#****** "); | fprintf(ficrescveij,"\n#****** "); |
| for(j=1;j<=cptcoveff;j++) { | for(j=1;j<=cptcoveff;j++) { |
| fprintf(ficresstdeij,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]); | fprintf(ficresstdeij,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]); |
| fprintf(ficrescveij,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]); | fprintf(ficrescveij,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]); |
| } | } |
| fprintf(ficresstdeij,"******\n"); | fprintf(ficresstdeij,"******\n"); |
| fprintf(ficrescveij,"******\n"); | fprintf(ficrescveij,"******\n"); |
| fprintf(ficresvij,"\n#****** "); | fprintf(ficresvij,"\n#****** "); |
| for(j=1;j<=cptcoveff;j++) | for(j=1;j<=cptcoveff;j++) |
| fprintf(ficresvij,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]); | fprintf(ficresvij,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]); |
| fprintf(ficresvij,"******\n"); | fprintf(ficresvij,"******\n"); |
| eij=ma3x(1,nlstate,1,nlstate,(int) bage, (int) fage); | eij=ma3x(1,nlstate,1,nlstate,(int) bage, (int) fage); |
| oldm=oldms;savm=savms; | oldm=oldms;savm=savms; |
| cvevsij(eij, p, nlstate, stepm, (int) bage, (int)fage, oldm, savm, k, estepm, delti, matcov, strstart); | printf(" cvevsij %d, ",k); |
| /* | fprintf(ficlog, " cvevsij %d, ",k); |
| */ | cvevsij(eij, p, nlstate, stepm, (int) bage, (int)fage, oldm, savm, k, estepm, delti, matcov, strstart); |
| /* goto endfree; */ | printf(" end cvevsij \n "); |
| fprintf(ficlog, " end cvevsij \n "); | |
| vareij=ma3x(1,nlstate,1,nlstate,(int) bage, (int) fage); | |
| pstamp(ficrest); | /* |
| */ | |
| /* goto endfree; */ | |
| for(vpopbased=0; vpopbased <= popbased; vpopbased++){ /* Done for vpopbased=0 and vpopbased=1 if popbased==1*/ | |
| oldm=oldms;savm=savms; /* ZZ Segmentation fault */ | vareij=ma3x(1,nlstate,1,nlstate,(int) bage, (int) fage); |
| cptcod= 0; /* To be deleted */ | pstamp(ficrest); |
| varevsij(optionfilefiname, vareij, matcov, p, delti, nlstate, stepm, (int) bage, (int) fage, oldm, savm, prlim, ftolpl, ncvyear, k, estepm, cptcov,cptcod,vpopbased,mobilav, strstart); /* cptcod not initialized Intel */ | |
| fprintf(ficrest,"# Total life expectancy with std error and decomposition into time to be expected in each health state\n# (weighted average of eij where weights are "); | |
| if(vpopbased==1) | for(vpopbased=0; vpopbased <= popbased; vpopbased++){ /* Done for vpopbased=0 and vpopbased=1 if popbased==1*/ |
| fprintf(ficrest,"the age specific prevalence observed (cross-sectionally) in the population i.e cross-sectionally\n in each health state (popbased=1) (mobilav=%d)\n",mobilav); | oldm=oldms;savm=savms; /* ZZ Segmentation fault */ |
| else | cptcod= 0; /* To be deleted */ |
| fprintf(ficrest,"the age specific period (stable) prevalences in each health state \n"); | printf("varevsij %d \n",vpopbased); |
| fprintf(ficrest,"# Age popbased mobilav e.. (std) "); | fprintf(ficlog, "varevsij %d \n",vpopbased); |
| for (i=1;i<=nlstate;i++) fprintf(ficrest,"e.%d (std) ",i); | varevsij(optionfilefiname, vareij, matcov, p, delti, nlstate, stepm, (int) bage, (int) fage, oldm, savm, prlim, ftolpl, ncvyear, k, estepm, cptcov,cptcod,vpopbased,mobilav, strstart); /* cptcod not initialized Intel */ |
| fprintf(ficrest,"\n"); | fprintf(ficrest,"# Total life expectancy with std error and decomposition into time to be expected in each health state\n# (weighted average of eij where weights are "); |
| /* printf("Which p?\n"); for(i=1;i<=npar;i++)printf("p[i=%d]=%lf,",i,p[i]);printf("\n"); */ | if(vpopbased==1) |
| epj=vector(1,nlstate+1); | fprintf(ficrest,"the age specific prevalence observed (cross-sectionally) in the population i.e cross-sectionally\n in each health state (popbased=1) (mobilav=%d)\n",mobilav); |
| for(age=bage; age <=fage ;age++){ | else |
| prevalim(prlim, nlstate, p, age, oldm, savm, ftolpl, ncvyear, k); /*ZZ Is it the correct prevalim */ | fprintf(ficrest,"the age specific period (stable) prevalences in each health state \n"); |
| if (vpopbased==1) { | fprintf(ficrest,"# Age popbased mobilav e.. (std) "); |
| if(mobilav ==0){ | for (i=1;i<=nlstate;i++) fprintf(ficrest,"e.%d (std) ",i); |
| for(i=1; i<=nlstate;i++) | fprintf(ficrest,"\n"); |
| prlim[i][i]=probs[(int)age][i][k]; | /* printf("Which p?\n"); for(i=1;i<=npar;i++)printf("p[i=%d]=%lf,",i,p[i]);printf("\n"); */ |
| }else{ /* mobilav */ | epj=vector(1,nlstate+1); |
| for(i=1; i<=nlstate;i++) | printf("Computing age specific period (stable) prevalences in each health state \n"); |
| prlim[i][i]=mobaverage[(int)age][i][k]; | fprintf(ficlog,"Computing age specific period (stable) prevalences in each health state \n"); |
| } | for(age=bage; age <=fage ;age++){ |
| } | prevalim(prlim, nlstate, p, age, oldm, savm, ftolpl, ncvyear, k); /*ZZ Is it the correct prevalim */ |
| if (vpopbased==1) { | |
| fprintf(ficrest," %4.0f %d %d",age, vpopbased, mobilav); | if(mobilav ==0){ |
| /* printf(" age %4.0f ",age); */ | for(i=1; i<=nlstate;i++) |
| for(j=1, epj[nlstate+1]=0.;j <=nlstate;j++){ | prlim[i][i]=probs[(int)age][i][k]; |
| for(i=1, epj[j]=0.;i <=nlstate;i++) { | }else{ /* mobilav */ |
| epj[j] += prlim[i][i]*eij[i][j][(int)age]; | for(i=1; i<=nlstate;i++) |
| /*ZZZ printf("%lf %lf ", prlim[i][i] ,eij[i][j][(int)age]);*/ | prlim[i][i]=mobaverage[(int)age][i][k]; |
| /* printf("%lf %lf ", prlim[i][i] ,eij[i][j][(int)age]); */ | |
| } | |
| epj[nlstate+1] +=epj[j]; | |
| } | } |
| /* printf(" age %4.0f \n",age); */ | } |
| for(i=1, vepp=0.;i <=nlstate;i++) | fprintf(ficrest," %4.0f %d %d",age, vpopbased, mobilav); |
| for(j=1;j <=nlstate;j++) | /* fprintf(ficrest," %4.0f %d %d %d %d",age, vpopbased, mobilav,Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]); */ /* to be done */ |
| vepp += vareij[i][j][(int)age]; | /* printf(" age %4.0f ",age); */ |
| fprintf(ficrest," %7.3f (%7.3f)", epj[nlstate+1],sqrt(vepp)); | for(j=1, epj[nlstate+1]=0.;j <=nlstate;j++){ |
| for(j=1;j <=nlstate;j++){ | for(i=1, epj[j]=0.;i <=nlstate;i++) { |
| fprintf(ficrest," %7.3f (%7.3f)", epj[j],sqrt(vareij[j][j][(int)age])); | epj[j] += prlim[i][i]*eij[i][j][(int)age]; |
| /*ZZZ printf("%lf %lf ", prlim[i][i] ,eij[i][j][(int)age]);*/ | |
| /* printf("%lf %lf ", prlim[i][i] ,eij[i][j][(int)age]); */ | |
| } | } |
| fprintf(ficrest,"\n"); | epj[nlstate+1] +=epj[j]; |
| } | } |
| /* printf(" age %4.0f \n",age); */ | |
| for(i=1, vepp=0.;i <=nlstate;i++) | |
| for(j=1;j <=nlstate;j++) | |
| vepp += vareij[i][j][(int)age]; | |
| fprintf(ficrest," %7.3f (%7.3f)", epj[nlstate+1],sqrt(vepp)); | |
| for(j=1;j <=nlstate;j++){ | |
| fprintf(ficrest," %7.3f (%7.3f)", epj[j],sqrt(vareij[j][j][(int)age])); | |
| } | |
| fprintf(ficrest,"\n"); | |
| } | } |
| free_ma3x(eij,1,nlstate,1,nlstate,(int) bage, (int)fage); | } /* End vpopbased */ |
| free_ma3x(vareij,1,nlstate,1,nlstate,(int) bage, (int)fage); | free_ma3x(eij,1,nlstate,1,nlstate,(int) bage, (int)fage); |
| free_vector(epj,1,nlstate+1); | free_ma3x(vareij,1,nlstate,1,nlstate,(int) bage, (int)fage); |
| free_vector(epj,1,nlstate+1); | |
| printf("done \n");fflush(stdout); | |
| fprintf(ficlog,"done\n");fflush(ficlog); | |
| /*}*/ | /*}*/ |
| } | } /* End k */ |
| free_vector(weight,1,n); | free_vector(weight,1,n); |
| free_imatrix(Tvard,1,NCOVMAX,1,2); | free_imatrix(Tvard,1,NCOVMAX,1,2); |
| free_imatrix(s,1,maxwav+1,1,n); | free_imatrix(s,1,maxwav+1,1,n); |
| Line 8152 Please run with mle=-1 to get a correct | Line 8275 Please run with mle=-1 to get a correct |
| fclose(ficrescveij); | fclose(ficrescveij); |
| fclose(ficresvij); | fclose(ficresvij); |
| fclose(ficrest); | fclose(ficrest); |
| printf("done Health expectancies\n");fflush(stdout); | |
| fprintf(ficlog,"done Health expectancies\n");fflush(ficlog); | |
| fclose(ficpar); | fclose(ficpar); |
| /*------- Variance of period (stable) prevalence------*/ | /*------- Variance of period (stable) prevalence------*/ |
| Line 8162 Please run with mle=-1 to get a correct | Line 8287 Please run with mle=-1 to get a correct |
| printf("Problem with variance of period (stable) prevalence resultfile: %s\n", fileresvpl); | printf("Problem with variance of period (stable) prevalence resultfile: %s\n", fileresvpl); |
| exit(0); | exit(0); |
| } | } |
| printf("Computing Variance-covariance of period (stable) prevalence: file '%s' \n", fileresvpl); | printf("Computing Variance-covariance of period (stable) prevalence: file '%s' ...", fileresvpl);fflush(stdout); |
| fprintf(ficlog, "Computing Variance-covariance of period (stable) prevalence: file '%s' ...", fileresvpl);fflush(ficlog); | |
| /*for(cptcov=1,k=0;cptcov<=i1;cptcov++){ | /*for(cptcov=1,k=0;cptcov<=i1;cptcov++){ |
| for(cptcod=1;cptcod<=ncodemax[cptcov];cptcod++){*/ | for(cptcod=1;cptcod<=ncodemax[cptcov];cptcod++){*/ |
| Line 8181 Please run with mle=-1 to get a correct | Line 8307 Please run with mle=-1 to get a correct |
| } | } |
| fclose(ficresvpl); | fclose(ficresvpl); |
| printf("done variance-covariance of period prevalence\n");fflush(stdout); | |
| fprintf(ficlog,"done variance-covariance of period prevalence\n");fflush(ficlog); | |
| /*---------- End : free ----------------*/ | /*---------- End : free ----------------*/ |
| if (mobilav!=0) free_ma3x(mobaverage,1, AGESUP,1,NCOVMAX, 1,NCOVMAX); | if (mobilav!=0) free_ma3x(mobaverage,1, AGESUP,1,NCOVMAX, 1,NCOVMAX); |