--- imach/src/imach.c 2016/09/07 17:14:18 1.249 +++ imach/src/imach.c 2016/09/08 16:07:27 1.250 @@ -1,6 +1,9 @@ -/* $Id: imach.c,v 1.249 2016/09/07 17:14:18 brouard Exp $ +/* $Id: imach.c,v 1.250 2016/09/08 16:07:27 brouard Exp $ $State: Exp $ $Log: imach.c,v $ + Revision 1.250 2016/09/08 16:07:27 brouard + Summary: continue + Revision 1.249 2016/09/07 17:14:18 brouard Summary: Starting values from frequencies @@ -949,12 +952,12 @@ typedef struct { #define ODIRSEPARATOR '\\' #endif -/* $Id: imach.c,v 1.249 2016/09/07 17:14:18 brouard Exp $ */ +/* $Id: imach.c,v 1.250 2016/09/08 16:07:27 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.249 $ $Date: 2016/09/07 17:14:18 $"; +char fullversion[]="$Revision: 1.250 $ $Date: 2016/09/08 16:07:27 $"; char strstart[80]; char optionfilext[10], optionfilefiname[FILENAMELENGTH]; int erreur=0, nberr=0, nbwarn=0; /* Error number, number of errors number of warnings */ @@ -4183,12 +4186,12 @@ void pstamp(FILE *fichier) } /************ Frequencies ********************/ -void freqsummary(char fileres[], int iagemin, int iagemax, int **s, double **agev, int nlstate, int imx, \ +void freqsummary(char fileres[], double p[], int iagemin, int iagemax, int **s, double **agev, int nlstate, int imx, \ int *Tvaraff, int *invalidvarcomb, int **nbcode, int *ncodemax,double **mint,double **anint, char strstart[], \ int firstpass, int lastpass, int stepm, int weightopt, char model[]) -{ /* Some frequencies */ +{ /* Some frequencies as well as proposing some starting values */ - int i, m, jk, j1, bool, z1,j, k, iv; + int i, m, jk, j1, bool, z1,j, k, iv, jj=0; int iind=0, iage=0; int mi; /* Effective wave */ int first; @@ -4298,15 +4301,15 @@ Title=%s
Datafile=%s Firstpass=%d La /* for (z1=1; z1<= nqfveff; z1++) { */ /* meanq[z1]+=coqvar[Tvar[z1]][iind]; /\* Computes mean of quantitative with selected filter *\/ */ /* } */ - for (z1=1; z1<=cptcoveff; z1++) { + for (z1=1; z1<=cptcoveff; z1++) { /* loops on covariates in the model */ /* if(Tvaraff[z1] ==-20){ */ /* /\* sumnew+=cotvar[mw[mi][iind]][z1][iind]; *\/ */ /* }else if(Tvaraff[z1] ==-10){ */ /* /\* sumnew+=coqvar[z1][iind]; *\/ */ /* }else */ - if (covar[Tvaraff[z1]][iind]!= nbcode[Tvaraff[z1]][codtabm(j1,z1)]){ - /* Tests if this individual iind responded to j1 (V4=1 V3=0) */ - bool=0; + if (covar[Tvaraff[z1]][iind]!= nbcode[Tvaraff[z1]][codtabm(j1,z1)]){ /* for combination j1 of covariates */ + /* Tests if this individual iind responded to combination j1 (V4=1 V3=0) */ + bool=0; /* bool should be equal to 1 to be selected, one covariate value failed */ /* printf("bool=%d i=%d, z1=%d, Tvaraff[%d]=%d, covar[Tvarff][%d]=%2f, codtabm(%d,%d)=%d, nbcode[Tvaraff][codtabm(%d,%d)=%d, j1=%d\n", bool,i,z1, z1, Tvaraff[z1],i,covar[Tvaraff[z1]][i],j1,z1,codtabm(j1,z1), j1,z1,nbcode[Tvaraff[z1]][codtabm(j1,z1)],j1);*/ @@ -4325,7 +4328,9 @@ Title=%s
Datafile=%s Firstpass=%d La for (z1=1; z1<=cptcoveff; z1++) { if( Fixed[Tmodelind[z1]]==1){ iv= Tvar[Tmodelind[z1]]-ncovcol-nqv; - if (cotvar[m][iv][iind]!= nbcode[Tvaraff[z1]][codtabm(j1,z1)]) /* iv=1 to ntv, right modality */ + if (cotvar[m][iv][iind]!= nbcode[Tvaraff[z1]][codtabm(j1,z1)]) /* iv=1 to ntv, right modality. If covariate's + value is -1, we don't select. It differs from the + constant and age model which counts them. */ bool=0; /* not selected */ }else if( Fixed[Tmodelind[z1]]== 0) { /* fixed */ if (covar[Tvaraff[z1]][iind]!= nbcode[Tvaraff[z1]][codtabm(j1,z1)]) { @@ -4354,6 +4359,8 @@ Title=%s
Datafile=%s Firstpass=%d La if(s[m][iind]==-1) printf(" num=%ld m=%d, iind=%d s1=%d s2=%d agev at m=%d agebegin=%.2f ageend=%.2f, agemed=%d\n", num[iind], m, iind,s[m][iind],s[m+1][iind], (int)agev[m][iind],agebegin, ageend, (int)((agebegin+ageend)/2.)); freq[s[m][iind]][s[m+1][iind]][(int)agev[m][iind]] += weight[iind]; /* At age of beginning of transition, where status is known */ + /* if((int)agev[m][iind] == 55) */ + /* printf("j=%d, j1=%d Age %d, iind=%d, num=%09ld m=%d\n",j,j1,(int)agev[m][iind],iind, num[iind],m); */ /* freq[s[m][iind]][s[m+1][iind]][(int)((agebegin+ageend)/2.)] += weight[iind]; */ freq[s[m][iind]][s[m+1][iind]][iagemax+3] += weight[iind]; /* Total is in iagemax+3 *//* At age of beginning of transition, where status is known */ } @@ -4363,7 +4370,9 @@ Title=%s
Datafile=%s Firstpass=%d La k2cpt++; /* printf("iind=%ld dateintmean = %lf dateintsum=%lf k2cpt=%lf k2=%lf\n",iind, dateintsum/k2cpt, dateintsum,k2cpt, k2); */ } - } /* end bool 2 */ + }else{ + bool=1; + }/* end bool 2 */ } /* end m */ } /* end bool */ } /* end iind = 1 to imx */ @@ -4540,18 +4549,43 @@ Title=%s
Datafile=%s Firstpass=%d La fprintf(ficresphtmfr,"\n"); } /* end selected combination of covariate j1 */ if(j==0){ /* We can estimate starting values from the occurences in each case */ + printf("#Freqsummary\n"); + fprintf(ficlog,"\n"); + for(i=1,jk=1; i <=nlstate; i++){ + for(k=1; k <=(nlstate+ndeath); k++){ + if (k != i) { + printf("%d%d ",i,k); + fprintf(ficlog,"%d%d ",i,k); + for(jj=1; jj <=ncovmodel; jj++){ + if(jj==1){ + printf("%12.7f ln(%12.1f/%12.1f)= %12.7f ",p[jk],freq[i][k][iagemax+3],freq[i][i][iagemax+3], log(freq[i][k][iagemax+3]/freq[i][i][iagemax+3])); + fprintf(ficlog,"%12.7f ln(%12.1f/%12.1f)= %12.7f ",p[jk],freq[i][k][iagemax+3],freq[i][i][iagemax+3], log(freq[i][k][iagemax+3]/freq[i][i][iagemax+3])); + } + /* printf("%12.7f )", param[i][jj][k]); */ + /* fprintf(ficlog,"%12.7f )", param[i][jj][k]); */ + jk++; + } + printf("\n"); + fprintf(ficlog,"\n"); + } + } + } + printf("#Freqsummary\n"); + fprintf(ficlog,"\n"); for(jk=-1; jk <=nlstate+ndeath; jk++){ for(m=-1; m <=nlstate+ndeath; m++){ /* param[i]|j][k]= freq[jk][m][iagemax+3] */ - if(freq[jk][m][iage] !=0 ) { /* minimizing output */ - if(first==1){ - printf(" %d%d=%.0f",jk,m,freq[jk][m][iage]); - } - fprintf(ficlog," %d%d=%.0f",jk,m,freq[jk][m][iage]); - } + printf(" %d%d=%.0f",jk,m,freq[jk][m][iagemax+3]); + fprintf(ficlog," %d%d=%.0f",jk,m,freq[jk][m][iagemax+3]); + /* if(freq[jk][m][iage] !=0 ) { /\* minimizing output *\/ */ + /* printf(" %d%d=%.0f",jk,m,freq[jk][m][iagemax+3]); */ + /* fprintf(ficlog," %d%d=%.0f",jk,m,freq[jk][m][iagemax+3]); */ + /* } */ } } /* end loop jk */ - } + printf("\n"); + fprintf(ficlog,"\n"); + } /* if j=0 */ } /* end j */ dateintmean=dateintsum/k2cpt; @@ -10438,7 +10472,7 @@ Title=%s
Datafile=%s Firstpass=%d La /* Calculates basic frequencies. Computes observed prevalence at single age and for any valid combination of covariates and prints on file fileres'p'. */ - freqsummary(fileres, agemin, agemax, s, agev, nlstate, imx, Tvaraff, invalidvarcomb, nbcode, ncodemax,mint,anint,strstart, \ + freqsummary(fileres, p, agemin, agemax, s, agev, nlstate, imx, Tvaraff, invalidvarcomb, nbcode, ncodemax,mint,anint,strstart, \ firstpass, lastpass, stepm, weightopt, model); fprintf(fichtm,"\n");