--- imach/src/imach.c 2016/07/01 13:16:01 1.224 +++ imach/src/imach.c 2016/07/12 08:40:03 1.225 @@ -1,6 +1,9 @@ -/* $Id: imach.c,v 1.224 2016/07/01 13:16:01 brouard Exp $ +/* $Id: imach.c,v 1.225 2016/07/12 08:40:03 brouard Exp $ $State: Exp $ $Log: imach.c,v $ + Revision 1.225 2016/07/12 08:40:03 brouard + Summary: saving but not running + Revision 1.224 2016/07/01 13:16:01 brouard Summary: Fixes @@ -840,12 +843,12 @@ typedef struct { #define ODIRSEPARATOR '\\' #endif -/* $Id: imach.c,v 1.224 2016/07/01 13:16:01 brouard Exp $ */ +/* $Id: imach.c,v 1.225 2016/07/12 08:40:03 brouard Exp $ */ /* $State: Exp $ */ #include "version.h" char version[]=__IMACH_VERSION__; char copyright[]="February 2016,INED-EUROREVES-Institut de longevite-Japan Society for the Promotion of Science (Grant-in-Aid for Scientific Research 25293121), Intel Software 2015-2018"; -char fullversion[]="$Revision: 1.224 $ $Date: 2016/07/01 13:16:01 $"; +char fullversion[]="$Revision: 1.225 $ $Date: 2016/07/12 08:40:03 $"; char strstart[80]; char optionfilext[10], optionfilefiname[FILENAMELENGTH]; int erreur=0, nberr=0, nbwarn=0; /* Error number, number of errors number of warnings */ @@ -853,12 +856,13 @@ int nagesqr=0, nforce=0; /* nagesqr=1 if /* Number of covariates model=V2+V1+ V3*age+V2*V4 */ int cptcovn=0; /**< cptcovn number of covariates added in the model (excepting constant and age and age*product) */ int cptcovt=0; /**< cptcovt number of covariates added in the model (excepting constant and age) */ -int cptcovs=0; /**< cptcovs number of simple covariates V2+V1 =2 */ +int cptcovs=0; /**< cptcovs number of simple covariates in the model V2+V1 =2 */ +int cptcovsnq=0; /**< cptcovsnq number of simple covariates in the model but non quantitative V2+V1 =2 */ int cptcovage=0; /**< Number of covariates with age: V3*age only =1 */ int cptcovprodnoage=0; /**< Number of covariate products without age */ int cptcoveff=0; /* Total number of covariates to vary for printing results */ int ncoveff=0; /* Total number of effective covariates in the model */ -int nqveff=0; /**< nqveff number of effective quantitative variables */ +int nqfveff=0; /**< nqfveff Number of Quantitative Fixed Variables Effective */ int ntveff=0; /**< ntveff number of effective time varying variables */ int nqtveff=0; /**< ntqveff number of effective time varying quantitative variables */ int cptcov=0; /* Working variable */ @@ -1006,11 +1010,12 @@ double *agedc; double **covar; /**< covar[j,i], value of jth covariate for individual i, * covar=matrix(0,NCOVMAX,1,n); * cov[Tage[kk]+2]=covar[Tvar[Tage[kk]]][i]*age; */ -double **coqvar; /* Fixed quantitative covariate */ -double ***cotvar; /* Time varying covariate */ -double ***cotqvar; /* Time varying quantitative covariate */ +double **coqvar; /* Fixed quantitative covariate iqv */ +double ***cotvar; /* Time varying covariate itv */ +double ***cotqvar; /* Time varying quantitative covariate itqv */ double idx; int **nbcode, *Tvar; /**< model=V2 => Tvar[1]= 2 */ +int *Typevar; /**< 1 for qualitative fixed, 2 for quantitative fixed, 3 for qualitive varying, 4 for quanti varying*/ int *Tage; int *Ndum; /** Freq of modality (tricode */ /* int **codtab;*/ /**< codtab=imatrix(1,100,1,10); */ @@ -1876,7 +1881,7 @@ function value at p , and iter is the nu #ifdef LINMINORIGINAL #else int *flatdir; /* Function is vanishing in that direction */ - int flat=0; /* Function is vanishing in that direction */ + int flat=0, flatd=0; /* Function is vanishing in that direction */ #endif void powell(double p[], double **xi, int n, double ftol, int *iter, double *fret, double (*func)(double [])) @@ -1980,8 +1985,8 @@ void powell(double p[], double **xi, int fprintf(ficlog," x(%d)=%.12e",j,xit[j]); } for(j=1;j<=n;j++) { - printf(" p(%d)=%lf ",j,p[j]); - fprintf(ficlog," p(%d)=%lf ",j,p[j]); + printf(" p(%d)=%.12e",j,p[j]); + fprintf(ficlog," p(%d)=%.12e",j,p[j]); } printf("\n"); fprintf(ficlog,"\n"); @@ -1991,12 +1996,13 @@ void powell(double p[], double **xi, int /* But p and xit have been updated at the end of linmin, *fret corresponds to new p, xit */ /* New value of last point Pn is not computed, P(n-1) */ for(j=1;j<=n;j++) { - printf(" p(%d)=%lf flat=%d ",j,p[j],flatdir[j]); - fprintf(ficlog," p(%d)=%lf flat=%d ",j,p[j],flatdir[j]); - } - printf("\n"); - fprintf(ficlog,"\n"); - + if(flatdir[j] >0){ + printf(" p(%d)=%lf flat=%d ",j,p[j],flatdir[j]); + fprintf(ficlog," p(%d)=%lf flat=%d ",j,p[j],flatdir[j]); + } + /* printf("\n"); */ + /* fprintf(ficlog,"\n"); */ + } if (2.0*fabs(fp-(*fret)) <= ftol*(fabs(fp)+fabs(*fret))) { /* Did we reach enough precision? */ /* We could compare with a chi^2. chisquare(0.95,ddl=1)=3.84 */ /* By adding age*age in a model, the new -2LL should be lower and the difference follows a */ @@ -2052,7 +2058,8 @@ void powell(double p[], double **xi, int fptt=(*func)(ptt); /* f_3 */ #ifdef NODIRECTIONCHANGEDUNTILNITER /* No change in drections until some iterations are done */ if (*iter <=4) { -#else +#else +#endif #ifdef POWELLNOF3INFF1TEST /* skips test F3 0) + flatd++; + } + if(flatd >0){ + printf("%d flat directions\n",flatd); + fprintf(ficlog,"%d flat directions\n",flatd); + for (j=1;j<=n;j++) { + if(flatdir[j]>0){ + printf("%d ",j); + fprintf(ficlog,"%d ",j); + } + } + printf("\n"); + fprintf(ficlog,"\n"); + } #endif printf("Gaining to use new average direction of P0 P%d instead of biggest increase direction %d :\n",n,ibig); fprintf(ficlog,"Gaining to use new average direction of P0 P%d instead of biggest increase direction %d :\n",n,ibig); @@ -2161,7 +2176,9 @@ void powell(double p[], double **xi, int #else } /* end if (fptt < fp) */ #endif +#ifdef NODIRECTIONCHANGEDUNTILNITER /* No change in drections until some iterations are done */ } /*NODIRECTIONCHANGEDUNTILNITER No change in drections until some iterations are done */ +#else #endif } /* loop iteration */ } @@ -2880,7 +2897,7 @@ double func( double *x) double sw; /* Sum of weights */ double lli; /* Individual log likelihood */ int s1, s2; - int iv=0, iqv=0, itv=0, iqtv=0 ; /* Index of varying covariate, fixed quantitative cov, time varying covariate */ + int iv=0, iqv=0, itv=0, iqtv=0 ; /* Index of varying covariate, fixed quantitative cov, time varying covariate, quatitative time varying covariate */ double bbh, survp; long ipmx; double agexact; @@ -2909,7 +2926,7 @@ double func( double *x) for (k=1; k<=ncoveff;k++){ /* Simple and product covariates without age* products */ cov[++ioffset]=covar[Tvar[k]][i]; } - for(iqv=1; iqv <= nqveff; iqv++){ /* Quantitatives covariates */ + for(iqv=1; iqv <= nqfveff; iqv++){ /* Quantitatives and Fixed covariates */ cov[++ioffset]=coqvar[iqv][i]; } @@ -2930,6 +2947,9 @@ double func( double *x) cov[ioffset+itv]=cotvar[mw[mi][i]][itv][i]; } for(iqtv=1; iqtv <= nqtveff; iqtv++){ /* Varying quantitatives covariates */ + if(cotqvar[mw[mi][i]][iqtv][i] == -1){ + printf("i=%d, mi=%d, iqtv=%d, cotqvar[mw[mi][i]][iqtv][i]=%f",i,mi,iqtv,cotqvar[mw[mi][i]][iqtv][i]); + } cov[ioffset+ntveff+iqtv]=cotqvar[mw[mi][i]][iqtv][i]; } /* ioffset=2+nagesqr+cptcovn+nqv+ntv+nqtv; */ @@ -3226,49 +3246,49 @@ double funcone( double *x) for(k=1; k<=nlstate; k++) ll[k]=0.; ioffset=0; for (i=1,ipmx=0, sw=0.; i<=imx; i++){ - ioffset=2+nagesqr+cptcovage; + ioffset=2+nagesqr+cptcovage; /* for (k=1; k<=cptcovn;k++) cov[2+nagesqr+k]=covar[Tvar[k]][i]; */ - for (k=1; k<=ncoveff;k++){ /* Simple and product covariates without age* products */ - cov[++ioffset]=covar[Tvar[k]][i]; - } - for(iqv=1; iqv <= nqveff; iqv++){ /* Quantitatives covariates */ - cov[++ioffset]=coqvar[iqv][i]; - } - + for (k=1; k<=ncoveff;k++){ /* Simple and product covariates without age* products */ + cov[++ioffset]=covar[Tvar[k]][i]; + } + for(iqv=1; iqv <= nqfveff; iqv++){ /* Quantitatives Fixed covariates */ + cov[++ioffset]=coqvar[iqv][i]; + } + for(mi=1; mi<= wav[i]-1; mi++){ - for(itv=1; itv <= ntveff; itv++){ /* Varying dummy covariates */ - cov[ioffset+itv]=cotvar[mw[mi][i]][itv][i]; - } - for(iqtv=1; iqtv <= nqtveff; iqtv++){ /* Varying quantitatives covariates */ - cov[ioffset+ntveff+iqtv]=cotqvar[mw[mi][i]][iqtv][i]; - } + for(itv=1; itv <= ntveff; itv++){ /* Varying dummy covariates */ + cov[ioffset+itv]=cotvar[mw[mi][i]][itv][i]; + } + for(iqtv=1; iqtv <= nqtveff; iqtv++){ /* Varying quantitatives covariates */ + cov[ioffset+ntveff+iqtv]=cotqvar[mw[mi][i]][iqtv][i]; + } for (ii=1;ii<=nlstate+ndeath;ii++) - for (j=1;j<=nlstate+ndeath;j++){ - oldm[ii][j]=(ii==j ? 1.0 : 0.0); - savm[ii][j]=(ii==j ? 1.0 : 0.0); - } + for (j=1;j<=nlstate+ndeath;j++){ + oldm[ii][j]=(ii==j ? 1.0 : 0.0); + savm[ii][j]=(ii==j ? 1.0 : 0.0); + } agebegin=agev[mw[mi][i]][i]; /* Age at beginning of effective wave */ ageend=agev[mw[mi][i]][i] + (dh[mi][i])*stepm/YEARM; /* Age at end of effective wave and at the end of transition */ for(d=0; d nlstate && (mle <5) ){ /* Jackson */ - lli=log(out[s1][s2] - savm[s1][s2]); + lli=log(out[s1][s2] - savm[s1][s2]); } else if ( s2==-1 ) { /* alive */ - for (j=1,survp=0. ; j<=nlstate; j++) - survp += (1.+bbh)*out[s1][j]- bbh*savm[s1][j]; - lli= log(survp); + for (j=1,survp=0. ; j<=nlstate; j++) + survp += (1.+bbh)*out[s1][j]- bbh*savm[s1][j]; + lli= log(survp); }else if (mle==1){ - lli= log((1.+bbh)*out[s1][s2]- bbh*savm[s1][s2]); /* linear interpolation */ + lli= log((1.+bbh)*out[s1][s2]- bbh*savm[s1][s2]); /* linear interpolation */ } else if(mle==2){ - lli= (savm[s1][s2]>(double)1.e-8 ?log((1.+bbh)*out[s1][s2]- bbh*savm[s1][s2]):log((1.+bbh)*out[s1][s2])); /* linear interpolation */ + lli= (savm[s1][s2]>(double)1.e-8 ?log((1.+bbh)*out[s1][s2]- bbh*savm[s1][s2]):log((1.+bbh)*out[s1][s2])); /* linear interpolation */ } else if(mle==3){ /* exponential inter-extrapolation */ - lli= (savm[s1][s2]>(double)1.e-8 ?(1.+bbh)*log(out[s1][s2])- bbh*log(savm[s1][s2]):log((1.+bbh)*out[s1][s2])); /* exponential inter-extrapolation */ + lli= (savm[s1][s2]>(double)1.e-8 ?(1.+bbh)*log(out[s1][s2])- bbh*log(savm[s1][s2]):log((1.+bbh)*out[s1][s2])); /* exponential inter-extrapolation */ } else if (mle==4){ /* mle=4 no inter-extrapolation */ - lli=log(out[s1][s2]); /* Original formula */ + lli=log(out[s1][s2]); /* Original formula */ } else{ /* mle=0 back to 1 */ - lli= log((1.+bbh)*out[s1][s2]- bbh*savm[s1][s2]); /* linear interpolation */ - /*lli=log(out[s1][s2]); */ /* Original formula */ + lli= log((1.+bbh)*out[s1][s2]- bbh*savm[s1][s2]); /* linear interpolation */ + /*lli=log(out[s1][s2]); */ /* Original formula */ } /* End of if */ ipmx +=1; sw += weight[i]; 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,"%9ld %6.1f %6.1f %6d %2d %2d %2d %2d %3d %15.6f %8.4f %8.3f\ + fprintf(ficresilk,"%9ld %6.1f %6.1f %6d %2d %2d %2d %2d %3d %15.6f %8.4f %8.3f\ %11.6f %11.6f %11.6f ", \ - num[i], agebegin, ageend, 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]); - 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); + num[i], agebegin, ageend, 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]); + 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 */ @@ -3841,7 +3861,7 @@ void pstamp(FILE *fichier) posprop=vector(1,nlstate); /* Counting the number of transition starting from a live state per age */ pospropt=vector(1,nlstate); /* Counting the number of transition starting from a live state */ /* prop=matrix(1,nlstate,iagemin,iagemax+3); */ - meanq=vector(1,nqveff); + meanq=vector(1,nqfveff); /* Number of Quantitative Fixed Variables Effective */ meanqt=matrix(1,lastpass,1,nqtveff); strcpy(fileresp,"P_"); strcat(fileresp,fileresu); @@ -3912,7 +3932,7 @@ Title=%s
Datafile=%s Firstpass=%d La posprop[i]=0; pospropt[i]=0; } - for (z1=1; z1<= nqveff; z1++) { + for (z1=1; z1<= nqfveff; z1++) { meanq[z1]+=0.; for(m=1;m<=lastpass;m++){ meanqt[m][z1]=0.; @@ -3924,8 +3944,8 @@ Title=%s
Datafile=%s Firstpass=%d La /* For that comination of covariate j1, we count and print the frequencies */ for (iind=1; iind<=imx; iind++) { /* For each individual iind */ bool=1; - if (nqveff >0) { /* Filter is here: Must be looked at for model=V1+V2+V3+V4 */ - for (z1=1; z1<= nqveff; z1++) { + if (nqfveff >0) { /* Filter is here: Must be looked at for model=V1+V2+V3+V4 */ + for (z1=1; z1<= nqfveff; z1++) { meanq[z1]+=coqvar[Tvar[z1]][iind]; } for (z1=1; z1<=ncoveff; z1++) { @@ -4149,7 +4169,7 @@ Title=%s
Datafile=%s Firstpass=%d La fclose(ficresp); fclose(ficresphtm); fclose(ficresphtmfr); - free_vector(meanq,1,nqveff); + free_vector(meanq,1,nqfveff); free_matrix(meanqt,1,lastpass,1,nqtveff); free_ma3x(freq,-5,nlstate+ndeath,-5,nlstate+ndeath, iagemin-AGEMARGE, iagemax+3+AGEMARGE); free_vector(pospropt,1,nlstate); @@ -4189,7 +4209,7 @@ Title=%s
Datafile=%s Firstpass=%d La if (cptcovn<1) {j=1;ncodemax[1]=1;} first=1; - for(j1=1; j1<= (int) pow(2,nqveff);j1++){ /* For each combination of covariate */ + for(j1=1; j1<= (int) pow(2,cptcoveff);j1++){ /* For each combination of covariate */ for (i=1; i<=nlstate; i++) for(iage=iagemin-AGEMARGE; iage <= iagemax+3+AGEMARGE; iage++) prop[i][iage]=0.0; @@ -4197,7 +4217,7 @@ Title=%s
Datafile=%s Firstpass=%d La for (i=1; i<=imx; i++) { /* Each individual */ bool=1; if (cptcovn>0) { /* Filter is here: Must be looked at for model=V1+V2+V3+V4 */ - for (z1=1; z1<=nqveff; z1++) /* For each covariate, look at the value for individual i and checks if it is equal to the corresponding value of this covariate according to current combination j1*/ + for (z1=1; z1<=cptcoveff; z1++) /* For each covariate, look at the value for individual i and checks if it is equal to the corresponding value of this covariate according to current combination j1*/ if (covar[Tvaraff[z1]][i]!= nbcode[Tvaraff[z1]][codtabm(j1,z1)]) bool=0; } @@ -4491,55 +4511,60 @@ void concatwav(int wav[], int **dh, int /* Loop on covariates without age and products and no quantitative variable */ /* for (j=1; j<=(cptcovs); j++) { /\* From model V1 + V2*age+ V3 + V3*V4 keeps V1 + V3 = 2 only *\/ */ - for (j=1; j<=(*cptcov); j++) { /* From model V1 + V2*age + V3 + V3*V4 keeps V1 + V3 = 2 only */ + for (j=1; j<=cptcovsnq; j++) { /* From model V1 + V2*age + V3 + V3*V4 keeps V1 + V3 = 2 only */ for (k=-1; k < maxncov; k++) Ndum[k]=0; for (i=1; i<=imx; i++) { /* Loop on individuals: reads the data file to get the maximum value of the - modality of this covariate Vj*/ - if(Tvar[j] >=1 && Tvar[j] <= *cptcov){ /* A real fixed covariate */ - ij=(int)(covar[Tvar[j]][i]); /* ij=0 or 1 or -1. Value of the covariate Tvar[j] for individual i - * If product of Vn*Vm, still boolean *: - * If it was coded 1, 2, 3, 4 should be splitted into 3 boolean variables - * 1 => 0 0 0, 2 => 0 0 1, 3 => 0 1 1, 4=1 0 0 */ - /* Finds for covariate j, n=Tvar[j] of Vn . ij is the - modality of the nth covariate of individual i. */ - if (ij > modmaxcovj) - modmaxcovj=ij; - else if (ij < modmincovj) - modmincovj=ij; - if ((ij < -1) && (ij > NCOVMAX)){ - printf( "Error: minimal is less than -1 or maximal is bigger than %d. Exiting. \n", NCOVMAX ); - exit(1); - }else - Ndum[ij]++; /*counts and stores the occurence of this modality 0, 1, -1*/ - /* If coded 1, 2, 3 , counts the number of 1 Ndum[1], number of 2, Ndum[2], etc */ - /*printf("i=%d ij=%d Ndum[ij]=%d imx=%d",i,ij,Ndum[ij],imx);*/ - /* getting the maximum value of the modality of the covariate - (should be 0 or 1 now) Tvar[j]. If V=sex and male is coded 0 and - female ies 1, then modmaxcovj=1.*/ - } - } /* end for loop on individuals i */ + modality of this covariate Vj*/ + switch(Typevar[j]) { + case 1: /* A real fixed dummy covariate */ + ij=(int)(covar[Tvar[j]][i]); /* ij=0 or 1 or -1. Value of the covariate Tvar[j] for individual i + * If product of Vn*Vm, still boolean *: + * If it was coded 1, 2, 3, 4 should be splitted into 3 boolean variables + * 1 => 0 0 0, 2 => 0 0 1, 3 => 0 1 1, 4=1 0 0 */ + /* Finds for covariate j, n=Tvar[j] of Vn . ij is the + modality of the nth covariate of individual i. */ + if (ij > modmaxcovj) + modmaxcovj=ij; + else if (ij < modmincovj) + modmincovj=ij; + if ((ij < -1) && (ij > NCOVMAX)){ + printf( "Error: minimal is less than -1 or maximal is bigger than %d. Exiting. \n", NCOVMAX ); + exit(1); + }else + Ndum[ij]++; /*counts and stores the occurence of this modality 0, 1, -1*/ + /* If coded 1, 2, 3 , counts the number of 1 Ndum[1], number of 2, Ndum[2], etc */ + /*printf("i=%d ij=%d Ndum[ij]=%d imx=%d",i,ij,Ndum[ij],imx);*/ + /* getting the maximum value of the modality of the covariate + (should be 0 or 1 now) Tvar[j]. If V=sex and male is coded 0 and + female ies 1, then modmaxcovj=1.*/ + break; + case 2: + break; + + } + } /* end for loop on individuals i */ printf(" Minimal and maximal values of %d th covariate V%d: min=%d max=%d \n", j, Tvar[j], modmincovj, modmaxcovj); fprintf(ficlog," Minimal and maximal values of %d th covariate V%d: min=%d max=%d \n", j, Tvar[j], modmincovj, modmaxcovj); cptcode=modmaxcovj; /* Ndum[0] = frequency of 0 for model-covariate j, Ndum[1] frequency of 1 etc. */ - /*for (i=0; i<=cptcode; i++) {*/ + /*for (i=0; i<=cptcode; i++) {*/ for (k=modmincovj; k<=modmaxcovj; k++) { /* k=-1 ? 0 and 1*//* For each value k of the modality of model-cov j */ printf("Frequencies of covariates %d ie V%d with value %d: %d\n", j, Tvar[j], k, Ndum[k]); fprintf(ficlog, "Frequencies of covariates %d ie V%d with value %d: %d\n", j, Tvar[j], k, Ndum[k]); if( Ndum[k] != 0 ){ /* Counts if nobody answered modality k ie empty modality, we skip it and reorder */ - if( k != -1){ - ncodemax[j]++; /* ncodemax[j]= Number of modalities of the j th - covariate for which somebody answered excluding - undefined. Usually 2: 0 and 1. */ - } - ncodemaxwundef[j]++; /* ncodemax[j]= Number of modalities of the j th - covariate for which somebody answered including - undefined. Usually 3: -1, 0 and 1. */ + if( k != -1){ + ncodemax[j]++; /* ncodemax[j]= Number of modalities of the j th + covariate for which somebody answered excluding + undefined. Usually 2: 0 and 1. */ + } + ncodemaxwundef[j]++; /* ncodemax[j]= Number of modalities of the j th + covariate for which somebody answered including + undefined. Usually 3: -1, 0 and 1. */ } /* In fact ncodemax[j]=2 (dichotom. variables only) but it could be more for - * historical reasons: 3 if coded 1, 2, 3 and 4 and Ndum[2]=0 */ + * historical reasons: 3 if coded 1, 2, 3 and 4 and Ndum[2]=0 */ } /* Ndum[-1] number of undefined modalities */ - + /* j is a covariate, n=Tvar[j] of Vn; Fills nbcode */ /* For covariate j, modalities could be 1, 2, 3, 4, 5, 6, 7. If Ndum[1]=0, Ndum[2]=0, Ndum[3]= 635, Ndum[4]=0, Ndum[5]=0, Ndum[6]=27, Ndum[7]=125; @@ -4555,14 +4580,14 @@ void concatwav(int wav[], int **dh, int */ ij=0; /* ij is similar to i but can jump over null modalities */ for (i=modmincovj; i<=modmaxcovj; i++) { /* i= 1 to 2 for dichotomous, or from 1 to 3 or from -1 or 0 to 1 currently*/ - if (Ndum[i] == 0) { /* If nobody responded to this modality k */ - break; - } - ij++; - nbcode[Tvar[j]][ij]=i; /* stores the original value of modality i in an array nbcode, ij modality from 1 to last non-nul modality.*/ - cptcode = ij; /* New max modality for covar j */ + if (Ndum[i] == 0) { /* If nobody responded to this modality k */ + break; + } + ij++; + nbcode[Tvar[j]][ij]=i; /* stores the original value of modality i in an array nbcode, ij modality from 1 to last non-nul modality.*/ + cptcode = ij; /* New max modality for covar j */ } /* end of loop on modality i=-1 to 1 or more */ - + /* for (k=0; k<= cptcode; k++) { /\* k=-1 ? k=0 to 1 *\//\* Could be 1 to 4 *\//\* cptcode=modmaxcovj *\/ */ /* /\*recode from 0 *\/ */ /* k is a modality. If we have model=V1+V1*sex */ @@ -4578,33 +4603,33 @@ void concatwav(int wav[], int **dh, int /* } /\* end of loop on modality k *\/ */ } /* end of loop on model-covariate j. nbcode[Tvarj][1]=0 and nbcode[Tvarj][2]=1 sets the value of covariate j*/ - for (k=-1; k< maxncov; k++) Ndum[k]=0; + for (k=-1; k< maxncov; k++) Ndum[k]=0; for (i=1; i<=ncovmodel-2-nagesqr; i++) { /* -2, cste and age and eventually age*age */ - /* Listing of all covariables in statement model to see if some covariates appear twice. For example, V1 appears twice in V1+V1*V2.*/ - ij=Tvar[i]; /* Tvar might be -1 if status was unknown */ - Ndum[ij]++; /* Might be supersed V1 + V1*age */ - } /* V4+V3+V5, Ndum[1]@5={0, 0, 1, 1, 1} */ - - ij=0; - for (i=0; i<= maxncov-1; i++) { /* modmaxcovj is unknown here. Only Ndum[2(V2),3(age*V3), 5(V3*V2) 6(V1*V4) */ - /*printf("Ndum[%d]=%d\n",i, Ndum[i]);*/ - if((Ndum[i]!=0) && (i<=ncovcol)){ - /*printf("diff Ndum[%d]=%d\n",i, Ndum[i]);*/ - Tvaraff[++ij]=i; /*For printing (unclear) */ - }else if((Ndum[i]!=0) && (i<=ncovcol+nqv)){ - Tvaraff[++ij]=-10; /* Dont'n know how to treat quantitative variables yet */ - }else if((Ndum[i]!=0) && (i<=ncovcol+nqv+ntv)){ - Tvaraff[++ij]=i; /*For printing (unclear) */ - }else if((Ndum[i]!=0) && (i<=ncovcol+nqv+ntv+nqtv)){ - Tvaraff[++ij]=-20; /* Dont'n know how to treat quantitative variables yet */ - } - } /* Tvaraff[1]@5 {3, 4, -20, 0, 0} Very strange */ - /* ij--; */ - /* cptcoveff=ij; /\*Number of total covariates*\/ */ - *cptcov=ij; /*Number of total real effective covariates: effective - * because they can be excluded from the model and real - * if in the model but excluded because missing values*/ + /* Listing of all covariables in statement model to see if some covariates appear twice. For example, V1 appears twice in V1+V1*V2.*/ + ij=Tvar[i]; /* Tvar might be -1 if status was unknown */ + Ndum[ij]++; /* Might be supersed V1 + V1*age */ + } /* V4+V3+V5, Ndum[1]@5={0, 0, 1, 1, 1} */ + + ij=0; + for (i=0; i<= maxncov-1; i++) { /* modmaxcovj is unknown here. Only Ndum[2(V2),3(age*V3), 5(V3*V2) 6(V1*V4) */ + /*printf("Ndum[%d]=%d\n",i, Ndum[i]);*/ + if((Ndum[i]!=0) && (i<=ncovcol)){ + /*printf("diff Ndum[%d]=%d\n",i, Ndum[i]);*/ + Tvaraff[++ij]=i; /*For printing (unclear) */ + }else if((Ndum[i]!=0) && (i<=ncovcol+nqv)){ + Tvaraff[++ij]=-10; /* Dont'n know how to treat quantitative variables yet */ + }else if((Ndum[i]!=0) && (i<=ncovcol+nqv+ntv)){ + Tvaraff[++ij]=i; /*For printing (unclear) */ + }else if((Ndum[i]!=0) && (i<=ncovcol+nqv+ntv+nqtv)){ + Tvaraff[++ij]=-20; /* Dont'n know how to treat quantitative variables yet */ + } + } /* Tvaraff[1]@5 {3, 4, -20, 0, 0} Very strange */ + /* ij--; */ + /* cptcoveff=ij; /\*Number of total covariates*\/ */ + *cptcov=ij; /*Number of total real effective covariates: effective + * because they can be excluded from the model and real + * if in the model but excluded because missing values*/ } @@ -5452,29 +5477,29 @@ To be simple, these graphs help to under cov[1]=1; /* tj=cptcoveff; */ - tj = (int) pow(2,nqveff); + tj = (int) pow(2,cptcoveff); if (cptcovn<1) {tj=1;ncodemax[1]=1;} j1=0; for(j1=1; j1<=tj;j1++){ /* For each valid combination of covariates or only once*/ if (cptcovn>0) { fprintf(ficresprob, "\n#********** Variable "); - for (z1=1; z1<=nqveff; z1++) fprintf(ficresprob, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtabm(j1,z1)]); + for (z1=1; z1<=cptcoveff; z1++) fprintf(ficresprob, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtabm(j1,z1)]); fprintf(ficresprob, "**********\n#\n"); fprintf(ficresprobcov, "\n#********** Variable "); - for (z1=1; z1<=nqveff; z1++) fprintf(ficresprobcov, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtabm(j1,z1)]); + for (z1=1; z1<=cptcoveff; z1++) fprintf(ficresprobcov, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtabm(j1,z1)]); fprintf(ficresprobcov, "**********\n#\n"); fprintf(ficgp, "\n#********** Variable "); - for (z1=1; z1<=nqveff; z1++) fprintf(ficgp, " V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtabm(j1,z1)]); + for (z1=1; z1<=cptcoveff; z1++) fprintf(ficgp, " V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtabm(j1,z1)]); fprintf(ficgp, "**********\n#\n"); fprintf(fichtmcov, "\n
********** Variable "); - for (z1=1; z1<=nqveff; z1++) fprintf(fichtm, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtabm(j1,z1)]); + for (z1=1; z1<=cptcoveff; z1++) fprintf(fichtm, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtabm(j1,z1)]); fprintf(fichtmcov, "**********\n
"); fprintf(ficresprobcor, "\n#********** Variable "); - for (z1=1; z1<=nqveff; z1++) fprintf(ficresprobcor, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtabm(j1,z1)]); + for (z1=1; z1<=cptcoveff; z1++) fprintf(ficresprobcor, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtabm(j1,z1)]); fprintf(ficresprobcor, "**********\n#"); if(invalidvarcomb[j1]){ fprintf(ficgp,"\n#Combination (%d) ignored because no cases \n",j1); @@ -5740,7 +5765,7 @@ void printinghtml(char fileresu[], char fprintf(fichtm," \n