Summary: Some new graphs of contribution to likelihood
authorN. Brouard <brouard@ined.fr>
Thu, 1 Oct 2015 16:20:26 +0000 (16:20 +0000)
committerN. Brouard <brouard@ined.fr>
Thu, 1 Oct 2015 16:20:26 +0000 (16:20 +0000)
src/imach.c

index 67f5fe3f03e68e509b157f7cc02a6d70d84b30c4..97239b660561fd3f35afe98738ffe6f905048531 100644 (file)
@@ -1,6 +1,13 @@
 /* $Id$
   $State$
   $Log$
+  Revision 1.203  2015/09/30 17:45:14  brouard
+  Summary: looking at better estimation of the hessian
+
+  Also a better criteria for convergence to the period prevalence And
+  therefore adding the number of years needed to converge. (The
+  prevalence in any alive state shold sum to one
+
   Revision 1.202  2015/09/22 19:45:16  brouard
   Summary: Adding some overall graph on contribution to likelihood. Might change
 
@@ -742,7 +749,7 @@ typedef struct {
 /* $State$ */
 #include "version.h"
 char version[]=__IMACH_VERSION__;
-char copyright[]="September 2015,INED-EUROREVES-Institut de longevite-Japan Society for the Promotion of Science (Grant-in-Aid for Scientific Research 25293121), Intel Software 2015";
+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$ $Date$"; 
 char strstart[80];
 char optionfilext[10], optionfilefiname[FILENAMELENGTH];
@@ -2645,9 +2652,17 @@ void likelione(FILE *ficres,double p[], int npar, int nlstate, int *globpri, lon
   if(*globpri !=0){
     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));
-    fprintf(fichtm,"<br>- The first 3 individuals are drawn with lines. The function drawn is -2Log(L) in log scale: <a href=\"%s.png\">%s.png</a><br> \
-<img src=\"%s.png\">",subdirf2(optionfilefiname,"ILK_"),subdirf2(optionfilefiname,"ILK_"),subdirf2(optionfilefiname,"ILK_"));
+    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);
+
+    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> \
+<img src=\"%s-p%dj.png\">",k,k,subdirf2(optionfilefiname,"ILK_"),k,subdirf2(optionfilefiname,"ILK_"),k,subdirf2(optionfilefiname,"ILK_"),k);
+
+    }
   } 
   return;
 }
@@ -4856,13 +4871,26 @@ void printinggnuplot(char fileresu[], char optionfilefiname[], double ageminpar,
     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 png size 640, 480");
-/* good 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 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.png\";",subdirf2(optionfilefiname,"ILK_"));
-    fprintf(ficgp,"\nplot  \"%s\" u 2:(-$11):3 t \"All sample, all transitions\" with dots lc variable",subdirf(fileresilk));
-    fprintf(ficgp,"\nreplot  \"%s\" u 2:($3 <= 3 ? -$11 : 1/0):3 t \"First 3 individuals\" with line lc variable", subdirf(fileresilk));
+    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 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));
+    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,"unset log;\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);
+      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,";\nset out; unset ylabel;\n"); 
+    }
+    /* unset log; plot  "rrtest1_sorted_4/ILK_rrtest1_sorted_4.txt" u  2:($4 == 1 && $5==2 ? $9 : 1/0):5 t "p12" with points lc variable */             
+    /* fprintf(ficgp,"\nset log y;plot  \"%s\" u 2:(-$11):3 t \"All sample, all transitions\" with dots lc variable",subdirf(fileresilk)); */
+    /* fprintf(ficgp,"\nreplot  \"%s\" u 2:($3 <= 3 ? -$11 : 1/0):3 t \"First 3 individuals\" with line lc variable", subdirf(fileresilk)); */
     fprintf(ficgp,"\nset out;unset log\n");
     /* fprintf(ficgp,"\nset out \"%s.svg\"; replot; set out; # bug gnuplot",subdirf2(optionfilefiname,"ILK_")); */
 
@@ -7312,7 +7340,7 @@ Please run with mle=-1 to get a correct covariance matrix.\n",optionfile,numline
     printf("Problem with file %s",optionfilegnuplot);
   }
   else{
-    fprintf(ficgp,"\n# %s\n", version); 
+    fprintf(ficgp,"\n# IMaCh-%s\n", version); 
     fprintf(ficgp,"# %s\n", optionfilegnuplot); 
     //fprintf(ficgp,"set missing 'NaNq'\n");
     fprintf(ficgp,"set datafile missing 'NaNq'\n");
@@ -7339,13 +7367,15 @@ Please run with mle=-1 to get a correct covariance matrix.\n",optionfile,numline
   else{
   fprintf(fichtmcov,"<html><head>\n<title>IMaCh Cov %s</title></head>\n <body><font size=\"2\">%s <br> %s</font> \
 <hr size=\"2\" color=\"#EC5E5E\"> \n\
-Title=%s <br>Datafile=%s Firstpass=%d Lastpass=%d Stepm=%d Weight=%d Model=%s<br>\n",\
+Title=%s <br>Datafile=%s Firstpass=%d Lastpass=%d Stepm=%d Weight=%d Model=1+age+%s<br>\n",\
          optionfilehtmcov,version,fullversion,title,datafile,firstpass,lastpass,stepm, weightopt, model);
   }
 
-  fprintf(fichtm,"<html><head>\n<title>IMaCh %s</title></head>\n <body><font size=\"2\">%s <br> %s</font> \
+  fprintf(fichtm,"<html><head>\n<head>\n<meta charset=\"utf-8\"/><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n<title>IMaCh %s</title></head>\n <body><font size=\"7\"><a href=http:/euroreves.ined.fr/imach>IMaCh for Interpolated Markov Chain</a> </font><br>\n<font size=\"3\">Sponsored by Copyright (C)  2002-2015 <a href=http://www.ined.fr>INED</a>-EUROREVES-Institut de longévité-Japan Society for the Promotion of Sciences 日本学術振興会 (<a href=https://www.jsps.go.jp/english/e-grants/>Grant-in-Aid for Scientific Research 25293121</a>) - <a href=https://software.intel.com/en-us>Intel Software 2015</a></font><br>  \
+<hr size=\"2\" color=\"#EC5E5E\"> \n\
+<font size=\"2\">IMaCh-%s <br> %s</font> \
 <hr size=\"2\" color=\"#EC5E5E\"> \n\
-Title=%s <br>Datafile=%s Firstpass=%d Lastpass=%d Stepm=%d Weight=%d Model=%s<br>\n\
+Title=%s <br>Datafile=%s Firstpass=%d Lastpass=%d Stepm=%d Weight=%d Model=1+age+%s<br>\n\
 \n\
 <hr  size=\"2\" color=\"#EC5E5E\">\
  <ul><li><h4>Parameter files</h4>\n\