version 1.283, 2018/04/19 14:49:16
|
version 1.285, 2018/04/21 21:02:16
|
Line 1
|
Line 1
|
/* $Id$ |
/* $Id$ |
$State$ |
$State$ |
$Log$ |
$Log$ |
|
Revision 1.285 2018/04/21 21:02:16 brouard |
|
Summary: Some bugs fixed, valgrind tested |
|
|
|
Revision 1.284 2018/04/20 05:22:13 brouard |
|
Summary: Computing mean and stdeviation of fixed quantitative variables |
|
|
Revision 1.283 2018/04/19 14:49:16 brouard |
Revision 1.283 2018/04/19 14:49:16 brouard |
Summary: Some minor bugs fixed |
Summary: Some minor bugs fixed |
|
|
Line 4371 void freqsummary(char fileres[], double
|
Line 4377 void freqsummary(char fileres[], double
|
double ***freq; /* Frequencies */ |
double ***freq; /* Frequencies */ |
double *x, *y, a=0.,b=0.,r=1., sa=0., sb=0.; /* for regression, y=b+m*x and r is the correlation coefficient */ |
double *x, *y, a=0.,b=0.,r=1., sa=0., sb=0.; /* for regression, y=b+m*x and r is the correlation coefficient */ |
int no=0, linreg(int ifi, int ila, int *no, const double x[], const double y[], double* a, double* b, double* r, double* sa, double * sb); |
int no=0, linreg(int ifi, int ila, int *no, const double x[], const double y[], double* a, double* b, double* r, double* sa, double * sb); |
double *meanq, *idq; |
double *meanq, *stdq, *idq; |
double **meanqt; |
double **meanqt; |
double *pp, **prop, *posprop, *pospropt; |
double *pp, **prop, *posprop, *pospropt; |
double pos=0., posproptt=0., pospropta=0., k2, dateintsum=0,k2cpt=0; |
double pos=0., posproptt=0., pospropta=0., k2, dateintsum=0,k2cpt=0; |
Line 4384 void freqsummary(char fileres[], double
|
Line 4390 void freqsummary(char fileres[], double
|
pospropt=vector(1,nlstate); /* Counting the number of transition starting from a live state */ |
pospropt=vector(1,nlstate); /* Counting the number of transition starting from a live state */ |
/* prop=matrix(1,nlstate,iagemin,iagemax+3); */ |
/* prop=matrix(1,nlstate,iagemin,iagemax+3); */ |
meanq=vector(1,nqfveff); /* Number of Quantitative Fixed Variables Effective */ |
meanq=vector(1,nqfveff); /* Number of Quantitative Fixed Variables Effective */ |
|
stdq=vector(1,nqfveff); /* Number of Quantitative Fixed Variables Effective */ |
idq=vector(1,nqfveff); /* Number of Quantitative Fixed Variables Effective */ |
idq=vector(1,nqfveff); /* Number of Quantitative Fixed Variables Effective */ |
meanqt=matrix(1,lastpass,1,nqtveff); |
meanqt=matrix(1,lastpass,1,nqtveff); |
strcpy(fileresp,"P_"); |
strcpy(fileresp,"P_"); |
Line 4494 Title=%s <br>Datafile=%s Firstpass=%d La
|
Line 4501 Title=%s <br>Datafile=%s Firstpass=%d La
|
pospropt[i]=0; |
pospropt[i]=0; |
} |
} |
for (z1=1; z1<= nqfveff; z1++) { /* zeroing for each combination j1 as well as for the total */ |
for (z1=1; z1<= nqfveff; z1++) { /* zeroing for each combination j1 as well as for the total */ |
idq[z1]+=0.; |
idq[z1]=0.; |
meanq[z1]+=0.; |
meanq[z1]=0.; |
|
stdq[z1]=0.; |
} |
} |
/* for (z1=1; z1<= nqtveff; z1++) { */ |
/* for (z1=1; z1<= nqtveff; z1++) { */ |
/* for(m=1;m<=lastpass;m++){ */ |
/* for(m=1;m<=lastpass;m++){ */ |
Line 4511 Title=%s <br>Datafile=%s Firstpass=%d La
|
Line 4519 Title=%s <br>Datafile=%s Firstpass=%d La
|
if(j !=0){ |
if(j !=0){ |
if(anyvaryingduminmodel==0){ /* If All fixed covariates */ |
if(anyvaryingduminmodel==0){ /* If All fixed covariates */ |
if (cptcoveff >0) { /* Filter is here: Must be looked at for model=V1+V2+V3+V4 */ |
if (cptcoveff >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]; /\* Computes mean of quantitative with selected filter *\/ */ |
|
/* } */ |
|
for (z1=1; z1<=cptcoveff; z1++) { /* loops on covariates in the model */ |
for (z1=1; z1<=cptcoveff; z1++) { /* loops on covariates in the model */ |
/* if(Tvaraff[z1] ==-20){ */ |
/* if(Tvaraff[z1] ==-20){ */ |
/* /\* sumnew+=cotvar[mw[mi][iind]][z1][iind]; *\/ */ |
/* /\* sumnew+=cotvar[mw[mi][iind]][z1][iind]; *\/ */ |
Line 4534 Title=%s <br>Datafile=%s Firstpass=%d La
|
Line 4539 Title=%s <br>Datafile=%s Firstpass=%d La
|
}/* end j==0 */ |
}/* end j==0 */ |
if (bool==1){ /* We selected an individual iind satisfying combination j1 (V4=1 V3=0) or all fixed covariates */ |
if (bool==1){ /* We selected an individual iind satisfying combination j1 (V4=1 V3=0) or all fixed covariates */ |
/* for(m=firstpass; m<=lastpass; m++){ */ |
/* for(m=firstpass; m<=lastpass; m++){ */ |
for(mi=1; mi<wav[iind];mi++){ /* For that wave */ |
for(mi=1; mi<wav[iind];mi++){ /* For each wave */ |
m=mw[mi][iind]; |
m=mw[mi][iind]; |
if(j!=0){ |
if(j!=0){ |
if(anyvaryingduminmodel==1){ /* Some are varying covariates */ |
if(anyvaryingduminmodel==1){ /* Some are varying covariates */ |
Line 4554 Title=%s <br>Datafile=%s Firstpass=%d La
|
Line 4559 Title=%s <br>Datafile=%s Firstpass=%d La
|
}/* Some are varying covariates, we tried to speed up if all fixed covariates in the model, avoiding waves loop */ |
}/* Some are varying covariates, we tried to speed up if all fixed covariates in the model, avoiding waves loop */ |
} /* end j==0 */ |
} /* end j==0 */ |
/* bool =0 we keep that guy which corresponds to the combination of dummy values */ |
/* bool =0 we keep that guy which corresponds to the combination of dummy values */ |
if(bool==1){ |
if(bool==1){ /*Selected */ |
/* dh[m][iind] or dh[mw[mi][iind]][iind] is the delay between two effective (mi) waves m=mw[mi][iind] |
/* dh[m][iind] or dh[mw[mi][iind]][iind] is the delay between two effective (mi) waves m=mw[mi][iind] |
and mw[mi+1][iind]. dh depends on stepm. */ |
and mw[mi+1][iind]. dh depends on stepm. */ |
agebegin=agev[m][iind]; /* Age at beginning of wave before transition*/ |
agebegin=agev[m][iind]; /* Age at beginning of wave before transition*/ |
Line 4572 Title=%s <br>Datafile=%s Firstpass=%d La
|
Line 4577 Title=%s <br>Datafile=%s Firstpass=%d La
|
if(s[m][iind]==-1) |
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.)); |
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 */ |
freq[s[m][iind]][s[m+1][iind]][(int)agev[m][iind]] += weight[iind]; /* At age of beginning of transition, where status is known */ |
|
for (z1=1; z1<= nqfveff; z1++) { /* Quantitative variables, calculating mean */ |
|
idq[z1]=idq[z1]+weight[iind]; |
|
meanq[z1]+=covar[ncovcol+z1][iind]*weight[iind]; /* Computes mean of quantitative with selected filter */ |
|
stdq[z1]+=covar[ncovcol+z1][iind]*covar[ncovcol+z1][iind]*weight[iind]*weight[iind]; /* *weight[iind];*/ /* Computes mean of quantitative with selected filter */ |
|
} |
/* if((int)agev[m][iind] == 55) */ |
/* 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); */ |
/* 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]][(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 */ |
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 */ |
} |
} |
for (z1=1; z1<= nqfveff; z1++) { |
|
idq[z1]++; |
|
meanq[z1]+=covar[ncovcol+z1][iind]; /* *weight[iind];*/ /* Computes mean of quantitative with selected filter */ |
|
/* meanq[z1]+=coqvar[Tvar[z1]][iind]; /\* Computes mean of quantitative with selected filter *\/ */ |
|
} |
|
} /* end if between passes */ |
} /* end if between passes */ |
if ((agev[m][iind]>1) && (agev[m][iind]< (iagemax+3)) && (anint[m][iind]!=9999) && (mint[m][iind]!=99) && (j==0)) { |
if ((agev[m][iind]>1) && (agev[m][iind]< (iagemax+3)) && (anint[m][iind]!=9999) && (mint[m][iind]!=99) && (j==0)) { |
dateintsum=dateintsum+k2; /* on all covariates ?*/ |
dateintsum=dateintsum+k2; /* on all covariates ?*/ |
Line 4592 Title=%s <br>Datafile=%s Firstpass=%d La
|
Line 4597 Title=%s <br>Datafile=%s Firstpass=%d La
|
bool=1; |
bool=1; |
}/* end bool 2 */ |
}/* end bool 2 */ |
} /* end m */ |
} /* end m */ |
|
/* for (z1=1; z1<= nqfveff; z1++) { /\* Quantitative variables, calculating mean *\/ */ |
|
/* idq[z1]=idq[z1]+weight[iind]; */ |
|
/* meanq[z1]+=covar[ncovcol+z1][iind]*weight[iind]; /\* Computes mean of quantitative with selected filter *\/ */ |
|
/* stdq[z1]+=covar[ncovcol+z1][iind]*covar[ncovcol+z1][iind]*weight[iind]*weight[iind]; /\* *weight[iind];*\/ /\* Computes mean of quantitative with selected filter *\/ */ |
|
/* } */ |
} /* end bool */ |
} /* end bool */ |
} /* end iind = 1 to imx */ |
} /* end iind = 1 to imx */ |
/* prop[s][age] is feeded for any initial and valid live state as well as |
/* prop[s][age] is feeded for any initial and valid live state as well as |
Line 4629 Title=%s <br>Datafile=%s Firstpass=%d La
|
Line 4639 Title=%s <br>Datafile=%s Firstpass=%d La
|
fprintf(ficresphtmfr, "**********</h3>\n"); |
fprintf(ficresphtmfr, "**********</h3>\n"); |
fprintf(ficlog, "**********\n"); |
fprintf(ficlog, "**********\n"); |
} |
} |
/* |
/* |
Printing means of quantitative variables if any |
Printing means of quantitative variables if any |
*/ |
*/ |
for (z1=1; z1<= nqfveff; z1++) { |
for (z1=1; z1<= nqfveff; z1++) { |
fprintf(ficresphtmfr,"V quantitative id %d, number of idividuals= %f, sum=%f", z1, idq[z1], meanq[z1]); |
fprintf(ficlog,"Mean of fixed quantitative variable V%d on %.0f individuals sum=%f", ncovcol+z1, idq[z1], meanq[z1]); |
fprintf(ficresphtmfr,", mean=%f<p>\n",meanq[z1]/idq[z1]); |
fprintf(ficlog,", mean=%.3g\n",meanq[z1]/idq[z1]); |
} |
if(weightopt==1){ |
/* for (z1=1; z1<= nqtveff; z1++) { */ |
printf(" Weighted mean and standard deviation of"); |
/* for(m=1;m<=lastpass;m++){ */ |
fprintf(ficlog," Weighted mean and standard deviation of"); |
/* fprintf(ficresphtmfr,"V quantitative id %d, pass id=%d, mean=%f<p>\n", z1, m, meanqt[m][z1]); */ |
fprintf(ficresphtmfr," Weighted mean and standard deviation of"); |
/* } */ |
} |
/* } */ |
printf(" fixed quantitative variable V%d on %.0f representatives of the population : %6.3g (%6.3g)\n", ncovcol+z1, idq[z1],meanq[z1]/idq[z1], sqrt((stdq[z1]-meanq[z1]*meanq[z1]/idq[z1])/idq[z1])); |
|
fprintf(ficlog," fixed quantitative variable V%d on %.0f representatives of the population : %6.3g (%6.3g)\n", ncovcol+z1, idq[z1],meanq[z1]/idq[z1], sqrt((stdq[z1]-meanq[z1]*meanq[z1]/idq[z1])/idq[z1])); |
|
fprintf(ficresphtmfr," fixed quantitative variable V%d on %.0f representatives of the population : %6.3g (%6.3g)<p>\n", ncovcol+z1, idq[z1],meanq[z1]/idq[z1], sqrt((stdq[z1]-meanq[z1]*meanq[z1]/idq[z1])/idq[z1])); |
|
} |
|
/* for (z1=1; z1<= nqtveff; z1++) { */ |
|
/* for(m=1;m<=lastpass;m++){ */ |
|
/* fprintf(ficresphtmfr,"V quantitative id %d, pass id=%d, mean=%f<p>\n", z1, m, meanqt[m][z1]); */ |
|
/* } */ |
|
/* } */ |
|
|
fprintf(ficresphtm,"<table style=\"text-align:center; border: 1px solid\">"); |
fprintf(ficresphtm,"<table style=\"text-align:center; border: 1px solid\">"); |
if((cptcoveff==0 && nj==1)|| nj==2 ) /* no covariate and first pass */ |
if((cptcoveff==0 && nj==1)|| nj==2 ) /* no covariate and first pass */ |
Line 4876 Title=%s <br>Datafile=%s Firstpass=%d La
|
Line 4894 Title=%s <br>Datafile=%s Firstpass=%d La
|
fprintf(ficlog,"\n"); |
fprintf(ficlog,"\n"); |
} |
} |
} |
} |
} |
} /* end of state i */ |
printf("#Freqsummary\n"); |
printf("#Freqsummary\n"); |
fprintf(ficlog,"\n"); |
fprintf(ficlog,"\n"); |
for(s1=-1; s1 <=nlstate+ndeath; s1++){ |
for(s1=-1; s1 <=nlstate+ndeath; s1++){ |
Line 4924 Title=%s <br>Datafile=%s Firstpass=%d La
|
Line 4942 Title=%s <br>Datafile=%s Firstpass=%d La
|
fclose(ficresphtmfr); |
fclose(ficresphtmfr); |
free_vector(idq,1,nqfveff); |
free_vector(idq,1,nqfveff); |
free_vector(meanq,1,nqfveff); |
free_vector(meanq,1,nqfveff); |
|
free_vector(stdq,1,nqfveff); |
free_matrix(meanqt,1,lastpass,1,nqtveff); |
free_matrix(meanqt,1,lastpass,1,nqtveff); |
free_vector(x, iagemin-AGEMARGE, iagemax+4+AGEMARGE); |
free_vector(x, iagemin-AGEMARGE, iagemax+4+AGEMARGE); |
free_vector(y, iagemin-AGEMARGE, iagemax+4+AGEMARGE); |
free_vector(y, iagemin-AGEMARGE, iagemax+4+AGEMARGE); |
Line 5339 void concatwav(int wav[], int **dh, int
|
Line 5358 void concatwav(int wav[], int **dh, int
|
/* *cptcov=0; */ |
/* *cptcov=0; */ |
|
|
for (k=1; k <= maxncov; k++) ncodemax[k]=0; /* Horrible constant again replaced by NCOVMAX */ |
for (k=1; k <= maxncov; k++) ncodemax[k]=0; /* Horrible constant again replaced by NCOVMAX */ |
|
for (k=1; k <= maxncov; k++) |
|
for(j=1; j<=2; j++) |
|
nbcode[k][j]=0; /* Valgrind */ |
|
|
/* Loop on covariates without age and products and no quantitative variable */ |
/* 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<=(cptcovs); j++) { /\* From model V1 + V2*age+ V3 + V3*V4 keeps V1 + V3 = 2 only *\/ */ |
Line 9714 Dummy[k] 0=dummy (0 1), 1 quantitative (
|
Line 9736 Dummy[k] 0=dummy (0 1), 1 quantitative (
|
Typevar: 0 for simple covariate (dummy, quantitative, fixed or varying), 1 for age product, 2 for product \n\ |
Typevar: 0 for simple covariate (dummy, quantitative, fixed or varying), 1 for age product, 2 for product \n\ |
Fixed[k] 0=fixed (product or simple), 1 varying, 2 fixed with age product, 3 varying with age product \n\ |
Fixed[k] 0=fixed (product or simple), 1 varying, 2 fixed with age product, 3 varying with age product \n\ |
Dummy[k] 0=dummy (0 1), 1 quantitative (single or product without age), 2 dummy with age product, 3 quant with age product\n",model); |
Dummy[k] 0=dummy (0 1), 1 quantitative (single or product without age), 2 dummy with age product, 3 quant with age product\n",model); |
for(k=1;k<=cptcovt; k++){ Fixed[k]=0; Dummy[k]=0;} |
for(k=-1;k<=cptcovt; k++){ Fixed[k]=0; Dummy[k]=0;} |
for(k=1, ncovf=0, nsd=0, nsq=0, ncovv=0, ncova=0, ncoveff=0, nqfveff=0, ntveff=0, nqtveff=0;k<=cptcovt; k++){ /* or cptocvt */ |
for(k=1, ncovf=0, nsd=0, nsq=0, ncovv=0, ncova=0, ncoveff=0, nqfveff=0, ntveff=0, nqtveff=0;k<=cptcovt; k++){ /* or cptocvt */ |
if (Tvar[k] <=ncovcol && Typevar[k]==0 ){ /* Simple fixed dummy (<=ncovcol) covariates */ |
if (Tvar[k] <=ncovcol && Typevar[k]==0 ){ /* Simple fixed dummy (<=ncovcol) covariates */ |
Fixed[k]= 0; |
Fixed[k]= 0; |
Line 9964 Dummy[k] 0=dummy (0 1), 1 quantitative (
|
Line 9986 Dummy[k] 0=dummy (0 1), 1 quantitative (
|
/* Searching for doublons in the model */ |
/* Searching for doublons in the model */ |
for(k1=1; k1<= cptcovt;k1++){ |
for(k1=1; k1<= cptcovt;k1++){ |
for(k2=1; k2 <k1;k2++){ |
for(k2=1; k2 <k1;k2++){ |
if((Typevar[k1]==Typevar[k2]) && (Fixed[Tvar[k1]]==Fixed[Tvar[k2]]) && (Dummy[Tvar[k1]]==Dummy[Tvar[k2]] )){ |
/* if((Typevar[k1]==Typevar[k2]) && (Fixed[Tvar[k1]]==Fixed[Tvar[k2]]) && (Dummy[Tvar[k1]]==Dummy[Tvar[k2]] )){ */ |
|
if((Typevar[k1]==Typevar[k2]) && (Fixed[k1]==Fixed[k2]) && (Dummy[k1]==Dummy[k2] )){ |
if((Typevar[k1] == 0 || Typevar[k1] == 1)){ /* Simple or age product */ |
if((Typevar[k1] == 0 || Typevar[k1] == 1)){ /* Simple or age product */ |
if(Tvar[k1]==Tvar[k2]){ |
if(Tvar[k1]==Tvar[k2]){ |
printf("Error duplication in the model=%s at positions (+) %d and %d, Tvar[%d]=V%d, Tvar[%d]=V%d, Typevar=%d, Fixed=%d, Dummy=%d\n", model, k1,k2, k1, Tvar[k1], k2, Tvar[k2],Typevar[k1],Fixed[Tvar[k1]],Dummy[Tvar[k1]]); |
printf("Error duplication in the model=%s at positions (+) %d and %d, Tvar[%d]=V%d, Tvar[%d]=V%d, Typevar=%d, Fixed=%d, Dummy=%d\n", model, k1,k2, k1, Tvar[k1], k2, Tvar[k2],Typevar[k1],Fixed[k1],Dummy[k1]); |
fprintf(ficlog,"Error duplication in the model=%s at positions (+) %d and %d, Tvar[%d]=V%d, Tvar[%d]=V%d, Typevar=%d, Fixed=%d, Dummy=%d\n", model, k1,k2, k1, Tvar[k1], k2, Tvar[k2],Typevar[k1],Fixed[Tvar[k1]],Dummy[Tvar[k1]]); fflush(ficlog); |
fprintf(ficlog,"Error duplication in the model=%s at positions (+) %d and %d, Tvar[%d]=V%d, Tvar[%d]=V%d, Typevar=%d, Fixed=%d, Dummy=%d\n", model, k1,k2, k1, Tvar[k1], k2, Tvar[k2],Typevar[k1],Fixed[k1],Dummy[k1]); fflush(ficlog); |
return(1); |
return(1); |
} |
} |
}else if (Typevar[k1] ==2){ |
}else if (Typevar[k1] ==2){ |