]> henry.ined.fr Git - .git/commitdiff
(Module): Max Covariate is now set to 20 instead of 8. A
authorN. Brouard <brouard@ined.fr>
Tue, 26 May 2009 06:44:34 +0000 (06:44 +0000)
committerN. Brouard <brouard@ined.fr>
Tue, 26 May 2009 06:44:34 +0000 (06:44 +0000)
lot of cleaning with variables initialized to 0. Trying to make
V2+V3*age+V1+V4 strb=V3*age+V1+V4 working better.

src/imach.c

index f79fd3d61943e859e021cea5fd1d4a13d6d981d6..737677b9837168422972d9c73cf681fc03242a23 100644 (file)
@@ -1,6 +1,9 @@
 /* $Id$
   $State$
   $Log$
+  Revision 1.129  2007/08/31 13:49:27  lievre
+  Modification of the way of exiting when the covariate is not binary in order to see on the window the error message before exiting
+
   Revision 1.128  2006/06/30 13:02:05  brouard
   (Module): Clarifications on computing e.j
 
@@ -370,7 +373,7 @@ extern int errno;
 #define NINTERVMAX 8
 #define NLSTATEMAX 8 /* Maximum number of live states (for func) */
 #define NDEATHMAX 8 /* Maximum number of dead states (for func) */
-#define NCOVMAX 8 /* Maximum number of covariates */
+#define NCOVMAX 20 /* Maximum number of covariates */
 #define MAXN 20000
 #define YEARM 12. /* Number of months per year */
 #define AGESUP 130
@@ -393,34 +396,34 @@ char version[]="Imach version 0.98i, June 2006, INED-EUROREVES-Institut de longe
 char fullversion[]="$Revision$ $Date$"; 
 char strstart[80];
 char optionfilext[10], optionfilefiname[FILENAMELENGTH];
-int erreur, nberr=0, nbwarn=0; /* Error number, number of errors number of warnings  */
-int nvar;
-int cptcovn=0, cptcovage=0, cptcoveff=0,cptcov;
+int erreur=0, nberr=0, nbwarn=0; /* Error number, number of errors number of warnings  */
+int nvar=0;
+int cptcovn=0, cptcovage=0, cptcoveff=0,cptcov=0; /* Number of covariates, of covariates with '*age' */
 int npar=NPARMAX;
 int nlstate=2; /* Number of live states */
 int ndeath=1; /* Number of dead states */
-int ncovmodel, ncovcol;     /* Total number of covariables including constant a12*1 +b12*x ncovmodel=2 */
+int ncovmodel=0, ncovcol=0;     /* Total number of covariables including constant a12*1 +b12*x ncovmodel=2 */
 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 ijmin, ijmax; /* Individuals having jmin and jmax */ 
-int gipmx, gsw; /* Global variables on the number of contributions 
+int maxwav=0; /* Maxim number of waves */
+int jmin=0, jmax=0; /* min, max spacing between 2 waves */
+int ijmin=0, ijmax=0; /* Individuals having jmin and jmax */ 
+int gipmx=0, gsw=0; /* Global variables on the number of contributions 
                   to the likelihood and the sum of weights (done by funcone)*/
-int mle, weightopt;
+int mle=1, weightopt=0;
 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 */
 int **bh; /* bh[mi][i] is the bias (+ or -) for this individual if the delay between
           * wave mi and wave mi+1 is not an exact multiple of stepm. */
-double jmean; /* Mean space between 2 waves */
+double jmean=1; /* Mean space between 2 waves */
 double **oldm, **newm, **savm; /* Working pointers to matrices */
 double **oldms, **newms, **savms; /* Fixed working pointers to matrices */
 FILE *fic,*ficpar, *ficparo,*ficres, *ficresp, *ficrespl, *ficrespij, *ficrest,*ficresf,*ficrespop;
 FILE *ficlog, *ficrespow;
-int globpr; /* Global variable for printing or not */
+int globpr=0; /* Global variable for printing or not */
 double fretone; /* Only one call to likelihood */
