--- imach/src/imach.c 2003/06/17 20:04:08 1.86 +++ imach/src/imach.c 2003/06/18 12:26:01 1.87 @@ -1,6 +1,9 @@ -/* $Id: imach.c,v 1.86 2003/06/17 20:04:08 brouard Exp $ +/* $Id: imach.c,v 1.87 2003/06/18 12:26:01 brouard Exp $ $State: Exp $ $Log: imach.c,v $ + Revision 1.87 2003/06/18 12:26:01 brouard + Version 0.96 + Revision 1.86 2003/06/17 20:04:08 brouard (Module): Change position of html and gnuplot routines and added routine fileappend. @@ -158,11 +161,11 @@ #define ODIRSEPARATOR '/' #endif -/* $Id: imach.c,v 1.86 2003/06/17 20:04:08 brouard Exp $ */ +/* $Id: imach.c,v 1.87 2003/06/18 12:26:01 brouard Exp $ */ /* $State: Exp $ */ -char version[]="Imach version 0.95a2, June 2003, INED-EUROREVES "; -char fullversion[]="$Revision: 1.86 $ $Date: 2003/06/17 20:04:08 $"; +char version[]="Imach version 0.96, June 2003, INED-EUROREVES "; +char fullversion[]="$Revision: 1.87 $ $Date: 2003/06/18 12:26:01 $"; int erreur; /* Error number */ int nvar; int cptcovn=0, cptcovage=0, cptcoveff=0,cptcov; @@ -175,6 +178,8 @@ int popbased=0; int *wav; /* Number of waves for this individuual 0 is possible */ int maxwav; /* Maxim number of waves */ int jmin, jmax; /* min, max spacing between 2 waves */ +int gipmx, gsw; /* Global variables on the number of contributions + to the likelihood and the sum of weights (done by funcone)*/ int mle, weightopt; int **mw; /* mw[mi][i] is number of the mi wave for this individual */ int **dh; /* dh[mi][i] is number of steps between mi,mi+1 for this individual */ @@ -1290,10 +1295,12 @@ double func( double *x) /*************** log-likelihood *************/ double funcone( double *x) { + /* Same as likeli but slower because of a lot of printf and if */ int i, ii, j, k, mi, d, kk; double l, ll[NLSTATEMAX], cov[NCOVMAX]; double **out; double lli; /* Individual log likelihood */ + double llt; int s1, s2; double bbh, survp; /*extern weight */ @@ -1354,54 +1361,55 @@ double funcone( double *x) %10.6f %10.6f %10.6f ", \ num[i],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,l=0.; k<=nlstate; k++) - fprintf(ficresilk," %10.6f",ll[k]); - fprintf(ficresilk,"\n"); + for(k=1,llt=0.,l=0.; k<=nlstate; k++){ + llt +=ll[k]*gipmx/gsw; + fprintf(ficresilk," %10.6f",-ll[k]*gipmx/gsw); + } + fprintf(ficresilk," %10.6f\n", -llt); } } /* end of wave */ } /* end of individual */ for(k=1,l=0.; k<=nlstate; k++) l += ll[k]; /* printf("l1=%f l2=%f ",ll[1],ll[2]); */ l= l*ipmx/sw; /* To get the same order of magnitude as if weight=1 for every body */ + if(globpr==0){ /* First time we count the contributions and weights */ + gipmx=ipmx; + gsw=sw; + } return -l; } -void likelione(FILE *ficres,double p[], int npar, int nlstate, int *globpr, long *ipmx, double *sw, double *fretone, double (*funcone)(double [])) +void likelione(FILE *ficres,double p[], int npar, int nlstate, int *globpri, long *ipmx, double *sw, double *fretone, double (*funcone)(double [])) { - /* This routine should help understanding what is done with the selection of individuals/waves and + /* This routine should help understanding what is done with + the selection of individuals/waves and to check the exact contribution to the likelihood. Plotting could be done. */ int k; - if(globpr !=0){ /* Just counts and sums no printings */ + + if(*globpri !=0){ /* Just counts and sums no printings */ strcpy(fileresilk,"ilk"); strcat(fileresilk,fileres); if((ficresilk=fopen(fileresilk,"w"))==NULL) { printf("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_product_matrix pij weight 2ln(pij)*weight 0pij_x 0pij_(x-stepm) cumulating_loglikeli_by_health_state\n"); + 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, "#num_i i s1 s2 mi mw dh likeli weight 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]); */ for(k=1; k<=nlstate; k++) - fprintf(ficresilk," ll[%d]",k); - fprintf(ficresilk,"\n"); + fprintf(ficresilk," -2*gipw/gsw*weight*ll[%d]++",k); + fprintf(ficresilk," -2*gipw/gsw*weight*ll(total)\n"); } *fretone=(*funcone)(p); - if(globpr !=0){ + if(*globpri !=0){ fclose(ficresilk); - if((fichtm=fopen(optionfilehtm,"a"))==NULL) { - printf("Problem with html file: %s\n", optionfilehtm); - fprintf(ficlog,"Problem with html file: %s\n", optionfilehtm); - exit(0); - } - else{ - fprintf(fichtm,"\n
File of contributions to the likelihood: %s
\n",fileresilk); - fclose(fichtm); - } - } + fprintf(fichtm,"\n
File of contributions to the likelihood: %s
\n",fileresilk,fileresilk); + fflush(fichtm); + } return; } @@ -2368,15 +2376,15 @@ void varevsij(char optionfilefiname[], d else{ fprintf(ficgp,"\n# Routine varevsij"); } - if((fichtm=fopen(optionfilehtm,"a"))==NULL) { - printf("Problem with html file: %s\n", optionfilehtm); - fprintf(ficlog,"Problem with html file: %s\n", optionfilehtm); - exit(0); - } - else{ - fprintf(fichtm,"\n
  • Computing probabilities of dying over estepm months as a weighted average (i.e global mortality independent of initial healh state)

  • \n"); - fprintf(fichtm,"\n
    %s
    \n",digitp); - } +/* if((fichtm=fopen(optionfilehtm,"a"))==NULL) { */ +/* printf("Problem with html file: %s\n", optionfilehtm); */ +/* fprintf(ficlog,"Problem with html file: %s\n", optionfilehtm); */ +/* exit(0); */ +/* } */ +/* else{ */ + fprintf(fichtm,"\n
  • Computing probabilities of dying over estepm months as a weighted average (i.e global mortality independent of initial healh state)

  • \n"); + fprintf(fichtm,"\n
    %s
    \n",digitp); +/* } */ varppt = matrix(nlstate+1,nlstate+ndeath,nlstate+1,nlstate+ndeath); fprintf(ficresvij,"# Variance and covariance of health expectancies e.j \n# (weighted average of eij where weights are the stable prevalence in health states i\n"); @@ -2606,7 +2614,7 @@ void varevsij(char optionfilefiname[], d if (mobilav!=0) free_ma3x(mobaverage,1, AGESUP,1,NCOVMAX, 1,NCOVMAX); fclose(ficresprobmorprev); fclose(ficgp); - fclose(fichtm); +/* fclose(fichtm); */ } /* end varevsij */ /************ Variance of prevlim ******************/ @@ -2771,12 +2779,12 @@ void varprob(char optionfilefiname[], do else{ fprintf(ficgp,"\n# Routine varprob"); } - if((fichtm=fopen(optionfilehtm,"a"))==NULL) { - printf("Problem with html file: %s\n", optionfilehtm); - fprintf(ficlog,"Problem with html file: %s\n", optionfilehtm); - exit(0); - } - else{ +/* if((fichtm=fopen(optionfilehtm,"a"))==NULL) { */ +/* printf("Problem with html file: %s\n", optionfilehtm); */ +/* fprintf(ficlog,"Problem with html file: %s\n", optionfilehtm); */ +/* exit(0); */ +/* } */ +/* else{ */ fprintf(fichtm,"\n
  • Computing and drawing one step probabilities with their confidence intervals

  • \n"); fprintf(fichtm,"\n"); @@ -2784,7 +2792,7 @@ void varprob(char optionfilefiname[], do fprintf(fichtm,"\nWe have drawn ellipsoids of confidence around the pij, pkl to understand the covariance between two incidences. They are expressed in year-1 in order to be less dependent of stepm.
    \n"); fprintf(fichtm,"\n
    We have drawn x'cov-1x = 4 where x is the column vector (pij,pkl). It means that if pij and pkl where uncorrelated the (2X2) matrix would have been (1/(var pij), 0 , 0, 1/(var pkl)), and the confidence interval would be 2 standard deviations wide on each axis.
    When both incidences are correlated we diagonalised the inverse of the covariance matrix and made the appropriate rotation.
    \n"); - } +/* } */ cov[1]=1; tj=cptcoveff; @@ -3001,7 +3009,6 @@ void varprob(char optionfilefiname[], do fclose(ficresprobcov); fclose(ficresprobcor); fclose(ficgp); - fclose(fichtm); } @@ -3014,10 +3021,10 @@ void printinghtml(char fileres[], char t double jprev2, double mprev2,double anprev2){ int jj1, k1, i1, cpt; /*char optionfilehtm[FILENAMELENGTH];*/ - if((fichtm=fopen(optionfilehtm,"a"))==NULL) { - printf("Problem with %s \n",optionfilehtm), exit(0); - fprintf(ficlog,"Problem with %s \n",optionfilehtm), exit(0); - } +/* if((fichtm=fopen(optionfilehtm,"a"))==NULL) { */ +/* printf("Problem with %s \n",optionfilehtm), exit(0); */ +/* fprintf(ficlog,"Problem with %s \n",optionfilehtm), exit(0); */ +/* } */ fprintf(fichtm,"