--- imach/src/imach.c 2003/06/17 20:04:08 1.86
+++ imach/src/imach.c 2003/06/23 17:54:56 1.88
@@ -1,6 +1,12 @@
-/* $Id: imach.c,v 1.86 2003/06/17 20:04:08 brouard Exp $
+/* $Id: imach.c,v 1.88 2003/06/23 17:54:56 brouard Exp $
$State: Exp $
$Log: imach.c,v $
+ Revision 1.88 2003/06/23 17:54:56 brouard
+ * imach.c (Repository): Create a sub-directory where all the secondary files are. Only imach, htm, gp and r(imach) are on the main directory. Correct time and other things.
+
+ 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 +164,11 @@
#define ODIRSEPARATOR '/'
#endif
-/* $Id: imach.c,v 1.86 2003/06/17 20:04:08 brouard Exp $ */
+/* $Id: imach.c,v 1.88 2003/06/23 17:54:56 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.96a, June 2003, INED-EUROREVES ";
+char fullversion[]="$Revision: 1.88 $ $Date: 2003/06/23 17:54:56 $";
int erreur; /* Error number */
int nvar;
int cptcovn=0, cptcovage=0, cptcoveff=0,cptcov;
@@ -175,6 +181,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 */
@@ -203,8 +211,12 @@ char fileresvpl[FILENAMELENGTH];
char title[MAXLINE];
char optionfile[FILENAMELENGTH], datafile[FILENAMELENGTH], filerespl[FILENAMELENGTH];
char optionfilext[10], optionfilefiname[FILENAMELENGTH], plotcmd[FILENAMELENGTH];
+char tmpout[FILENAMELENGTH];
+char command[FILENAMELENGTH];
+int outcmd=0;
char fileres[FILENAMELENGTH], filerespij[FILENAMELENGTH], filereso[FILENAMELENGTH], rfileres[FILENAMELENGTH];
+char lfileres[FILENAMELENGTH];
char filelog[FILENAMELENGTH]; /* Log file */
char filerest[FILENAMELENGTH];
char fileregp[FILENAMELENGTH];
@@ -1290,10 +1302,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 */
@@ -1350,61 +1364,91 @@ double funcone( double *x)
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]); */
if(globpr){
- fprintf(ficresilk,"%ld %6d %1d %1d %1d %1d %3d %10.6f %6.4f\
+ fprintf(ficresilk,"%9d %6d %1d %1d %1d %1d %3d %10.6f %6.4f\
%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;
}
+char *subdirf(char fileres[])
+{
+
+ strcpy(tmpout,optionfilefiname);
+ strcat(tmpout,"/"); /* Add to the right */
+ strcat(tmpout,fileres);
+ return tmpout;
+}
-void likelione(FILE *ficres,double p[], int npar, int nlstate, int *globpr, long *ipmx, double *sw, double *fretone, double (*funcone)(double []))
+char *subdirf2(char fileres[], char *preop)
{
- /* This routine should help understanding what is done with the selection of individuals/waves and
+
+ strcpy(tmpout,optionfilefiname);
+ strcat(tmpout,"/");
+ strcat(tmpout,preop);
+ strcat(tmpout,fileres);
+ return tmpout;
+}
+char *subdirf3(char fileres[], char *preop, char *preop2)
+{
+
+ strcpy(tmpout,optionfilefiname);
+ strcat(tmpout,"/");
+ strcat(tmpout,preop);
+ strcat(tmpout,preop2);
+ strcat(tmpout,fileres);
+ return tmpout;
+}
+
+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
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, "#num_i i s1 s2 mi mw dh likeli weight out sav ");
+ 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 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]); */
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",subdirf(fileresilk),subdirf(fileresilk));
+ fflush(fichtm);
+ }
return;
}
+
/*********** Maximum Likelihood Estimation ***************/
void mlikeli(FILE *ficres,double p[], int npar, int ncovmodel, int nlstate, double ftol, double (*func)(double []))
@@ -2360,23 +2404,10 @@ void varevsij(char optionfilefiname[], d
fprintf(ficresprobmorprev," w%1d p%-d%-d",i,i,j);
}
fprintf(ficresprobmorprev,"\n");
- if((ficgp=fopen(optionfilegnuplot,"a"))==NULL) {
- printf("Problem with gnuplot file: %s\n", optionfilegnuplot);
- fprintf(ficlog,"Problem with gnuplot file: %s\n", optionfilegnuplot);
- exit(0);
- }
- 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
"); @@ -3043,24 +3066,24 @@ fprintf(fichtm," \n