-long ipmx; /* Number of contributions */
+long ipmx=0; /* Number of contributions */
 double sw; /* Sum of weights */
 char filerespow[FILENAMELENGTH];
 char fileresilk[FILENAMELENGTH]; /* File of individual contributions to the likelihood */
@@ -2041,7 +2044,7 @@ void pstamp(FILE *fichier)
 void  freqsummary(char fileres[], int iagemin, int iagemax, int **s, double **agev, int nlstate, int imx, int *Tvaraff, int **nbcode, int *ncodemax,double **mint,double **anint, char strstart[])
 {  /* Some frequencies */
   
-  int i, m, jk, k1,i1, j1, bool, z1,z2,j;
+  int i, m, jk, k1,i1, j1, bool, z1,j;
   int first;
   double ***freq; /* Frequencies */
   double *pp, **prop;
@@ -2210,7 +2213,7 @@ void prevalence(double ***probs, double agemin, double agemax, int **s, double *
      We still use firstpass and lastpass as another selection.
   */
  
-  int i, m, jk, k1, i1, j1, bool, z1,z2,j;
+  int i, m, jk, k1, i1, j1, bool, z1,j;
   double ***freq; /* Frequencies */
   double *pp, **prop;
   double pos,posprop; 
@@ -2427,7 +2430,9 @@ void  concatwav(int wav[], int **dh, int **bh,  int **mw, int **s, double *agedc
 void tricode(int *Tvar, int **nbcode, int imx)
 {
   
-  int Ndum[20],ij=1, k, j, i, maxncov=19;
+  /*     Tvar[i]=atoi(stre); /* find 'n' in Vn and stores in Tvar. If model=V2+V1 Tvar[1]=2 and Tvar[2]=1 */
+
+  int Ndum[20],ij=1, k=0, j=0, i=0, maxncov=19;
   int cptcode=0;
   cptcoveff=0; 
  
@@ -3644,8 +3649,8 @@ true period expectancies (those weighted with period prevalences are also\
 void printinggnuplot(char fileres[], char optionfilefiname[], double ageminpar, double agemaxpar, double fage , char pathc[], double p[]){
 
   char dirfileres[132],optfileres[132];
-  int m,cpt,k1,i,k,j,jk,k2,k3,ij,l;
-  int ng;
+  int m0,cpt=0,k1=0,i=0,k=0,j=0,jk=0,k2=0,k3=0,ij=0,l=0;
+  int ng=0;
 /*   if((ficgp=fopen(optionfilegnuplot,"a"))==NULL) { */
 /*     printf("Problem with file %s",optionfilegnuplot); */
 /*     fprintf(ficlog,"Problem with file %s",optionfilegnuplot); */
@@ -4963,8 +4968,8 @@ run imach with mle=-1 to get a correct template of the parameter file.\n",numlin
     j=0, j1=0, k1=1, k2=1;
     j=nbocc(model,'+'); /* j=Number of '+' */
     j1=nbocc(model,'*'); /* j1=Number of '*' */
-    cptcovn=j+1; 
-    cptcovprod=j1; /*Number of products */
+    cptcovn=j+1; /* Number of covariates V1+V2+V3 =>2+1=3 */
+    cptcovprod=j1; /*Number of products  V1*V2 =1 */
     
     strcpy(modelsav,model); 
     if ((strcmp(model,"age")==0) || (strcmp(model,"age*age")==0)){
@@ -4974,21 +4979,24 @@ run imach with mle=-1 to get a correct template of the parameter file.\n",numlin
     }
     
     /* This loop fills the array Tvar from the string 'model'.*/
-
+    /* j is the number of + signs in the model V1+V2+V3 j=2 i=3 to 1 */
     for(i=(j+1); i>=1;i--){
-      cutv(stra,strb,modelsav,'+'); /* keeps in strb after the last + */ 
+      cutv(stra,strb,modelsav,'+'); /* keeps in strb after the first '+' 
+                                    modelsav=V2+V3*age+V1+V4 strb=V3*age+V1+V4 
+                                    stra=V2
+                                   */ 
       if (nbocc(modelsav,'+')==0) strcpy(strb,modelsav); /* and analyzes it */
       /*      printf("i=%d a=%s b=%s sav=%s\n",i, stra,strb,modelsav);*/
       /*scanf("%d",i);*/
-      if (strchr(strb,'*')) {  /* Model includes a product */
-       cutv(strd,strc,strb,'*'); /* strd*strc  Vm*Vn (if not *age)*/
+      if (strchr(strb,'*')) {  /* Model includes a product V1+V3*age+V2 strb=V3*age*/
+       cutv(strd,strc,strb,'*'); /* strd*strc  Vm*Vn: V3*age strc=age strd=V3 ; V3*V2 strc=V2, strd=V3 */
        if (strcmp(strc,"age")==0) { /* Vn*age */
          cptcovprod--;
          cutv(strb,stre,strd,'V');
-         Tvar[i]=atoi(stre); /* computes n in Vn and stores in Tvar*/
-         cptcovage++;
-           Tage[cptcovage]=i;
-           /*printf("stre=%s ", stre);*/
+         Tvar[i]=atoi(stre);  /* V1+V3*age+V2 Tvar[2]=3 */
+         cptcovage++; /* Sum the number of covariates including ages as a product */
+         Tage[cptcovage]=i;  /* Tage[1] =2 */
+         /*printf("stre=%s ", stre);*/
        }
        else if (strcmp(strd,"age")==0) { /* or age*Vn */
          cptcovprod--;
@@ -4997,11 +5005,12 @@ run imach with mle=-1 to get a correct template of the parameter file.\n",numlin
          cptcovage++;
          Tage[cptcovage]=i;
        }
-       else {  /* Age is not in the model */
-         cutv(strb,stre,strc,'V'); /* strc= Vn, stre is n*/
-         Tvar[i]=ncovcol+k1;
+       else {  /* Age is not in the model V1+V3*V2+V2  strb=V3*V2*/
+         cutv(strb,stre,strc,'V'); /* strc= Vn, stre is n; strb=V3*V2 stre=3 strc=*/
+         Tvar[i]=ncovcol+k1;  /* find 'n' in Vn and stores in Tvar. 
+                                 If already ncovcol=2 and model=V2*V1 Tvar[1]=2+1 and Tvar[2]=2+2 etc */
          cutv(strb,strc,strd,'V'); /* strd was Vm, strc is m */
-         Tprod[k1]=i;
+         Tprod[k1]=i;  /* Tprod[1]  */
          Tvard[k1][1]=atoi(strc); /* m*/
          Tvard[k1][2]=atoi(stre); /* n */
          Tvar[cptcovn+k2]=Tvard[k1][1];
@@ -5018,7 +5027,7 @@ run imach with mle=-1 to get a correct template of the parameter file.\n",numlin
       cutv(strd,strc,strb,'V');
       Tvar[i]=atoi(strc);
       }
-      strcpy(modelsav,stra);  
+      strcpy(modelsav,stra);  /* modelsav=V2+V3*age+V1+V4 strb=V3*age+V1+V4 */ 
       /*printf("a=%s b=%s sav=%s\n", stra,strb,modelsav);
        scanf("%d",i);*/
     } /* end of loop + */
@@ -5164,7 +5173,7 @@ run imach with mle=-1 to get a correct template of the parameter file.\n",numlin
        for(cpt=1; cpt <=(m/pow(2,cptcoveff+1-k)); cpt++){
          h++;
          if (h>m) h=1;codtab[h][k]=j;codtab[h][Tvar[k]]=j;
-         /*  printf("h=%d k=%d j=%d codtab[h][k]=%d tvar[k]=%d \n",h, k,j,codtab[h][k],Tvar[k]);*/
+         printf("h=%d k=%d j=%d codtab[h][k]=%d Tvar[k]=%d codtab[h][Tvar[k]]=%d \n",h, k,j,codtab[h][k],Tvar[k],codtab[h][Tvar[k]]);
        } 
       }
     }