| 
 |   
| version 1.316, 2022/05/11 15:11:31 | version 1.317, 2022/05/15 15:06:23 | 
|---|---|
| Line 1 | Line 1 | 
| /* $Id$ | /* $Id$ | 
| $State$ | $State$ | 
| $Log$ | $Log$ | 
| Revision 1.317 2022/05/15 15:06:23 brouard | |
| * imach.c (Module): Some minor improvements | |
| Revision 1.316 2022/05/11 15:11:31 brouard | Revision 1.316 2022/05/11 15:11:31 brouard | 
| Summary: r27 | Summary: r27 | 
| Line 2259 void linmin(double p[], double xi[], int | Line 2262 void linmin(double p[], double xi[], int | 
| #endif | #endif | 
| #ifdef LINMINORIGINAL | #ifdef LINMINORIGINAL | 
| #else | #else | 
| if(fb == fx){ /* Flat function in the direction */ | if(fb == fx){ /* Flat function in the direction */ | 
| xmin=xx; | xmin=xx; | 
| *flat=1; | *flat=1; | 
| }else{ | }else{ | 
| *flat=0; | *flat=0; | 
| #endif | #endif | 
| /*Flat mnbrak2 shift (*ax=0.000000000000, *fa=51626.272983130431), (*bx=-1.618034000000, *fb=51590.149499362531), (*cx=-4.236068025156, *fc=51590.149499362531) */ | /*Flat mnbrak2 shift (*ax=0.000000000000, *fa=51626.272983130431), (*bx=-1.618034000000, *fb=51590.149499362531), (*cx=-4.236068025156, *fc=51590.149499362531) */ | 
| Line 2320 void linmin(double p[], double xi[], int | Line 2323 void linmin(double p[], double xi[], int | 
| /*************** powell ************************/ | /*************** powell ************************/ | 
| /* | /* | 
| Minimization of a function func of n variables. Input consists of an initial starting point | Minimization of a function func of n variables. Input consists in an initial starting point | 
| p[1..n] ; an initial matrix xi[1..n][1..n] , whose columns contain the initial set of di- | p[1..n] ; an initial matrix xi[1..n][1..n] whose columns contain the initial set of di- | 
| rections (usually the n unit vectors); and ftol , the fractional tolerance in the function value | rections (usually the n unit vectors); and ftol, the fractional tolerance in the function value | 
| such that failure to decrease by more than this amount on one iteration signals doneness. On | such that failure to decrease by more than this amount in one iteration signals doneness. On | 
| output, p is set to the best point found, xi is the then-current direction set, fret is the returned | output, p is set to the best point found, xi is the then-current direction set, fret is the returned | 
| function value at p , and iter is the number of iterations taken. The routine linmin is used. | function value at p , and iter is the number of iterations taken. The routine linmin is used. | 
| */ | */ | 
| Line 2804 void powell(double p[], double **xi, int | Line 2807 void powell(double p[], double **xi, int | 
| if(!first){ | if(!first){ | 
| first=1; | 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); | 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); | |
| }else if (first >=1 && first <10){ | |
| 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); | |
| first++; | |
| }else if (first ==10){ | |
| 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); | |
| printf("Warning: the stable prevalence dit not converge. This warning came too often, IMaCh will stop notifying, even in its log file. Look at the graphs to appreciate the non convergence.\n"); | |
| fprintf(ficlog,"Warning: the stable prevalence no convergence; too many cases, giving up noticing, even in log file\n"); | |
| first++; | |
| } | } | 
| 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); | 
| Line 5327 void concatwav(int wav[], int **dh, int | Line 5338 void concatwav(int wav[], int **dh, int | 
| #ifdef UNKNOWNSTATUSNOTCONTRIBUTING | #ifdef UNKNOWNSTATUSNOTCONTRIBUTING | 
| break; | break; | 
| #else | #else | 
| if(s[m][i]==-1 && (int) andc[i] == 9999 && (int)anint[m][i] != 9999){ /* case -2 (vital status unknown is warned later */ | if(s[m][i]==-1 && (int) andc[i] == 9999 && (int)anint[m][i] != 9999){ /* no death date and known date of interview, case -2 (vital status unknown is warned later */ | 
| if(firsthree == 0){ | if(firsthree == 0){ | 
| printf("Information! Unknown status for individual %ld line=%d occurred at last wave %d at known date %d/%d. Please, check if your unknown date of death %d/%d means a live state %d at wave %d. This case(%d)/wave(%d) contributes to the likelihood as 1-p_{%d%d} .\nOthers in log file only\n",num[i],i,lastpass,(int)mint[m][i],(int)anint[m][i], (int) moisdc[i], (int) andc[i], s[m][i], m, i, m, s[m][i], nlstate+ndeath); | printf("Information! Unknown status for individual %ld line=%d occurred at last wave %d at known date %d/%d. Please, check if your unknown date of death %d/%d means a live state %d at wave %d. This case(%d)/wave(%d) contributes to the likelihood as 1-p_{%d%d} .\nOthers in log file only\n",num[i],i,lastpass,(int)mint[m][i],(int)anint[m][i], (int) moisdc[i], (int) andc[i], s[m][i], m, i, m, s[m][i], nlstate+ndeath); | 
| firsthree=1; | firsthree=1; | 
| }else if(firsthree >=1 && firsthree < 10){ | |
| fprintf(ficlog,"Information! Unknown status for individual %ld line=%d occurred at last wave %d at known date %d/%d. Please, check if your unknown date of death %d/%d means a live state %d at wave %d. This case(%d)/wave(%d) contributes to the likelihood as 1-p_{%d%d} .\n",num[i],i,lastpass,(int)mint[m][i],(int)anint[m][i], (int) moisdc[i], (int) andc[i], s[m][i], m, i, m, s[m][i], nlstate+ndeath); | |
| firsthree++; | |
| }else if(firsthree == 10){ | |
| printf("Information, too many Information flags: no more reported to log either\n"); | |
| fprintf(ficlog,"Information, too many Information flags: no more reported to log either\n"); | |
| firsthree++; | |
| }else{ | |
| firsthree++; | |
| } | } | 
| fprintf(ficlog,"Information! Unknown status for individual %ld line=%d occurred at last wave %d at known date %d/%d. Please, check if your unknown date of death %d/%d means a live state %d at wave %d. This case(%d)/wave(%d) contributes to the likelihood as 1-p_{%d%d} .\n",num[i],i,lastpass,(int)mint[m][i],(int)anint[m][i], (int) moisdc[i], (int) andc[i], s[m][i], m, i, m, s[m][i], nlstate+ndeath); | |
| mw[++mi][i]=m; /* Valid transition with unknown status */ | mw[++mi][i]=m; /* Valid transition with unknown status */ | 
| mli=m; | mli=m; | 
| } | } | 
| Line 5405 void concatwav(int wav[], int **dh, int | Line 5424 void concatwav(int wav[], int **dh, int | 
| } /* End individuals */ | } /* End individuals */ | 
| /* wav and mw are no more changed */ | /* wav and mw are no more changed */ | 
| printf("Information, you have to check %d informations which haven't been logged!\n",firsthree); | |
| fprintf(ficlog,"Information, you have to check %d informations which haven't been logged!\n",firsthree); | |
| for(i=1; i<=imx; i++){ | for(i=1; i<=imx; i++){ | 
| for(mi=1; mi<wav[i];mi++){ | for(mi=1; mi<wav[i];mi++){ | 
| if (stepm <=0) | if (stepm <=0) | 
| Line 6986 void printinghtml(char fileresu[], char | Line 7008 void printinghtml(char fileresu[], char | 
| m=pow(2,cptcoveff); | m=pow(2,cptcoveff); | 
| if (cptcovn < 1) {m=1;ncodemax[1]=1;} | if (cptcovn < 1) {m=1;ncodemax[1]=1;} | 
| fprintf(fichtm," \n<ul><li><b>Graphs</b></li><p>"); | fprintf(fichtm," \n<ul><li><b>Graphs (first order)</b></li><p>"); | 
| jj1=0; | jj1=0; | 
| Line 7021 void printinghtml(char fileresu[], char | Line 7043 void printinghtml(char fileresu[], char | 
| fprintf(fichtm,"</a></li>"); | fprintf(fichtm,"</a></li>"); | 
| } /* cptcovn >0 */ | } /* cptcovn >0 */ | 
| } | } | 
| fprintf(fichtm," \n</ul>"); | fprintf(fichtm," \n</ul>"); | 
| jj1=0; | jj1=0; | 
| Line 7173 See page 'Matrix of variance-covariance | Line 7195 See page 'Matrix of variance-covariance | 
| /* else */ | /* else */ | 
| /* fprintf(fichtm,"\n No population forecast: popforecast = %d (instead of 1) or stepm = %d (instead of 1) or model=%s (instead of .)<br><br></li>\n",popforecast, stepm, model); */ | /* fprintf(fichtm,"\n No population forecast: popforecast = %d (instead of 1) or stepm = %d (instead of 1) or model=%s (instead of .)<br><br></li>\n",popforecast, stepm, model); */ | 
| fflush(fichtm); | fflush(fichtm); | 
| fprintf(fichtm," <ul><li><b>Graphs</b></li><p>"); | |
| m=pow(2,cptcoveff); | m=pow(2,cptcoveff); | 
| if (cptcovn < 1) {m=1;ncodemax[1]=1;} | if (cptcovn < 1) {m=1;ncodemax[1]=1;} | 
| fprintf(fichtm," <ul><li><b>Graphs (second order)</b></li><p>"); | |
| jj1=0; | |
| fprintf(fichtm," \n<ul>"); | |
| for(nres=1; nres <= nresult; nres++) /* For each resultline */ | |
| for(k1=1; k1<=m;k1++){ /* For each combination of covariate */ | |
| if(m != 1 && TKresult[nres]!= k1) | |
| continue; | |
| jj1++; | |
| if (cptcovn > 0) { | |
| fprintf(fichtm,"\n<li><a size=\"1\" color=\"#EC5E5E\" href=\"#rescovsecond"); | |
| for (cpt=1; cpt<=cptcoveff;cpt++){ | |
| fprintf(fichtm,"_V%d=%d_",Tvresult[nres][cpt],(int)Tresult[nres][cpt]); | |
| } | |
| for (k4=1; k4<= nsq; k4++){ /* For each selected (single) quantitative value */ | |
| fprintf(fichtm,"_V%d=%f_",Tvqresult[nres][k4],Tqresult[nres][k4]); | |
| } | |
| fprintf(fichtm,"\">"); | |
| /* if(nqfveff+nqtveff 0) */ /* Test to be done */ | |
| fprintf(fichtm,"************ Results for covariates"); | |
| for (cpt=1; cpt<=cptcoveff;cpt++){ | |
| fprintf(fichtm," V%d=%d ",Tvresult[nres][cpt],(int)Tresult[nres][cpt]); | |
| } | |
| for (k4=1; k4<= nsq; k4++){ /* For each selected (single) quantitative value */ | |
| fprintf(fichtm," V%d=%f ",Tvqresult[nres][k4],Tqresult[nres][k4]); | |
| } | |
| if(invalidvarcomb[k1]){ | |
| fprintf(fichtm," Warning Combination (%d) ignored because no cases ",k1); | |
| continue; | |
| } | |
| fprintf(fichtm,"</a></li>"); | |
| } /* cptcovn >0 */ | |
| } | |
| fprintf(fichtm," \n</ul>"); | |
| jj1=0; | jj1=0; | 
| for(nres=1; nres <= nresult; nres++){ /* For each resultline */ | for(nres=1; nres <= nresult; nres++){ /* For each resultline */ | 
| Line 7187 See page 'Matrix of variance-covariance | Line 7245 See page 'Matrix of variance-covariance | 
| /* for(i1=1; i1<=ncodemax[k1];i1++){ */ | /* for(i1=1; i1<=ncodemax[k1];i1++){ */ | 
| jj1++; | jj1++; | 
| if (cptcovn > 0) { | if (cptcovn > 0) { | 
| fprintf(fichtm,"\n<p><a name=\"rescovsecond"); | |
| for (cpt=1; cpt<=cptcoveff;cpt++){ | |
| fprintf(fichtm,"_V%d=%d_",Tvresult[nres][cpt],(int)Tresult[nres][cpt]); | |
| } | |
| for (k4=1; k4<= nsq; k4++){ /* For each selected (single) quantitative value */ | |
| fprintf(fichtm,"_V%d=%f_",Tvqresult[nres][k4],Tqresult[nres][k4]); | |
| } | |
| fprintf(fichtm,"\"</a>"); | |
| fprintf(fichtm,"<hr size=\"2\" color=\"#EC5E5E\">************ Results for covariates"); | fprintf(fichtm,"<hr size=\"2\" color=\"#EC5E5E\">************ Results for covariates"); | 
| for (cpt=1; cpt<=cptcoveff;cpt++) /**< cptcoveff number of variables */ | for (cpt=1; cpt<=cptcoveff;cpt++){ /**< cptcoveff number of variables */ | 
| fprintf(fichtm," V%d=%d ",Tvresult[nres][cpt],Tresult[nres][cpt]); | fprintf(fichtm," V%d=%d ",Tvresult[nres][cpt],Tresult[nres][cpt]); | 
| printf(" V%d=%d ",Tvresult[nres][cpt],Tresult[nres][cpt]);fflush(stdout); | |
| /* fprintf(fichtm," V%d=%d ",Tvaraff[cpt],nbcode[Tvaraff[cpt]][codtabm(jj1,cpt)]); */ | /* fprintf(fichtm," V%d=%d ",Tvaraff[cpt],nbcode[Tvaraff[cpt]][codtabm(jj1,cpt)]); */ | 
| } | |
| for (k4=1; k4<= nsq; k4++){ /* For each selected (single) quantitative value */ | for (k4=1; k4<= nsq; k4++){ /* For each selected (single) quantitative value */ | 
| fprintf(fichtm," V%d=%f ",Tvqresult[nres][k4],Tqresult[nres][k4]); | fprintf(fichtm," V%d=%f ",Tvqresult[nres][k4],Tqresult[nres][k4]); | 
| } | } | 
| Line 11034 int main(int argc, char *argv[]) | Line 11103 int main(int argc, char *argv[]) | 
| double ftolpl=FTOL; | double ftolpl=FTOL; | 
| double **prlim; | double **prlim; | 
| double **bprlim; | double **bprlim; | 
| double ***param; /* Matrix of parameters */ | double ***param; /* Matrix of parameters, param[i][j][k] param=ma3x(1,nlstate,1,nlstate+ndeath-1,1,ncovmodel) | 
| state of origin, state of destination including death, for each covariate: constante, age, and V1 V2 etc. */ | |
| double ***paramstart; /* Matrix of starting parameter values */ | double ***paramstart; /* Matrix of starting parameter values */ | 
| double *p, *pstart; /* p=param[1][1] pstart is for starting values guessed by freqsummary */ | double *p, *pstart; /* p=param[1][1] pstart is for starting values guessed by freqsummary */ | 
| double **matcov; /* Matrix of covariance */ | double **matcov; /* Matrix of covariance */ | 
| Line 11961 Title=%s <br>Datafile=%s Firstpass=%d La | Line 12031 Title=%s <br>Datafile=%s Firstpass=%d La | 
| <img src=\"%s_.svg\">", subdirf2(optionfilefiname,"D_"),subdirf2(optionfilefiname,"D_"),subdirf2(optionfilefiname,"D_")); | <img src=\"%s_.svg\">", subdirf2(optionfilefiname,"D_"),subdirf2(optionfilefiname,"D_"),subdirf2(optionfilefiname,"D_")); | 
| fprintf(fichtm,"\n<h4>Some descriptive statistics </h4>\n<br>Total number of observations=%d <br>\n\ | fprintf(fichtm,"\n<h4>Some descriptive statistics </h4>\n<br>Number of (used) observations=%d <br>\n\ | 
| Youngest age at first (selected) pass %.2f, oldest age %.2f<br>\n\ | Youngest age at first (selected) pass %.2f, oldest age %.2f<br>\n\ | 
| Interval (in months) between two waves: Min=%d Max=%d Mean=%.2lf<br>\n",\ | Interval (in months) between two waves: Min=%d Max=%d Mean=%.2lf<br>\n",\ | 
| imx,agemin,agemax,jmin,jmax,jmean); | imx,agemin,agemax,jmin,jmax,jmean); |