|
|
| version 1.284, 2018/04/20 05:22:13 | version 1.288, 2018/05/02 20:58:27 |
|---|---|
| Line 1 | Line 1 |
| /* $Id$ | /* $Id$ |
| $State$ | $State$ |
| $Log$ | $Log$ |
| Revision 1.288 2018/05/02 20:58:27 brouard | |
| Summary: Some bugs fixed | |
| Revision 1.287 2018/05/01 17:57:25 brouard | |
| Summary: Bug fixed by providing frequencies only for non missing covariates | |
| Revision 1.286 2018/04/27 14:27:04 brouard | |
| Summary: some minor bugs | |
| 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 | Revision 1.284 2018/04/20 05:22:13 brouard |
| Summary: Computing mean and stdeviation of fixed quantitative variables | Summary: Computing mean and stdeviation of fixed quantitative variables |
| Line 1041 typedef struct { | Line 1053 typedef struct { |
| #define MAXN 20000 | #define MAXN 20000 |
| #define YEARM 12. /**< Number of months per year */ | #define YEARM 12. /**< Number of months per year */ |
| /* #define AGESUP 130 */ | /* #define AGESUP 130 */ |
| #define AGESUP 150 | /* #define AGESUP 150 */ |
| #define AGESUP 200 | |
| #define AGEINF 0 | #define AGEINF 0 |
| #define AGEMARGE 25 /* Marge for agemin and agemax for(iage=agemin-AGEMARGE; iage <= agemax+3+AGEMARGE; iage++) */ | #define AGEMARGE 25 /* Marge for agemin and agemax for(iage=agemin-AGEMARGE; iage <= agemax+3+AGEMARGE; iage++) */ |
| #define AGEBASE 40 | #define AGEBASE 40 |
| Line 2568 void powell(double p[], double **xi, int | Line 2581 void powell(double p[], double **xi, int |
| double **newm; | double **newm; |
| double agefin, delaymax=200. ; /* 100 Max number of years to converge */ | double agefin, delaymax=200. ; /* 100 Max number of years to converge */ |
| int ncvloop=0; | int ncvloop=0; |
| int first=0; | |
| min=vector(1,nlstate); | min=vector(1,nlstate); |
| max=vector(1,nlstate); | max=vector(1,nlstate); |
| Line 2664 void powell(double p[], double **xi, int | Line 2678 void powell(double p[], double **xi, int |
| free_vector(meandiff,1,nlstate); | free_vector(meandiff,1,nlstate); |
| return prlim; | return prlim; |
| } | } |
| } /* age loop */ | } /* agefin loop */ |
| /* After some age loop it doesn't converge */ | /* After some age loop it doesn't converge */ |
| printf("Warning: the stable prevalence at age %d did not converge with the required precision (%g > ftolpl=%g) within %.0f years. Try to lower 'ftolpl'. \n\ | if(!first){ |
| Earliest age to start was %d-%d=%d, ncvloop=%d, ncvyear=%d\n", (int)age, maxmax, ftolpl, delaymax, (int)age, (int)delaymax, (int)agefin, ncvloop, *ncvyear); | first=1; |
| printf("Warning: the stable prevalence at age %d did not converge with the required precision (%g > ftolpl=%g) within %.d years and %d loops. Try to lower 'ftolpl'. Youngest age to start was %d=(%d-%d). Others in log file only...\n", (int)age, maxmax, ftolpl, *ncvyear, ncvloop, (int)(agefin+stepm/YEARM), (int)(age-stepm/YEARM), (int)delaymax); | |
| } | |
| fprintf(ficlog, "Warning: the stable prevalence at age %d did not converge with the required precision (%g > ftolpl=%g) within %.d years and %d loops. Try to lower 'ftolpl'. Youngest age to start was %d=(%d-%d).\n", (int)age, maxmax, ftolpl, *ncvyear, ncvloop, (int)(agefin+stepm/YEARM), (int)(age-stepm/YEARM), (int)delaymax); | |
| /* Try to lower 'ftol', for example from 1.e-8 to 6.e-9.\n", ftolpl, (int)age, (int)delaymax, (int)agefin, ncvloop, (int)age-(int)agefin); */ | /* Try to lower 'ftol', for example from 1.e-8 to 6.e-9.\n", ftolpl, (int)age, (int)delaymax, (int)agefin, ncvloop, (int)age-(int)agefin); */ |
| free_vector(min,1,nlstate); | free_vector(min,1,nlstate); |
| free_vector(max,1,nlstate); | free_vector(max,1,nlstate); |
| Line 2733 Earliest age to start was %d-%d=%d, ncvl | Line 2751 Earliest age to start was %d-%d=%d, ncvl |
| /* Even if hstepm = 1, at least one multiplication by the unit matrix */ | /* Even if hstepm = 1, at least one multiplication by the unit matrix */ |
| /* Start at agefin= age, computes the matrix of passage and loops decreasing agefin until convergence is reached */ | /* Start at agefin= age, computes the matrix of passage and loops decreasing agefin until convergence is reached */ |
| /* for(agefin=age+stepm/YEARM; agefin<=age+delaymax; agefin=agefin+stepm/YEARM){ /\* A changer en age *\/ */ | /* for(agefin=age+stepm/YEARM; agefin<=age+delaymax; agefin=agefin+stepm/YEARM){ /\* A changer en age *\/ */ |
| for(agefin=age; agefin<AGESUP; agefin=agefin+stepm/YEARM){ /* A changer en age */ | /* for(agefin=age; agefin<AGESUP; agefin=agefin+stepm/YEARM){ /\* A changer en age *\/ */ |
| for(agefin=age; agefin<FMIN(AGESUP,age+delaymax); agefin=agefin+stepm/YEARM){ /* A changer en age */ | |
| ncvloop++; | ncvloop++; |
| newm=savm; /* oldm should be kept from previous iteration or unity at start */ | newm=savm; /* oldm should be kept from previous iteration or unity at start */ |
| /* newm points to the allocated table savm passed by the function it can be written, savm could be reallocated */ | /* newm points to the allocated table savm passed by the function it can be written, savm could be reallocated */ |
| Line 2847 Earliest age to start was %d-%d=%d, ncvl | Line 2866 Earliest age to start was %d-%d=%d, ncvl |
| free_vector(meandiff,1,nlstate); | free_vector(meandiff,1,nlstate); |
| return bprlim; | return bprlim; |
| } | } |
| } /* age loop */ | } /* agefin loop */ |
| /* After some age loop it doesn't converge */ | /* After some age loop it doesn't converge */ |
| if(first){ | if(!first){ |
| first=1; | first=1; |
| printf("Warning: the back stable prevalence at age %d did not converge with the required precision (%g > ftolpl=%g) within %.0f years. Try to lower 'ftolpl'. Others in log file only...\n\ | printf("Warning: the back stable prevalence at age %d did not converge with the required precision (%g > ftolpl=%g) within %.0f years. Try to lower 'ftolpl'. Others in log file only...\n\ |
| Oldest age to start was %d-%d=%d, ncvloop=%d, ncvyear=%d\n", (int)age, maxmax, ftolpl, delaymax, (int)age, (int)delaymax, (int)agefin, ncvloop, *ncvyear); | Oldest age to start was %d-%d=%d, ncvloop=%d, ncvyear=%d\n", (int)age, maxmax, ftolpl, delaymax, (int)age, (int)delaymax, (int)agefin, ncvloop, *ncvyear); |
| Line 4640 Title=%s <br>Datafile=%s Firstpass=%d La | Line 4659 Title=%s <br>Datafile=%s Firstpass=%d La |
| 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(ficlog,"Mean of quantitative variable V%d on %.0f individuals sum=%f", ncovcol+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(ficlog,", mean=%.3g\n",meanq[z1]/idq[z1]); | fprintf(ficlog,", mean=%.3g\n",meanq[z1]/idq[z1]); |
| if(weightopt==1){ | if(weightopt==1){ |
| printf(" Weighted mean and standard deviation of"); | printf(" Weighted mean and standard deviation of"); |
| fprintf(ficlog," Weighted mean and standard deviation of"); | fprintf(ficlog," Weighted mean and standard deviation of"); |
| fprintf(ficresphtmfr," Weighted mean and standard deviation of"); | fprintf(ficresphtmfr," Weighted mean and standard deviation of"); |
| } | } |
| printf(" 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])); | 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," 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," 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])); | 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 (z1=1; z1<= nqtveff; z1++) { */ |
| /* for(m=1;m<=lastpass;m++){ */ | /* for(m=1;m<=lastpass;m++){ */ |
| Line 5046 void prevalence(double ***probs, double | Line 5065 void prevalence(double ***probs, double |
| /*j=cptcoveff;*/ | /*j=cptcoveff;*/ |
| if (cptcovn<1) {j=1;ncodemax[1]=1;} | if (cptcovn<1) {j=1;ncodemax[1]=1;} |
| first=1; | first=0; |
| for(j1=1; j1<= (int) pow(2,cptcoveff);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 (i=1; i<=nlstate; i++) |
| for(iage=iagemin-AGEMARGE; iage <= iagemax+4+AGEMARGE; iage++) | for(iage=iagemin-AGEMARGE; iage <= iagemax+4+AGEMARGE; iage++) |
| Line 5104 void prevalence(double ***probs, double | Line 5123 void prevalence(double ***probs, double |
| if(posprop>=1.e-5){ | if(posprop>=1.e-5){ |
| probs[i][jk][j1]= prop[jk][i]/posprop; | probs[i][jk][j1]= prop[jk][i]/posprop; |
| } else{ | } else{ |
| if(first==1){ | if(!first){ |
| first=0; | first=1; |
| printf("Warning Observed prevalence doesn't sum to 1 for state %d: probs[%d][%d][%d]=%lf because of lack of cases\nSee others in log file...\n",jk,i,jk, j1,probs[i][jk][j1]); | printf("Warning Observed prevalence doesn't sum to 1 for state %d: probs[%d][%d][%d]=%lf because of lack of cases\nSee others in log file...\n",jk,i,jk, j1,probs[i][jk][j1]); |
| fprintf(ficlog,"Warning Observed prevalence doesn't sum to 1 for state %d: probs[%d][%d][%d]=%lf because of lack of cases\nSee others in log file...\n",jk,i,jk, j1,probs[i][jk][j1]); | |
| }else{ | }else{ |
| fprintf(ficlog,"Warning Observed prevalence doesn't sum to 1 for state %d: probs[%d][%d][%d]=%lf because of lack of cases\nSee others in log file...\n",jk,i,jk, j1,probs[i][jk][j1]); | fprintf(ficlog,"Warning Observed prevalence doesn't sum to 1 for state %d: probs[%d][%d][%d]=%lf because of lack of cases.\n",jk,i,jk, j1,probs[i][jk][j1]); |
| } | } |
| } | } |
| } | } |
| Line 5355 void concatwav(int wav[], int **dh, int | Line 5373 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 (k=1; k<=cptcovt; k++) { /* From model V1 + V2*age + V3 + V3*V4 keeps V1 + V3 = 2 only */ | for (k=1; k<=cptcovt; k++) { /* From model V1 + V2*age + V3 + V3*V4 keeps V1 + V3 = 2 only */ |
| for (j=-1; (j < maxncov); j++) Ndum[j]=0; | for (j=-1; (j < maxncov); j++) Ndum[j]=0; |
| if(Dummy[k]==0 && Typevar[k] !=1){ /* Dummy covariate and not age product */ | if(Dummy[k]==0 && Typevar[k] !=1){ /* Dummy covariate and not age product */ |
| Line 5375 void concatwav(int wav[], int **dh, int | Line 5395 void concatwav(int wav[], int **dh, int |
| modmaxcovj=ij; | modmaxcovj=ij; |
| else if (ij < modmincovj) | else if (ij < modmincovj) |
| modmincovj=ij; | modmincovj=ij; |
| if ((ij < -1) && (ij > NCOVMAX)){ | if (ij <0 || ij >1 ){ |
| printf("Information, IMaCh doesn't treat covariate with missing values (-1), individual %d will be skipped.\n",i); | |
| fprintf(ficlog,"Information, currently IMaCh doesn't treat covariate with missing values (-1), individual %d will be skipped.\n",i); | |
| } | |
| if ((ij < -1) || (ij > NCOVMAX)){ | |
| printf( "Error: minimal is less than -1 or maximal is bigger than %d. Exiting. \n", NCOVMAX ); | printf( "Error: minimal is less than -1 or maximal is bigger than %d. Exiting. \n", NCOVMAX ); |
| exit(1); | exit(1); |
| }else | }else |
| Line 5421 void concatwav(int wav[], int **dh, int | Line 5445 void concatwav(int wav[], int **dh, int |
| /* nbcode[Tvar[j]][3]=2; */ | /* nbcode[Tvar[j]][3]=2; */ |
| /* To be continued (not working yet). */ | /* To be continued (not working yet). */ |
| ij=0; /* ij is similar to i but can jump over null modalities */ | 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*/ | |
| /* 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*/ | |
| /* Skipping the case of missing values by reducing nbcode to 0 and 1 and not -1, 0, 1 */ | |
| /* model=V1+V2+V3, if V2=-1, 0 or 1, then nbcode[2][1]=0 and nbcode[2][2]=1 instead of | |
| * nbcode[2][1]=-1, nbcode[2][2]=0 and nbcode[2][3]=1 */ | |
| /*, could be restored in the future */ | |
| for (i=0; i<=1; 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 */ | if (Ndum[i] == 0) { /* If nobody responded to this modality k */ |
| break; | break; |
| } | } |
| ij++; | ij++; |
| nbcode[Tvar[k]][ij]=i; /* stores the original value of modality i in an array nbcode, ij modality from 1 to last non-nul modality. nbcode[1][1]=0 nbcode[1][2]=1*/ | nbcode[Tvar[k]][ij]=i; /* stores the original value of modality i in an array nbcode, ij modality from 1 to last non-nul modality. nbcode[1][1]=0 nbcode[1][2]=1 . Could be -1*/ |
| cptcode = ij; /* New max modality for covar j */ | cptcode = ij; /* New max modality for covar j */ |
| } /* end of loop on modality i=-1 to 1 or more */ | } /* end of loop on modality i=-1 to 1 or more */ |
| break; | break; |
| Line 5442 void concatwav(int wav[], int **dh, int | Line 5472 void concatwav(int wav[], int **dh, int |
| break; | break; |
| } /* end switch */ | } /* end switch */ |
| } /* end dummy test */ | } /* end dummy test */ |
| } /* end of loop on model-covariate k. nbcode[Tvark][1]=-1, nbcode[Tvark][1]=0 and nbcode[Tvark][2]=1 sets the value of covariate k*/ | |
| /* 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 */ | |
| /* then: nbcode[1][1]=0 ; nbcode[1][2]=1; nbcode[2][1]=0 ; nbcode[2][2]=1; */ | |
| /* But if some modality were not used, it is recoded from 0 to a newer modmaxcovj=cptcode *\/ */ | |
| /* } */ | |
| /* /\* cptcode = ij; *\/ /\* New max modality for covar j *\/ */ | |
| /* if (ij > ncodemax[j]) { */ | |
| /* printf( " Error ij=%d > ncodemax[%d]=%d\n", ij, j, ncodemax[j]); */ | |
| /* fprintf(ficlog, " Error ij=%d > ncodemax[%d]=%d\n", ij, j, ncodemax[j]); */ | |
| /* break; */ | |
| /* } */ | |
| /* } /\* 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; |
| /* Look at fixed dummy (single or product) covariates to check empty modalities */ | /* Look at fixed dummy (single or product) covariates to check empty modalities */ |
| Line 5840 void concatwav(int wav[], int **dh, int | Line 5856 void concatwav(int wav[], int **dh, int |
| double **dnewm,**doldm; | double **dnewm,**doldm; |
| double **dnewmp,**doldmp; | double **dnewmp,**doldmp; |
| int i, j, nhstepm, hstepm, h, nstepm ; | int i, j, nhstepm, hstepm, h, nstepm ; |
| int first=0; | |
| int k; | int k; |
| double *xp; | double *xp; |
| double **gp, **gm; /**< for var eij */ | double **gp, **gm; /**< for var eij */ |
| Line 5964 void concatwav(int wav[], int **dh, int | Line 5981 void concatwav(int wav[], int **dh, int |
| } | } |
| /**< Computes the prevalence limit with parameter theta shifted of delta up to ftolpl precision and | /**< Computes the prevalence limit with parameter theta shifted of delta up to ftolpl precision and |
| * returns into prlim . | * returns into prlim . |
| */ | */ |
| prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyearp,ij, nres); | prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyearp,ij, nres); |
| /* If popbased = 1 we use crossection prevalences. Previous step is useless but prlim is created */ | /* If popbased = 1 we use crossection prevalences. Previous step is useless but prlim is created */ |
| Line 6002 void concatwav(int wav[], int **dh, int | Line 6019 void concatwav(int wav[], int **dh, int |
| for(i=1; i<=npar; i++) /* Computes gradient x - delta */ | for(i=1; i<=npar; i++) /* Computes gradient x - delta */ |
| xp[i] = x[i] - (i==theta ?delti[theta]:0); | xp[i] = x[i] - (i==theta ?delti[theta]:0); |
| prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyearp, ij, nres); | prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyearp, ij, nres); |
| if (popbased==1) { | if (popbased==1) { |
| Line 6188 void concatwav(int wav[], int **dh, int | Line 6205 void concatwav(int wav[], int **dh, int |
| int theta; | int theta; |
| pstamp(ficresvpl); | pstamp(ficresvpl); |
| fprintf(ficresvpl,"# Standard deviation of period (stable) prevalences \n"); | fprintf(ficresvpl,"# Standard deviation of period (forward stable) prevalences \n"); |
| fprintf(ficresvpl,"# Age "); | fprintf(ficresvpl,"# Age "); |
| if(nresult >=1) | if(nresult >=1) |
| fprintf(ficresvpl," Result# "); | fprintf(ficresvpl," Result# "); |
| Line 6217 void concatwav(int wav[], int **dh, int | Line 6234 void concatwav(int wav[], int **dh, int |
| for(i=1; i<=npar; i++){ /* Computes gradient */ | for(i=1; i<=npar; i++){ /* Computes gradient */ |
| xp[i] = x[i] + (i==theta ?delti[theta]:0); | xp[i] = x[i] + (i==theta ?delti[theta]:0); |
| } | } |
| if((int)age==79 ||(int)age== 80 ||(int)age== 81 ) | /* if((int)age==79 ||(int)age== 80 ||(int)age== 81 ) */ |
| prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyearp,ij,nres); | /* prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyearp,ij,nres); */ |
| else | /* else */ |
| prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyearp,ij,nres); | prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyearp,ij,nres); |
| for(i=1;i<=nlstate;i++){ | for(i=1;i<=nlstate;i++){ |
| gp[i] = prlim[i][i]; | gp[i] = prlim[i][i]; |
| mgp[theta][i] = prlim[i][i]; | mgp[theta][i] = prlim[i][i]; |
| } | } |
| for(i=1; i<=npar; i++) /* Computes gradient */ | for(i=1; i<=npar; i++) /* Computes gradient */ |
| xp[i] = x[i] - (i==theta ?delti[theta]:0); | xp[i] = x[i] - (i==theta ?delti[theta]:0); |
| if((int)age==79 ||(int)age== 80 ||(int)age== 81 ) | /* if((int)age==79 ||(int)age== 80 ||(int)age== 81 ) */ |
| prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyearp,ij,nres); | /* prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyearp,ij,nres); */ |
| else | /* else */ |
| prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyearp,ij,nres); | prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyearp,ij,nres); |
| for(i=1;i<=nlstate;i++){ | for(i=1;i<=nlstate;i++){ |
| gm[i] = prlim[i][i]; | gm[i] = prlim[i][i]; |
| mgm[theta][i] = prlim[i][i]; | mgm[theta][i] = prlim[i][i]; |
| Line 6279 void concatwav(int wav[], int **dh, int | Line 6296 void concatwav(int wav[], int **dh, int |
| fprintf(ficresvpl,"%.0f ",age ); | fprintf(ficresvpl,"%.0f ",age ); |
| if(nresult >=1) | if(nresult >=1) |
| fprintf(ficresvpl,"%d ",nres ); | fprintf(ficresvpl,"%d ",nres ); |
| for(i=1; i<=nlstate;i++) | for(i=1; i<=nlstate;i++){ |
| fprintf(ficresvpl," %.5f (%.5f)",prlim[i][i],sqrt(varpl[i][(int)age])); | fprintf(ficresvpl," %.5f (%.5f)",prlim[i][i],sqrt(varpl[i][(int)age])); |
| /* for(j=1;j<=nlstate;j++) */ | |
| /* fprintf(ficresvpl," %d %.5f ",j,prlim[j][i]); */ | |
| } | |
| fprintf(ficresvpl,"\n"); | fprintf(ficresvpl,"\n"); |
| free_vector(gp,1,nlstate); | free_vector(gp,1,nlstate); |
| free_vector(gm,1,nlstate); | free_vector(gm,1,nlstate); |
| Line 6497 void varprob(char optionfilefiname[], do | Line 6517 void varprob(char optionfilefiname[], do |
| fprintf(fichtm,"\n<li><h4> Computing and drawing one step probabilities with their confidence intervals</h4></li>\n"); | fprintf(fichtm,"\n<li><h4> Computing and drawing one step probabilities with their confidence intervals</h4></li>\n"); |
| fprintf(fichtm,"\n"); | fprintf(fichtm,"\n"); |
| fprintf(fichtm,"\n<li><h4> <a href=\"%s\">Matrix of variance-covariance of one-step probabilities (drawings)</a></h4> this page is important in order to visualize confidence intervals and especially correlation between disability and recovery, or more generally, way in and way back. %s</li>\n",optionfilehtmcov,optionfilehtmcov); | fprintf(fichtm,"\n<li><h4> <a href=\"%s\">Matrix of variance-covariance of one-step probabilities (drawings)</a></h4> this page is important in order to visualize confidence intervals and especially correlation between disability and recovery, or more generally, way in and way back. File %s</li>\n",optionfilehtmcov,optionfilehtmcov); |
| fprintf(fichtmcov,"Current page is file <a href=\"%s\">%s</a><br>\n\n<h4>Matrix of variance-covariance of pairs of step probabilities</h4>\n",optionfilehtmcov, optionfilehtmcov); | fprintf(fichtmcov,"Current page is file <a href=\"%s\">%s</a><br>\n\n<h4>Matrix of variance-covariance of pairs of step probabilities</h4>\n",optionfilehtmcov, optionfilehtmcov); |
| fprintf(fichtmcov,"\nEllipsoids of confidence centered on point (p<inf>ij</inf>, p<inf>kl</inf>) are estimated \ | fprintf(fichtmcov,"\nEllipsoids of confidence centered on point (p<inf>ij</inf>, p<inf>kl</inf>) are estimated \ |
| and drawn. It helps understanding how is the covariance between two incidences.\ | and drawn. It helps understanding how is the covariance between two incidences.\ |
| Line 6790 void printinghtml(char fileresu[], char | Line 6810 void printinghtml(char fileresu[], char |
| - Estimated back transition probabilities over %d (stepm) months: <a href=\"%s\">%s</a><br>\n ", | - Estimated back transition probabilities over %d (stepm) months: <a href=\"%s\">%s</a><br>\n ", |
| stepm,subdirf2(fileresu,"PIJB_"),subdirf2(fileresu,"PIJB_")); | stepm,subdirf2(fileresu,"PIJB_"),subdirf2(fileresu,"PIJB_")); |
| fprintf(fichtm,"\ | fprintf(fichtm,"\ |
| - Period (stable) prevalence in each health state: <a href=\"%s\">%s</a> <br>\n", | - Period (forward) prevalence in each health state: <a href=\"%s\">%s</a> <br>\n", |
| subdirf2(fileresu,"PL_"),subdirf2(fileresu,"PL_")); | subdirf2(fileresu,"PL_"),subdirf2(fileresu,"PL_")); |
| fprintf(fichtm,"\ | fprintf(fichtm,"\ |
| - Period (stable) back prevalence in each health state: <a href=\"%s\">%s</a> <br>\n", | - Backward prevalence in each health state: <a href=\"%s\">%s</a> <br>\n", |
| subdirf2(fileresu,"PLB_"),subdirf2(fileresu,"PLB_")); | subdirf2(fileresu,"PLB_"),subdirf2(fileresu,"PLB_")); |
| fprintf(fichtm,"\ | fprintf(fichtm,"\ |
| - (a) Life expectancies by health status at initial age, e<sub>i.</sub> (b) health expectancies by health status at initial age, e<sub>ij</sub> . If one or more covariates are included, specific tables for each value of the covariate are output in sequences within the same file (estepm=%2d months): \ | - (a) Life expectancies by health status at initial age, e<sub>i.</sub> (b) health expectancies by health status at initial age, e<sub>ij</sub> . If one or more covariates are included, specific tables for each value of the covariate are output in sequences within the same file (estepm=%2d months): \ |
| Line 6908 divided by h: <sub>h</sub>P<sub>ij</sub> | Line 6928 divided by h: <sub>h</sub>P<sub>ij</sub> |
| Or probability to survive in various states (1 to %d) being in state %d at different ages. \ | Or probability to survive in various states (1 to %d) being in state %d at different ages. \ |
| <a href=\"%s_%d-%d-%d.svg\">%s_%d-%d-%d.svg</a><br> <img src=\"%s_%d-%d-%d.svg\">", cpt, nlstate, cpt, subdirf2(optionfilefiname,"LIJT_"),cpt,k1,nres,subdirf2(optionfilefiname,"LIJT_"),cpt,k1,nres,subdirf2(optionfilefiname,"LIJT_"),cpt,k1,nres); | <a href=\"%s_%d-%d-%d.svg\">%s_%d-%d-%d.svg</a><br> <img src=\"%s_%d-%d-%d.svg\">", cpt, nlstate, cpt, subdirf2(optionfilefiname,"LIJT_"),cpt,k1,nres,subdirf2(optionfilefiname,"LIJT_"),cpt,k1,nres,subdirf2(optionfilefiname,"LIJT_"),cpt,k1,nres); |
| } | } |
| /* Period (stable) prevalence in each health state */ | /* Period (forward stable) prevalence in each health state */ |
| for(cpt=1; cpt<=nlstate;cpt++){ | for(cpt=1; cpt<=nlstate;cpt++){ |
| fprintf(fichtm,"<br>\n- Convergence to period (stable) prevalence in state %d. Or probability for a person being in state (1 to %d) at different ages, to be in state %d some years after. <a href=\"%s_%d-%d-%d.svg\">%s_%d-%d-%d.svg</a><br> \ | fprintf(fichtm,"<br>\n- Convergence to period (stable) prevalence in state %d. Or probability for a person being in state (1 to %d) at different ages, to be in state %d some years after. <a href=\"%s_%d-%d-%d.svg\">%s_%d-%d-%d.svg</a><br> \ |
| <img src=\"%s_%d-%d-%d.svg\">", cpt, nlstate, cpt, subdirf2(optionfilefiname,"P_"),cpt,k1,nres,subdirf2(optionfilefiname,"P_"),cpt,k1,nres,subdirf2(optionfilefiname,"P_"),cpt,k1,nres); | <img src=\"%s_%d-%d-%d.svg\">", cpt, nlstate, cpt, subdirf2(optionfilefiname,"P_"),cpt,k1,nres,subdirf2(optionfilefiname,"P_"),cpt,k1,nres,subdirf2(optionfilefiname,"P_"),cpt,k1,nres); |
| } | } |
| if(backcast==1){ | if(backcast==1){ |
| /* Period (stable) back prevalence in each health state */ | /* Backward prevalence in each health state */ |
| for(cpt=1; cpt<=nlstate;cpt++){ | for(cpt=1; cpt<=nlstate;cpt++){ |
| fprintf(fichtm,"<br>\n- Convergence to mixed (stable) back prevalence in state %d. Or probability for a person to be in state %d at a younger age, knowing that she/he was in state (1 to %d) at different older ages. <a href=\"%s_%d-%d-%d.svg\">%s_%d-%d-%d.svg</a><br> \ | fprintf(fichtm,"<br>\n- Convergence to mixed (stable) back prevalence in state %d. Or probability for a person to be in state %d at a younger age, knowing that she/he was in state (1 to %d) at different older ages. <a href=\"%s_%d-%d-%d.svg\">%s_%d-%d-%d.svg</a><br> \ |
| <img src=\"%s_%d-%d-%d.svg\">", cpt, cpt, nlstate, subdirf2(optionfilefiname,"PB_"),cpt,k1,nres,subdirf2(optionfilefiname,"PB_"),cpt,k1,nres,subdirf2(optionfilefiname,"PB_"),cpt,k1,nres); | <img src=\"%s_%d-%d-%d.svg\">", cpt, cpt, nlstate, subdirf2(optionfilefiname,"PB_"),cpt,k1,nres,subdirf2(optionfilefiname,"PB_"),cpt,k1,nres,subdirf2(optionfilefiname,"PB_"),cpt,k1,nres); |
| } | } |
| } | } |
| if(prevfcast==1){ | if(prevfcast==1){ |
| /* Projection of prevalence up to period (stable) prevalence in each health state */ | /* Projection of prevalence up to period (forward stable) prevalence in each health state */ |
| for(cpt=1; cpt<=nlstate;cpt++){ | for(cpt=1; cpt<=nlstate;cpt++){ |
| fprintf(fichtm,"<br>\n- Projection of cross-sectional prevalence (estimated with cases observed from %.1f to %.1f and mobil_average=%d), from year %.1f up to year %.1f tending to period (stable) prevalence in state %d. Or probability to be in state %d being in an observed weighted state (from 1 to %d). <a href=\"%s_%d-%d-%d.svg\">%s_%d-%d-%d.svg</a><br> \ | fprintf(fichtm,"<br>\n- Projection of cross-sectional prevalence (estimated with cases observed from %.1f to %.1f and mobil_average=%d), from year %.1f up to year %.1f tending to period (stable) forward prevalence in state %d. Or probability to be in state %d being in an observed weighted state (from 1 to %d). <a href=\"%s_%d-%d-%d.svg\">%s_%d-%d-%d.svg</a><br> \ |
| <img src=\"%s_%d-%d-%d.svg\">", dateprev1, dateprev2, mobilavproj, dateproj1, dateproj2, cpt, cpt, nlstate, subdirf2(optionfilefiname,"PROJ_"),cpt,k1,nres,subdirf2(optionfilefiname,"PROJ_"),cpt,k1,nres,subdirf2(optionfilefiname,"PROJ_"),cpt,k1,nres); | <img src=\"%s_%d-%d-%d.svg\">", dateprev1, dateprev2, mobilavproj, dateproj1, dateproj2, cpt, cpt, nlstate, subdirf2(optionfilefiname,"PROJ_"),cpt,k1,nres,subdirf2(optionfilefiname,"PROJ_"),cpt,k1,nres,subdirf2(optionfilefiname,"PROJ_"),cpt,k1,nres); |
| } | } |
| } | } |
| Line 6976 See page 'Matrix of variance-covariance | Line 6996 See page 'Matrix of variance-covariance |
| <a href=\"%s\">%s</a> <br>\n</li>", | <a href=\"%s\">%s</a> <br>\n</li>", |
| estepm,subdirf2(fileresu,"STDE_"),subdirf2(fileresu,"STDE_")); | estepm,subdirf2(fileresu,"STDE_"),subdirf2(fileresu,"STDE_")); |
| fprintf(fichtm,"\ | fprintf(fichtm,"\ |
| - Variances and covariances of health expectancies by age. Status (i) based health expectancies (in state j), e<sup>ij</sup> are weighted by the period prevalences in each state i (if popbased=1, an additional computation is done using the cross-sectional prevalences, i.e population based) (estepm=%d months): <a href=\"%s\">%s</a><br>\n", | - Variances and covariances of health expectancies by age. Status (i) based health expectancies (in state j), e<sup>ij</sup> are weighted by the forward (period) prevalences in each state i (if popbased=1, an additional computation is done using the cross-sectional prevalences, i.e population based) (estepm=%d months): <a href=\"%s\">%s</a><br>\n", |
| estepm, subdirf2(fileresu,"V_"),subdirf2(fileresu,"V_")); | estepm, subdirf2(fileresu,"V_"),subdirf2(fileresu,"V_")); |
| fprintf(fichtm,"\ | fprintf(fichtm,"\ |
| - Total life expectancy and total health expectancies to be spent in each health state e<sup>.j</sup> with their standard errors (if popbased=1, an additional computation is done using the cross-sectional prevalences, i.e population based) (estepm=%d months): <a href=\"%s\">%s</a> <br>\n", | - Total life expectancy and total health expectancies to be spent in each health state e<sup>.j</sup> with their standard errors (if popbased=1, an additional computation is done using the cross-sectional prevalences, i.e population based) (estepm=%d months): <a href=\"%s\">%s</a> <br>\n", |
| estepm, subdirf2(fileresu,"T_"),subdirf2(fileresu,"T_")); | estepm, subdirf2(fileresu,"T_"),subdirf2(fileresu,"T_")); |
| fprintf(fichtm,"\ | fprintf(fichtm,"\ |
| - Standard deviation of period (stable) prevalences: <a href=\"%s\">%s</a> <br>\n",\ | - Standard deviation of forward (period) prevalences: <a href=\"%s\">%s</a> <br>\n",\ |
| subdirf2(fileresu,"VPL_"),subdirf2(fileresu,"VPL_")); | subdirf2(fileresu,"VPL_"),subdirf2(fileresu,"VPL_")); |
| /* if(popforecast==1) fprintf(fichtm,"\n */ | /* if(popforecast==1) fprintf(fichtm,"\n */ |
| Line 7118 void printinggnuplot(char fileresu[], ch | Line 7138 void printinggnuplot(char fileresu[], ch |
| continue; | continue; |
| /* We are interested in selected combination by the resultline */ | /* We are interested in selected combination by the resultline */ |
| /* printf("\n# 1st: Period (stable) prevalence with CI: 'VPL_' files and live state =%d ", cpt); */ | /* printf("\n# 1st: Period (stable) prevalence with CI: 'VPL_' files and live state =%d ", cpt); */ |
| fprintf(ficgp,"\n# 1st: Period (stable) prevalence with CI: 'VPL_' files and live state =%d ", cpt); | fprintf(ficgp,"\n# 1st: Forward (stable period) prevalence with CI: 'VPL_' files and live state =%d ", cpt); |
| strcpy(gplotlabel,"("); | strcpy(gplotlabel,"("); |
| for (k=1; k<=cptcoveff; k++){ /* For each covariate k get corresponding value lv for combination k1 */ | for (k=1; k<=cptcoveff; k++){ /* For each covariate k get corresponding value lv for combination k1 */ |
| lv= decodtabm(k1,k,cptcoveff); /* Should be the value of the covariate corresponding to k1 combination */ | lv= decodtabm(k1,k,cptcoveff); /* Should be the value of the covariate corresponding to k1 combination */ |
| Line 7156 void printinggnuplot(char fileresu[], ch | Line 7176 void printinggnuplot(char fileresu[], ch |
| if (i==cpt) fprintf(ficgp," %%lf (%%lf)"); | if (i==cpt) fprintf(ficgp," %%lf (%%lf)"); |
| else fprintf(ficgp," %%*lf (%%*lf)"); | else fprintf(ficgp," %%*lf (%%*lf)"); |
| } | } |
| fprintf(ficgp,"\" t\"Period (stable) prevalence\" w l lt 0,\"%s\" every :::%d::%d u 1:($2==%d ? $3+1.96*$4 : 1/0) \"%%lf %%lf",subdirf2(fileresu,"VPL_"),nres-1,nres-1,nres); | fprintf(ficgp,"\" t\"Forward prevalence\" w l lt 0,\"%s\" every :::%d::%d u 1:($2==%d ? $3+1.96*$4 : 1/0) \"%%lf %%lf",subdirf2(fileresu,"VPL_"),nres-1,nres-1,nres); |
| for (i=1; i<= nlstate ; i ++) { | for (i=1; i<= nlstate ; i ++) { |
| if (i==cpt) fprintf(ficgp," %%lf (%%lf)"); | if (i==cpt) fprintf(ficgp," %%lf (%%lf)"); |
| else fprintf(ficgp," %%*lf (%%*lf)"); | else fprintf(ficgp," %%*lf (%%*lf)"); |
| Line 7485 set ter svg size 640, 480\nunset log y\n | Line 7505 set ter svg size 640, 480\nunset log y\n |
| continue; | continue; |
| for (cpt=1; cpt<=nlstate ; cpt ++) { /* For each life state of arrival */ | for (cpt=1; cpt<=nlstate ; cpt ++) { /* For each life state of arrival */ |
| strcpy(gplotlabel,"("); | strcpy(gplotlabel,"("); |
| fprintf(ficgp,"\n#\n#\n#CV preval stable (period): 'pij' files, covariatecombination#=%d state=%d",k1, cpt); | fprintf(ficgp,"\n#\n#\n#CV preval stable (forward): 'pij' files, covariatecombination#=%d state=%d",k1, cpt); |
| for (k=1; k<=cptcoveff; k++){ /* For each covariate and each value */ | for (k=1; k<=cptcoveff; k++){ /* For each covariate and each value */ |
| lv= decodtabm(k1,k,cptcoveff); /* Should be the covariate number corresponding to k1 combination */ | lv= decodtabm(k1,k,cptcoveff); /* Should be the covariate number corresponding to k1 combination */ |
| /* decodtabm(1,1,4) = 1 because h=1 k= (1) 1 1 1 */ | /* decodtabm(1,1,4) = 1 because h=1 k= (1) 1 1 1 */ |
| Line 7529 set ter svg size 640, 480\nunset log y\n | Line 7549 set ter svg size 640, 480\nunset log y\n |
| /* 7eme */ | /* 7eme */ |
| if(backcast == 1){ | if(backcast == 1){ |
| /* CV back preval stable (period) for each covariate */ | /* CV backward prevalence for each covariate */ |
| for (k1=1; k1<= m ; k1 ++) /* For each covariate combination if any */ | for (k1=1; k1<= m ; k1 ++) /* For each covariate combination if any */ |
| for(nres=1; nres <= nresult; nres++){ /* For each resultline */ | for(nres=1; nres <= nresult; nres++){ /* For each resultline */ |
| if(m != 1 && TKresult[nres]!= k1) | if(m != 1 && TKresult[nres]!= k1) |
| continue; | continue; |
| for (cpt=1; cpt<=nlstate ; cpt ++) { /* For each life origin state */ | for (cpt=1; cpt<=nlstate ; cpt ++) { /* For each life origin state */ |
| strcpy(gplotlabel,"("); | strcpy(gplotlabel,"("); |
| fprintf(ficgp,"\n#\n#\n#CV Back preval stable (period): 'pijb' files, covariatecombination#=%d state=%d",k1, cpt); | fprintf(ficgp,"\n#\n#\n#CV Backward stable prevalence: 'pijb' files, covariatecombination#=%d state=%d",k1, cpt); |
| for (k=1; k<=cptcoveff; k++){ /* For each covariate and each value */ | for (k=1; k<=cptcoveff; k++){ /* For each covariate and each value */ |
| lv= decodtabm(k1,k,cptcoveff); /* Should be the covariate number corresponding to k1 combination */ | lv= decodtabm(k1,k,cptcoveff); /* Should be the covariate number corresponding to k1 combination */ |
| /* decodtabm(1,1,4) = 1 because h=1 k= (1) 1 1 1 */ | /* decodtabm(1,1,4) = 1 because h=1 k= (1) 1 1 1 */ |
| Line 7584 set ter svg size 640, 480\nunset log y\n | Line 7604 set ter svg size 640, 480\nunset log y\n |
| /* 8eme */ | /* 8eme */ |
| if(prevfcast==1){ | if(prevfcast==1){ |
| /* Projection from cross-sectional to stable (period) for each covariate */ | /* Projection from cross-sectional to forward stable (period) prevalence for each covariate */ |
| for (k1=1; k1<= m ; k1 ++) /* For each covariate combination if any */ | for (k1=1; k1<= m ; k1 ++) /* For each covariate combination if any */ |
| for(nres=1; nres <= nresult; nres++){ /* For each resultline */ | for(nres=1; nres <= nresult; nres++){ /* For each resultline */ |
| Line 7592 set ter svg size 640, 480\nunset log y\n | Line 7612 set ter svg size 640, 480\nunset log y\n |
| continue; | continue; |
| for (cpt=1; cpt<=nlstate ; cpt ++) { /* For each life state */ | for (cpt=1; cpt<=nlstate ; cpt ++) { /* For each life state */ |
| strcpy(gplotlabel,"("); | strcpy(gplotlabel,"("); |
| fprintf(ficgp,"\n#\n#\n#Projection of prevalence to stable (period): 'PROJ_' files, covariatecombination#=%d state=%d",k1, cpt); | fprintf(ficgp,"\n#\n#\n#Projection of prevalence to forward stable prevalence (period): 'PROJ_' files, covariatecombination#=%d state=%d",k1, cpt); |
| for (k=1; k<=cptcoveff; k++){ /* For each correspondig covariate value */ | for (k=1; k<=cptcoveff; k++){ /* For each correspondig covariate value */ |
| lv= decodtabm(k1,k,cptcoveff); /* Should be the covariate value corresponding to k1 combination and kth covariate */ | lv= decodtabm(k1,k,cptcoveff); /* Should be the covariate value corresponding to k1 combination and kth covariate */ |
| /* decodtabm(1,1,4) = 1 because h=1 k= (1) 1 1 1 */ | /* decodtabm(1,1,4) = 1 because h=1 k= (1) 1 1 1 */ |
| Line 8026 set ter svg size 640, 480\nunset log y\n | Line 8046 set ter svg size 640, 480\nunset log y\n |
| int modcovmax =1; | int modcovmax =1; |
| int mobilavrange, mob; | int mobilavrange, mob; |
| int iage=0; | int iage=0; |
| int firstA1=0, firstA2=0; | |
| double sum=0., sumr=0.; | double sum=0., sumr=0.; |
| double age; | double age; |
| Line 8123 set ter svg size 640, 480\nunset log y\n | Line 8144 set ter svg size 640, 480\nunset log y\n |
| } /* age */ | } /* age */ |
| /* Thus we have agemingood and agemaxgood as well as goodr for raw (preobs) */ | /* Thus we have agemingood and agemaxgood as well as goodr for raw (preobs) */ |
| /* but they will change */ | /* but they will change */ |
| firstA1=0;firstA2=0; | |
| for (age=fage-(mob-1)/2; age>=bage; age--){/* From oldest to youngest, filling up to the youngest */ | for (age=fage-(mob-1)/2; age>=bage; age--){/* From oldest to youngest, filling up to the youngest */ |
| sumnewm[cptcod]=0.; | sumnewm[cptcod]=0.; |
| sumnewmr[cptcod]=0.; | sumnewmr[cptcod]=0.; |
| Line 8155 set ter svg size 640, 480\nunset log y\n | Line 8177 set ter svg size 640, 480\nunset log y\n |
| sumr+=probs[(int)age][i][cptcod]; | sumr+=probs[(int)age][i][cptcod]; |
| } | } |
| if(fabs(sum - 1.) > 1.e-3) { /* bad */ | if(fabs(sum - 1.) > 1.e-3) { /* bad */ |
| printf("Moving average A1: For this combination of covariate cptcod=%d, we can't get a smoothed prevalence which sums to one (%f) at any descending age! age=%d, could you increase bage=%d\n",cptcod,sumr, (int)age, (int)bage); | if(!firstA1){ |
| firstA1=1; | |
| printf("Moving average A1: For this combination of covariate cptcod=%d, we can't get a smoothed prevalence which sums to one (%f) at any descending age! age=%d, could you increase bage=%d. Others in log file...\n",cptcod,sumr, (int)age, (int)bage); | |
| } | |
| fprintf(ficlog,"Moving average A1: For this combination of covariate cptcod=%d, we can't get a smoothed prevalence which sums to one (%f) at any descending age! age=%d, could you increase bage=%d\n",cptcod,sumr, (int)age, (int)bage); | |
| } /* end bad */ | } /* end bad */ |
| /* else{ /\* We found some ages summing to one, we will smooth the oldest *\/ */ | /* else{ /\* We found some ages summing to one, we will smooth the oldest *\/ */ |
| if(fabs(sumr - 1.) > 1.e-3) { /* bad */ | if(fabs(sumr - 1.) > 1.e-3) { /* bad */ |
| printf("Moving average A2: For this combination of covariate cptcod=%d, the raw prevalence doesn't sums to one (%f) even with smoothed values at young ages! age=%d, could you increase bage=%d\n",cptcod,sumr, (int)age, (int)bage); | if(!firstA2){ |
| firstA2=1; | |
| printf("Moving average A2: For this combination of covariate cptcod=%d, the raw prevalence doesn't sums to one (%f) even with smoothed values at young ages! age=%d, could you increase bage=%d. Others in log file...\n",cptcod,sumr, (int)age, (int)bage); | |
| } | |
| fprintf(ficlog,"Moving average A2: For this combination of covariate cptcod=%d, the raw prevalence doesn't sums to one (%f) even with smoothed values at young ages! age=%d, could you increase bage=%d\n",cptcod,sumr, (int)age, (int)bage); | |
| } /* end bad */ | } /* end bad */ |
| }/* age */ | }/* age */ |
| Line 8534 set ter svg size 640, 480\nunset log y\n | Line 8564 set ter svg size 640, 480\nunset log y\n |
| /* Variance of prevalence limit: varprlim */ | /* Variance of prevalence limit: varprlim */ |
| void varprlim(char fileresu[], int nresult, double ***prevacurrent, int mobilavproj, double bage, double fage, double **prlim, int *ncvyearp, double ftolpl, double p[], double **matcov, double *delti, int stepm, int cptcoveff){ | void varprlim(char fileresu[], int nresult, double ***prevacurrent, int mobilavproj, double bage, double fage, double **prlim, int *ncvyearp, double ftolpl, double p[], double **matcov, double *delti, int stepm, int cptcoveff){ |
| /*------- Variance of period (stable) prevalence------*/ | /*------- Variance of forward period (stable) prevalence------*/ |
| char fileresvpl[FILENAMELENGTH]; | char fileresvpl[FILENAMELENGTH]; |
| FILE *ficresvpl; | FILE *ficresvpl; |
| Line 8545 set ter svg size 640, 480\nunset log y\n | Line 8575 set ter svg size 640, 480\nunset log y\n |
| strcpy(fileresvpl,"VPL_"); | strcpy(fileresvpl,"VPL_"); |
| strcat(fileresvpl,fileresu); | strcat(fileresvpl,fileresu); |
| if((ficresvpl=fopen(fileresvpl,"w"))==NULL) { | if((ficresvpl=fopen(fileresvpl,"w"))==NULL) { |
| printf("Problem with variance of period (stable) prevalence resultfile: %s\n", fileresvpl); | printf("Problem with variance of forward period (stable) prevalence resultfile: %s\n", fileresvpl); |
| exit(0); | exit(0); |
| } | } |
| printf("Computing Variance-covariance of period (stable) prevalence: file '%s' ...", fileresvpl);fflush(stdout); | printf("Computing Variance-covariance of forward period (stable) prevalence: file '%s' ...", fileresvpl);fflush(stdout); |
| fprintf(ficlog, "Computing Variance-covariance of period (stable) prevalence: file '%s' ...", fileresvpl);fflush(ficlog); | fprintf(ficlog, "Computing Variance-covariance of forward period (stable) prevalence: file '%s' ...", fileresvpl);fflush(ficlog); |
| /*for(cptcov=1,k=0;cptcov<=i1;cptcov++){ | /*for(cptcov=1,k=0;cptcov<=i1;cptcov++){ |
| for(cptcod=1;cptcod<=ncodemax[cptcov];cptcod++){*/ | for(cptcod=1;cptcod<=ncodemax[cptcov];cptcod++){*/ |
| Line 8586 set ter svg size 640, 480\nunset log y\n | Line 8616 set ter svg size 640, 480\nunset log y\n |
| } | } |
| fclose(ficresvpl); | fclose(ficresvpl); |
| printf("done variance-covariance of period prevalence\n");fflush(stdout); | printf("done variance-covariance of forward period prevalence\n");fflush(stdout); |
| fprintf(ficlog,"done variance-covariance of period prevalence\n");fflush(ficlog); | fprintf(ficlog,"done variance-covariance of forward period prevalence\n");fflush(ficlog); |
| } | } |
| /* Variance of back prevalence: varbprlim */ | /* Variance of back prevalence: varbprlim */ |
| Line 9730 Dummy[k] 0=dummy (0 1), 1 quantitative ( | Line 9760 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 9980 Dummy[k] 0=dummy (0 1), 1 quantitative ( | Line 10010 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){ |
| Line 10295 void syscompilerinfo(int logged) | Line 10326 void syscompilerinfo(int logged) |
| #endif | #endif |
| #endif | #endif |
| // void main() | // void main () |
| // { | // { |
| #if defined(_MSC_VER) | #if defined(_MSC_VER) |
| if (IsWow64()){ | if (IsWow64()){ |
| Line 10316 void syscompilerinfo(int logged) | Line 10347 void syscompilerinfo(int logged) |
| } | } |
| int prevalence_limit(double *p, double **prlim, double ageminpar, double agemaxpar, double ftolpl, int *ncvyearp){ | int prevalence_limit(double *p, double **prlim, double ageminpar, double agemaxpar, double ftolpl, int *ncvyearp){ |
| /*--------------- Prevalence limit (period or stable prevalence) --------------*/ | /*--------------- Prevalence limit (forward period or forward stable prevalence) --------------*/ |
| int i, j, k, i1, k4=0, nres=0 ; | int i, j, k, i1, k4=0, nres=0 ; |
| /* double ftolpl = 1.e-10; */ | /* double ftolpl = 1.e-10; */ |
| double age, agebase, agelim; | double age, agebase, agelim; |
| Line 10325 int prevalence_limit(double *p, double * | Line 10356 int prevalence_limit(double *p, double * |
| strcpy(filerespl,"PL_"); | strcpy(filerespl,"PL_"); |
| strcat(filerespl,fileresu); | strcat(filerespl,fileresu); |
| if((ficrespl=fopen(filerespl,"w"))==NULL) { | if((ficrespl=fopen(filerespl,"w"))==NULL) { |
| printf("Problem with period (stable) prevalence resultfile: %s\n", filerespl);return 1; | printf("Problem with forward period (stable) prevalence resultfile: %s\n", filerespl);return 1; |
| fprintf(ficlog,"Problem with period (stable) prevalence resultfile: %s\n", filerespl);return 1; | fprintf(ficlog,"Problem with forward period (stable) prevalence resultfile: %s\n", filerespl);return 1; |
| } | } |
| printf("\nComputing period (stable) prevalence: result on file '%s' \n", filerespl); | printf("\nComputing forward period (stable) prevalence: result on file '%s' \n", filerespl); |
| fprintf(ficlog,"\nComputing period (stable) prevalence: result on file '%s' \n", filerespl); | fprintf(ficlog,"\nComputing forward period (stable) prevalence: result on file '%s' \n", filerespl); |
| pstamp(ficrespl); | pstamp(ficrespl); |
| fprintf(ficrespl,"# Period (stable) prevalence. Precision given by ftolpl=%g \n", ftolpl); | fprintf(ficrespl,"# Forward period (stable) prevalence. Precision given by ftolpl=%g \n", ftolpl); |
| fprintf(ficrespl,"#Age "); | fprintf(ficrespl,"#Age "); |
| for(i=1; i<=nlstate;i++) fprintf(ficrespl,"%d-%d ",i,i); | for(i=1; i<=nlstate;i++) fprintf(ficrespl,"%d-%d ",i,i); |
| fprintf(ficrespl,"\n"); | fprintf(ficrespl,"\n"); |
| Line 10406 int prevalence_limit(double *p, double * | Line 10437 int prevalence_limit(double *p, double * |
| } | } |
| int back_prevalence_limit(double *p, double **bprlim, double ageminpar, double agemaxpar, double ftolpl, int *ncvyearp, double dateprev1,double dateprev2, int firstpass, int lastpass, int mobilavproj){ | int back_prevalence_limit(double *p, double **bprlim, double ageminpar, double agemaxpar, double ftolpl, int *ncvyearp, double dateprev1,double dateprev2, int firstpass, int lastpass, int mobilavproj){ |
| /*--------------- Back Prevalence limit (period or stable prevalence) --------------*/ | /*--------------- Back Prevalence limit (backward stable prevalence) --------------*/ |
| /* Computes the back prevalence limit for any combination of covariate values | /* Computes the back prevalence limit for any combination of covariate values |
| * at any age between ageminpar and agemaxpar | * at any age between ageminpar and agemaxpar |
| Line 10421 int back_prevalence_limit(double *p, dou | Line 10452 int back_prevalence_limit(double *p, dou |
| strcpy(fileresplb,"PLB_"); | strcpy(fileresplb,"PLB_"); |
| strcat(fileresplb,fileresu); | strcat(fileresplb,fileresu); |
| if((ficresplb=fopen(fileresplb,"w"))==NULL) { | if((ficresplb=fopen(fileresplb,"w"))==NULL) { |
| printf("Problem with period (stable) back prevalence resultfile: %s\n", fileresplb);return 1; | printf("Problem with backward prevalence resultfile: %s\n", fileresplb);return 1; |
| fprintf(ficlog,"Problem with period (stable) back prevalence resultfile: %s\n", fileresplb);return 1; | fprintf(ficlog,"Problem with backward prevalence resultfile: %s\n", fileresplb);return 1; |
| } | } |
| printf("Computing period (stable) back prevalence: result on file '%s' \n", fileresplb); | printf("Computing backward prevalence: result on file '%s' \n", fileresplb); |
| fprintf(ficlog,"Computing period (stable) back prevalence: result on file '%s' \n", fileresplb); | fprintf(ficlog,"Computing backward prevalence: result on file '%s' \n", fileresplb); |
| pstamp(ficresplb); | pstamp(ficresplb); |
| fprintf(ficresplb,"# Period (stable) back prevalence. Precision given by ftolpl=%g \n", ftolpl); | fprintf(ficresplb,"# Backward prevalence. Precision given by ftolpl=%g \n", ftolpl); |
| fprintf(ficresplb,"#Age "); | fprintf(ficresplb,"#Age "); |
| for(i=1; i<=nlstate;i++) fprintf(ficresplb,"%d-%d ",i,i); | for(i=1; i<=nlstate;i++) fprintf(ficresplb,"%d-%d ",i,i); |
| fprintf(ficresplb,"\n"); | fprintf(ficresplb,"\n"); |
| Line 11019 int main(int argc, char *argv[]) | Line 11050 int main(int argc, char *argv[]) |
| fprintf(ficlog,"Not 11 parameters, for example:ftol=1.e-8 stepm=12 ncovcol=2 nqv=1 ntv=2 nqtv=1 nlstate=2 ndeath=1 maxwav=3 mle=1 weight=1\n"); | fprintf(ficlog,"Not 11 parameters, for example:ftol=1.e-8 stepm=12 ncovcol=2 nqv=1 ntv=2 nqtv=1 nlstate=2 ndeath=1 maxwav=3 mle=1 weight=1\n"); |
| fprintf(ficlog,"but line=%s\n",line); | fprintf(ficlog,"but line=%s\n",line); |
| } | } |
| printf("ftol=%e stepm=%d ncovcol=%d nqv=%d ntv=%d nqtv=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d\n",ftol, stepm, ncovcol, nqv, ntv, nqtv, nlstate, ndeath, maxwav, mle, weightopt); | if( lastpass > maxwav){ |
| printf("Error (lastpass = %d) > (maxwav = %d)\n",lastpass, maxwav); | |
| fprintf(ficlog,"Error (lastpass = %d) > (maxwav = %d)\n",lastpass, maxwav); | |
| fflush(ficlog); | |
| goto end; | |
| } | |
| printf("ftol=%e stepm=%d ncovcol=%d nqv=%d ntv=%d nqtv=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d\n",ftol, stepm, ncovcol, nqv, ntv, nqtv, nlstate, ndeath, maxwav, mle, weightopt); | |
| fprintf(ficparo,"ftol=%e stepm=%d ncovcol=%d nqv=%d ntv=%d nqtv=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d\n",ftol, stepm, ncovcol, nqv, ntv, nqtv, nlstate, ndeath, maxwav, mle, weightopt); | fprintf(ficparo,"ftol=%e stepm=%d ncovcol=%d nqv=%d ntv=%d nqtv=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d\n",ftol, stepm, ncovcol, nqv, ntv, nqtv, nlstate, ndeath, maxwav, mle, weightopt); |
| fprintf(ficres,"ftol=%e stepm=%d ncovcol=%d nqv=%d ntv=%d nqtv=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d\n",ftol, stepm, ncovcol, nqv, ntv, nqtv, nlstate, ndeath, maxwav, mle, weightopt); | fprintf(ficres,"ftol=%e stepm=%d ncovcol=%d nqv=%d ntv=%d nqtv=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d\n",ftol, stepm, ncovcol, nqv, ntv, nqtv, nlstate, ndeath, maxwav, 0, weightopt); |
| fprintf(ficlog,"ftol=%e stepm=%d ncovcol=%d nqv=%d ntv=%d nqtv=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d\n",ftol, stepm, ncovcol, nqv, ntv, nqtv, nlstate, ndeath, maxwav, mle, weightopt); | fprintf(ficlog,"ftol=%e stepm=%d ncovcol=%d nqv=%d ntv=%d nqtv=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d\n",ftol, stepm, ncovcol, nqv, ntv, nqtv, nlstate, ndeath, maxwav, mle, weightopt); |
| } | } |
| /* ftolpl=6*ftol*1.e5; /\* 6.e-3 make convergences in less than 80 loops for the prevalence limit *\/ */ | /* ftolpl=6*ftol*1.e5; /\* 6.e-3 make convergences in less than 80 loops for the prevalence limit *\/ */ |
| Line 11630 Title=%s <br>Datafile=%s Firstpass=%d La | Line 11667 Title=%s <br>Datafile=%s Firstpass=%d La |
| firstpass, lastpass, stepm, weightopt, model); | firstpass, lastpass, stepm, weightopt, model); |
| fprintf(fichtm,"\n"); | fprintf(fichtm,"\n"); |
| fprintf(fichtm,"<h4>Parameter line 2</h4><ul><li>Tolerance for the convergence of the likelihood: ftol=%f \n<li>Interval for the elementary matrix (in month): stepm=%d",\ | fprintf(fichtm,"<h4>Parameter line 2</h4><ul><li>Tolerance for the convergence of the likelihood: ftol=%g \n<li>Interval for the elementary matrix (in month): stepm=%d",\ |
| ftol, stepm); | ftol, stepm); |
| fprintf(fichtm,"\n<li>Number of fixed dummy covariates: ncovcol=%d ", ncovcol); | fprintf(fichtm,"\n<li>Number of fixed dummy covariates: ncovcol=%d ", ncovcol); |
| ncurrv=1; | ncurrv=1; |
| Line 12556 Please run with mle=-1 to get a correct | Line 12593 Please run with mle=-1 to get a correct |
| if(vpopbased==1) | if(vpopbased==1) |
| fprintf(ficrest,"the age specific prevalence observed (cross-sectionally) in the population i.e cross-sectionally\n in each health state (popbased=1) (mobilav=%d)\n",mobilav); | fprintf(ficrest,"the age specific prevalence observed (cross-sectionally) in the population i.e cross-sectionally\n in each health state (popbased=1) (mobilav=%d)\n",mobilav); |
| else | else |
| fprintf(ficrest,"the age specific period (stable) prevalences in each health state \n"); | fprintf(ficrest,"the age specific forward period (stable) prevalences in each health state \n"); |
| fprintf(ficrest,"# Age popbased mobilav e.. (std) "); | fprintf(ficrest,"# Age popbased mobilav e.. (std) "); |
| for (i=1;i<=nlstate;i++) fprintf(ficrest,"e.%d (std) ",i); | for (i=1;i<=nlstate;i++) fprintf(ficrest,"e.%d (std) ",i); |
| fprintf(ficrest,"\n"); | fprintf(ficrest,"\n"); |
| /* printf("Which p?\n"); for(i=1;i<=npar;i++)printf("p[i=%d]=%lf,",i,p[i]);printf("\n"); */ | /* printf("Which p?\n"); for(i=1;i<=npar;i++)printf("p[i=%d]=%lf,",i,p[i]);printf("\n"); */ |
| printf("Computing age specific period (stable) prevalences in each health state \n"); | printf("Computing age specific forward period (stable) prevalences in each health state \n"); |
| fprintf(ficlog,"Computing age specific period (stable) prevalences in each health state \n"); | fprintf(ficlog,"Computing age specific forward period (stable) prevalences in each health state \n"); |
| for(age=bage; age <=fage ;age++){ | for(age=bage; age <=fage ;age++){ |
| prevalim(prlim, nlstate, p, age, oldm, savm, ftolpl, &ncvyear, k, nres); /*ZZ Is it the correct prevalim */ | prevalim(prlim, nlstate, p, age, oldm, savm, ftolpl, &ncvyear, k, nres); /*ZZ Is it the correct prevalim */ |
| if (vpopbased==1) { | if (vpopbased==1) { |
| Line 12609 Please run with mle=-1 to get a correct | Line 12646 Please run with mle=-1 to get a correct |
| printf("done State-specific expectancies\n");fflush(stdout); | printf("done State-specific expectancies\n");fflush(stdout); |
| fprintf(ficlog,"done State-specific expectancies\n");fflush(ficlog); | fprintf(ficlog,"done State-specific expectancies\n");fflush(ficlog); |
| /* variance-covariance of period prevalence*/ | /* variance-covariance of forward period prevalence*/ |
| varprlim(fileresu, nresult, mobaverage, mobilavproj, bage, fage, prlim, &ncvyear, ftolpl, p, matcov, delti, stepm, cptcoveff); | varprlim(fileresu, nresult, mobaverage, mobilavproj, bage, fage, prlim, &ncvyear, ftolpl, p, matcov, delti, stepm, cptcoveff); |