--- imach/src/imach.c 2016/02/12 11:29:23 1.218
+++ imach/src/imach.c 2016/02/15 23:35:36 1.221
@@ -1,6 +1,12 @@
-/* $Id: imach.c,v 1.218 2016/02/12 11:29:23 brouard Exp $
+/* $Id: imach.c,v 1.221 2016/02/15 23:35:36 brouard Exp $
$State: Exp $
$Log: imach.c,v $
+ Revision 1.221 2016/02/15 23:35:36 brouard
+ Summary: minor bug
+
+ Revision 1.219 2016/02/15 00:48:12 brouard
+ *** empty log message ***
+
Revision 1.218 2016/02/12 11:29:23 brouard
Summary: 0.99 Back projections
@@ -733,7 +739,7 @@ Back prevalence and projections:
/* #define DEBUGLINMIN */
/* #define DEBUGHESS */
#define DEBUGHESSIJ
-/* #define LINMINORIGINAL /\* Don't use loop on scale in linmin (accepting nan)*\/ */
+#define LINMINORIGINAL /* Don't use loop on scale in linmin (accepting nan)*/
#define POWELL /* Instead of NLOPT */
#define POWELLF1F3 /* Skip test */
/* #define POWELLORIGINAL /\* Don't use Directest to decide new direction but original Powell test *\/ */
@@ -825,12 +831,12 @@ typedef struct {
#define ODIRSEPARATOR '\\'
#endif
-/* $Id: imach.c,v 1.218 2016/02/12 11:29:23 brouard Exp $ */
+/* $Id: imach.c,v 1.221 2016/02/15 23:35:36 brouard Exp $ */
/* $State: Exp $ */
#include "version.h"
char version[]=__IMACH_VERSION__;
char copyright[]="October 2015,INED-EUROREVES-Institut de longevite-Japan Society for the Promotion of Science (Grant-in-Aid for Scientific Research 25293121), Intel Software 2015";
-char fullversion[]="$Revision: 1.218 $ $Date: 2016/02/12 11:29:23 $";
+char fullversion[]="$Revision: 1.221 $ $Date: 2016/02/15 23:35:36 $";
char strstart[80];
char optionfilext[10], optionfilefiname[FILENAMELENGTH];
int erreur=0, nberr=0, nbwarn=0; /* Error number, number of errors number of warnings */
@@ -976,7 +982,7 @@ int *ncodemaxwundef; /* ncodemax[j]= Nu
undefined. Usually 3: -1, 0 and 1. */
double **agev,*moisnais, *annais, *moisdc, *andc,**mint, **anint;
double **pmmij, ***probs; /* Global pointer */
-double ***mobaverage; /* New global variable */
+double ***mobaverage, ***mobaverages; /* New global variable */
double *ageexmed,*agecens;
double dateintmean=0;
@@ -991,7 +997,7 @@ int **nbcode, *Tvar; /**< model=V2 => Tv
int *Tage;
int *Ndum; /** Freq of modality (tricode */
/* int **codtab;*/ /**< codtab=imatrix(1,100,1,10); */
-int **Tvard, *Tprod, cptcovprod, *Tvaraff;
+int **Tvard, *Tprod, cptcovprod, *Tvaraff, *invalidvarcomb;
double *lsurv, *lpop, *tpop;
double ftol=FTOL; /**< Tolerance for computing Max Likelihood */
@@ -2286,7 +2292,7 @@ Earliest age to start was %d-%d=%d, ncvl
*ncvyear= -( (int)age- (int)agefin);
/* printf("Back maxmax=%lf ncvloop=%d, age=%d, agefin=%d ncvyear=%d \n", maxmax, ncvloop, (int)age, (int)agefin, *ncvyear);*/
if(maxmax < ftolpl){
- printf("OK Back maxmax=%lf ncvloop=%d, age=%d, agefin=%d ncvyear=%d \n", maxmax, ncvloop, (int)age, (int)agefin, *ncvyear);
+ /* printf("OK Back maxmax=%lf ncvloop=%d, age=%d, agefin=%d ncvyear=%d \n", maxmax, ncvloop, (int)age, (int)agefin, *ncvyear); */
free_vector(min,1,nlstate);
free_vector(max,1,nlstate);
free_vector(meandiff,1,nlstate);
@@ -3668,276 +3674,325 @@ void pstamp(FILE *fichier)
}
/************ Frequencies ********************/
-void freqsummary(char fileres[], int iagemin, int iagemax, int **s, double **agev, int nlstate, int imx, \
- int *Tvaraff, int **nbcode, int *ncodemax,double **mint,double **anint, char strstart[],\
- int firstpass, int lastpass, int stepm, int weightopt, char model[])
-{ /* Some frequencies */
-
- int i, m, jk, j1, bool, z1,j;
- int mi; /* Effective wave */
- int first;
- double ***freq; /* Frequencies */
- double *pp, **prop;
- double pos,posprop, k2, dateintsum=0,k2cpt=0;
- char fileresp[FILENAMELENGTH], fileresphtm[FILENAMELENGTH], fileresphtmfr[FILENAMELENGTH];
- double agebegin, ageend;
-
- pp=vector(1,nlstate);
- prop=matrix(1,nlstate,iagemin-AGEMARGE,iagemax+3+AGEMARGE);
- /* prop=matrix(1,nlstate,iagemin,iagemax+3); */
- strcpy(fileresp,"P_");
- strcat(fileresp,fileresu);
- /*strcat(fileresphtm,fileresu);*/
- if((ficresp=fopen(fileresp,"w"))==NULL) {
- printf("Problem with prevalence resultfile: %s\n", fileresp);
- fprintf(ficlog,"Problem with prevalence resultfile: %s\n", fileresp);
- exit(0);
- }
+ void freqsummary(char fileres[], 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 */
+
+ int i, m, jk, j1, bool, z1,j;
+ int iind=0, iage=0;
+ int mi; /* Effective wave */
+ int first;
+ double ***freq; /* Frequencies */
+ double *pp, **prop, *posprop, *pospropt;
+ double pos=0., posproptt=0., pospropta=0., k2, dateintsum=0,k2cpt=0;
+ char fileresp[FILENAMELENGTH], fileresphtm[FILENAMELENGTH], fileresphtmfr[FILENAMELENGTH];
+ double agebegin, ageend;
+
+ pp=vector(1,nlstate);
+ prop=matrix(1,nlstate,iagemin-AGEMARGE,iagemax+3+AGEMARGE);
+ posprop=vector(1,nlstate); /* Counting the number of transition starting from a live state per age */
+ pospropt=vector(1,nlstate); /* Counting the number of transition starting from a live state */
+ /* prop=matrix(1,nlstate,iagemin,iagemax+3); */
+ strcpy(fileresp,"P_");
+ strcat(fileresp,fileresu);
+ /*strcat(fileresphtm,fileresu);*/
+ if((ficresp=fopen(fileresp,"w"))==NULL) {
+ printf("Problem with prevalence resultfile: %s\n", fileresp);
+ fprintf(ficlog,"Problem with prevalence resultfile: %s\n", fileresp);
+ exit(0);
+ }
- strcpy(fileresphtm,subdirfext(optionfilefiname,"PHTM_",".htm"));
- if((ficresphtm=fopen(fileresphtm,"w"))==NULL) {
- printf("Problem with prevalence HTM resultfile '%s' with errno='%s'\n",fileresphtm,strerror(errno));
- fprintf(ficlog,"Problem with prevalence HTM resultfile '%s' with errno='%s'\n",fileresphtm,strerror(errno));
- fflush(ficlog);
- exit(70);
- }
- else{
- fprintf(ficresphtm,"
\nIMaCh PHTM_ %s\n %s
%s \
+ strcpy(fileresphtm,subdirfext(optionfilefiname,"PHTM_",".htm"));
+ if((ficresphtm=fopen(fileresphtm,"w"))==NULL) {
+ printf("Problem with prevalence HTM resultfile '%s' with errno='%s'\n",fileresphtm,strerror(errno));
+ fprintf(ficlog,"Problem with prevalence HTM resultfile '%s' with errno='%s'\n",fileresphtm,strerror(errno));
+ fflush(ficlog);
+ exit(70);
+ }
+ else{
+ fprintf(ficresphtm,"\nIMaCh PHTM_ %s\n %s
%s \
\n\
Title=%s
Datafile=%s Firstpass=%d Lastpass=%d Stepm=%d Weight=%d Model=1+age+%s
\n",\
- fileresphtm,version,fullversion,title,datafile,firstpass,lastpass,stepm, weightopt, model);
- }
- fprintf(ficresphtm,"Current page is file %s
\n\nFrequencies and prevalence by age at begin of transition
\n",fileresphtm, fileresphtm);
+ fileresphtm,version,fullversion,title,datafile,firstpass,lastpass,stepm, weightopt, model);
+ }
+ fprintf(ficresphtm,"Current page is file %s
\n\nFrequencies and prevalence by age at begin of transition
\n",fileresphtm, fileresphtm);
- strcpy(fileresphtmfr,subdirfext(optionfilefiname,"PHTMFR_",".htm"));
- if((ficresphtmfr=fopen(fileresphtmfr,"w"))==NULL) {
- printf("Problem with frequency table HTM resultfile '%s' with errno='%s'\n",fileresphtmfr,strerror(errno));
- fprintf(ficlog,"Problem with frequency table HTM resultfile '%s' with errno='%s'\n",fileresphtmfr,strerror(errno));
- fflush(ficlog);
- exit(70);
- }
- else{
- fprintf(ficresphtmfr,"\nIMaCh PHTM_Frequency table %s\n %s
%s \
+ strcpy(fileresphtmfr,subdirfext(optionfilefiname,"PHTMFR_",".htm"));
+ if((ficresphtmfr=fopen(fileresphtmfr,"w"))==NULL) {
+ printf("Problem with frequency table HTM resultfile '%s' with errno='%s'\n",fileresphtmfr,strerror(errno));
+ fprintf(ficlog,"Problem with frequency table HTM resultfile '%s' with errno='%s'\n",fileresphtmfr,strerror(errno));
+ fflush(ficlog);
+ exit(70);
+ }
+ else{
+ fprintf(ficresphtmfr,"\nIMaCh PHTM_Frequency table %s\n %s
%s \
\n\
Title=%s
Datafile=%s Firstpass=%d Lastpass=%d Stepm=%d Weight=%d Model=1+age+%s
\n",\
- fileresphtmfr,version,fullversion,title,datafile,firstpass,lastpass,stepm, weightopt, model);
- }
- fprintf(ficresphtmfr,"Current page is file %s
\n\nFrequencies of all effective transitions by age at begin of transition
Unknown status is -1
\n",fileresphtmfr, fileresphtmfr);
+ fileresphtmfr,version,fullversion,title,datafile,firstpass,lastpass,stepm, weightopt, model);
+ }
+ fprintf(ficresphtmfr,"Current page is file %s
\n\nFrequencies of all effective transitions by age at begin of transition
Unknown status is -1
\n",fileresphtmfr, fileresphtmfr);
- freq= ma3x(-5,nlstate+ndeath,-5,nlstate+ndeath,iagemin-AGEMARGE,iagemax+3+AGEMARGE);
- j1=0;
+ freq= ma3x(-5,nlstate+ndeath,-5,nlstate+ndeath,iagemin-AGEMARGE,iagemax+3+AGEMARGE);
+ j1=0;
- j=cptcoveff;
- if (cptcovn<1) {j=1;ncodemax[1]=1;}
+ j=cptcoveff;
+ if (cptcovn<1) {j=1;ncodemax[1]=1;}
- first=1;
+ first=1;
+
+ /* Detects if a combination j1 is empty: for a multinomial variable like 3 education levels:
+ reference=low_education V1=0,V2=0
+ med_educ V1=1 V2=0,
+ high_educ V1=0 V2=1
+ Then V1=1 and V2=1 is a noisy combination that we want to exclude for the list 2**cptcoveff
+ */
+
+ for (j1 = 1; j1 <= (int) pow(2,cptcoveff); j1++){ /* Loop on covariates combination */
+ posproptt=0.;
+ /*printf("cptcoveff=%d Tvaraff=%d", cptcoveff,Tvaraff[1]);
+ scanf("%d", i);*/
+ for (i=-5; i<=nlstate+ndeath; i++)
+ for (jk=-5; jk<=nlstate+ndeath; jk++)
+ for(m=iagemin; m <= iagemax+3; m++)
+ freq[i][jk][m]=0;
+
+ for (i=1; i<=nlstate; i++) {
+ for(m=iagemin; m <= iagemax+3; m++)
+ prop[i][m]=0;
+ posprop[i]=0;
+ pospropt[i]=0;
+ }
+
+ dateintsum=0;
+ k2cpt=0;
- for (j1 = 1; j1 <= (int) pow(2,cptcoveff); j1++){ /* Loop on covariates combination */
- /*printf("cptcoveff=%d Tvaraff=%d", cptcoveff,Tvaraff[1]);
- scanf("%d", i);*/
- for (i=-5; i<=nlstate+ndeath; i++)
- for (jk=-5; jk<=nlstate+ndeath; jk++)
- for(m=iagemin; m <= iagemax+3; m++)
- freq[i][jk][m]=0;
-
- for (i=1; i<=nlstate; i++)
- for(m=iagemin; m <= iagemax+3; m++)
- prop[i][m]=0;
-
- dateintsum=0;
- k2cpt=0;
- for (i=1; i<=imx; i++) { /* For each individual i */
- bool=1;
- if (cptcovn>0) { /* Filter is here: Must be looked at for model=V1+V2+V3+V4 */
- for (z1=1; z1<=cptcoveff; z1++)
- if (covar[Tvaraff[z1]][i]!= nbcode[Tvaraff[z1]][codtabm(j1,z1)]){
- /* Tests if the value of each of the covariates of i is equal to filter j1 */
- bool=0;
- /* 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",
+ for (iind=1; iind<=imx; iind++) { /* For each individual iind */
+ bool=1;
+ if (cptcovn>0) { /* Filter is here: Must be looked at for model=V1+V2+V3+V4 */
+ for (z1=1; z1<=cptcoveff; z1++) {
+ if (covar[Tvaraff[z1]][iind]!= nbcode[Tvaraff[z1]][codtabm(j1,z1)]){
+ /* Tests if the value of each of the covariates of i is equal to filter j1 */
+ bool=0;
+ /* 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);*/
- /* For j1=7 in V1+V2+V3+V4 = 0 1 1 0 and codtabm(7,3)=1 and nbcde[3][?]=1*/
- }
- } /* cptcovn > 0 */
-
- if (bool==1){
- /* for(m=firstpass; m<=lastpass; m++){ */
- for(mi=1; mi=firstpass && m <=lastpass){
- k2=anint[m][i]+(mint[m][i]/12.);
- /*if ((k2>=dateprev1) && (k2<=dateprev2)) {*/
- if(agev[m][i]==0) agev[m][i]=iagemax+1; /* All ages equal to 0 are in iagemax+1 */
- if(agev[m][i]==1) agev[m][i]=iagemax+2; /* All ages equal to 1 are in iagemax+2 */
- if (s[m][i]>0 && s[m][i]<=nlstate) /* If status at wave m is known and a live state */
- prop[s[m][i]][(int)agev[m][i]] += weight[i]; /* At age of beginning of transition, where status is known */
- if (m1) && (agev[m][i]< (iagemax+3)) && (anint[m][i]!=9999) && (mint[m][i]!=99)) {
- dateintsum=dateintsum+k2;
- k2cpt++;
- /* printf("i=%ld dateintmean = %lf dateintsum=%lf k2cpt=%lf k2=%lf\n",i, dateintsum/k2cpt, dateintsum,k2cpt, k2); */
- }
- /*}*/
- } /* end m */
- } /* end bool */
- } /* end i = 1 to imx */
-
- /* fprintf(ficresp, "#Count between %.lf/%.lf/%.lf and %.lf/%.lf/%.lf\n",jprev1, mprev1,anprev1,jprev2, mprev2,anprev2);*/
- pstamp(ficresp);
- if (cptcovn>0) {
- fprintf(ficresp, "\n#********** Variable ");
- fprintf(ficresphtm, "\n
********** Variable ");
- fprintf(ficresphtmfr, "\n
********** Variable ");
- for (z1=1; z1<=cptcoveff; z1++){
- fprintf(ficresp, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtabm(j1,z1)]);
- fprintf(ficresphtm, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtabm(j1,z1)]);
- fprintf(ficresphtmfr, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtabm(j1,z1)]);
- }
- fprintf(ficresp, "**********\n#");
- fprintf(ficresphtm, "**********
\n");
- fprintf(ficresphtmfr, "**********
\n");
- fprintf(ficlog, "\n#********** Variable ");
- for (z1=1; z1<=cptcoveff; z1++) fprintf(ficlog, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtabm(j1,z1)]);
- fprintf(ficlog, "**********\n");
- }
- fprintf(ficresphtm,"");
- for(i=1; i<=nlstate;i++) {
- fprintf(ficresp, " Age Prev(%d) N(%d) N",i,i);
- fprintf(ficresphtm, "Age | Prev(%d) | N(%d) | N | ",i,i);
- }
- fprintf(ficresp, "\n");
- fprintf(ficresphtm, "\n");
-
- /* Header of frequency table by age */
- fprintf(ficresphtmfr,"");
- fprintf(ficresphtmfr,"Age | ");
- for(jk=-1; jk <=nlstate+ndeath; jk++){
- for(m=-1; m <=nlstate+ndeath; m++){
- if(jk!=0 && m!=0)
- fprintf(ficresphtmfr,"%d%d | ",jk,m);
- }
- }
- fprintf(ficresphtmfr, "\n");
+ /* For j1=7 in V1+V2+V3+V4 = 0 1 1 0 and codtabm(7,3)=1 and nbcde[3][?]=1*/
+ }
+ } /* end z1 */
+ } /* cptcovn > 0 */
+
+ if (bool==1){
+ /* for(m=firstpass; m<=lastpass; m++){ */
+ for(mi=1; mi=firstpass && m <=lastpass){
+ k2=anint[m][iind]+(mint[m][iind]/12.);
+ /*if ((k2>=dateprev1) && (k2<=dateprev2)) {*/
+ if(agev[m][iind]==0) agev[m][iind]=iagemax+1; /* All ages equal to 0 are in iagemax+1 */
+ if(agev[m][iind]==1) agev[m][iind]=iagemax+2; /* All ages equal to 1 are in iagemax+2 */
+ if (s[m][iind]>0 && s[m][iind]<=nlstate) /* If status at wave m is known and a live state */
+ prop[s[m][iind]][(int)agev[m][iind]] += weight[iind]; /* At age of beginning of transition, where status is known */
+ if (m1) && (agev[m][iind]< (iagemax+3)) && (anint[m][iind]!=9999) && (mint[m][iind]!=99)) {
+ dateintsum=dateintsum+k2;
+ k2cpt++;
+ /* printf("iind=%ld dateintmean = %lf dateintsum=%lf k2cpt=%lf k2=%lf\n",iind, dateintsum/k2cpt, dateintsum,k2cpt, k2); */
+ }
+ /*}*/
+ } /* end m */
+ } /* end bool */
+ } /* end iind = 1 to imx */
+ /* prop[s][age] is feeded for any initial and valid live state as well as
+ freq[s1][s2][age] at single age of beginning the transition, for a combination j1 */
+
+
+ /* fprintf(ficresp, "#Count between %.lf/%.lf/%.lf and %.lf/%.lf/%.lf\n",jprev1, mprev1,anprev1,jprev2, mprev2,anprev2);*/
+ pstamp(ficresp);
+ if (cptcovn>0) {
+ fprintf(ficresp, "\n#********** Variable ");
+ fprintf(ficresphtm, "\n
********** Variable ");
+ fprintf(ficresphtmfr, "\n
********** Variable ");
+ for (z1=1; z1<=cptcoveff; z1++){
+ fprintf(ficresp, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtabm(j1,z1)]);
+ fprintf(ficresphtm, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtabm(j1,z1)]);
+ fprintf(ficresphtmfr, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtabm(j1,z1)]);
+ }
+ fprintf(ficresp, "**********\n#");
+ fprintf(ficresphtm, "**********
\n");
+ fprintf(ficresphtmfr, "**********
\n");
+ fprintf(ficlog, "\n#********** Variable ");
+ for (z1=1; z1<=cptcoveff; z1++) fprintf(ficlog, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtabm(j1,z1)]);
+ fprintf(ficlog, "**********\n");
+ }
+ fprintf(ficresphtm,"");
+ for(i=1; i<=nlstate;i++) {
+ fprintf(ficresp, " Age Prev(%d) N(%d) N",i,i);
+ fprintf(ficresphtm, "Age | Prev(%d) | N(%d) | N | ",i,i);
+ }
+ fprintf(ficresp, "\n");
+ fprintf(ficresphtm, "\n");
- /* For each age */
- for(i=iagemin; i <= iagemax+3; i++){
- fprintf(ficresphtm,"");
- if(i==iagemax+1){
- fprintf(ficlog,"1");
- fprintf(ficresphtmfr,"
0 | ");
- }else if(i==iagemax+2){
- fprintf(ficlog,"0");
- fprintf(ficresphtmfr,"
---|
Unknown | ");
- }else if(i==iagemax+3){
- fprintf(ficlog,"Total");
- fprintf(ficresphtmfr,"
---|
Total | ");
- }else{
- if(first==1){
- first=0;
- printf("See log file for details...\n");
- }
- fprintf(ficresphtmfr,"
---|
%d | ",i);
- fprintf(ficlog,"Age %d", i);
- }
- for(jk=1; jk <=nlstate ; jk++){
- for(m=-1, pp[jk]=0; m <=nlstate+ndeath ; m++)
- pp[jk] += freq[jk][m][i];
- }
- for(jk=1; jk <=nlstate ; jk++){
- for(m=-1, pos=0; m <=0 ; m++)
- pos += freq[jk][m][i];
- if(pp[jk]>=1.e-10){
- if(first==1){
- printf(" %d.=%.0f loss[%d]=%.1f%%",jk,pp[jk],jk,100*pos/pp[jk]);
- }
- fprintf(ficlog," %d.=%.0f loss[%d]=%.1f%%",jk,pp[jk],jk,100*pos/pp[jk]);
- }else{
- if(first==1)
- printf(" %d.=%.0f loss[%d]=NaNQ%%",jk,pp[jk],jk);
- fprintf(ficlog," %d.=%.0f loss[%d]=NaNQ%%",jk,pp[jk],jk);
- }
- }
-
- for(jk=1; jk <=nlstate ; jk++){
- for(m=0, pp[jk]=0; m <=nlstate+ndeath; m++)
- pp[jk] += freq[jk][m][i];
- }
- for(jk=1,pos=0,posprop=0; jk <=nlstate ; jk++){
- pos += pp[jk];
- posprop += prop[jk][i];
- }
- for(jk=1; jk <=nlstate ; jk++){
- if(pos>=1.e-5){
- if(first==1)
- printf(" %d.=%.0f prev[%d]=%.1f%%",jk,pp[jk],jk,100*pp[jk]/pos);
- fprintf(ficlog," %d.=%.0f prev[%d]=%.1f%%",jk,pp[jk],jk,100*pp[jk]/pos);
- }else{
- if(first==1)
- printf(" %d.=%.0f prev[%d]=NaNQ%%",jk,pp[jk],jk);
- fprintf(ficlog," %d.=%.0f prev[%d]=NaNQ%%",jk,pp[jk],jk);
- }
- if( i <= iagemax){
- if(pos>=1.e-5){
- fprintf(ficresp," %d %.5f %.0f %.0f",i,prop[jk][i]/posprop, prop[jk][i],posprop);
- fprintf(ficresphtm,"%d | %.5f | %.0f | %.0f | ",i,prop[jk][i]/posprop, prop[jk][i],posprop);
- /*probs[i][jk][j1]= pp[jk]/pos;*/
- /*printf("\ni=%d jk=%d j1=%d %.5f %.0f %.0f %f",i,jk,j1,pp[jk]/pos, pp[jk],pos,probs[i][jk][j1]);*/
- }
- else{
- fprintf(ficresp," %d NaNq %.0f %.0f",i,prop[jk][i],posprop);
- fprintf(ficresphtm,"%d | NaNq | %.0f | %.0f | ",i, prop[jk][i],posprop);
- }
- }
- }
-
- for(jk=-1; jk <=nlstate+ndeath; jk++){
- for(m=-1; m <=nlstate+ndeath; m++){
- if(freq[jk][m][i] !=0 ) { /* minimizing output */
- if(first==1){
- printf(" %d%d=%.0f",jk,m,freq[jk][m][i]);
- }
- fprintf(ficlog," %d%d=%.0f",jk,m,freq[jk][m][i]);
- }
- if(jk!=0 && m!=0)
- fprintf(ficresphtmfr,"%.0f | ",freq[jk][m][i]);
- }
- }
- fprintf(ficresphtmfr,"
\n ");
- if(i <= iagemax){
- fprintf(ficresp,"\n");
- fprintf(ficresphtm,"\n");
- }
- if(first==1)
- printf("Others in log...\n");
- fprintf(ficlog,"\n");
- } /* end loop i */
- fprintf(ficresphtm,"
\n");
- fprintf(ficresphtmfr,"
\n");
- /*}*/
- } /* end j1 */
- dateintmean=dateintsum/k2cpt;
-
- fclose(ficresp);
- fclose(ficresphtm);
- fclose(ficresphtmfr);
- free_ma3x(freq,-5,nlstate+ndeath,-5,nlstate+ndeath, iagemin-AGEMARGE, iagemax+3+AGEMARGE);
- free_vector(pp,1,nlstate);
- free_matrix(prop,1,nlstate,iagemin-AGEMARGE, iagemax+3+AGEMARGE);
- /* End of Freq */
-}
+ /* Header of frequency table by age */
+ fprintf(ficresphtmfr,"");
+ fprintf(ficresphtmfr,"Age | ");
+ for(jk=-1; jk <=nlstate+ndeath; jk++){
+ for(m=-1; m <=nlstate+ndeath; m++){
+ if(jk!=0 && m!=0)
+ fprintf(ficresphtmfr,"%d%d | ",jk,m);
+ }
+ }
+ fprintf(ficresphtmfr, "\n");
+
+ /* For each age */
+ for(iage=iagemin; iage <= iagemax+3; iage++){
+ fprintf(ficresphtm,"");
+ if(iage==iagemax+1){
+ fprintf(ficlog,"1");
+ fprintf(ficresphtmfr,"
0 | ");
+ }else if(iage==iagemax+2){
+ fprintf(ficlog,"0");
+ fprintf(ficresphtmfr,"
---|
Unknown | ");
+ }else if(iage==iagemax+3){
+ fprintf(ficlog,"Total");
+ fprintf(ficresphtmfr,"
---|
Total | ");
+ }else{
+ if(first==1){
+ first=0;
+ printf("See log file for details...\n");
+ }
+ fprintf(ficresphtmfr,"
---|
%d | ",iage);
+ fprintf(ficlog,"Age %d", iage);
+ }
+ for(jk=1; jk <=nlstate ; jk++){
+ for(m=-1, pp[jk]=0; m <=nlstate+ndeath ; m++)
+ pp[jk] += freq[jk][m][iage];
+ }
+ for(jk=1; jk <=nlstate ; jk++){
+ for(m=-1, pos=0; m <=0 ; m++)
+ pos += freq[jk][m][iage];
+ if(pp[jk]>=1.e-10){
+ if(first==1){
+ printf(" %d.=%.0f loss[%d]=%.1f%%",jk,pp[jk],jk,100*pos/pp[jk]);
+ }
+ fprintf(ficlog," %d.=%.0f loss[%d]=%.1f%%",jk,pp[jk],jk,100*pos/pp[jk]);
+ }else{
+ if(first==1)
+ printf(" %d.=%.0f loss[%d]=NaNQ%%",jk,pp[jk],jk);
+ fprintf(ficlog," %d.=%.0f loss[%d]=NaNQ%%",jk,pp[jk],jk);
+ }
+ }
+
+ for(jk=1; jk <=nlstate ; jk++){
+ /* posprop[jk]=0; */
+ for(m=0, pp[jk]=0; m <=nlstate+ndeath; m++)/* Summing on all ages */
+ pp[jk] += freq[jk][m][iage];
+ } /* pp[jk] is the total number of transitions starting from state jk and any ending status until this age */
+
+ for(jk=1,pos=0, pospropta=0.; jk <=nlstate ; jk++){
+ pos += pp[jk]; /* pos is the total number of transitions until this age */
+ posprop[jk] += prop[jk][iage]; /* prop is the number of transitions from a live state
+ from jk at age iage prop[s[m][iind]][(int)agev[m][iind]] += weight[iind] */
+ pospropta += prop[jk][iage]; /* prop is the number of transitions from a live state
+ from jk at age iage prop[s[m][iind]][(int)agev[m][iind]] += weight[iind] */
+ }
+ for(jk=1; jk <=nlstate ; jk++){
+ if(pos>=1.e-5){
+ if(first==1)
+ printf(" %d.=%.0f prev[%d]=%.1f%%",jk,pp[jk],jk,100*pp[jk]/pos);
+ fprintf(ficlog," %d.=%.0f prev[%d]=%.1f%%",jk,pp[jk],jk,100*pp[jk]/pos);
+ }else{
+ if(first==1)
+ printf(" %d.=%.0f prev[%d]=NaNQ%%",jk,pp[jk],jk);
+ fprintf(ficlog," %d.=%.0f prev[%d]=NaNQ%%",jk,pp[jk],jk);
+ }
+ if( iage <= iagemax){
+ if(pos>=1.e-5){
+ fprintf(ficresp," %d %.5f %.0f %.0f",iage,prop[jk][iage]/pospropta, prop[jk][iage],pospropta);
+ fprintf(ficresphtm,"%d | %.5f | %.0f | %.0f | ",iage,prop[jk][iage]/pospropta, prop[jk][iage],pospropta);
+ /*probs[iage][jk][j1]= pp[jk]/pos;*/
+ /*printf("\niage=%d jk=%d j1=%d %.5f %.0f %.0f %f",iage,jk,j1,pp[jk]/pos, pp[jk],pos,probs[iage][jk][j1]);*/
+ }
+ else{
+ fprintf(ficresp," %d NaNq %.0f %.0f",iage,prop[jk][iage],pospropta);
+ fprintf(ficresphtm,"%d | NaNq | %.0f | %.0f | ",iage, prop[jk][iage],pospropta);
+ }
+ }
+ pospropt[jk] +=posprop[jk];
+ } /* end loop jk */
+ /* pospropt=0.; */
+ for(jk=-1; jk <=nlstate+ndeath; jk++){
+ for(m=-1; m <=nlstate+ndeath; m++){
+ 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]);
+ }
+ if(jk!=0 && m!=0)
+ fprintf(ficresphtmfr,"%.0f | ",freq[jk][m][iage]);
+ }
+ } /* end loop jk */
+ posproptt=0.;
+ for(jk=1; jk <=nlstate; jk++){
+ posproptt += pospropt[jk];
+ }
+ fprintf(ficresphtmfr,"
\n ");
+ if(iage <= iagemax){
+ fprintf(ficresp,"\n");
+ fprintf(ficresphtm,"\n");
+ }
+ if(first==1)
+ printf("Others in log...\n");
+ fprintf(ficlog,"\n");
+ } /* end loop age iage */
+ fprintf(ficresphtm,"Tot | ");
+ for(jk=1; jk <=nlstate ; jk++){
+ if(posproptt < 1.e-5){
+ fprintf(ficresphtm,"Nanq | %.0f | %.0f | ",pospropt[jk],posproptt);
+ }else{
+ fprintf(ficresphtm,"%.5f | %.0f | %.0f | ",pospropt[jk]/posproptt,pospropt[jk],posproptt);
+ }
+ }
+ fprintf(ficresphtm,"
\n");
+ fprintf(ficresphtm,"
\n");
+ fprintf(ficresphtmfr,"
\n");
+ if(posproptt < 1.e-5){
+ fprintf(ficresphtm,"\n This combination (%d) is not valid and no result will be produced
",j1);
+ fprintf(ficresphtmfr,"\n This combination (%d) is not valid and no result will be produced
",j1);
+ fprintf(ficres,"\n This combination (%d) is not valid and no result will be produced\n\n",j1);
+ invalidvarcomb[j1]=1;
+ }else{
+ fprintf(ficresphtm,"\n This combination (%d) is valid and result will be produced.
",j1);
+ invalidvarcomb[j1]=0;
+ }
+ fprintf(ficresphtmfr,"\n");
+ } /* end selected combination of covariate j1 */
+ dateintmean=dateintsum/k2cpt;
+
+ fclose(ficresp);
+ fclose(ficresphtm);
+ fclose(ficresphtmfr);
+ free_ma3x(freq,-5,nlstate+ndeath,-5,nlstate+ndeath, iagemin-AGEMARGE, iagemax+3+AGEMARGE);
+ free_vector(pospropt,1,nlstate);
+ free_vector(posprop,1,nlstate);
+ free_matrix(prop,1,nlstate,iagemin-AGEMARGE, iagemax+3+AGEMARGE);
+ free_vector(pp,1,nlstate);
+ /* End of Freq */
+ }
/************ Prevalence ********************/
void prevalence(double ***probs, double agemin, double agemax, int **s, double **agev, int nlstate, int imx, int *Tvar, int **nbcode, int *ncodemax,double **mint,double **anint, double dateprev1,double dateprev2, int firstpass, int lastpass)
@@ -3969,7 +4024,7 @@ void prevalence(double ***probs, double
if (cptcovn<1) {j=1;ncodemax[1]=1;}
first=1;
- for(j1=1; j1<= (int) pow(2,cptcoveff);j1++){
+ for(j1=1; j1<= (int) pow(2,cptcoveff);j1++){ /* For each combination of covariate */
for (i=1; i<=nlstate; i++)
for(iage=iagemin-AGEMARGE; iage <= iagemax+3+AGEMARGE; iage++)
prop[i][iage]=0.0;
@@ -3977,11 +4032,11 @@ void prevalence(double ***probs, double
for (i=1; i<=imx; i++) { /* Each individual */
bool=1;
if (cptcovn>0) { /* Filter is here: Must be looked at for model=V1+V2+V3+V4 */
- for (z1=1; z1<=cptcoveff; z1++)
+ for (z1=1; z1<=cptcoveff; z1++) /* For each covariate, look at the value for individual i and checks if it is equal to the corresponding value of this covariate according to current combination j1*/
if (covar[Tvaraff[z1]][i]!= nbcode[Tvaraff[z1]][codtabm(j1,z1)])
bool=0;
}
- if (bool==1) {
+ if (bool==1) { /* For this combination of covariates values, this individual fits */
/* for(m=firstpass; m<=lastpass; m++){/\* Other selection (we can limit to certain interviews*\/ */
for(mi=1; mi 0 0 0, 2 => 0 0 1, 3 => 0 1 1, 4=1 0 0 */
+ * If product of Vn*Vm, still boolean *:
+ * If it was coded 1, 2, 3, 4 should be splitted into 3 boolean variables
+ * 1 => 0 0 0, 2 => 0 0 1, 3 => 0 1 1, 4=1 0 0 */
/* Finds for covariate j, n=Tvar[j] of Vn . ij is the
modality of the nth covariate of individual i. */
if (ij > modmaxcovj)
modmaxcovj=ij;
else if (ij < modmincovj)
- modmincovj=ij;
+ modmincovj=ij;
if ((ij < -1) && (ij > NCOVMAX)){
- printf( "Error: minimal is less than -1 or maximal is bigger than %d. Exiting. \n", NCOVMAX );
- exit(1);
+ printf( "Error: minimal is less than -1 or maximal is bigger than %d. Exiting. \n", NCOVMAX );
+ exit(1);
}else
Ndum[ij]++; /*counts and stores the occurence of this modality 0, 1, -1*/
/* If coded 1, 2, 3 , counts the number of 1 Ndum[1], number of 2, Ndum[2], etc */
@@ -4273,19 +4329,19 @@ void tricode(int *Tvar, int **nbcode, in
printf("Frequencies of covariates %d ie V%d with value %d: %d\n", j, Tvar[j], k, Ndum[k]);
fprintf(ficlog, "Frequencies of covariates %d ie V%d with value %d: %d\n", j, Tvar[j], k, Ndum[k]);
if( Ndum[k] != 0 ){ /* Counts if nobody answered modality k ie empty modality, we skip it and reorder */
- if( k != -1){
- ncodemax[j]++; /* ncodemax[j]= Number of modalities of the j th
- covariate for which somebody answered excluding
- undefined. Usually 2: 0 and 1. */
- }
- ncodemaxwundef[j]++; /* ncodemax[j]= Number of modalities of the j th
- covariate for which somebody answered including
- undefined. Usually 3: -1, 0 and 1. */
+ if( k != -1){
+ ncodemax[j]++; /* ncodemax[j]= Number of modalities of the j th
+ covariate for which somebody answered excluding
+ undefined. Usually 2: 0 and 1. */
+ }
+ ncodemaxwundef[j]++; /* ncodemax[j]= Number of modalities of the j th
+ covariate for which somebody answered including
+ undefined. Usually 3: -1, 0 and 1. */
}
/* In fact ncodemax[j]=2 (dichotom. variables only) but it could be more for
- historical reasons: 3 if coded 1, 2, 3 and 4 and Ndum[2]=0 */
+ historical reasons: 3 if coded 1, 2, 3 and 4 and Ndum[2]=0 */
} /* Ndum[-1] number of undefined modalities */
-
+
/* j is a covariate, n=Tvar[j] of Vn; Fills nbcode */
/* For covariate j, modalities could be 1, 2, 3, 4, 5, 6, 7.
If Ndum[1]=0, Ndum[2]=0, Ndum[3]= 635, Ndum[4]=0, Ndum[5]=0, Ndum[6]=27, Ndum[7]=125;
@@ -4302,8 +4358,8 @@ void tricode(int *Tvar, int **nbcode, in
ij=0; /* ij is similar to i but can jump over null modalities */
for (i=modmincovj; i<=modmaxcovj; i++) { /* i= 1 to 2 for dichotomous, or from 1 to 3 or from -1 or 0 to 1 currently*/
if (Ndum[i] == 0) { /* If nobody responded to this modality k */
- break;
- }
+ break;
+ }
ij++;
nbcode[Tvar[j]][ij]=i; /* stores the original value of modality i in an array nbcode, ij modality from 1 to last non-nul modality.*/
cptcode = ij; /* New max modality for covar j */
@@ -4324,28 +4380,29 @@ void tricode(int *Tvar, int **nbcode, in
/* } /\* end of loop on modality k *\/ */
} /* end of loop on model-covariate j. nbcode[Tvarj][1]=0 and nbcode[Tvarj][2]=1 sets the value of covariate j*/
- for (k=-1; k< maxncov; k++) Ndum[k]=0;
+ for (k=-1; k< maxncov; k++) Ndum[k]=0;
for (i=1; i<=ncovmodel-2-nagesqr; i++) { /* -2, cste and age and eventually age*age */
- /* Listing of all covariables in statement model to see if some covariates appear twice. For example, V1 appears twice in V1+V1*V2.*/
- ij=Tvar[i]; /* Tvar might be -1 if status was unknown */
- Ndum[ij]++; /* Might be supersed V1 + V1*age */
- }
-
- ij=0;
- for (i=0; i<= maxncov-1; i++) { /* modmaxcovj is unknown here. Only Ndum[2(V2),3(age*V3), 5(V3*V2) 6(V1*V4) */
- /*printf("Ndum[%d]=%d\n",i, Ndum[i]);*/
- if((Ndum[i]!=0) && (i<=ncovcol)){
- ij++;
- /*printf("diff Ndum[%d]=%d\n",i, Ndum[i]);*/
- Tvaraff[ij]=i; /*For printing (unclear) */
- }else{
- /* Tvaraff[ij]=0; */
- }
- }
- /* ij--; */
- cptcoveff=ij; /*Number of total covariates*/
-
+ /* Listing of all covariables in statement model to see if some covariates appear twice. For example, V1 appears twice in V1+V1*V2.*/
+ ij=Tvar[i]; /* Tvar might be -1 if status was unknown */
+ Ndum[ij]++; /* Might be supersed V1 + V1*age */
+ }
+
+ ij=0;
+ for (i=0; i<= maxncov-1; i++) { /* modmaxcovj is unknown here. Only Ndum[2(V2),3(age*V3), 5(V3*V2) 6(V1*V4) */
+ /*printf("Ndum[%d]=%d\n",i, Ndum[i]);*/
+ if((Ndum[i]!=0) && (i<=ncovcol)){
+ ij++;
+ /*printf("diff Ndum[%d]=%d\n",i, Ndum[i]);*/
+ Tvaraff[ij]=i; /*For printing (unclear) */
+ }else{
+ /* Tvaraff[ij]=0; */
+ }
+ }
+ /* ij--; */
+ /* cptcoveff=ij; /\*Number of total covariates*\/ */
+ *cptcov=ij; /*Number of total covariates*/
+
}
@@ -5196,235 +5253,236 @@ To be simple, these graphs help to under
tj = (int) pow(2,cptcoveff);
if (cptcovn<1) {tj=1;ncodemax[1]=1;}
j1=0;
- for(j1=1; j1<=tj;j1++){
- /*for(i1=1; i1<=ncodemax[t];i1++){ */
- /*j1++;*/
- if (cptcovn>0) {
- fprintf(ficresprob, "\n#********** Variable ");
- for (z1=1; z1<=cptcoveff; z1++) fprintf(ficresprob, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtabm(j1,z1)]);
- fprintf(ficresprob, "**********\n#\n");
- fprintf(ficresprobcov, "\n#********** Variable ");
- for (z1=1; z1<=cptcoveff; z1++) fprintf(ficresprobcov, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtabm(j1,z1)]);
- fprintf(ficresprobcov, "**********\n#\n");
-
- fprintf(ficgp, "\n#********** Variable ");
- for (z1=1; z1<=cptcoveff; z1++) fprintf(ficgp, " V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtabm(j1,z1)]);
- fprintf(ficgp, "**********\n#\n");
-
-
- fprintf(fichtmcov, "\n
********** Variable ");
- for (z1=1; z1<=cptcoveff; z1++) fprintf(fichtm, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtabm(j1,z1)]);
- fprintf(fichtmcov, "**********\n
");
-
- fprintf(ficresprobcor, "\n#********** Variable ");
- for (z1=1; z1<=cptcoveff; z1++) fprintf(ficresprobcor, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtabm(j1,z1)]);
- fprintf(ficresprobcor, "**********\n#");
- }
-
- gradg=matrix(1,npar,1,(nlstate)*(nlstate+ndeath));
- trgradg=matrix(1,(nlstate)*(nlstate+ndeath),1,npar);
- gp=vector(1,(nlstate)*(nlstate+ndeath));
- gm=vector(1,(nlstate)*(nlstate+ndeath));
- for (age=bage; age<=fage; age ++){
- cov[2]=age;
- if(nagesqr==1)
- cov[3]= age*age;
- for (k=1; k<=cptcovn;k++) {
- cov[2+nagesqr+k]=nbcode[Tvar[k]][codtabm(j1,k)];
- /*cov[2+nagesqr+k]=nbcode[Tvar[k]][codtabm(j1,Tvar[k])];*//* j1 1 2 3 4
- * 1 1 1 1 1
- * 2 2 1 1 1
- * 3 1 2 1 1
- */
- /* nbcode[1][1]=0 nbcode[1][2]=1;*/
- }
- /* for (k=1; k<=cptcovage;k++) cov[2+Tage[k]]=cov[2+Tage[k]]*cov[2]; */
- for (k=1; k<=cptcovage;k++) cov[2+Tage[k]]=nbcode[Tvar[Tage[k]]][codtabm(ij,k)]*cov[2];
- for (k=1; k<=cptcovprod;k++)
- cov[2+nagesqr+Tprod[k]]=nbcode[Tvard[k][1]][codtabm(ij,k)]*nbcode[Tvard[k][2]][codtabm(ij,k)];
-
-
- for(theta=1; theta <=npar; theta++){
- for(i=1; i<=npar; i++)
- xp[i] = x[i] + (i==theta ?delti[theta]:(double)0);
-
- pmij(pmmij,cov,ncovmodel,xp,nlstate);
-
- k=0;
- for(i=1; i<= (nlstate); i++){
- for(j=1; j<=(nlstate+ndeath);j++){
- k=k+1;
- gp[k]=pmmij[i][j];
- }
- }
-
- for(i=1; i<=npar; i++)
- xp[i] = x[i] - (i==theta ?delti[theta]:(double)0);
-
- pmij(pmmij,cov,ncovmodel,xp,nlstate);
- k=0;
- for(i=1; i<=(nlstate); i++){
- for(j=1; j<=(nlstate+ndeath);j++){
- k=k+1;
- gm[k]=pmmij[i][j];
- }
- }
-
- for(i=1; i<= (nlstate)*(nlstate+ndeath); i++)
- gradg[theta][i]=(gp[i]-gm[i])/(double)2./delti[theta];
- }
-
- for(j=1; j<=(nlstate)*(nlstate+ndeath);j++)
- for(theta=1; theta <=npar; theta++)
- trgradg[j][theta]=gradg[theta][j];
-
- matprod2(dnewm,trgradg,1,(nlstate)*(nlstate+ndeath),1,npar,1,npar,matcov);
- matprod2(doldm,dnewm,1,(nlstate)*(nlstate+ndeath),1,npar,1,(nlstate)*(nlstate+ndeath),gradg);
+ for(j1=1; j1<=tj;j1++){ /* For each valid combination of covariates */
+ if (cptcovn>0) {
+ fprintf(ficresprob, "\n#********** Variable ");
+ for (z1=1; z1<=cptcoveff; z1++) fprintf(ficresprob, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtabm(j1,z1)]);
+ fprintf(ficresprob, "**********\n#\n");
+ fprintf(ficresprobcov, "\n#********** Variable ");
+ for (z1=1; z1<=cptcoveff; z1++) fprintf(ficresprobcov, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtabm(j1,z1)]);
+ fprintf(ficresprobcov, "**********\n#\n");
+
+ fprintf(ficgp, "\n#********** Variable ");
+ for (z1=1; z1<=cptcoveff; z1++) fprintf(ficgp, " V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtabm(j1,z1)]);
+ fprintf(ficgp, "**********\n#\n");
+
+
+ fprintf(fichtmcov, "\n
********** Variable ");
+ for (z1=1; z1<=cptcoveff; z1++) fprintf(fichtm, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtabm(j1,z1)]);
+ fprintf(fichtmcov, "**********\n
");
+
+ fprintf(ficresprobcor, "\n#********** Variable ");
+ for (z1=1; z1<=cptcoveff; z1++) fprintf(ficresprobcor, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtabm(j1,z1)]);
+ fprintf(ficresprobcor, "**********\n#");
+ if(invalidvarcomb[j1]){
+ fprintf(ficgp,"\n#Combination (%d) ignored because no cases \n",j1);
+ fprintf(fichtmcov,"\nCombination (%d) ignored because no cases
\n",j1);
+ continue;
+ }
+ }
+ gradg=matrix(1,npar,1,(nlstate)*(nlstate+ndeath));
+ trgradg=matrix(1,(nlstate)*(nlstate+ndeath),1,npar);
+ gp=vector(1,(nlstate)*(nlstate+ndeath));
+ gm=vector(1,(nlstate)*(nlstate+ndeath));
+ for (age=bage; age<=fage; age ++){
+ cov[2]=age;
+ if(nagesqr==1)
+ cov[3]= age*age;
+ for (k=1; k<=cptcovn;k++) {
+ cov[2+nagesqr+k]=nbcode[Tvar[k]][codtabm(j1,k)];
+ /*cov[2+nagesqr+k]=nbcode[Tvar[k]][codtabm(j1,Tvar[k])];*//* j1 1 2 3 4
+ * 1 1 1 1 1
+ * 2 2 1 1 1
+ * 3 1 2 1 1
+ */
+ /* nbcode[1][1]=0 nbcode[1][2]=1;*/
+ }
+ /* for (k=1; k<=cptcovage;k++) cov[2+Tage[k]]=cov[2+Tage[k]]*cov[2]; */
+ for (k=1; k<=cptcovage;k++) cov[2+Tage[k]]=nbcode[Tvar[Tage[k]]][codtabm(ij,k)]*cov[2];
+ for (k=1; k<=cptcovprod;k++)
+ cov[2+nagesqr+Tprod[k]]=nbcode[Tvard[k][1]][codtabm(ij,k)]*nbcode[Tvard[k][2]][codtabm(ij,k)];
+
+
+ for(theta=1; theta <=npar; theta++){
+ for(i=1; i<=npar; i++)
+ xp[i] = x[i] + (i==theta ?delti[theta]:(double)0);
+
+ pmij(pmmij,cov,ncovmodel,xp,nlstate);
+
+ k=0;
+ for(i=1; i<= (nlstate); i++){
+ for(j=1; j<=(nlstate+ndeath);j++){
+ k=k+1;
+ gp[k]=pmmij[i][j];
+ }
+ }
+
+ for(i=1; i<=npar; i++)
+ xp[i] = x[i] - (i==theta ?delti[theta]:(double)0);
+
+ pmij(pmmij,cov,ncovmodel,xp,nlstate);
+ k=0;
+ for(i=1; i<=(nlstate); i++){
+ for(j=1; j<=(nlstate+ndeath);j++){
+ k=k+1;
+ gm[k]=pmmij[i][j];
+ }
+ }
+
+ for(i=1; i<= (nlstate)*(nlstate+ndeath); i++)
+ gradg[theta][i]=(gp[i]-gm[i])/(double)2./delti[theta];
+ }
- pmij(pmmij,cov,ncovmodel,x,nlstate);
-
- k=0;
- for(i=1; i<=(nlstate); i++){
- for(j=1; j<=(nlstate+ndeath);j++){
- k=k+1;
- mu[k][(int) age]=pmmij[i][j];
- }
- }
+ for(j=1; j<=(nlstate)*(nlstate+ndeath);j++)
+ for(theta=1; theta <=npar; theta++)
+ trgradg[j][theta]=gradg[theta][j];
+
+ matprod2(dnewm,trgradg,1,(nlstate)*(nlstate+ndeath),1,npar,1,npar,matcov);
+ matprod2(doldm,dnewm,1,(nlstate)*(nlstate+ndeath),1,npar,1,(nlstate)*(nlstate+ndeath),gradg);
+
+ pmij(pmmij,cov,ncovmodel,x,nlstate);
+
+ k=0;
+ for(i=1; i<=(nlstate); i++){
+ for(j=1; j<=(nlstate+ndeath);j++){
+ k=k+1;
+ mu[k][(int) age]=pmmij[i][j];
+ }
+ }
for(i=1;i<=(nlstate)*(nlstate+ndeath);i++)
- for(j=1;j<=(nlstate)*(nlstate+ndeath);j++)
- varpij[i][j][(int)age] = doldm[i][j];
-
- /*printf("\n%d ",(int)age);
- for (i=1; i<=(nlstate)*(nlstate+ndeath);i++){
- printf("%e [%e ;%e] ",gm[i],gm[i]-2*sqrt(doldm[i][i]),gm[i]+2*sqrt(doldm[i][i]));
- fprintf(ficlog,"%e [%e ;%e] ",gm[i],gm[i]-2*sqrt(doldm[i][i]),gm[i]+2*sqrt(doldm[i][i]));
- }*/
-
- fprintf(ficresprob,"\n%d ",(int)age);
- fprintf(ficresprobcov,"\n%d ",(int)age);
- fprintf(ficresprobcor,"\n%d ",(int)age);
-
- for (i=1; i<=(nlstate)*(nlstate+ndeath);i++)
- fprintf(ficresprob,"%11.3e (%11.3e) ",mu[i][(int) age],sqrt(varpij[i][i][(int)age]));
- for (i=1; i<=(nlstate)*(nlstate+ndeath);i++){
- fprintf(ficresprobcov,"%11.3e ",mu[i][(int) age]);
- fprintf(ficresprobcor,"%11.3e ",mu[i][(int) age]);
- }
- i=0;
- for (k=1; k<=(nlstate);k++){
- for (l=1; l<=(nlstate+ndeath);l++){
- i++;
- fprintf(ficresprobcov,"\n%d %d-%d",(int)age,k,l);
- fprintf(ficresprobcor,"\n%d %d-%d",(int)age,k,l);
- for (j=1; j<=i;j++){
- /* printf(" k=%d l=%d i=%d j=%d\n",k,l,i,j);fflush(stdout); */
- fprintf(ficresprobcov," %11.3e",varpij[i][j][(int)age]);
- fprintf(ficresprobcor," %11.3e",varpij[i][j][(int) age]/sqrt(varpij[i][i][(int) age])/sqrt(varpij[j][j][(int)age]));
- }
- }
- }/* end of loop for state */
- } /* end of loop for age */
- free_vector(gp,1,(nlstate+ndeath)*(nlstate+ndeath));
- free_vector(gm,1,(nlstate+ndeath)*(nlstate+ndeath));
- free_matrix(trgradg,1,(nlstate+ndeath)*(nlstate+ndeath),1,npar);
- free_matrix(gradg,1,(nlstate+ndeath)*(nlstate+ndeath),1,npar);
-
- /* Confidence intervalle of pij */
- /*
- fprintf(ficgp,"\nunset parametric;unset label");
- fprintf(ficgp,"\nset log y;unset log x; set xlabel \"Age\";set ylabel \"probability (year-1)\"");
- fprintf(ficgp,"\nset ter png small\nset size 0.65,0.65");
- fprintf(fichtm,"\n
Probability with confidence intervals expressed in year-1 :pijgr%s.png, ",optionfilefiname,optionfilefiname);
- fprintf(fichtm,"\n
",optionfilefiname);
- fprintf(ficgp,"\nset out \"pijgr%s.png\"",optionfilefiname);
- fprintf(ficgp,"\nplot \"%s\" every :::%d::%d u 1:2 \"\%%lf",k1,k2,xfilevarprob);
- */
-
- /* Drawing ellipsoids of confidence of two variables p(k1-l1,k2-l2)*/
- first1=1;first2=2;
- for (k2=1; k2<=(nlstate);k2++){
- for (l2=1; l2<=(nlstate+ndeath);l2++){
- if(l2==k2) continue;
- j=(k2-1)*(nlstate+ndeath)+l2;
- for (k1=1; k1<=(nlstate);k1++){
- for (l1=1; l1<=(nlstate+ndeath);l1++){
- if(l1==k1) continue;
- i=(k1-1)*(nlstate+ndeath)+l1;
- if(i<=j) continue;
- for (age=bage; age<=fage; age ++){
- if ((int)age %5==0){
- v1=varpij[i][i][(int)age]/stepm*YEARM/stepm*YEARM;
- v2=varpij[j][j][(int)age]/stepm*YEARM/stepm*YEARM;
- cv12=varpij[i][j][(int)age]/stepm*YEARM/stepm*YEARM;
- mu1=mu[i][(int) age]/stepm*YEARM ;
- mu2=mu[j][(int) age]/stepm*YEARM;
- c12=cv12/sqrt(v1*v2);
- /* Computing eigen value of matrix of covariance */
- lc1=((v1+v2)+sqrt((v1+v2)*(v1+v2) - 4*(v1*v2-cv12*cv12)))/2.;
- lc2=((v1+v2)-sqrt((v1+v2)*(v1+v2) - 4*(v1*v2-cv12*cv12)))/2.;
- if ((lc2 <0) || (lc1 <0) ){
- if(first2==1){
- first1=0;
- printf("Strange: j1=%d One eigen value of 2x2 matrix of covariance is negative, lc1=%11.3e, lc2=%11.3e, v1=%11.3e, v2=%11.3e, cv12=%11.3e.\n It means that the matrix was not well estimated (varpij), for i=%2d, j=%2d, age=%4d .\n See files %s and %s. Probably WRONG RESULTS. See log file for details...\n", j1, lc1, lc2, v1, v2, cv12, i, j, (int)age,fileresprobcov, fileresprobcor);
- }
- fprintf(ficlog,"Strange: j1=%d One eigen value of 2x2 matrix of covariance is negative, lc1=%11.3e, lc2=%11.3e, v1=%11.3e, v2=%11.3e, cv12=%11.3e.\n It means that the matrix was not well estimated (varpij), for i=%2d, j=%2d, age=%4d .\n See files %s and %s. Probably WRONG RESULTS.\n", j1, lc1, lc2, v1, v2, cv12, i, j, (int)age,fileresprobcov, fileresprobcor);fflush(ficlog);
- /* lc1=fabs(lc1); */ /* If we want to have them positive */
- /* lc2=fabs(lc2); */
- }
-
- /* Eigen vectors */
- v11=(1./sqrt(1+(v1-lc1)*(v1-lc1)/cv12/cv12));
- /*v21=sqrt(1.-v11*v11); *//* error */
- v21=(lc1-v1)/cv12*v11;
- v12=-v21;
- v22=v11;
- tnalp=v21/v11;
- if(first1==1){
- first1=0;
- printf("%d %d%d-%d%d mu %.4e %.4e Var %.4e %.4e cor %.3f cov %.4e Eig %.3e %.3e 1stv %.3f %.3f tang %.3f\nOthers in log...\n",(int) age,k1,l1,k2,l2,mu1,mu2,v1,v2,c12,cv12,lc1,lc2,v11,v21,tnalp);
- }
- fprintf(ficlog,"%d %d%d-%d%d mu %.4e %.4e Var %.4e %.4e cor %.3f cov %.4e Eig %.3e %.3e 1stv %.3f %.3f tan %.3f\n",(int) age,k1,l1,k2,l2,mu1,mu2,v1,v2,c12,cv12,lc1,lc2,v11,v21,tnalp);
- /*printf(fignu*/
- /* mu1+ v11*lc1*cost + v12*lc2*sin(t) */
- /* mu2+ v21*lc1*cost + v22*lc2*sin(t) */
- if(first==1){
- first=0;
- fprintf(ficgp,"\n# Ellipsoids of confidence\n#\n");
- fprintf(ficgp,"\nset parametric;unset label");
- fprintf(ficgp,"\nset log y;set log x; set xlabel \"p%1d%1d (year-1)\";set ylabel \"p%1d%1d (year-1)\"",k1,l1,k2,l2);
- fprintf(ficgp,"\nset ter svg size 640, 480");
- fprintf(fichtmcov,"\n
Ellipsoids of confidence cov(p%1d%1d,p%1d%1d) expressed in year-1\
- :\
+ for(j=1;j<=(nlstate)*(nlstate+ndeath);j++)
+ varpij[i][j][(int)age] = doldm[i][j];
+
+ /*printf("\n%d ",(int)age);
+ for (i=1; i<=(nlstate)*(nlstate+ndeath);i++){
+ printf("%e [%e ;%e] ",gm[i],gm[i]-2*sqrt(doldm[i][i]),gm[i]+2*sqrt(doldm[i][i]));
+ fprintf(ficlog,"%e [%e ;%e] ",gm[i],gm[i]-2*sqrt(doldm[i][i]),gm[i]+2*sqrt(doldm[i][i]));
+ }*/
+
+ fprintf(ficresprob,"\n%d ",(int)age);
+ fprintf(ficresprobcov,"\n%d ",(int)age);
+ fprintf(ficresprobcor,"\n%d ",(int)age);
+
+ for (i=1; i<=(nlstate)*(nlstate+ndeath);i++)
+ fprintf(ficresprob,"%11.3e (%11.3e) ",mu[i][(int) age],sqrt(varpij[i][i][(int)age]));
+ for (i=1; i<=(nlstate)*(nlstate+ndeath);i++){
+ fprintf(ficresprobcov,"%11.3e ",mu[i][(int) age]);
+ fprintf(ficresprobcor,"%11.3e ",mu[i][(int) age]);
+ }
+ i=0;
+ for (k=1; k<=(nlstate);k++){
+ for (l=1; l<=(nlstate+ndeath);l++){
+ i++;
+ fprintf(ficresprobcov,"\n%d %d-%d",(int)age,k,l);
+ fprintf(ficresprobcor,"\n%d %d-%d",(int)age,k,l);
+ for (j=1; j<=i;j++){
+ /* printf(" k=%d l=%d i=%d j=%d\n",k,l,i,j);fflush(stdout); */
+ fprintf(ficresprobcov," %11.3e",varpij[i][j][(int)age]);
+ fprintf(ficresprobcor," %11.3e",varpij[i][j][(int) age]/sqrt(varpij[i][i][(int) age])/sqrt(varpij[j][j][(int)age]));
+ }
+ }
+ }/* end of loop for state */
+ } /* end of loop for age */
+ free_vector(gp,1,(nlstate+ndeath)*(nlstate+ndeath));
+ free_vector(gm,1,(nlstate+ndeath)*(nlstate+ndeath));
+ free_matrix(trgradg,1,(nlstate+ndeath)*(nlstate+ndeath),1,npar);
+ free_matrix(gradg,1,(nlstate+ndeath)*(nlstate+ndeath),1,npar);
+
+ /* Confidence intervalle of pij */
+ /*
+ fprintf(ficgp,"\nunset parametric;unset label");
+ fprintf(ficgp,"\nset log y;unset log x; set xlabel \"Age\";set ylabel \"probability (year-1)\"");
+ fprintf(ficgp,"\nset ter png small\nset size 0.65,0.65");
+ fprintf(fichtm,"\n
Probability with confidence intervals expressed in year-1 :pijgr%s.png, ",optionfilefiname,optionfilefiname);
+ fprintf(fichtm,"\n
",optionfilefiname);
+ fprintf(ficgp,"\nset out \"pijgr%s.png\"",optionfilefiname);
+ fprintf(ficgp,"\nplot \"%s\" every :::%d::%d u 1:2 \"\%%lf",k1,k2,xfilevarprob);
+ */
+
+ /* Drawing ellipsoids of confidence of two variables p(k1-l1,k2-l2)*/
+ first1=1;first2=2;
+ for (k2=1; k2<=(nlstate);k2++){
+ for (l2=1; l2<=(nlstate+ndeath);l2++){
+ if(l2==k2) continue;
+ j=(k2-1)*(nlstate+ndeath)+l2;
+ for (k1=1; k1<=(nlstate);k1++){
+ for (l1=1; l1<=(nlstate+ndeath);l1++){
+ if(l1==k1) continue;
+ i=(k1-1)*(nlstate+ndeath)+l1;
+ if(i<=j) continue;
+ for (age=bage; age<=fage; age ++){
+ if ((int)age %5==0){
+ v1=varpij[i][i][(int)age]/stepm*YEARM/stepm*YEARM;
+ v2=varpij[j][j][(int)age]/stepm*YEARM/stepm*YEARM;
+ cv12=varpij[i][j][(int)age]/stepm*YEARM/stepm*YEARM;
+ mu1=mu[i][(int) age]/stepm*YEARM ;
+ mu2=mu[j][(int) age]/stepm*YEARM;
+ c12=cv12/sqrt(v1*v2);
+ /* Computing eigen value of matrix of covariance */
+ lc1=((v1+v2)+sqrt((v1+v2)*(v1+v2) - 4*(v1*v2-cv12*cv12)))/2.;
+ lc2=((v1+v2)-sqrt((v1+v2)*(v1+v2) - 4*(v1*v2-cv12*cv12)))/2.;
+ if ((lc2 <0) || (lc1 <0) ){
+ if(first2==1){
+ first1=0;
+ printf("Strange: j1=%d One eigen value of 2x2 matrix of covariance is negative, lc1=%11.3e, lc2=%11.3e, v1=%11.3e, v2=%11.3e, cv12=%11.3e.\n It means that the matrix was not well estimated (varpij), for i=%2d, j=%2d, age=%4d .\n See files %s and %s. Probably WRONG RESULTS. See log file for details...\n", j1, lc1, lc2, v1, v2, cv12, i, j, (int)age,fileresprobcov, fileresprobcor);
+ }
+ fprintf(ficlog,"Strange: j1=%d One eigen value of 2x2 matrix of covariance is negative, lc1=%11.3e, lc2=%11.3e, v1=%11.3e, v2=%11.3e, cv12=%11.3e.\n It means that the matrix was not well estimated (varpij), for i=%2d, j=%2d, age=%4d .\n See files %s and %s. Probably WRONG RESULTS.\n", j1, lc1, lc2, v1, v2, cv12, i, j, (int)age,fileresprobcov, fileresprobcor);fflush(ficlog);
+ /* lc1=fabs(lc1); */ /* If we want to have them positive */
+ /* lc2=fabs(lc2); */
+ }
+
+ /* Eigen vectors */
+ v11=(1./sqrt(1+(v1-lc1)*(v1-lc1)/cv12/cv12));
+ /*v21=sqrt(1.-v11*v11); *//* error */
+ v21=(lc1-v1)/cv12*v11;
+ v12=-v21;
+ v22=v11;
+ tnalp=v21/v11;
+ if(first1==1){
+ first1=0;
+ printf("%d %d%d-%d%d mu %.4e %.4e Var %.4e %.4e cor %.3f cov %.4e Eig %.3e %.3e 1stv %.3f %.3f tang %.3f\nOthers in log...\n",(int) age,k1,l1,k2,l2,mu1,mu2,v1,v2,c12,cv12,lc1,lc2,v11,v21,tnalp);
+ }
+ fprintf(ficlog,"%d %d%d-%d%d mu %.4e %.4e Var %.4e %.4e cor %.3f cov %.4e Eig %.3e %.3e 1stv %.3f %.3f tan %.3f\n",(int) age,k1,l1,k2,l2,mu1,mu2,v1,v2,c12,cv12,lc1,lc2,v11,v21,tnalp);
+ /*printf(fignu*/
+ /* mu1+ v11*lc1*cost + v12*lc2*sin(t) */
+ /* mu2+ v21*lc1*cost + v22*lc2*sin(t) */
+ if(first==1){
+ first=0;
+ fprintf(ficgp,"\n# Ellipsoids of confidence\n#\n");
+ fprintf(ficgp,"\nset parametric;unset label");
+ fprintf(ficgp,"\nset log y;set log x; set xlabel \"p%1d%1d (year-1)\";set ylabel \"p%1d%1d (year-1)\"",k1,l1,k2,l2);
+ fprintf(ficgp,"\nset ter svg size 640, 480");
+ fprintf(fichtmcov,"\n
Ellipsoids of confidence cov(p%1d%1d,p%1d%1d) expressed in year-1\
+ : \
%s_%d%1d%1d-%1d%1d.svg, ",k1,l1,k2,l2,\
- subdirf2(optionfilefiname,"VARPIJGR_"), j1,k1,l1,k2,l2,\
- subdirf2(optionfilefiname,"VARPIJGR_"), j1,k1,l1,k2,l2);
- fprintf(fichtmcov,"\n
",subdirf2(optionfilefiname,"VARPIJGR_"), j1,k1,l1,k2,l2);
- fprintf(fichtmcov,"\n
Correlation at age %d (%.3f),",(int) age, c12);
- fprintf(ficgp,"\nset out \"%s_%d%1d%1d-%1d%1d.svg\"",subdirf2(optionfilefiname,"VARPIJGR_"), j1,k1,l1,k2,l2);
+ subdirf2(optionfilefiname,"VARPIJGR_"), j1,k1,l1,k2,l2, \
+ subdirf2(optionfilefiname,"VARPIJGR_"), j1,k1,l1,k2,l2);
+ fprintf(fichtmcov,"\n
",subdirf2(optionfilefiname,"VARPIJGR_"), j1,k1,l1,k2,l2);
+ fprintf(fichtmcov,"\n
Correlation at age %d (%.3f),",(int) age, c12);
+ fprintf(ficgp,"\nset out \"%s_%d%1d%1d-%1d%1d.svg\"",subdirf2(optionfilefiname,"VARPIJGR_"), j1,k1,l1,k2,l2);
fprintf(ficgp,"\nset label \"%d\" at %11.3e,%11.3e center",(int) age, mu1,mu2);
fprintf(ficgp,"\n# Age %d, p%1d%1d - p%1d%1d",(int) age, k1,l1,k2,l2);
- fprintf(ficgp,"\nplot [-pi:pi] %11.3e+ %.3f*(%11.3e*%11.3e*cos(t)+%11.3e*%11.3e*sin(t)), %11.3e +%.3f*(%11.3e*%11.3e*cos(t)+%11.3e*%11.3e*sin(t)) not",\
- mu1,std,v11,sqrt(lc1),v12,sqrt(lc2),\
- mu2,std,v21,sqrt(lc1),v22,sqrt(lc2));
- }else{
- first=0;
- fprintf(fichtmcov," %d (%.3f),",(int) age, c12);
- fprintf(ficgp,"\n# Age %d, p%1d%1d - p%1d%1d",(int) age, k1,l1,k2,l2);
- fprintf(ficgp,"\nset label \"%d\" at %11.3e,%11.3e center",(int) age, mu1,mu2);
- fprintf(ficgp,"\nreplot %11.3e+ %.3f*(%11.3e*%11.3e*cos(t)+%11.3e*%11.3e*sin(t)), %11.3e +%.3f*(%11.3e*%11.3e*cos(t)+%11.3e*%11.3e*sin(t)) not",\
- mu1,std,v11,sqrt(lc1),v12,sqrt(lc2),\
- mu2,std,v21,sqrt(lc1),v22,sqrt(lc2));
- }/* if first */
- } /* age mod 5 */
- } /* end loop age */
- fprintf(ficgp,"\nset out;\nset out \"%s_%d%1d%1d-%1d%1d.svg\";replot;set out;",subdirf2(optionfilefiname,"VARPIJGR_"), j1,k1,l1,k2,l2);
- first=1;
- } /*l12 */
- } /* k12 */
- } /*l1 */
- }/* k1 */
- /* } */ /* loop covariates */
- }
+ fprintf(ficgp,"\nplot [-pi:pi] %11.3e+ %.3f*(%11.3e*%11.3e*cos(t)+%11.3e*%11.3e*sin(t)), %11.3e +%.3f*(%11.3e*%11.3e*cos(t)+%11.3e*%11.3e*sin(t)) not", \
+ mu1,std,v11,sqrt(lc1),v12,sqrt(lc2), \
+ mu2,std,v21,sqrt(lc1),v22,sqrt(lc2));
+ }else{
+ first=0;
+ fprintf(fichtmcov," %d (%.3f),",(int) age, c12);
+ fprintf(ficgp,"\n# Age %d, p%1d%1d - p%1d%1d",(int) age, k1,l1,k2,l2);
+ fprintf(ficgp,"\nset label \"%d\" at %11.3e,%11.3e center",(int) age, mu1,mu2);
+ fprintf(ficgp,"\nreplot %11.3e+ %.3f*(%11.3e*%11.3e*cos(t)+%11.3e*%11.3e*sin(t)), %11.3e +%.3f*(%11.3e*%11.3e*cos(t)+%11.3e*%11.3e*sin(t)) not", \
+ mu1,std,v11,sqrt(lc1),v12,sqrt(lc2), \
+ mu2,std,v21,sqrt(lc1),v22,sqrt(lc2));
+ }/* if first */
+ } /* age mod 5 */
+ } /* end loop age */
+ fprintf(ficgp,"\nset out;\nset out \"%s_%d%1d%1d-%1d%1d.svg\";replot;set out;",subdirf2(optionfilefiname,"VARPIJGR_"), j1,k1,l1,k2,l2);
+ first=1;
+ } /*l12 */
+ } /* k12 */
+ } /*l1 */
+ }/* k1 */
+ } /* loop on combination of covariates j1 */
free_ma3x(varpij,1,nlstate,1,nlstate+ndeath,(int) bage, (int)fage);
free_matrix(mu,1,(nlstate+ndeath)*(nlstate+ndeath),(int) bage, (int)fage);
free_matrix(doldm,1,(nlstate)*(nlstate+ndeath),1,(nlstate)*(nlstate+ndeath));
@@ -5485,63 +5543,69 @@ fprintf(fichtm," \n- Graphs
jj1=0;
for(k1=1; k1<=m;k1++){
+
/* for(i1=1; i1<=ncodemax[k1];i1++){ */
- jj1++;
- if (cptcovn > 0) {
- fprintf(fichtm,"
************ Results for covariates");
- for (cpt=1; cpt<=cptcoveff;cpt++){
- fprintf(fichtm," V%d=%d ",Tvaraff[cpt],nbcode[Tvaraff[cpt]][codtabm(jj1,cpt)]);
- printf(" V%d=%d ",Tvaraff[cpt],nbcode[Tvaraff[cpt]][codtabm(jj1,cpt)]);fflush(stdout);
- }
- fprintf(fichtm," ************\n
");
- }
- /* aij, bij */
- fprintf(fichtm,"
- Logit model (yours is: 1+age+%s), for example: logit(pij)=log(pij/pii)= aij+ bij age + V1 age + etc. as a function of age: %s_%d-1.svg
\
+ jj1++;
+ if (cptcovn > 0) {
+ fprintf(fichtm,"
************ Results for covariates");
+ for (cpt=1; cpt<=cptcoveff;cpt++){
+ fprintf(fichtm," V%d=%d ",Tvaraff[cpt],nbcode[Tvaraff[cpt]][codtabm(jj1,cpt)]);
+ printf(" V%d=%d ",Tvaraff[cpt],nbcode[Tvaraff[cpt]][codtabm(jj1,cpt)]);fflush(stdout);
+ }
+ fprintf(fichtm," ************\n
");
+ if(invalidvarcomb[k1]){
+ fprintf(fichtm,"\nCombination (%d) ignored because no cases
\n",k1);
+ printf("\nCombination (%d) ignored because no cases \n",k1);
+ continue;
+ }
+ }
+ /* aij, bij */
+ fprintf(fichtm,"
- Logit model (yours is: 1+age+%s), for example: logit(pij)=log(pij/pii)= aij+ bij age + V1 age + etc. as a function of age: %s_%d-1.svg
\
",model,subdirf2(optionfilefiname,"PE_"),jj1,subdirf2(optionfilefiname,"PE_"),jj1,subdirf2(optionfilefiname,"PE_"),jj1);
- /* Pij */
- fprintf(fichtm,"
\n- Pij or conditional probabilities to be observed in state j being in state i, %d (stepm) months before: %s_%d-2.svg
\
+ /* Pij */
+ fprintf(fichtm,"
\n- Pij or conditional probabilities to be observed in state j being in state i, %d (stepm) months before: %s_%d-2.svg
\
",stepm,subdirf2(optionfilefiname,"PE_"),jj1,subdirf2(optionfilefiname,"PE_"),jj1,subdirf2(optionfilefiname,"PE_"),jj1);
- /* Quasi-incidences */
- fprintf(fichtm,"
\n- Iij or Conditional probabilities to be observed in state j being in state i %d (stepm) months\
- before but expressed in per year i.e. quasi incidences if stepm is small and probabilities too,\
+ /* Quasi-incidences */
+ fprintf(fichtm,"
\n- Iij or Conditional probabilities to be observed in state j being in state i %d (stepm) months\
+ before but expressed in per year i.e. quasi incidences if stepm is small and probabilities too, \
incidence (rates) are the limit when h tends to zero of the ratio of the probability hPij \
divided by h: hPij/h : %s_%d-3.svg
\
",stepm,subdirf2(optionfilefiname,"PE_"),jj1,subdirf2(optionfilefiname,"PE_"),jj1,subdirf2(optionfilefiname,"PE_"),jj1);
- /* Survival functions (period) in state j */
- for(cpt=1; cpt<=nlstate;cpt++){
- fprintf(fichtm,"
\n- Survival functions in state %d. Or probability to survive in state %d being in state (1 to %d) at different ages. %s%d_%d.svg
\
+ /* Survival functions (period) in state j */
+ for(cpt=1; cpt<=nlstate;cpt++){
+ fprintf(fichtm,"
\n- Survival functions in state %d. Or probability to survive in state %d being in state (1 to %d) at different ages. %s%d_%d.svg
\
", cpt, cpt, nlstate, subdirf2(optionfilefiname,"LIJ_"),cpt,jj1,subdirf2(optionfilefiname,"LIJ_"),cpt,jj1,subdirf2(optionfilefiname,"LIJ_"),cpt,jj1);
- }
- /* State specific survival functions (period) */
- for(cpt=1; cpt<=nlstate;cpt++){
- fprintf(fichtm,"
\n- Survival functions from state %d in each live state and total.\
- Or probability to survive in various states (1 to %d) being in state %d at different ages.\
+ }
+ /* State specific survival functions (period) */
+ for(cpt=1; cpt<=nlstate;cpt++){
+ fprintf(fichtm,"
\n- Survival functions from state %d in each live state and total.\
+ Or probability to survive in various states (1 to %d) being in state %d at different ages. \
%s%d_%d.svg
", cpt, nlstate, cpt, subdirf2(optionfilefiname,"LIJT_"),cpt,jj1,subdirf2(optionfilefiname,"LIJT_"),cpt,jj1,subdirf2(optionfilefiname,"LIJT_"),cpt,jj1);
- }
- /* Period (stable) prevalence in each health state */
- for(cpt=1; cpt<=nlstate;cpt++){
- fprintf(fichtm,"
\n- Convergence to period (stable) prevalence in state %d. Or probability to be in state %d being in state (1 to %d) at different ages. %s_%d-%d.svg
\
+ }
+ /* Period (stable) prevalence in each health state */
+ for(cpt=1; cpt<=nlstate;cpt++){
+ fprintf(fichtm,"
\n- Convergence to period (stable) prevalence in state %d. Or probability to be in state %d being in state (1 to %d) at different ages. %s_%d-%d.svg
\
", cpt, cpt, nlstate, subdirf2(optionfilefiname,"P_"),cpt,jj1,subdirf2(optionfilefiname,"P_"),cpt,jj1,subdirf2(optionfilefiname,"P_"),cpt,jj1);
- }
- if(backcast==1){
+ }
+ if(backcast==1){
/* Period (stable) back prevalence in each health state */
for(cpt=1; cpt<=nlstate;cpt++){
fprintf(fichtm,"
\n- Convergence to period (stable) back prevalence in state %d. Or probability to be in state %d being in state (1 to %d) at different ages. %s_%d-%d.svg
\
", cpt, cpt, nlstate, subdirf2(optionfilefiname,"PB_"),cpt,jj1,subdirf2(optionfilefiname,"PB_"),cpt,jj1,subdirf2(optionfilefiname,"PB_"),cpt,jj1);
}
- }
- if(prevfcast==1){
- /* Projection of prevalence up to period (stable) prevalence in each health state */
- for(cpt=1; cpt<=nlstate;cpt++){
- fprintf(fichtm,"
\n- Projection of cross-sectional prevalence (estimated with cases observed from %.1f to %.1f) up to period (stable) prevalence in state %d. Or probability to be in state %d being in state (1 to %d) at different ages. %s%d_%d.svg
\
+ }
+ if(prevfcast==1){
+ /* Projection of prevalence up to period (stable) prevalence in each health state */
+ for(cpt=1; cpt<=nlstate;cpt++){
+ fprintf(fichtm,"
\n- Projection of cross-sectional prevalence (estimated with cases observed from %.1f to %.1f) up to period (stable) prevalence in state %d. Or probability to be in state %d being in state (1 to %d) at different ages. %s%d_%d.svg
\
", dateprev1, dateprev2, cpt, cpt, nlstate, subdirf2(optionfilefiname,"PROJ_"),cpt,jj1,subdirf2(optionfilefiname,"PROJ_"),cpt,jj1,subdirf2(optionfilefiname,"PROJ_"),cpt,jj1);
- }
- }
-
- for(cpt=1; cpt<=nlstate;cpt++) {
- fprintf(fichtm,"\n
- Life expectancy by health state (%d) at initial age and its decomposition into health expectancies in each alive state (1 to %d) (or area under each survival functions): %s_%d%d.svg
\
+ }
+ }
+
+ for(cpt=1; cpt<=nlstate;cpt++) {
+ fprintf(fichtm,"\n
- Life expectancy by health state (%d) at initial age and its decomposition into health expectancies in each alive state (1 to %d) (or area under each survival functions): %s_%d%d.svg
\
",cpt,nlstate,subdirf2(optionfilefiname,"EXP_"),cpt,jj1,subdirf2(optionfilefiname,"EXP_"),cpt,jj1,subdirf2(optionfilefiname,"EXP_"),cpt,jj1);
- }
+ }
/* } /\* end i1 *\/ */
}/* End k1 */
fprintf(fichtm,"
");
@@ -5599,13 +5663,18 @@ See page 'Matrix of variance-covariance
jj1=0;
for(k1=1; k1<=m;k1++){
- /* for(i1=1; i1<=ncodemax[k1];i1++){ */
- jj1++;
+ /* for(i1=1; i1<=ncodemax[k1];i1++){ */
+ jj1++;
if (cptcovn > 0) {
fprintf(fichtm,"
************ Results for covariates");
for (cpt=1; cpt<=cptcoveff;cpt++)
- 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)]);
fprintf(fichtm," ************\n
");
+
+ if(invalidvarcomb[k1]){
+ fprintf(fichtm,"\nCombination (%d) ignored because no cases
\n",k1);
+ continue;
+ }
}
for(cpt=1; cpt<=nlstate;cpt++) {
fprintf(fichtm,"\n
- Observed (cross-sectional) and period (incidence based) \
@@ -5628,10 +5697,13 @@ true period expectancies (those weighted
void printinggnuplot(char fileresu[], char optionfilefiname[], double ageminpar, double agemaxpar, double fage , int prevfcast, int backcast, char pathc[], double p[]){
char dirfileres[132],optfileres[132];
+ char gplotcondition[132];
int cpt=0,k1=0,i=0,k=0,j=0,jk=0,k2=0,k3=0,ij=0,l=0;
int lv=0, vlv=0, kl=0;
int ng=0;
int vpopbased;
+ int ioffset; /* variable offset for columns */
+
/* if((ficgp=fopen(optionfilegnuplot,"a"))==NULL) { */
/* printf("Problem with file %s",optionfilegnuplot); */
/* fprintf(ficlog,"Problem with file %s",optionfilegnuplot); */
@@ -5661,7 +5733,7 @@ true period expectancies (those weighted
fprintf(ficgp,"unset log;\n# plot weighted, mean weight should have point size of 0.5\n plot \"%s\"",subdirf(fileresilk));
fprintf(ficgp," u 2:($5 == %d && $6==%d ? $10 : 1/0):($12/4.):6 t \"p%d%d\" with points pointtype 7 ps variable lc variable \\\n",i,1,i,1);
for (j=2; j<= nlstate+ndeath ; j ++) {
- fprintf(ficgp,",\\\n \"\" u 2:($5 == %d && $6==%d ? $10 : 1/0):($12/4.):6 t \"p%d%d\" with points pointtype 7 ps variable lc variable ",i,j,i,j);
+ fprintf(ficgp,",\\\n \"\" u 2:($5 == %d && $6==%d ? $10 : 1/0):($12/4.):6 t \"p%d%d\" with points pointtype 7 ps variable lc variable ",i,j,i,j);
}
fprintf(ficgp,";\nset out; unset ylabel;\n");
}
@@ -5675,223 +5747,277 @@ true period expectancies (those weighted
strcpy(optfileres,"vpl");
/* 1eme*/
for (cpt=1; cpt<= nlstate ; cpt ++) { /* For each live state */
- for (k1=1; k1<= m ; k1 ++) { /* For each combination of covariate */
+ for (k1=1; k1<= m ; k1 ++) { /* For each valid combination of covariate */
/* plot [100000000000000000000:-100000000000000000000] "mysbiaspar/vplrmysbiaspar.txt to check */
fprintf(ficgp,"\n# 1st: Period (stable) prevalence with CI: 'VPL_' files ");
- 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 */
- /* decodtabm(1,1,4) = 1 because h=1 k= (1) 1 1 1 */
- /* decodtabm(1,2,4) = 1 because h=1 k= 1 (1) 1 1 */
- /* decodtabm(13,3,4)= 2 because h=13 k= 1 1 (2) 2 */
- vlv= nbcode[Tvaraff[lv]][lv];
- fprintf(ficgp," V%d=%d ",k,vlv);
+ 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 */
+ /* decodtabm(1,1,4) = 1 because h=1 k= (1) 1 1 1 */
+ /* decodtabm(1,2,4) = 1 because h=1 k= 1 (1) 1 1 */
+ /* decodtabm(13,3,4)= 2 because h=13 k= 1 1 (2) 2 */
+ vlv= nbcode[Tvaraff[k]][lv]; /* vlv is the value of the covariate lv, 0 or 1 */
+ /* For each combination of covariate k1 (V1=1, V3=0), we printed the current covariate k and its value vlv */
+ fprintf(ficgp," V%d=%d ",Tvaraff[k],vlv);
}
fprintf(ficgp,"\n#\n");
+ if(invalidvarcomb[k1]){
+ fprintf(ficgp,"#Combination (%d) ignored because no cases \n",k1);
+ continue;
+ }
- fprintf(ficgp,"\nset out \"%s_%d-%d.svg\" \n",subdirf2(optionfilefiname,"V_"),cpt,k1);
- fprintf(ficgp,"\n#set out \"V_%s_%d-%d.svg\" \n",optionfilefiname,cpt,k1);
- fprintf(ficgp,"set xlabel \"Age\" \n\
-set ylabel \"Probability\" \n\
-set ter svg size 640, 480\n\
+ fprintf(ficgp,"\nset out \"%s_%d-%d.svg\" \n",subdirf2(optionfilefiname,"V_"),cpt,k1);
+ fprintf(ficgp,"\n#set out \"V_%s_%d-%d.svg\" \n",optionfilefiname,cpt,k1);
+ fprintf(ficgp,"set xlabel \"Age\" \n\
+set ylabel \"Probability\" \n \
+set ter svg size 640, 480\n \
plot [%.f:%.f] \"%s\" every :::%d::%d u 1:2 \"%%lf",ageminpar,fage,subdirf2(fileresu,"VPL_"),k1-1,k1-1);
-
- for (i=1; i<= nlstate ; i ++) {
- if (i==cpt) 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+1.96*$3) \"%%lf",subdirf2(fileresu,"VPL_"),k1-1,k1-1);
- for (i=1; i<= nlstate ; i ++) {
- if (i==cpt) fprintf(ficgp," %%lf (%%lf)");
- else fprintf(ficgp," %%*lf (%%*lf)");
- }
- fprintf(ficgp,"\" t\"95%% CI\" w l lt 1,\"%s\" every :::%d::%d u 1:($2-1.96*$3) \"%%lf",subdirf2(fileresu,"VPL_"),k1-1,k1-1);
- for (i=1; i<= nlstate ; i ++) {
- if (i==cpt) fprintf(ficgp," %%lf (%%lf)");
- else fprintf(ficgp," %%*lf (%%*lf)");
- }
- fprintf(ficgp,"\" t\"\" w l lt 1,\"%s\" every :::%d::%d u 1:($%d) t\"Observed prevalence\" w l lt 2",subdirf2(fileresu,"P_"),k1-1,k1-1,2+4*(cpt-1));
- if(backcast==1){
- fprintf(ficgp,",\"%s\" every :::%d::%d u 1:($%d) t\"Backward stable prevalence\" w l lt 3",subdirf2(fileresu,"PLB_"),k1-1,k1-1,1+cpt);
- }
- fprintf(ficgp,"\nset out \n");
+
+ for (i=1; i<= nlstate ; i ++) {
+ if (i==cpt) 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+1.96*$3) \"%%lf",subdirf2(fileresu,"VPL_"),k1-1,k1-1);
+ for (i=1; i<= nlstate ; i ++) {
+ if (i==cpt) fprintf(ficgp," %%lf (%%lf)");
+ else fprintf(ficgp," %%*lf (%%*lf)");
+ }
+ fprintf(ficgp,"\" t\"95%% CI\" w l lt 1,\"%s\" every :::%d::%d u 1:($2-1.96*$3) \"%%lf",subdirf2(fileresu,"VPL_"),k1-1,k1-1);
+ for (i=1; i<= nlstate ; i ++) {
+ if (i==cpt) fprintf(ficgp," %%lf (%%lf)");
+ else fprintf(ficgp," %%*lf (%%*lf)");
+ }
+ fprintf(ficgp,"\" t\"\" w l lt 1,\"%s\" every :::%d::%d u 1:($%d) t\"Observed prevalence\" w l lt 2",subdirf2(fileresu,"P_"),k1-1,k1-1,2+4*(cpt-1));
+ if(backcast==1){ /* We need to get the corresponding values of the covariates involved in this combination k1 */
+ /* fprintf(ficgp,",\"%s\" every :::%d::%d u 1:($%d) t\"Backward stable prevalence\" w l lt 3",subdirf2(fileresu,"PLB_"),k1-1,k1-1,1+cpt); */
+ fprintf(ficgp,",\"%s\" u 1:((",subdirf2(fileresu,"PLB_")); /* Age is in 1 */
+ kl=0;
+ for (k=1; k<=cptcoveff; k++){ /* For each combination of 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,2,4) = 1 because h=1 k= 1 (1) 1 1 */
+ /* decodtabm(13,3,4)= 2 because h=13 k= 1 1 (2) 2 */
+ vlv= nbcode[Tvaraff[k]][lv];
+ kl++;
+ /* kl=6+(cpt-1)*(nlstate+1)+1+(i-1); /\* 6+(1-1)*(2+1)+1+(1-1)=7, 6+(2-1)(2+1)+1+(1-1)=10 *\/ */
+ /*6+(cpt-1)*(nlstate+1)+1+(i-1)+(nlstate+1)*nlstate; 6+(1-1)*(2+1)+1+(1-1) +(2+1)*2=13 */
+ /*6+1+(i-1)+(nlstate+1)*nlstate; 6+1+(1-1) +(2+1)*2=13 */
+ /* '' u 6:(($1==1 && $2==0 && $3==2 && $4==0)? $9/(1.-$15) : 1/0):($5==2000? 3:2) t 'p.1' with line lc variable*/
+ if(k==cptcoveff){
+ fprintf(ficgp,"$%d==%d && $%d==%d)? $%d : 1/0) t 'Backward prevalence in state %d' with line ",kl+1, Tvaraff[k],kl+1+1,nbcode[Tvaraff[k]][lv], \
+ 6+(cpt-1), cpt );
+ }else{
+ fprintf(ficgp,"$%d==%d && $%d==%d && ",kl+1, Tvaraff[k],kl+1+1,nbcode[Tvaraff[k]][lv]);
+ kl++;
+ }
+ } /* end covariate */
+ }
+ fprintf(ficgp,"\nset out \n");
} /* k1 */
} /* cpt */
/*2 eme*/
for (k1=1; k1<= m ; k1 ++) {
+
fprintf(ficgp,"\n# 2nd: Total life expectancy with CI: 't' files ");
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 */
- /* decodtabm(1,1,4) = 1 because h=1 k= (1) 1 1 1 */
- /* decodtabm(1,2,4) = 1 because h=1 k= 1 (1) 1 1 */
- /* decodtabm(13,3,4)= 2 because h=13 k= 1 1 (2) 2 */
- vlv= nbcode[Tvaraff[lv]][lv];
- fprintf(ficgp," V%d=%d ",k,vlv);
+ 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,2,4) = 1 because h=1 k= 1 (1) 1 1 */
+ /* decodtabm(13,3,4)= 2 because h=13 k= 1 1 (2) 2 */
+ vlv= nbcode[Tvaraff[k]][lv];
+ fprintf(ficgp," V%d=%d ",Tvaraff[k],vlv);
}
fprintf(ficgp,"\n#\n");
-
- fprintf(ficgp,"\nset out \"%s_%d.svg\" \n",subdirf2(optionfilefiname,"E_"),k1);
- for(vpopbased=0; vpopbased <= popbased; vpopbased++){ /* Done for vpopbased=0 and vpopbased=1 if popbased==1*/
- if(vpopbased==0)
- fprintf(ficgp,"set ylabel \"Years\" \nset ter svg size 640, 480\nplot [%.f:%.f] ",ageminpar,fage);
- else
- fprintf(ficgp,"\nreplot ");
- for (i=1; i<= nlstate+1 ; i ++) {
- k=2*i;
- fprintf(ficgp,"\"%s\" every :::%d::%d u 1:($2==%d && $4!=0 ?$4 : 1/0) \"%%lf %%lf %%lf",subdirf2(fileresu,"T_"),k1-1,k1-1, vpopbased);
- for (j=1; j<= nlstate+1 ; j ++) {
- if (j==i) fprintf(ficgp," %%lf (%%lf)");
- else fprintf(ficgp," %%*lf (%%*lf)");
- }
- if (i== 1) fprintf(ficgp,"\" t\"TLE\" w l lt %d, \\\n",i);
- else fprintf(ficgp,"\" t\"LE in state (%d)\" w l lt %d, \\\n",i-1,i+1);
- fprintf(ficgp,"\"%s\" every :::%d::%d u 1:($2==%d && $4!=0 ? $4-$5*2 : 1/0) \"%%lf %%lf %%lf",subdirf2(fileresu,"T_"),k1-1,k1-1,vpopbased);
- for (j=1; j<= nlstate+1 ; j ++) {
- if (j==i) fprintf(ficgp," %%lf (%%lf)");
- else fprintf(ficgp," %%*lf (%%*lf)");
- }
- fprintf(ficgp,"\" t\"\" w l lt 0,");
- fprintf(ficgp,"\"%s\" every :::%d::%d u 1:($2==%d && $4!=0 ? $4+$5*2 : 1/0) \"%%lf %%lf %%lf",subdirf2(fileresu,"T_"),k1-1,k1-1,vpopbased);
- for (j=1; j<= nlstate+1 ; j ++) {
- if (j==i) fprintf(ficgp," %%lf (%%lf)");
- else fprintf(ficgp," %%*lf (%%*lf)");
- }
- if (i== (nlstate+1)) fprintf(ficgp,"\" t\"\" w l lt 0");
- else fprintf(ficgp,"\" t\"\" w l lt 0,\\\n");
- } /* state */
- } /* vpopbased */
- fprintf(ficgp,"\nset out;set out \"%s_%d.svg\"; replot; set out; \n",subdirf2(optionfilefiname,"E_"),k1); /* Buggy gnuplot */
+ if(invalidvarcomb[k1]){
+ fprintf(ficgp,"#Combination (%d) ignored because no cases \n",k1);
+ continue;
+ }
+
+ fprintf(ficgp,"\nset out \"%s_%d.svg\" \n",subdirf2(optionfilefiname,"E_"),k1);
+ for(vpopbased=0; vpopbased <= popbased; vpopbased++){ /* Done for vpopbased=0 and vpopbased=1 if popbased==1*/
+ if(vpopbased==0)
+ fprintf(ficgp,"set ylabel \"Years\" \nset ter svg size 640, 480\nplot [%.f:%.f] ",ageminpar,fage);
+ else
+ fprintf(ficgp,"\nreplot ");
+ for (i=1; i<= nlstate+1 ; i ++) {
+ k=2*i;
+ fprintf(ficgp,"\"%s\" every :::%d::%d u 1:($2==%d && $4!=0 ?$4 : 1/0) \"%%lf %%lf %%lf",subdirf2(fileresu,"T_"),k1-1,k1-1, vpopbased);
+ for (j=1; j<= nlstate+1 ; j ++) {
+ if (j==i) fprintf(ficgp," %%lf (%%lf)");
+ else fprintf(ficgp," %%*lf (%%*lf)");
+ }
+ if (i== 1) fprintf(ficgp,"\" t\"TLE\" w l lt %d, \\\n",i);
+ else fprintf(ficgp,"\" t\"LE in state (%d)\" w l lt %d, \\\n",i-1,i+1);
+ fprintf(ficgp,"\"%s\" every :::%d::%d u 1:($2==%d && $4!=0 ? $4-$5*2 : 1/0) \"%%lf %%lf %%lf",subdirf2(fileresu,"T_"),k1-1,k1-1,vpopbased);
+ for (j=1; j<= nlstate+1 ; j ++) {
+ if (j==i) fprintf(ficgp," %%lf (%%lf)");
+ else fprintf(ficgp," %%*lf (%%*lf)");
+ }
+ fprintf(ficgp,"\" t\"\" w l lt 0,");
+ fprintf(ficgp,"\"%s\" every :::%d::%d u 1:($2==%d && $4!=0 ? $4+$5*2 : 1/0) \"%%lf %%lf %%lf",subdirf2(fileresu,"T_"),k1-1,k1-1,vpopbased);
+ for (j=1; j<= nlstate+1 ; j ++) {
+ if (j==i) fprintf(ficgp," %%lf (%%lf)");
+ else fprintf(ficgp," %%*lf (%%*lf)");
+ }
+ if (i== (nlstate+1)) fprintf(ficgp,"\" t\"\" w l lt 0");
+ else fprintf(ficgp,"\" t\"\" w l lt 0,\\\n");
+ } /* state */
+ } /* vpopbased */
+ fprintf(ficgp,"\nset out;set out \"%s_%d.svg\"; replot; set out; \n",subdirf2(optionfilefiname,"E_"),k1); /* Buggy gnuplot */
} /* k1 */
-
-
+
+
/*3eme*/
for (k1=1; k1<= m ; k1 ++) {
+
for (cpt=1; cpt<= nlstate ; cpt ++) {
fprintf(ficgp,"\n# 3d: Life expectancy with EXP_ files: cov=%d state=%d",k1, cpt);
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 */
- /* decodtabm(1,1,4) = 1 because h=1 k= (1) 1 1 1 */
- /* decodtabm(1,2,4) = 1 because h=1 k= 1 (1) 1 1 */
- /* decodtabm(13,3,4)= 2 because h=13 k= 1 1 (2) 2 */
- vlv= nbcode[Tvaraff[lv]][lv];
- fprintf(ficgp," V%d=%d ",k,vlv);
+ 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,2,4) = 1 because h=1 k= 1 (1) 1 1 */
+ /* decodtabm(13,3,4)= 2 because h=13 k= 1 1 (2) 2 */
+ vlv= nbcode[Tvaraff[k]][lv];
+ fprintf(ficgp," V%d=%d ",Tvaraff[k],vlv);
}
fprintf(ficgp,"\n#\n");
-
+ if(invalidvarcomb[k1]){
+ fprintf(ficgp,"#Combination (%d) ignored because no cases \n",k1);
+ continue;
+ }
+
/* k=2+nlstate*(2*cpt-2); */
k=2+(nlstate+1)*(cpt-1);
fprintf(ficgp,"\nset out \"%s_%d%d.svg\" \n",subdirf2(optionfilefiname,"EXP_"),cpt,k1);
fprintf(ficgp,"set ter svg size 640, 480\n\
plot [%.f:%.f] \"%s\" every :::%d::%d u 1:%d t \"e%d1\" w l",ageminpar,fage,subdirf2(fileresu,"E_"),k1-1,k1-1,k,cpt);
/*fprintf(ficgp,",\"e%s\" every :::%d::%d u 1:($%d-2*$%d) \"\%%lf ",fileres,k1-1,k1-1,k,k+1);
- for (i=1; i<= nlstate*2 ; i ++) fprintf(ficgp,"\%%lf (\%%lf) ");
- fprintf(ficgp,"\" t \"e%d1\" w l",cpt);
- fprintf(ficgp,",\"e%s\" every :::%d::%d u 1:($%d+2*$%d) \"\%%lf ",fileres,k1-1,k1-1,k,k+1);
- for (i=1; i<= nlstate*2 ; i ++) fprintf(ficgp,"\%%lf (\%%lf) ");
- fprintf(ficgp,"\" t \"e%d1\" w l",cpt);
-
+ for (i=1; i<= nlstate*2 ; i ++) fprintf(ficgp,"\%%lf (\%%lf) ");
+ fprintf(ficgp,"\" t \"e%d1\" w l",cpt);
+ fprintf(ficgp,",\"e%s\" every :::%d::%d u 1:($%d+2*$%d) \"\%%lf ",fileres,k1-1,k1-1,k,k+1);
+ for (i=1; i<= nlstate*2 ; i ++) fprintf(ficgp,"\%%lf (\%%lf) ");
+ fprintf(ficgp,"\" t \"e%d1\" w l",cpt);
+
*/
for (i=1; i< nlstate ; i ++) {
- fprintf(ficgp," ,\"%s\" every :::%d::%d u 1:%d t \"e%d%d\" w l",subdirf2(fileresu,"E_"),k1-1,k1-1,k+i,cpt,i+1);
- /* fprintf(ficgp," ,\"%s\" every :::%d::%d u 1:%d t \"e%d%d\" w l",subdirf2(fileres,"e"),k1-1,k1-1,k+2*i,cpt,i+1);*/
-
+ fprintf(ficgp," ,\"%s\" every :::%d::%d u 1:%d t \"e%d%d\" w l",subdirf2(fileresu,"E_"),k1-1,k1-1,k+i,cpt,i+1);
+ /* fprintf(ficgp," ,\"%s\" every :::%d::%d u 1:%d t \"e%d%d\" w l",subdirf2(fileres,"e"),k1-1,k1-1,k+2*i,cpt,i+1);*/
+
}
fprintf(ficgp," ,\"%s\" every :::%d::%d u 1:%d t \"e%d.\" w l",subdirf2(fileresu,"E_"),k1-1,k1-1,k+nlstate,cpt);
}
}
+ /* 4eme */
/* Survival functions (period) from state i in state j by initial state i */
for (k1=1; k1<= m ; k1 ++) { /* For each multivariate if any */
+
for (cpt=1; cpt<=nlstate ; cpt ++) { /* For each life state */
fprintf(ficgp,"\n#\n#\n# Survival functions in state j : 'LIJ_' files, cov=%d state=%d",k1, cpt);
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 */
- /* decodtabm(1,1,4) = 1 because h=1 k= (1) 1 1 1 */
- /* decodtabm(1,2,4) = 1 because h=1 k= 1 (1) 1 1 */
- /* decodtabm(13,3,4)= 2 because h=13 k= 1 1 (2) 2 */
- vlv= nbcode[Tvaraff[lv]][lv];
- fprintf(ficgp," V%d=%d ",k,vlv);
+ 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,2,4) = 1 because h=1 k= 1 (1) 1 1 */
+ /* decodtabm(13,3,4)= 2 because h=13 k= 1 1 (2) 2 */
+ vlv= nbcode[Tvaraff[k]][lv];
+ fprintf(ficgp," V%d=%d ",Tvaraff[k],vlv);
}
fprintf(ficgp,"\n#\n");
-
+ if(invalidvarcomb[k1]){
+ fprintf(ficgp,"#Combination (%d) ignored because no cases \n",k1);
+ continue;
+ }
+
fprintf(ficgp,"\nset out \"%s_%d-%d.svg\" \n",subdirf2(optionfilefiname,"LIJ_"),cpt,k1);
fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability to be alive\" \n\
-set ter svg size 640, 480\n\
-unset log y\n\
+set ter svg size 640, 480\n \
+unset log y\n \
plot [%.f:%.f] ", ageminpar, agemaxpar);
k=3;
for (i=1; i<= nlstate ; i ++){
- if(i==1){
- fprintf(ficgp,"\"%s\"",subdirf2(fileresu,"PIJ_"));
- }else{
- fprintf(ficgp,", '' ");
- }
- l=(nlstate+ndeath)*(i-1)+1;
- fprintf(ficgp," u ($1==%d ? ($3):1/0):($%d/($%d",k1,k+l+(cpt-1),k+l);
- for (j=2; j<= nlstate+ndeath ; j ++)
- fprintf(ficgp,"+$%d",k+l+j-1);
- fprintf(ficgp,")) t \"l(%d,%d)\" w l",i,cpt);
+ if(i==1){
+ fprintf(ficgp,"\"%s\"",subdirf2(fileresu,"PIJ_"));
+ }else{
+ fprintf(ficgp,", '' ");
+ }
+ l=(nlstate+ndeath)*(i-1)+1;
+ fprintf(ficgp," u ($1==%d ? ($3):1/0):($%d/($%d",k1,k+l+(cpt-1),k+l);
+ for (j=2; j<= nlstate+ndeath ; j ++)
+ fprintf(ficgp,"+$%d",k+l+j-1);
+ fprintf(ficgp,")) t \"l(%d,%d)\" w l",i,cpt);
} /* nlstate */
fprintf(ficgp,"\nset out\n");
} /* end cpt state*/
} /* end covariate */
-
+
+/* 5eme */
/* Survival functions (period) from state i in state j by final state j */
for (k1=1; k1<= m ; k1 ++) { /* For each covariate if any */
for (cpt=1; cpt<=nlstate ; cpt ++) { /* For each inital state */
+
fprintf(ficgp,"\n#\n#\n# Survival functions in state j and all livestates from state i by final state j: 'lij' files, cov=%d state=%d",k1, cpt);
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 */
- /* decodtabm(1,1,4) = 1 because h=1 k= (1) 1 1 1 */
- /* decodtabm(1,2,4) = 1 because h=1 k= 1 (1) 1 1 */
- /* decodtabm(13,3,4)= 2 because h=13 k= 1 1 (2) 2 */
- vlv= nbcode[Tvaraff[lv]][lv];
- fprintf(ficgp," V%d=%d ",k,vlv);
+ 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,2,4) = 1 because h=1 k= 1 (1) 1 1 */
+ /* decodtabm(13,3,4)= 2 because h=13 k= 1 1 (2) 2 */
+ vlv= nbcode[Tvaraff[k]][lv];
+ fprintf(ficgp," V%d=%d ",Tvaraff[k],vlv);
}
fprintf(ficgp,"\n#\n");
-
+ if(invalidvarcomb[k1]){
+ fprintf(ficgp,"#Combination (%d) ignored because no cases \n",k1);
+ continue;
+ }
+
fprintf(ficgp,"\nset out \"%s_%d-%d.svg\" \n",subdirf2(optionfilefiname,"LIJT_"),cpt,k1);
fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability to be alive\" \n\
-set ter svg size 640, 480\n\
-unset log y\n\
+set ter svg size 640, 480\n \
+unset log y\n \
plot [%.f:%.f] ", ageminpar, agemaxpar);
k=3;
for (j=1; j<= nlstate ; j ++){ /* Lived in state j */
- if(j==1)
- fprintf(ficgp,"\"%s\"",subdirf2(fileresu,"PIJ_"));
- else
- fprintf(ficgp,", '' ");
- l=(nlstate+ndeath)*(cpt-1) +j;
- fprintf(ficgp," u (($1==%d && (floor($2)%%5 == 0)) ? ($3):1/0):($%d",k1,k+l);
- /* for (i=2; i<= nlstate+ndeath ; i ++) */
- /* fprintf(ficgp,"+$%d",k+l+i-1); */
- fprintf(ficgp,") t \"l(%d,%d)\" w l",cpt,j);
+ if(j==1)
+ fprintf(ficgp,"\"%s\"",subdirf2(fileresu,"PIJ_"));
+ else
+ fprintf(ficgp,", '' ");
+ l=(nlstate+ndeath)*(cpt-1) +j;
+ fprintf(ficgp," u (($1==%d && (floor($2)%%5 == 0)) ? ($3):1/0):($%d",k1,k+l);
+ /* for (i=2; i<= nlstate+ndeath ; i ++) */
+ /* fprintf(ficgp,"+$%d",k+l+i-1); */
+ fprintf(ficgp,") t \"l(%d,%d)\" w l",cpt,j);
} /* nlstate */
fprintf(ficgp,", '' ");
fprintf(ficgp," u (($1==%d && (floor($2)%%5 == 0)) ? ($3):1/0):(",k1);
for (j=1; j<= nlstate ; j ++){ /* Lived in state j */
- l=(nlstate+ndeath)*(cpt-1) +j;
- if(j < nlstate)
- fprintf(ficgp,"$%d +",k+l);
- else
- fprintf(ficgp,"$%d) t\"l(%d,.)\" w l",k+l,cpt);
+ l=(nlstate+ndeath)*(cpt-1) +j;
+ if(j < nlstate)
+ fprintf(ficgp,"$%d +",k+l);
+ else
+ fprintf(ficgp,"$%d) t\"l(%d,.)\" w l",k+l,cpt);
}
fprintf(ficgp,"\nset out\n");
} /* end cpt state*/
} /* end covariate */
-
+
+/* 6eme */
/* CV preval stable (period) for each covariate */
for (k1=1; k1<= m ; k1 ++) { /* For each covariate combination (1 to m=2**k), if any covariate is present */
for (cpt=1; cpt<=nlstate ; cpt ++) { /* For each life state */
+
fprintf(ficgp,"\n#\n#\n#CV preval stable (period): 'pij' files, covariatecombination#=%d state=%d",k1, cpt);
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 */
- /* decodtabm(1,1,4) = 1 because h=1 k= (1) 1 1 1 */
- /* decodtabm(1,2,4) = 1 because h=1 k= 1 (1) 1 1 */
- /* decodtabm(13,3,4)= 2 because h=13 k= 1 1 (2) 2 */
- vlv= nbcode[Tvaraff[lv]][lv];
- fprintf(ficgp," V%d=%d ",k,vlv);
+ 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,2,4) = 1 because h=1 k= 1 (1) 1 1 */
+ /* decodtabm(13,3,4)= 2 because h=13 k= 1 1 (2) 2 */
+ vlv= nbcode[Tvaraff[k]][lv];
+ fprintf(ficgp," V%d=%d ",Tvaraff[k],vlv);
}
fprintf(ficgp,"\n#\n");
+ if(invalidvarcomb[k1]){
+ fprintf(ficgp,"#Combination (%d) ignored because no cases \n",k1);
+ continue;
+ }
fprintf(ficgp,"\nset out \"%s_%d-%d.svg\" \n",subdirf2(optionfilefiname,"P_"),cpt,k1);
fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability\" \n\
@@ -5900,140 +6026,162 @@ unset log y\n\
plot [%.f:%.f] ", ageminpar, agemaxpar);
k=3; /* Offset */
for (i=1; i<= nlstate ; i ++){
- if(i==1)
- fprintf(ficgp,"\"%s\"",subdirf2(fileresu,"PIJ_"));
- else
- fprintf(ficgp,", '' ");
- l=(nlstate+ndeath)*(i-1)+1;
- fprintf(ficgp," u ($1==%d ? ($3):1/0):($%d/($%d",k1,k+l+(cpt-1),k+l);
- for (j=2; j<= nlstate ; j ++)
- fprintf(ficgp,"+$%d",k+l+j-1);
- fprintf(ficgp,")) t \"prev(%d,%d)\" w l",i,cpt);
+ if(i==1)
+ fprintf(ficgp,"\"%s\"",subdirf2(fileresu,"PIJ_"));
+ else
+ fprintf(ficgp,", '' ");
+ l=(nlstate+ndeath)*(i-1)+1;
+ fprintf(ficgp," u ($1==%d ? ($3):1/0):($%d/($%d",k1,k+l+(cpt-1),k+l);
+ for (j=2; j<= nlstate ; j ++)
+ fprintf(ficgp,"+$%d",k+l+j-1);
+ fprintf(ficgp,")) t \"prev(%d,%d)\" w l",i,cpt);
} /* nlstate */
fprintf(ficgp,"\nset out\n");
} /* end cpt state*/
} /* end covariate */
+
+
+/* 7eme */
if(backcast == 1){
/* CV back preval stable (period) for each covariate */
for (k1=1; k1<= m ; k1 ++) { /* For each covariate combination (1 to m=2**k), if any covariate is present */
for (cpt=1; cpt<=nlstate ; cpt ++) { /* For each life state */
- fprintf(ficgp,"\n#\n#\n#CV Back preval stable (period): 'pij' files, covariatecombination#=%d state=%d",k1, cpt);
- 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 */
- /* decodtabm(1,1,4) = 1 because h=1 k= (1) 1 1 1 */
- /* decodtabm(1,2,4) = 1 because h=1 k= 1 (1) 1 1 */
- /* decodtabm(13,3,4)= 2 because h=13 k= 1 1 (2) 2 */
- vlv= nbcode[Tvaraff[lv]][lv];
- fprintf(ficgp," V%d=%d ",k,vlv);
- }
- fprintf(ficgp,"\n#\n");
-
- fprintf(ficgp,"\nset out \"%s_%d-%d.svg\" \n",subdirf2(optionfilefiname,"PB_"),cpt,k1);
- fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability\" \n\
-set ter svg size 640, 480\n \
-unset log y\n \
-plot [%.f:%.f] ", ageminpar, agemaxpar);
- k=3; /* Offset */
- for (i=1; i<= nlstate ; i ++){
- if(i==1)
- fprintf(ficgp,"\"%s\"",subdirf2(fileresu,"PIJB_"));
- else
- fprintf(ficgp,", '' ");
- /* l=(nlstate+ndeath)*(i-1)+1; */
- l=(nlstate+ndeath)*(cpt-1)+1;
- /* fprintf(ficgp," u ($1==%d ? ($3):1/0):($%d/($%d",k1,k+l+(cpt-1),k+l); /\* a vérifier *\/ */
- /* fprintf(ficgp," u ($1==%d ? ($3):1/0):($%d/($%d",k1,k+l+(cpt-1),k+l+(cpt-1)+i-1); /\* a vérifier *\/ */
- fprintf(ficgp," u ($1==%d ? ($3):1/0):($%d",k1,k+l+(cpt-1)+i-1); /* a vérifier */
- /* for (j=2; j<= nlstate ; j ++) */
- /* fprintf(ficgp,"+$%d",k+l+j-1); */
- /* /\* fprintf(ficgp,"+$%d",k+l+j-1); *\/ */
- fprintf(ficgp,") t \"bprev(%d,%d)\" w l",i,cpt);
- } /* nlstate */
- fprintf(ficgp,"\nset out\n");
+ fprintf(ficgp,"\n#\n#\n#CV Back preval stable (period): 'pij' files, covariatecombination#=%d state=%d",k1, cpt);
+ 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 */
+ /* decodtabm(1,1,4) = 1 because h=1 k= (1) 1 1 1 */
+ /* decodtabm(1,2,4) = 1 because h=1 k= 1 (1) 1 1 */
+ /* decodtabm(13,3,4)= 2 because h=13 k= 1 1 (2) 2 */
+ vlv= nbcode[Tvaraff[k]][lv];
+ fprintf(ficgp," V%d=%d ",Tvaraff[k],vlv);
+ }
+ fprintf(ficgp,"\n#\n");
+ if(invalidvarcomb[k1]){
+ fprintf(ficgp,"#Combination (%d) ignored because no cases \n",k1);
+ continue;
+ }
+
+ fprintf(ficgp,"\nset out \"%s_%d-%d.svg\" \n",subdirf2(optionfilefiname,"PB_"),cpt,k1);
+ fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability\" \n\
+set ter svg size 640, 480\n \
+unset log y\n \
+plot [%.f:%.f] ", ageminpar, agemaxpar);
+ k=3; /* Offset */
+ for (i=1; i<= nlstate ; i ++){
+ if(i==1)
+ fprintf(ficgp,"\"%s\"",subdirf2(fileresu,"PIJB_"));
+ else
+ fprintf(ficgp,", '' ");
+ /* l=(nlstate+ndeath)*(i-1)+1; */
+ l=(nlstate+ndeath)*(cpt-1)+1;
+ /* fprintf(ficgp," u ($1==%d ? ($3):1/0):($%d/($%d",k1,k+l+(cpt-1),k+l); /\* a vérifier *\/ */
+ /* fprintf(ficgp," u ($1==%d ? ($3):1/0):($%d/($%d",k1,k+l+(cpt-1),k+l+(cpt-1)+i-1); /\* a vérifier *\/ */
+ fprintf(ficgp," u ($1==%d ? ($3):1/0):($%d",k1,k+l+(cpt-1)+i-1); /* a vérifier */
+ /* for (j=2; j<= nlstate ; j ++) */
+ /* fprintf(ficgp,"+$%d",k+l+j-1); */
+ /* /\* fprintf(ficgp,"+$%d",k+l+j-1); *\/ */
+ fprintf(ficgp,") t \"bprev(%d,%d)\" w l",i,cpt);
+ } /* nlstate */
+ fprintf(ficgp,"\nset out\n");
} /* end cpt state*/
} /* end covariate */
} /* End if backcast */
+ /* 8eme */
if(prevfcast==1){
/* Projection from cross-sectional to stable (period) for each covariate */
for (k1=1; k1<= m ; k1 ++) { /* For each covariate combination (1 to m=2**k), if any covariate is present */
for (cpt=1; cpt<=nlstate ; cpt ++) { /* For each life state */
- fprintf(ficgp,"\n#\n#\n#Projection of prevalence to stable (period): 'PROJ_' files, covariatecombination#=%d state=%d",k1, cpt);
- 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 */
- /* decodtabm(1,1,4) = 1 because h=1 k= (1) 1 1 1 */
- /* decodtabm(1,2,4) = 1 because h=1 k= 1 (1) 1 1 */
- /* decodtabm(13,3,4)= 2 because h=13 k= 1 1 (2) 2 */
- vlv= nbcode[Tvaraff[lv]][lv];
- fprintf(ficgp," V%d=%d ",k,vlv);
- }
- fprintf(ficgp,"\n#\n");
-
- fprintf(ficgp,"# hpijx=probability over h years, hp.jx is weighted by observed prev\n ");
- fprintf(ficgp,"\nset out \"%s_%d-%d.svg\" \n",subdirf2(optionfilefiname,"PROJ_"),cpt,k1);
- fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Prevalence\" \n\
-set ter svg size 640, 480\n\
-unset log y\n\
+ fprintf(ficgp,"\n#\n#\n#Projection of prevalence to stable (period): 'PROJ_' files, covariatecombination#=%d state=%d",k1, cpt);
+ 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 */
+ /* decodtabm(1,1,4) = 1 because h=1 k= (1) 1 1 1 */
+ /* decodtabm(1,2,4) = 1 because h=1 k= 1 (1) 1 1 */
+ /* decodtabm(13,3,4)= 2 because h=13 k= 1 1 (2) 2 */
+ vlv= nbcode[Tvaraff[k]][lv];
+ fprintf(ficgp," V%d=%d ",Tvaraff[k],vlv);
+ }
+ fprintf(ficgp,"\n#\n");
+ if(invalidvarcomb[k1]){
+ fprintf(ficgp,"#Combination (%d) ignored because no cases \n",k1);
+ continue;
+ }
+
+ fprintf(ficgp,"# hpijx=probability over h years, hp.jx is weighted by observed prev\n ");
+ fprintf(ficgp,"\nset out \"%s_%d-%d.svg\" \n",subdirf2(optionfilefiname,"PROJ_"),cpt,k1);
+ fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Prevalence\" \n\
+set ter svg size 640, 480\n \
+unset log y\n \
plot [%.f:%.f] ", ageminpar, agemaxpar);
- for (i=1; i<= nlstate+1 ; i ++){ /* nlstate +1 p11 p21 p.1 */
- /*# V1 = 1 V2 = 0 yearproj age p11 p21 p.1 p12 p22 p.2 p13 p23 p.3*/
- /*# 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 */
- /*# yearproj age p11 p21 p.1 p12 p22 p.2 p13 p23 p.3*/
- /*# 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 */
- if(i==1){
- fprintf(ficgp,"\"%s\"",subdirf2(fileresu,"F_"));
- }else{
- fprintf(ficgp,",\\\n '' ");
- }
- if(cptcoveff ==0){ /* No covariate */
- fprintf(ficgp," u 2:("); /* Age is in 2 */
- /*# yearproj age p11 p21 p31 p.1 p12 p22 p32 p.2 p13 p23 p33 p.3 p14 p24 p34 p.4*/
- /*# 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 */
- if(i==nlstate+1)
- fprintf(ficgp," $%d/(1.-$%d)) t 'p.%d' with line ", \
- 2+(cpt-1)*(nlstate+1)+1+(i-1), 2+1+(i-1)+(nlstate+1)*nlstate,cpt );
- else
- fprintf(ficgp," $%d/(1.-$%d)) t 'p%d%d' with line ", \
- 2+(cpt-1)*(nlstate+1)+1+(i-1), 2+1+(i-1)+(nlstate+1)*nlstate,i,cpt );
- }else{
- fprintf(ficgp,"u 6:(("); /* Age is in 6 */
- /*# V1 = 1 V2 = 0 yearproj age p11 p21 p.1 p12 p22 p.2 p13 p23 p.3*/
- /*# 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 */
- kl=0;
- for (k=1; k<=cptcoveff; k++){ /* For each 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,2,4) = 1 because h=1 k= 1 (1) 1 1 */
- /* decodtabm(13,3,4)= 2 because h=13 k= 1 1 (2) 2 */
- vlv= nbcode[Tvaraff[lv]][lv];
- kl++;
- /* kl=6+(cpt-1)*(nlstate+1)+1+(i-1); /\* 6+(1-1)*(2+1)+1+(1-1)=7, 6+(2-1)(2+1)+1+(1-1)=10 *\/ */
- /*6+(cpt-1)*(nlstate+1)+1+(i-1)+(nlstate+1)*nlstate; 6+(1-1)*(2+1)+1+(1-1) +(2+1)*2=13 */
- /*6+1+(i-1)+(nlstate+1)*nlstate; 6+1+(1-1) +(2+1)*2=13 */
- /* '' u 6:(($1==1 && $2==0 && $3==2 && $4==0)? $9/(1.-$15) : 1/0):($5==2000? 3:2) t 'p.1' with line lc variable*/
- if(k==cptcoveff)
- if(i==nlstate+1)
- fprintf(ficgp,"$%d==%d && $%d==%d)? $%d/(1.-$%d) : 1/0) t 'p.%d' with line ",kl, k,kl+1,nbcode[Tvaraff[lv]][lv], \
- 6+(cpt-1)*(nlstate+1)+1+(i-1), 6+1+(i-1)+(nlstate+1)*nlstate,cpt );
- else
- fprintf(ficgp,"$%d==%d && $%d==%d)? $%d/(1.-$%d) : 1/0) t 'p%d%d' with line ",kl, k,kl+1,nbcode[Tvaraff[lv]][lv], \
- 6+(cpt-1)*(nlstate+1)+1+(i-1), 6+1+(i-1)+(nlstate+1)*nlstate,i,cpt );
- else{
- fprintf(ficgp,"$%d==%d && $%d==%d && ",kl, k,kl+1,nbcode[Tvaraff[lv]][lv]);
- kl++;
- }
- } /* end covariate */
- } /* end if covariate */
- } /* nlstate */
- fprintf(ficgp,"\nset out\n");
- } /* end cpt state*/
- } /* end covariate */
- } /* End if prevfcast */
-
-
- /* proba elementaires */
- fprintf(ficgp,"\n##############\n#MLE estimated parameters\n#############\n");
+ for (i=1; i<= nlstate+1 ; i ++){ /* nlstate +1 p11 p21 p.1 */
+ /*# V1 = 1 V2 = 0 yearproj age p11 p21 p.1 p12 p22 p.2 p13 p23 p.3*/
+ /*# 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 */
+ /*# yearproj age p11 p21 p.1 p12 p22 p.2 p13 p23 p.3*/
+ /*# 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 */
+ if(i==1){
+ fprintf(ficgp,"\"%s\"",subdirf2(fileresu,"F_"));
+ }else{
+ fprintf(ficgp,",\\\n '' ");
+ }
+ if(cptcoveff ==0){ /* No covariate */
+ ioffset=2; /* Age is in 2 */
+ /*# yearproj age p11 p21 p31 p.1 p12 p22 p32 p.2 p13 p23 p33 p.3 p14 p24 p34 p.4*/
+ /*# 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 */
+ /*# V1 = 1 yearproj age p11 p21 p31 p.1 p12 p22 p32 p.2 p13 p23 p33 p.3 p14 p24 p34 p.4*/
+ /*# 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 */
+ fprintf(ficgp," u %d:(", ioffset);
+ if(i==nlstate+1)
+ fprintf(ficgp," $%d/(1.-$%d)) t 'pw.%d' with line ", \
+ ioffset+(cpt-1)*(nlstate+1)+1+(i-1), ioffset+1+(i-1)+(nlstate+1)*nlstate,cpt );
+ else
+ fprintf(ficgp," $%d/(1.-$%d)) t 'p%d%d' with line ", \
+ ioffset+(cpt-1)*(nlstate+1)+1+(i-1), ioffset+1+(i-1)+(nlstate+1)*nlstate,i,cpt );
+ }else{ /* more than 2 covariates */
+ if(cptcoveff ==1){
+ ioffset=4; /* Age is in 4 */
+ }else{
+ ioffset=6; /* Age is in 6 */
+ /*# V1 = 1 V2 = 0 yearproj age p11 p21 p.1 p12 p22 p.2 p13 p23 p.3*/
+ /*# 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 */
+ }
+ fprintf(ficgp," u %d:(",ioffset);
+ kl=0;
+ strcpy(gplotcondition,"(");
+ for (k=1; k<=cptcoveff; k++){ /* For each covariate writing the chain of conditions */
+ lv= decodtabm(k1,k,cptcoveff); /* Should be the covariate value corresponding to combination k1 and covariate k */
+ /* decodtabm(1,1,4) = 1 because h=1 k= (1) 1 1 1 */
+ /* decodtabm(1,2,4) = 1 because h=1 k= 1 (1) 1 1 */
+ /* decodtabm(13,3,4)= 2 because h=13 k= 1 1 (2) 2 */
+ vlv= nbcode[Tvaraff[k]][lv]; /* Value of the modality of Tvaraff[k] */
+ kl++;
+ sprintf(gplotcondition+strlen(gplotcondition),"$%d==%d && $%d==%d " ,kl,Tvaraff[k], kl+1, nbcode[Tvaraff[k]][lv]);
+ kl++;
+ if(k 1)
+ sprintf(gplotcondition+strlen(gplotcondition)," && ");
+ }
+ strcpy(gplotcondition+strlen(gplotcondition),")");
+ /* kl=6+(cpt-1)*(nlstate+1)+1+(i-1); /\* 6+(1-1)*(2+1)+1+(1-1)=7, 6+(2-1)(2+1)+1+(1-1)=10 *\/ */
+ /*6+(cpt-1)*(nlstate+1)+1+(i-1)+(nlstate+1)*nlstate; 6+(1-1)*(2+1)+1+(1-1) +(2+1)*2=13 */
+ /*6+1+(i-1)+(nlstate+1)*nlstate; 6+1+(1-1) +(2+1)*2=13 */
+ /* '' u 6:(($1==1 && $2==0 && $3==2 && $4==0)? $9/(1.-$15) : 1/0):($5==2000? 3:2) t 'p.1' with line lc variable*/
+ if(i==nlstate+1){
+ fprintf(ficgp,"%s ? $%d/(1.-$%d) : 1/0) t 'p.%d' with line ", gplotcondition, \
+ ioffset+(cpt-1)*(nlstate+1)+1+(i-1), ioffset+1+(i-1)+(nlstate+1)*nlstate,cpt );
+ }else{
+ fprintf(ficgp,"%s ? $%d/(1.-$%d) : 1/0) t 'p%d%d' with line ", gplotcondition, \
+ ioffset+(cpt-1)*(nlstate+1)+1+(i-1), ioffset +1+(i-1)+(nlstate+1)*nlstate,i,cpt );
+ }
+ } /* end if covariate */
+ } /* nlstate */
+ fprintf(ficgp,"\nset out\n");
+ } /* end cpt state*/
+ } /* end covariate */
+ } /* End if prevfcast */
+
+
+ /* proba elementaires */
+ fprintf(ficgp,"\n##############\n#MLE estimated parameters\n#############\n");
for(i=1,jk=1; i <=nlstate; i++){
fprintf(ficgp,"# initial state %d\n",i);
for(k=1; k <=(nlstate+ndeath); k++){
@@ -6175,119 +6323,151 @@ plot [%.f:%.f] ", ageminpar, agemaxpar)
/*************** Moving average **************/
- /* int movingaverage(double ***probs, double bage, double fage, double ***mobaverage, int mobilav, double bageout, double fageout){ */
+/* int movingaverage(double ***probs, double bage, double fage, double ***mobaverage, int mobilav, double bageout, double fageout){ */
int movingaverage(double ***probs, double bage, double fage, double ***mobaverage, int mobilav){
int i, cpt, cptcod;
int modcovmax =1;
int mobilavrange, mob;
- double age;
int iage=0;
+
+ double sum=0.;
+ double age;
double *sumnewp, *sumnewm;
double *agemingood, *agemaxgood; /* Currently identical for all covariates */
- sumnewp = vector(1,modcovmax);
- sumnewm = vector(1,modcovmax);
- agemingood = vector(1,modcovmax);
- agemaxgood = vector(1,modcovmax);
-
- modcovmax=2*cptcoveff;/* Max number of modalities. We suppose
- a covariate has 2 modalities, should be equal to ncovcombmax */
- if (cptcovn<1) modcovmax=1; /* At least 1 pass */
+ /* modcovmax=2*cptcoveff;/\* Max number of modalities. We suppose */
+ /* a covariate has 2 modalities, should be equal to ncovcombmax *\/ */
+
+ sumnewp = vector(1,ncovcombmax);
+ sumnewm = vector(1,ncovcombmax);
+ agemingood = vector(1,ncovcombmax);
+ agemaxgood = vector(1,ncovcombmax);
+
+ for (cptcod=1;cptcod<=ncovcombmax;cptcod++){
+ sumnewm[cptcod]=0.;
+ sumnewp[cptcod]=0.;
+ agemingood[cptcod]=0;
+ agemaxgood[cptcod]=0;
+ }
+ if (cptcovn<1) ncovcombmax=1; /* At least 1 pass */
if(mobilav==1||mobilav ==3 ||mobilav==5 ||mobilav== 7){
if(mobilav==1) mobilavrange=5; /* default */
else mobilavrange=mobilav;
for (age=bage; age<=fage; age++)
for (i=1; i<=nlstate;i++)
- for (cptcod=1;cptcod<=modcovmax;cptcod++)
- mobaverage[(int)age][i][cptcod]=probs[(int)age][i][cptcod];
+ for (cptcod=1;cptcod<=ncovcombmax;cptcod++)
+ mobaverage[(int)age][i][cptcod]=probs[(int)age][i][cptcod];
/* We keep the original values on the extreme ages bage, fage and for
fage+1 and bage-1 we use a 3 terms moving average; for fage+2 bage+2
we use a 5 terms etc. until the borders are no more concerned.
*/
for (mob=3;mob <=mobilavrange;mob=mob+2){
for (age=bage+(mob-1)/2; age<=fage-(mob-1)/2; age++){
- for (i=1; i<=nlstate;i++){
- for (cptcod=1;cptcod<=modcovmax;cptcod++){
- mobaverage[(int)age][i][cptcod] =probs[(int)age][i][cptcod];
- for (cpt=1;cpt<=(mob-1)/2;cpt++){
- mobaverage[(int)age][i][cptcod] +=probs[(int)age-cpt][i][cptcod];
- mobaverage[(int)age][i][cptcod] +=probs[(int)age+cpt][i][cptcod];
- }
- mobaverage[(int)age][i][cptcod]=mobaverage[(int)age][i][cptcod]/mob;
- }
- }
+ for (i=1; i<=nlstate;i++){
+ for (cptcod=1;cptcod<=ncovcombmax;cptcod++){
+ mobaverage[(int)age][i][cptcod] =probs[(int)age][i][cptcod];
+ for (cpt=1;cpt<=(mob-1)/2;cpt++){
+ mobaverage[(int)age][i][cptcod] +=probs[(int)age-cpt][i][cptcod];
+ mobaverage[(int)age][i][cptcod] +=probs[(int)age+cpt][i][cptcod];
+ }
+ mobaverage[(int)age][i][cptcod]=mobaverage[(int)age][i][cptcod]/mob;
+ }
+ }
}/* end age */
}/* end mob */
}else
return -1;
- for (cptcod=1;cptcod<=modcovmax;cptcod++){
+ for (cptcod=1;cptcod<=ncovcombmax;cptcod++){
/* for (age=bage+(mob-1)/2; age<=fage-(mob-1)/2; age++){ */
- agemingood[cptcod]=fage+(mob-1)/2;
+ agemingood[cptcod]=fage-(mob-1)/2;
for (age=fage-(mob-1)/2; age>=bage; age--){/* From oldest to youngest, finding the youngest wrong */
sumnewm[cptcod]=0.;
for (i=1; i<=nlstate;i++){
sumnewm[cptcod]+=mobaverage[(int)age][i][cptcod];
}
if(fabs(sumnewm[cptcod] - 1.) <= 1.e-3) { /* good */
- agemingood[cptcod]=age;
+ agemingood[cptcod]=age;
}else{ /* bad */
- for (i=1; i<=nlstate;i++){
- mobaverage[(int)age][i][cptcod]=mobaverage[(int)agemingood[cptcod]][i][cptcod];
- } /* i */
+ for (i=1; i<=nlstate;i++){
+ mobaverage[(int)age][i][cptcod]=mobaverage[(int)agemingood[cptcod]][i][cptcod];
+ } /* i */
} /* end bad */
}/* age */
- /* From youngest, finding the oldest wrong */
- agemaxgood[cptcod]=bage+(mob-1)/2;
- for (age=bage+(mob-1)/2; age<=fage; age++){
- sumnewm[cptcod]=0.;
- for (i=1; i<=nlstate;i++){
- sumnewm[cptcod]+=mobaverage[(int)age][i][cptcod];
- }
- if(fabs(sumnewm[cptcod] - 1.) <= 1.e-3) { /* good */
- agemaxgood[cptcod]=age;
- }else{ /* bad */
- for (i=1; i<=nlstate;i++){
- mobaverage[(int)age][i][cptcod]=mobaverage[(int)agemaxgood[cptcod]][i][cptcod];
- } /* i */
- } /* end bad */
- }/* age */
- for (age=bage; age<=fage; age++){
- printf("%d %d ", cptcod, (int)age);
- sumnewp[cptcod]=0.;
- sumnewm[cptcod]=0.;
- for (i=1; i<=nlstate;i++){
- sumnewp[cptcod]+=probs[(int)age][i][cptcod];
- sumnewm[cptcod]+=mobaverage[(int)age][i][cptcod];
- printf("%.4f %.4f ",probs[(int)age][i][cptcod], mobaverage[(int)age][i][cptcod]);
- }
- printf("%.4f %.4f \n",sumnewp[cptcod], sumnewm[cptcod]);
+ sum=0.;
+ for (i=1; i<=nlstate;i++){
+ sum+=mobaverage[(int)agemingood[cptcod]][i][cptcod];
}
- printf("\n");
+ if(fabs(sum - 1.) > 1.e-3) { /* bad */
+ printf("For this combination of covariate cptcod=%d, we can't get a smoothed prevalence which sums to one at any descending age!\n",cptcod);
+ /* for (i=1; i<=nlstate;i++){ */
+ /* mobaverage[(int)age][i][cptcod]=mobaverage[(int)agemingood[cptcod]][i][cptcod]; */
+ /* } /\* i *\/ */
+ } /* end bad */
+ /* else{ /\* We found some ages summing to one, we will smooth the oldest *\/ */
+ /* From youngest, finding the oldest wrong */
+ agemaxgood[cptcod]=bage+(mob-1)/2;
+ for (age=bage+(mob-1)/2; age<=fage; age++){
+ sumnewm[cptcod]=0.;
+ for (i=1; i<=nlstate;i++){
+ sumnewm[cptcod]+=mobaverage[(int)age][i][cptcod];
+ }
+ if(fabs(sumnewm[cptcod] - 1.) <= 1.e-3) { /* good */
+ agemaxgood[cptcod]=age;
+ }else{ /* bad */
+ for (i=1; i<=nlstate;i++){
+ mobaverage[(int)age][i][cptcod]=mobaverage[(int)agemaxgood[cptcod]][i][cptcod];
+ } /* i */
+ } /* end bad */
+ }/* age */
+ sum=0.;
+ for (i=1; i<=nlstate;i++){
+ sum+=mobaverage[(int)agemaxgood[cptcod]][i][cptcod];
+ }
+ if(fabs(sum - 1.) > 1.e-3) { /* bad */
+ printf("For this combination of covariate cptcod=%d, we can't get a smoothed prevalence which sums to one at any ascending age!\n",cptcod);
+ /* for (i=1; i<=nlstate;i++){ */
+ /* mobaverage[(int)age][i][cptcod]=mobaverage[(int)agemingood[cptcod]][i][cptcod]; */
+ /* } /\* i *\/ */
+ } /* end bad */
+
+ for (age=bage; age<=fage; age++){
+ printf("%d %d ", cptcod, (int)age);
+ sumnewp[cptcod]=0.;
+ sumnewm[cptcod]=0.;
+ for (i=1; i<=nlstate;i++){
+ sumnewp[cptcod]+=probs[(int)age][i][cptcod];
+ sumnewm[cptcod]+=mobaverage[(int)age][i][cptcod];
+ /* printf("%.4f %.4f ",probs[(int)age][i][cptcod], mobaverage[(int)age][i][cptcod]); */
+ }
+ /* printf("%.4f %.4f \n",sumnewp[cptcod], sumnewm[cptcod]); */
+ }
+ /* printf("\n"); */
+ /* } */
/* brutal averaging */
for (i=1; i<=nlstate;i++){
for (age=1; age<=bage; age++){
- mobaverage[(int)age][i][cptcod]=mobaverage[(int)agemingood[cptcod]][i][cptcod];
- printf("age=%d i=%d cptcod=%d mobaverage=%.4f \n",(int)age,i, cptcod, mobaverage[(int)age][i][cptcod]);
+ mobaverage[(int)age][i][cptcod]=mobaverage[(int)agemingood[cptcod]][i][cptcod];
+ /* printf("age=%d i=%d cptcod=%d mobaverage=%.4f \n",(int)age,i, cptcod, mobaverage[(int)age][i][cptcod]); */
}
for (age=fage; age<=AGESUP; age++){
- mobaverage[(int)age][i][cptcod]=mobaverage[(int)agemaxgood[cptcod]][i][cptcod];
- printf("age=%d i=%d cptcod=%d mobaverage=%.4f \n",(int)age,i, cptcod, mobaverage[(int)age][i][cptcod]);
+ mobaverage[(int)age][i][cptcod]=mobaverage[(int)agemaxgood[cptcod]][i][cptcod];
+ /* printf("age=%d i=%d cptcod=%d mobaverage=%.4f \n",(int)age,i, cptcod, mobaverage[(int)age][i][cptcod]); */
}
} /* end i status */
for (i=nlstate+1; i<=nlstate+ndeath;i++){
for (age=1; age<=AGESUP; age++){
- /*printf("i=%d, age=%d, cptcod=%d\n",i, (int)age, cptcod);*/
- mobaverage[(int)age][i][cptcod]=0.;
+ /*printf("i=%d, age=%d, cptcod=%d\n",i, (int)age, cptcod);*/
+ mobaverage[(int)age][i][cptcod]=0.;
}
}
}/* end cptcod */
- free_vector(sumnewm,1, modcovmax);
- free_vector(sumnewp,1, modcovmax);
- free_vector(agemaxgood,1, modcovmax);
- free_vector(agemingood,1, modcovmax);
+ free_vector(sumnewm,1, ncovcombmax);
+ free_vector(sumnewp,1, ncovcombmax);
+ free_vector(agemaxgood,1, ncovcombmax);
+ free_vector(agemingood,1, ncovcombmax);
return 0;
}/* End movingaverage */
@@ -6358,54 +6538,54 @@ void prevforecast(char fileres[], double
k=k+1;
fprintf(ficresf,"\n#****** hpijx=probability over h years, hp.jx is weighted by observed prev \n#");
for(j=1;j<=cptcoveff;j++) {
- fprintf(ficresf," V%d (=) %d",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
+ fprintf(ficresf," V%d (=) %d",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
}
fprintf(ficresf," yearproj age");
for(j=1; j<=nlstate+ndeath;j++){
- for(i=1; i<=nlstate;i++)
+ for(i=1; i<=nlstate;i++)
fprintf(ficresf," p%d%d",i,j);
- fprintf(ficresf," p.%d",j);
+ fprintf(ficresf," wp.%d",j);
}
for (yearp=0; yearp<=(anproj2-anproj1);yearp +=stepsize) {
- fprintf(ficresf,"\n");
- fprintf(ficresf,"\n# Forecasting at date %.lf/%.lf/%.lf ",jproj1,mproj1,anproj1+yearp);
- for (agec=fage; agec>=(ageminpar-1); agec--){
- nhstepm=(int) rint((agelim-agec)*YEARM/stepm);
- nhstepm = nhstepm/hstepm;
- p3mat=ma3x(1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);
- oldm=oldms;savm=savms;
- hpxij(p3mat,nhstepm,agec,hstepm,p,nlstate,stepm,oldm,savm, k);
-
- for (h=0; h<=nhstepm; h++){
- if (h*hstepm/YEARM*stepm ==yearp) {
+ fprintf(ficresf,"\n");
+ fprintf(ficresf,"\n# Forecasting at date %.lf/%.lf/%.lf ",jproj1,mproj1,anproj1+yearp);
+ for (agec=fage; agec>=(ageminpar-1); agec--){
+ nhstepm=(int) rint((agelim-agec)*YEARM/stepm);
+ nhstepm = nhstepm/hstepm;
+ p3mat=ma3x(1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);
+ oldm=oldms;savm=savms;
+ hpxij(p3mat,nhstepm,agec,hstepm,p,nlstate,stepm,oldm,savm, k);
+
+ for (h=0; h<=nhstepm; h++){
+ if (h*hstepm/YEARM*stepm ==yearp) {
fprintf(ficresf,"\n");
for(j=1;j<=cptcoveff;j++)
fprintf(ficresf,"%d %d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
- fprintf(ficresf,"%.f %.f ",anproj1+yearp,agec+h*hstepm/YEARM*stepm);
- }
- for(j=1; j<=nlstate+ndeath;j++) {
- ppij=0.;
- for(i=1; i<=nlstate;i++) {
- if (mobilav==1)
- ppij=ppij+p3mat[i][j][h]*mobaverage[(int)agec][i][cptcod];
- else {
- ppij=ppij+p3mat[i][j][h]*probs[(int)(agec)][i][cptcod];
- }
- if (h*hstepm/YEARM*stepm== yearp) {
- fprintf(ficresf," %.3f", p3mat[i][j][h]);
- }
- } /* end i */
- if (h*hstepm/YEARM*stepm==yearp) {
- fprintf(ficresf," %.3f", ppij);
- }
- }/* end j */
- } /* end h */
- free_ma3x(p3mat,1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);
- } /* end agec */
+ fprintf(ficresf,"%.f %.f ",anproj1+yearp,agec+h*hstepm/YEARM*stepm);
+ }
+ for(j=1; j<=nlstate+ndeath;j++) {
+ ppij=0.;
+ for(i=1; i<=nlstate;i++) {
+ if (mobilav==1)
+ ppij=ppij+p3mat[i][j][h]*mobaverage[(int)agec][i][cptcod];
+ else {
+ ppij=ppij+p3mat[i][j][h]*probs[(int)(agec)][i][cptcod];
+ }
+ if (h*hstepm/YEARM*stepm== yearp) {
+ fprintf(ficresf," %.3f", p3mat[i][j][h]);
+ }
+ } /* end i */
+ if (h*hstepm/YEARM*stepm==yearp) {
+ fprintf(ficresf," %.3f", ppij);
+ }
+ }/* end j */
+ } /* end h */
+ free_ma3x(p3mat,1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);
+ } /* end agec */
} /* end yearp */
} /* end cptcod */
} /* end cptcov */
-
+
fclose(ficresf);
printf("End of Computing forecasting \n");
fprintf(ficlog,"End of Computing forecasting\n");
@@ -6843,7 +7023,7 @@ double gompertz(double x[])
double A,B,L=0.0,sump=0.,num=0.;
int i,n=0; /* n is the size of the sample */
- for (i=0;i<=imx-1 ; i++) {
+ for (i=1;i<=imx ; i++) {
sump=sump+weight[i];
/* sump=sump+1;*/
num=num+1;
@@ -7656,9 +7836,9 @@ void syscompilerinfo(int logged)
#endif
- }
+}
- 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) --------------*/
int i, j, k, i1 ;
/* double ftolpl = 1.e-10; */
@@ -7679,55 +7859,62 @@ void syscompilerinfo(int logged)
for(i=1; i<=nlstate;i++) fprintf(ficrespl,"%d-%d ",i,i);
fprintf(ficrespl,"\n");
- /* prlim=matrix(1,nlstate,1,nlstate);*/ /* back in main */
+ /* prlim=matrix(1,nlstate,1,nlstate);*/ /* back in main */
- agebase=ageminpar;
- agelim=agemaxpar;
+ agebase=ageminpar;
+ agelim=agemaxpar;
- i1=pow(2,cptcoveff);
- if (cptcovn < 1){i1=1;}
+ i1=pow(2,cptcoveff);
+ if (cptcovn < 1){i1=1;}
- for(cptcov=1,k=0;cptcov<=i1;cptcov++){
+ for(k=1; k<=i1;k++){
+ /* for(cptcov=1,k=0;cptcov<=i1;cptcov++){ */
/* for(cptcov=1,k=0;cptcov<=1;cptcov++){ */
- //for(cptcod=1;cptcod<=ncodemax[cptcov];cptcod++){
- k=k+1;
- /* to clean */
- //printf("cptcov=%d cptcod=%d codtab=%d\n",cptcov, cptcod,codtabm(cptcod,cptcov));
- fprintf(ficrespl,"#******");
- printf("#******");
- fprintf(ficlog,"#******");
- for(j=1;j<=cptcoveff;j++) {
- fprintf(ficrespl," V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
- printf(" V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
- fprintf(ficlog," V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
- }
- fprintf(ficrespl,"******\n");
- printf("******\n");
- fprintf(ficlog,"******\n");
-
- fprintf(ficrespl,"#Age ");
- for(j=1;j<=cptcoveff;j++) {
- fprintf(ficrespl,"V%d %d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
- }
- for(i=1; i<=nlstate;i++) fprintf(ficrespl," %d-%d ",i,i);
- fprintf(ficrespl,"Total Years_to_converge\n");
+ //for(cptcod=1;cptcod<=ncodemax[cptcov];cptcod++){
+ /* k=k+1; */
+ /* to clean */
+ //printf("cptcov=%d cptcod=%d codtab=%d\n",cptcov, cptcod,codtabm(cptcod,cptcov));
+ fprintf(ficrespl,"#******");
+ printf("#******");
+ fprintf(ficlog,"#******");
+ for(j=1;j<=cptcoveff;j++) {
+ fprintf(ficrespl," V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
+ printf(" V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
+ fprintf(ficlog," V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
+ }
+ fprintf(ficrespl,"******\n");
+ printf("******\n");
+ fprintf(ficlog,"******\n");
+ if(invalidvarcomb[k]){
+ printf("\nCombination (%d) ignored because no cases \n",k);
+ fprintf(ficrespl,"#Combination (%d) ignored because no cases \n",k);
+ fprintf(ficlog,"\nCombination (%d) ignored because no cases \n",k);
+ continue;
+ }
+
+ fprintf(ficrespl,"#Age ");
+ for(j=1;j<=cptcoveff;j++) {
+ fprintf(ficrespl,"V%d %d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
+ }
+ for(i=1; i<=nlstate;i++) fprintf(ficrespl," %d-%d ",i,i);
+ fprintf(ficrespl,"Total Years_to_converge\n");
- for (age=agebase; age<=agelim; age++){
- /* for (age=agebase; age<=agebase; age++){ */
- prevalim(prlim, nlstate, p, age, oldm, savm, ftolpl, ncvyearp, k);
- fprintf(ficrespl,"%.0f ",age );
- for(j=1;j<=cptcoveff;j++)
- fprintf(ficrespl,"%d %d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
- tot=0.;
- for(i=1; i<=nlstate;i++){
- tot += prlim[i][i];
- fprintf(ficrespl," %.5f", prlim[i][i]);
- }
- fprintf(ficrespl," %.3f %d\n", tot, *ncvyearp);
- } /* Age */
- /* was end of cptcod */
- } /* cptcov */
- return 0;
+ for (age=agebase; age<=agelim; age++){
+ /* for (age=agebase; age<=agebase; age++){ */
+ prevalim(prlim, nlstate, p, age, oldm, savm, ftolpl, ncvyearp, k);
+ fprintf(ficrespl,"%.0f ",age );
+ for(j=1;j<=cptcoveff;j++)
+ fprintf(ficrespl,"%d %d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
+ tot=0.;
+ for(i=1; i<=nlstate;i++){
+ tot += prlim[i][i];
+ fprintf(ficrespl," %.5f", prlim[i][i]);
+ }
+ fprintf(ficrespl," %.3f %d\n", tot, *ncvyearp);
+ } /* Age */
+ /* was end of cptcod */
+ } /* cptcov */
+ return 0;
}
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){
@@ -7766,11 +7953,12 @@ int back_prevalence_limit(double *p, dou
i1=pow(2,cptcoveff);
if (cptcovn < 1){i1=1;}
-
- for(cptcov=1,k=0;cptcov<=i1;cptcov++){
+
+ for(k=1; k<=i1;k++){
+ /* for(cptcov=1,k=0;cptcov<=i1;cptcov++){ */
/* for(cptcov=1,k=0;cptcov<=1;cptcov++){ */
//for(cptcod=1;cptcod<=ncodemax[cptcov];cptcod++){
- k=k+1;
+ /* k=k+1; */
/* to clean */
//printf("cptcov=%d cptcod=%d codtab=%d\n",cptcov, cptcod,codtabm(cptcod,cptcov));
fprintf(ficresplb,"#******");
@@ -7784,6 +7972,12 @@ int back_prevalence_limit(double *p, dou
fprintf(ficresplb,"******\n");
printf("******\n");
fprintf(ficlog,"******\n");
+ if(invalidvarcomb[k]){
+ printf("\nCombination (%d) ignored because no cases \n",k);
+ fprintf(ficresplb,"#Combination (%d) ignored because no cases \n",k);
+ fprintf(ficlog,"\nCombination (%d) ignored because no cases \n",k);
+ continue;
+ }
fprintf(ficresplb,"#Age ");
for(j=1;j<=cptcoveff;j++) {
@@ -7798,22 +7992,22 @@ int back_prevalence_limit(double *p, dou
if(mobilavproj > 0){
/* bprevalim(bprlim, mobaverage, nlstate, p, age, ageminpar, agemaxpar, oldm, savm, doldm, dsavm, ftolpl, ncvyearp, k); */
/* bprevalim(bprlim, mobaverage, nlstate, p, age, oldm, savm, dnewm, doldm, dsavm, ftolpl, ncvyearp, k); */
- bprevalim(bprlim, mobaverage, nlstate, p, age, ftolpl, ncvyearp, k);
+ bprevalim(bprlim, mobaverage, nlstate, p, age, ftolpl, ncvyearp, k);
}else if (mobilavproj == 0){
- printf("There is no chance to get back prevalence limit if data aren't non zero and summing to 1, please try a non null mobil_average(=%d) parameter or mobil_average=-1 if you want to try at your own risk.\n",mobilavproj);
- fprintf(ficlog,"There is no chance to get back prevalence limit if data aren't non zero and summing to 1, please try a non null mobil_average(=%d) parameter or mobil_average=-1 if you want to try at your own risk.\n",mobilavproj);
- exit(1);
+ printf("There is no chance to get back prevalence limit if data aren't non zero and summing to 1, please try a non null mobil_average(=%d) parameter or mobil_average=-1 if you want to try at your own risk.\n",mobilavproj);
+ fprintf(ficlog,"There is no chance to get back prevalence limit if data aren't non zero and summing to 1, please try a non null mobil_average(=%d) parameter or mobil_average=-1 if you want to try at your own risk.\n",mobilavproj);
+ exit(1);
}else{
- /* bprevalim(bprlim, probs, nlstate, p, age, oldm, savm, dnewm, doldm, dsavm, ftolpl, ncvyearp, k); */
- bprevalim(bprlim, probs, nlstate, p, age, ftolpl, ncvyearp, k);
+ /* bprevalim(bprlim, probs, nlstate, p, age, oldm, savm, dnewm, doldm, dsavm, ftolpl, ncvyearp, k); */
+ bprevalim(bprlim, probs, nlstate, p, age, ftolpl, ncvyearp, k);
}
fprintf(ficresplb,"%.0f ",age );
for(j=1;j<=cptcoveff;j++)
- fprintf(ficresplb,"%d %d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
+ fprintf(ficresplb,"%d %d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
tot=0.;
for(i=1; i<=nlstate;i++){
- tot += bprlim[i][i];
- fprintf(ficresplb," %.5f", bprlim[i][i]);
+ tot += bprlim[i][i];
+ fprintf(ficresplb," %.5f", bprlim[i][i]);
}
fprintf(ficresplb," %.3f %d\n", tot, *ncvyearp);
} /* Age */
@@ -8004,7 +8198,7 @@ int main(int argc, char *argv[])
double agedeb=0.;
double ageminpar=AGEOVERFLOW,agemin=AGEOVERFLOW, agemaxpar=-AGEOVERFLOW, agemax=-AGEOVERFLOW;
- double ageminout=-AGEOVERFLOW,agemaxout=AGEOVERFLOW; /* Smaller Age range redefined after movingaverage */
+ double ageminout=-AGEOVERFLOW,agemaxout=AGEOVERFLOW; /* Smaller Age range redefined after movingaverage */
double fret;
double dum=0.; /* Dummy variable */
@@ -8354,16 +8548,14 @@ int main(int argc, char *argv[])
fclose (ficlog);
goto end;
exit(0);
- }
- else if(mle==-3) { /* Main Wizard */
+ } else if(mle==-5) { /* Main Wizard */
prwizard(ncovmodel, nlstate, ndeath, model, ficparo);
printf(" You chose mle=-3, look at file %s for a template of covariance matrix \n",filereso);
fprintf(ficlog," You chose mle=-3, look at file %s for a template of covariance matrix \n",filereso);
param= ma3x(1,nlstate,1,nlstate+ndeath-1,1,ncovmodel);
matcov=matrix(1,npar,1,npar);
hess=matrix(1,npar,1,npar);
- }
- else{
+ } else{ /* Begin of mle != -1 or -5 */
/* Read guessed parameters */
/* Reads comments: lines beginning with '#' */
while((c=getc(ficpar))=='#' && c!= EOF){
@@ -8378,37 +8570,37 @@ int main(int argc, char *argv[])
param= ma3x(1,nlstate,1,nlstate+ndeath-1,1,ncovmodel);
for(i=1; i <=nlstate; i++){
- j=0;
+ j=0;
for(jj=1; jj <=nlstate+ndeath; jj++){
- if(jj==i) continue;
- j++;
- fscanf(ficpar,"%1d%1d",&i1,&j1);
- if ((i1 != i) || (j1 != jj)){
- printf("Error in line parameters number %d, %1d%1d instead of %1d%1d \n \
+ if(jj==i) continue;
+ j++;
+ fscanf(ficpar,"%1d%1d",&i1,&j1);
+ if ((i1 != i) || (j1 != jj)){
+ printf("Error in line parameters number %d, %1d%1d instead of %1d%1d \n \
It might be a problem of design; if ncovcol and the model are correct\n \
run imach with mle=-1 to get a correct template of the parameter file.\n",numlinepar, i,j, i1, j1);
- exit(1);
- }
- fprintf(ficparo,"%1d%1d",i1,j1);
- if(mle==1)
- printf("%1d%1d",i,jj);
- fprintf(ficlog,"%1d%1d",i,jj);
- for(k=1; k<=ncovmodel;k++){
- fscanf(ficpar," %lf",¶m[i][j][k]);
- if(mle==1){
- printf(" %lf",param[i][j][k]);
- fprintf(ficlog," %lf",param[i][j][k]);
- }
- else
- fprintf(ficlog," %lf",param[i][j][k]);
- fprintf(ficparo," %lf",param[i][j][k]);
- }
- fscanf(ficpar,"\n");
- numlinepar++;
- if(mle==1)
- printf("\n");
- fprintf(ficlog,"\n");
- fprintf(ficparo,"\n");
+ exit(1);
+ }
+ fprintf(ficparo,"%1d%1d",i1,j1);
+ if(mle==1)
+ printf("%1d%1d",i,jj);
+ fprintf(ficlog,"%1d%1d",i,jj);
+ for(k=1; k<=ncovmodel;k++){
+ fscanf(ficpar," %lf",¶m[i][j][k]);
+ if(mle==1){
+ printf(" %lf",param[i][j][k]);
+ fprintf(ficlog," %lf",param[i][j][k]);
+ }
+ else
+ fprintf(ficlog," %lf",param[i][j][k]);
+ fprintf(ficparo," %lf",param[i][j][k]);
+ }
+ fscanf(ficpar,"\n");
+ numlinepar++;
+ if(mle==1)
+ printf("\n");
+ fprintf(ficlog,"\n");
+ fprintf(ficparo,"\n");
}
}
fflush(ficlog);
@@ -8429,35 +8621,35 @@ run imach with mle=-1 to get a correct t
for(i=1; i <=nlstate; i++){
for(j=1; j <=nlstate+ndeath-1; j++){
- fscanf(ficpar,"%1d%1d",&i1,&j1);
- if ( (i1-i) * (j1-j) != 0){
- printf("Error in line parameters number %d, %1d%1d instead of %1d%1d \n",numlinepar, i,j, i1, j1);
- exit(1);
- }
- printf("%1d%1d",i,j);
- fprintf(ficparo,"%1d%1d",i1,j1);
- fprintf(ficlog,"%1d%1d",i1,j1);
- for(k=1; k<=ncovmodel;k++){
- fscanf(ficpar,"%le",&delti3[i][j][k]);
- printf(" %le",delti3[i][j][k]);
- fprintf(ficparo," %le",delti3[i][j][k]);
- fprintf(ficlog," %le",delti3[i][j][k]);
- }
- fscanf(ficpar,"\n");
- numlinepar++;
- printf("\n");
- fprintf(ficparo,"\n");
- fprintf(ficlog,"\n");
+ fscanf(ficpar,"%1d%1d",&i1,&j1);
+ if ( (i1-i) * (j1-j) != 0){
+ printf("Error in line parameters number %d, %1d%1d instead of %1d%1d \n",numlinepar, i,j, i1, j1);
+ exit(1);
+ }
+ printf("%1d%1d",i,j);
+ fprintf(ficparo,"%1d%1d",i1,j1);
+ fprintf(ficlog,"%1d%1d",i1,j1);
+ for(k=1; k<=ncovmodel;k++){
+ fscanf(ficpar,"%le",&delti3[i][j][k]);
+ printf(" %le",delti3[i][j][k]);
+ fprintf(ficparo," %le",delti3[i][j][k]);
+ fprintf(ficlog," %le",delti3[i][j][k]);
+ }
+ fscanf(ficpar,"\n");
+ numlinepar++;
+ printf("\n");
+ fprintf(ficparo,"\n");
+ fprintf(ficlog,"\n");
}
}
fflush(ficlog);
-
+
/* Reads covariance matrix */
delti=delti3[1][1];
-
-
+
+
/* free_ma3x(delti3,1,nlstate,1,nlstate+ndeath-1,1,ncovmodel); */ /* Hasn't to to freed here otherwise delti is no more allocated */
-
+
/* Reads comments: lines beginning with '#' */
while((c=getc(ficpar))=='#' && c!= EOF){
ungetc(c,ficpar);
@@ -8468,47 +8660,48 @@ run imach with mle=-1 to get a correct t
fputs(line,ficlog);
}
ungetc(c,ficpar);
-
+
matcov=matrix(1,npar,1,npar);
hess=matrix(1,npar,1,npar);
for(i=1; i <=npar; i++)
for(j=1; j <=npar; j++) matcov[i][j]=0.;
-
+
/* Scans npar lines */
for(i=1; i <=npar; i++){
count=fscanf(ficpar,"%1d%1d%1d",&i1,&j1,&jk);
if(count != 3){
- printf("Error! Error in parameter file %s at line %d after line starting with %1d%1d%1d\n\
+ printf("Error! Error in parameter file %s at line %d after line starting with %1d%1d%1d\n\
This is probably because your covariance matrix doesn't \n contain exactly %d lines corresponding to your model line '1+age+%s'.\n\
Please run with mle=-1 to get a correct covariance matrix.\n",optionfile,numlinepar, i1,j1,jk, npar, model);
- fprintf(ficlog,"Error! Error in parameter file %s at line %d after line starting with %1d%1d%1d\n\
+ fprintf(ficlog,"Error! Error in parameter file %s at line %d after line starting with %1d%1d%1d\n\
This is probably because your covariance matrix doesn't \n contain exactly %d lines corresponding to your model line '1+age+%s'.\n\
Please run with mle=-1 to get a correct covariance matrix.\n",optionfile,numlinepar, i1,j1,jk, npar, model);
- exit(1);
- }else
- if(mle==1)
- printf("%1d%1d%1d",i1,j1,jk);
+ exit(1);
+ }else{
+ if(mle==1)
+ printf("%1d%1d%1d",i1,j1,jk);
+ }
fprintf(ficlog,"%1d%1d%1d",i1,j1,jk);
fprintf(ficparo,"%1d%1d%1d",i1,j1,jk);
for(j=1; j <=i; j++){
- fscanf(ficpar," %le",&matcov[i][j]);
- if(mle==1){
- printf(" %.5le",matcov[i][j]);
- }
- fprintf(ficlog," %.5le",matcov[i][j]);
- fprintf(ficparo," %.5le",matcov[i][j]);
+ fscanf(ficpar," %le",&matcov[i][j]);
+ if(mle==1){
+ printf(" %.5le",matcov[i][j]);
+ }
+ fprintf(ficlog," %.5le",matcov[i][j]);
+ fprintf(ficparo," %.5le",matcov[i][j]);
}
fscanf(ficpar,"\n");
numlinepar++;
if(mle==1)
- printf("\n");
+ printf("\n");
fprintf(ficlog,"\n");
fprintf(ficparo,"\n");
}
/* End of read covariance matrix npar lines */
for(i=1; i <=npar; i++)
for(j=i+1;j<=npar;j++)
- matcov[i][j]=matcov[j][i];
+ matcov[i][j]=matcov[j][i];
if(mle==1)
printf("\n");
@@ -8536,10 +8729,19 @@ Please run with mle=-1 to get a correct
annais=vector(1,n);
moisdc=vector(1,n);
andc=vector(1,n);
+ weight=vector(1,n);
agedc=vector(1,n);
cod=ivector(1,n);
- weight=vector(1,n);
- for(i=1;i<=n;i++) weight[i]=1.0; /* Equal weights, 1 by default */
+ for(i=1;i<=n;i++){
+ num[i]=0;
+ moisnais[i]=0;
+ annais[i]=0;
+ moisdc[i]=0;
+ andc[i]=0;
+ agedc[i]=0;
+ cod[i]=0;
+ weight[i]=1.0; /* Equal weights, 1 by default */
+ }
mint=matrix(1,maxwav,1,n);
anint=matrix(1,maxwav,1,n);
s=imatrix(1,maxwav+1,1,n); /* s[i][j] health state for wave i and individual j */
@@ -8636,12 +8838,19 @@ Please run with mle=-1 to get a correct
free_vector(andc,1,n);
/* Routine tricode is to calculate cptcoveff (real number of unique covariates) and to associate covariable number and modality */
-
nbcode=imatrix(0,NCOVMAX,0,NCOVMAX);
ncodemax[1]=1;
Ndum =ivector(-1,NCOVMAX);
- if (ncovmodel-nagesqr > 2 ) /* That is if covariate other than cst, age and age*age */
- tricode(Tvar,nbcode,imx, Ndum); /**< Fills nbcode[Tvar[j]][l]; */
+ cptcoveff=0;
+ if (ncovmodel-nagesqr > 2 ){ /* That is if covariate other than cst, age and age*age */
+ tricode(&cptcoveff,Tvar,nbcode,imx, Ndum); /**< Fills nbcode[Tvar[j]][l]; */
+ }
+
+ ncovcombmax=pow(2,cptcoveff);
+ invalidvarcomb=ivector(1, ncovcombmax);
+ for(i=1;i 0) */
-
-
m=pow(2,cptcoveff);
/**< codtab(h,k) k = codtab[h,k]=( (h-1) - mod(k-1,2**(k-1) )/2**(k-1) + 1
@@ -8702,11 +8907,11 @@ Please run with mle=-1 to get a correct
* bbbbbbbb
* 76543210
* h-1 00000101 (6-1=5)
- *(h-1)>>(k-1)= 00000001 >> (2-1) = 1 right shift
+ *(h-1)>>(k-1)= 00000010 >> (2-1) = 1 right shift
* &
* 1 00000001 (1)
- * 00000001 = 1 & ((h-1) >> (k-1))
- * +1= 00000010 =2
+ * 00000000 = 1 & ((h-1) >> (k-1))
+ * +1= 00000001 =1
*
* h=14, k=3 => h'=h-1=13, k'=k-1=2
* h' 1101 =2^3+2^2+0x2^1+2^0
@@ -8728,40 +8933,9 @@ Please run with mle=-1 to get a correct
* 2211
* V1=1+1, V2=0+1, V3=1+1, V4=1+1
* V3=2
+ * codtabm and decodtabm are identical
*/
- /* /\* for(h=1; h <=100 ;h++){ *\/ */
- /* /\* printf("h=%2d ", h); *\/ */
- /* /\* for(k=1; k <=10; k++){ *\/ */
- /* /\* printf("k=%d %d ",k,codtabm(h,k)); *\/ */
- /* /\* codtab[h][k]=codtabm(h,k); *\/ */
- /* /\* } *\/ */
- /* /\* printf("\n"); *\/ */
- /* } */
- /* for(k=1;k<=cptcoveff; k++){ /\* scans any effective covariate *\/ */
- /* for(i=1; i <=pow(2,cptcoveff-k);i++){ /\* i=1 to 8/1=8; i=1 to 8/2=4; i=1 to 8/8=1 *\/ */
- /* for(j=1; j <= ncodemax[k]; j++){ /\* For each modality of this covariate ncodemax=2*\/ */
- /* for(cpt=1; cpt <=pow(2,k-1); cpt++){ /\* cpt=1 to 8/2**(3+1-1 or 3+1-3) =1 or 4 *\/ */
- /* h++; */
- /* if (h>m) */
- /* h=1; */
- /* codtab[h][k]=j; */
- /* /\* codtab[12][3]=1; *\/ */
- /* /\*codtab[h][Tvar[k]]=j;*\/ */
- /* /\* printf("h=%d k=%d j=%d codtab[h][k]=%d Tvar[k]=%d codtab[h][Tvar[k]]=%d \n",h, k,j,codtab[h][k],Tvar[k],codtab[h][Tvar[k]]); *\/ */
- /* } */
- /* } */
- /* } */
- /* } */
- /* printf("codtab[1][2]=%d codtab[2][2]=%d",codtab[1][2],codtab[2][2]);
- codtab[1][2]=1;codtab[2][2]=2; */
- /* for(i=1; i <=m ;i++){ */
- /* for(k=1; k <=cptcovn; k++){ */
- /* printf("i=%d k=%d %d %d ",i,k,codtab[i][k], cptcoveff); */
- /* } */
- /* printf("\n"); */
- /* } */
- /* scanf("%d",i);*/
free_ivector(Ndum,-1,NCOVMAX);
@@ -8836,9 +9010,10 @@ Title=%s
Datafile=%s Firstpass=%d La
#endif
- /* Calculates basic frequencies. Computes observed prevalence at single age
+ /* 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,nbcode, ncodemax,mint,anint,strstart,\
+ freqsummary(fileres, agemin, agemax, s, agev, nlstate, imx, Tvaraff, invalidvarcomb, nbcode, ncodemax,mint,anint,strstart, \
firstpass, lastpass, stepm, weightopt, model);
fprintf(fichtm,"\n");
@@ -8847,10 +9022,10 @@ Youngest age at first (selected) pass %.
Interval (in months) between two waves: Min=%d Max=%d Mean=%.2lf
\n",\
imx,agemin,agemax,jmin,jmax,jmean);
pmmij= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */
- oldms= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */
- newms= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */
- savms= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */
- oldm=oldms; newm=newms; savm=savms; /* Keeps fixed addresses to free */
+ oldms= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */
+ newms= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */
+ savms= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */
+ oldm=oldms; newm=newms; savm=savms; /* Keeps fixed addresses to free */
/* For Powell, parameters are in a vector p[] starting at p[1]
so we point p on param[1][1] so that p[1] maps on param[1][1][1] */
@@ -8860,6 +9035,9 @@ Interval (in months) between two waves:
/* For mortality only */
if (mle==-3){
ximort=matrix(1,NDIM,1,NDIM);
+ for(i=1;i<=NDIM;i++)
+ for(j=1;j<=NDIM;j++)
+ ximort[i][j]=0.;
/* ximort=gsl_matrix_alloc(1,NDIM,1,NDIM); */
cens=ivector(1,n);
ageexmed=vector(1,n);
@@ -9008,14 +9186,14 @@ Interval (in months) between two waves:
for(i=1; i <=NDIM; i++)
for(j=i+1;j<=NDIM;j++)
- matcov[i][j]=matcov[j][i];
+ matcov[i][j]=matcov[j][i];
printf("\nCovariance matrix\n ");
fprintf(ficlog,"\nCovariance matrix\n ");
for(i=1; i <=NDIM; i++) {
for(j=1;j<=NDIM;j++){
- printf("%f ",matcov[i][j]);
- fprintf(ficlog,"%f ",matcov[i][j]);
+ printf("%f ",matcov[i][j]);
+ fprintf(ficlog,"%f ",matcov[i][j]);
}
printf("\n "); fprintf(ficlog,"\n ");
}
@@ -9056,6 +9234,8 @@ Interval (in months) between two waves:
replace_back_to_slash(pathc,pathcd); /* Even gnuplot wants a / */
+ ageminpar=50;
+ agemaxpar=100;
if(ageminpar == AGEOVERFLOW ||agemaxpar == AGEOVERFLOW){
printf("Warning! Error in gnuplot file with ageminpar %f or agemaxpar %f overflow\n\
This is probably because your parameter file doesn't \n contain the exact number of lines (or columns) corresponding to your model line.\n\
@@ -9063,8 +9243,11 @@ Please run with mle=-1 to get a correct
fprintf(ficlog,"Warning! Error in gnuplot file with ageminpar %f or agemaxpar %f overflow\n\
This is probably because your parameter file doesn't \n contain the exact number of lines (or columns) corresponding to your model line.\n\
Please run with mle=-1 to get a correct covariance matrix.\n",ageminpar,agemaxpar);
- }else
+ }else{
+ printf("Warning! ageminpar %f and agemaxpar %f have been fixed because for simplification until it is fixed...\n\n",ageminpar,agemaxpar);
+ fprintf(ficlog,"Warning! ageminpar %f and agemaxpar %f have been fixed because for simplification until it is fixed...\n\n",ageminpar,agemaxpar);
printinggnuplotmort(fileresu, optionfilefiname,ageminpar,agemaxpar,fage, pathc,p);
+ }
printinghtmlmort(fileresu,title,datafile, firstpass, lastpass, \
stepm, weightopt,\
model,imx,p,matcov,agemortsup);
@@ -9072,11 +9255,11 @@ Please run with mle=-1 to get a correct
free_vector(lsurv,1,AGESUP);
free_vector(lpop,1,AGESUP);
free_vector(tpop,1,AGESUP);
-#ifdef GSL
+ free_matrix(ximort,1,NDIM,1,NDIM);
free_ivector(cens,1,n);
free_vector(agecens,1,n);
free_ivector(dcwave,1,n);
- free_matrix(ximort,1,NDIM,1,NDIM);
+#ifdef GSL
#endif
} /* Endof if mle==-3 mortality only */
/* Standard */
@@ -9113,20 +9296,20 @@ Please run with mle=-1 to get a correct
fprintf(ficlog,"# Parameters nlstate*nlstate*ncov a12*1 + b12 * age + ...\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);
- fprintf(ficres,"%1d%1d ",i,k);
- for(j=1; j <=ncovmodel; j++){
- printf("%12.7f ",p[jk]);
- fprintf(ficlog,"%12.7f ",p[jk]);
- fprintf(ficres,"%12.7f ",p[jk]);
- jk++;
- }
- printf("\n");
- fprintf(ficlog,"\n");
- fprintf(ficres,"\n");
- }
+ if (k != i) {
+ printf("%d%d ",i,k);
+ fprintf(ficlog,"%d%d ",i,k);
+ fprintf(ficres,"%1d%1d ",i,k);
+ for(j=1; j <=ncovmodel; j++){
+ printf("%12.7f ",p[jk]);
+ fprintf(ficlog,"%12.7f ",p[jk]);
+ fprintf(ficres,"%12.7f ",p[jk]);
+ jk++;
+ }
+ printf("\n");
+ fprintf(ficlog,"\n");
+ fprintf(ficres,"\n");
+ }
}
}
if(mle != 0){
@@ -9136,42 +9319,42 @@ Please run with mle=-1 to get a correct
printf("Parameters and 95%% confidence intervals\n W is simply the result of the division of the parameter by the square root of covariance of the parameter.\n And Wald-based confidence intervals plus and minus 1.96 * W .\n But be careful that parameters are highly correlated because incidence of disability is highly correlated to incidence of recovery.\n It might be better to visualize the covariance matrix. See the page 'Matrix of variance-covariance of one-step probabilities' and its graphs.\n");
fprintf(ficlog, "Parameters, Wald tests and Wald-based confidence intervals\n W is simply the result of the division of the parameter by the square root of covariance of the parameter.\n And Wald-based confidence intervals plus and minus 1.96 * W \n It might be better to visualize the covariance matrix. See the page 'Matrix of variance-covariance of one-step probabilities' and its graphs.\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(j=1; j <=ncovmodel; j++){
- printf("%12.7f W=%8.3f CI=[%12.7f ; %12.7f] ",p[jk], p[jk]/sqrt(matcov[jk][jk]), p[jk]-1.96*sqrt(matcov[jk][jk]),p[jk]+1.96*sqrt(matcov[jk][jk]));
- fprintf(ficlog,"%12.7f W=%8.3f CI=[%12.7f ; %12.7f] ",p[jk], p[jk]/sqrt(matcov[jk][jk]), p[jk]-1.96*sqrt(matcov[jk][jk]),p[jk]+1.96*sqrt(matcov[jk][jk]));
- jk++;
- }
- printf("\n");
- fprintf(ficlog,"\n");
- }
- }
+ for(k=1; k <=(nlstate+ndeath); k++){
+ if (k != i) {
+ printf("%d%d ",i,k);
+ fprintf(ficlog,"%d%d ",i,k);
+ for(j=1; j <=ncovmodel; j++){
+ printf("%12.7f W=%8.3f CI=[%12.7f ; %12.7f] ",p[jk], p[jk]/sqrt(matcov[jk][jk]), p[jk]-1.96*sqrt(matcov[jk][jk]),p[jk]+1.96*sqrt(matcov[jk][jk]));
+ fprintf(ficlog,"%12.7f W=%8.3f CI=[%12.7f ; %12.7f] ",p[jk], p[jk]/sqrt(matcov[jk][jk]), p[jk]-1.96*sqrt(matcov[jk][jk]),p[jk]+1.96*sqrt(matcov[jk][jk]));
+ jk++;
+ }
+ printf("\n");
+ fprintf(ficlog,"\n");
+ }
+ }
}
} /* end of hesscov and Wald tests */
-
+
/* */
fprintf(ficres,"# Scales (for hessian or gradient estimation)\n");
printf("# Scales (for hessian or gradient estimation)\n");
fprintf(ficlog,"# Scales (for hessian or gradient estimation)\n");
for(i=1,jk=1; i <=nlstate; i++){
for(j=1; j <=nlstate+ndeath; j++){
- if (j!=i) {
- fprintf(ficres,"%1d%1d",i,j);
- printf("%1d%1d",i,j);
- fprintf(ficlog,"%1d%1d",i,j);
- for(k=1; k<=ncovmodel;k++){
- printf(" %.5e",delti[jk]);
- fprintf(ficlog," %.5e",delti[jk]);
- fprintf(ficres," %.5e",delti[jk]);
- jk++;
- }
- printf("\n");
- fprintf(ficlog,"\n");
- fprintf(ficres,"\n");
- }
+ if (j!=i) {
+ fprintf(ficres,"%1d%1d",i,j);
+ printf("%1d%1d",i,j);
+ fprintf(ficlog,"%1d%1d",i,j);
+ for(k=1; k<=ncovmodel;k++){
+ printf(" %.5e",delti[jk]);
+ fprintf(ficlog," %.5e",delti[jk]);
+ fprintf(ficres," %.5e",delti[jk]);
+ jk++;
+ }
+ printf("\n");
+ fprintf(ficlog,"\n");
+ fprintf(ficres,"\n");
+ }
}
}
@@ -9195,83 +9378,83 @@ Please run with mle=-1 to get a correct
for(itimes=1;itimes<=2;itimes++){
jj=0;
for(i=1; i <=nlstate; i++){
- for(j=1; j <=nlstate+ndeath; j++){
- if(j==i) continue;
- for(k=1; k<=ncovmodel;k++){
- jj++;
- ca[0]= k+'a'-1;ca[1]='\0';
- if(itimes==1){
- if(mle>=1)
- printf("#%1d%1d%d",i,j,k);
- fprintf(ficlog,"#%1d%1d%d",i,j,k);
- fprintf(ficres,"#%1d%1d%d",i,j,k);
- }else{
- if(mle>=1)
- printf("%1d%1d%d",i,j,k);
- fprintf(ficlog,"%1d%1d%d",i,j,k);
- fprintf(ficres,"%1d%1d%d",i,j,k);
- }
- ll=0;
- for(li=1;li <=nlstate; li++){
- for(lj=1;lj <=nlstate+ndeath; lj++){
- if(lj==li) continue;
- for(lk=1;lk<=ncovmodel;lk++){
- ll++;
- if(ll<=jj){
- cb[0]= lk +'a'-1;cb[1]='\0';
- if(ll=1)
- printf(" Cov(%s%1d%1d,%s%1d%1d)",ca,i,j,cb, li,lj);
- fprintf(ficlog," Cov(%s%1d%1d,%s%1d%1d)",ca,i,j,cb, li,lj);
- fprintf(ficres," Cov(%s%1d%1d,%s%1d%1d)",ca,i,j,cb, li,lj);
- }else{
- if(mle>=1)
- printf(" %.5e",matcov[jj][ll]);
- fprintf(ficlog," %.5e",matcov[jj][ll]);
- fprintf(ficres," %.5e",matcov[jj][ll]);
- }
- }else{
- if(itimes==1){
- if(mle>=1)
- printf(" Var(%s%1d%1d)",ca,i,j);
- fprintf(ficlog," Var(%s%1d%1d)",ca,i,j);
- fprintf(ficres," Var(%s%1d%1d)",ca,i,j);
- }else{
- if(mle>=1)
- printf(" %.7e",matcov[jj][ll]);
- fprintf(ficlog," %.7e",matcov[jj][ll]);
- fprintf(ficres," %.7e",matcov[jj][ll]);
- }
- }
- }
- } /* end lk */
- } /* end lj */
- } /* end li */
- if(mle>=1)
- printf("\n");
- fprintf(ficlog,"\n");
- fprintf(ficres,"\n");
- numlinepar++;
- } /* end k*/
- } /*end j */
+ for(j=1; j <=nlstate+ndeath; j++){
+ if(j==i) continue;
+ for(k=1; k<=ncovmodel;k++){
+ jj++;
+ ca[0]= k+'a'-1;ca[1]='\0';
+ if(itimes==1){
+ if(mle>=1)
+ printf("#%1d%1d%d",i,j,k);
+ fprintf(ficlog,"#%1d%1d%d",i,j,k);
+ fprintf(ficres,"#%1d%1d%d",i,j,k);
+ }else{
+ if(mle>=1)
+ printf("%1d%1d%d",i,j,k);
+ fprintf(ficlog,"%1d%1d%d",i,j,k);
+ fprintf(ficres,"%1d%1d%d",i,j,k);
+ }
+ ll=0;
+ for(li=1;li <=nlstate; li++){
+ for(lj=1;lj <=nlstate+ndeath; lj++){
+ if(lj==li) continue;
+ for(lk=1;lk<=ncovmodel;lk++){
+ ll++;
+ if(ll<=jj){
+ cb[0]= lk +'a'-1;cb[1]='\0';
+ if(ll=1)
+ printf(" Cov(%s%1d%1d,%s%1d%1d)",ca,i,j,cb, li,lj);
+ fprintf(ficlog," Cov(%s%1d%1d,%s%1d%1d)",ca,i,j,cb, li,lj);
+ fprintf(ficres," Cov(%s%1d%1d,%s%1d%1d)",ca,i,j,cb, li,lj);
+ }else{
+ if(mle>=1)
+ printf(" %.5e",matcov[jj][ll]);
+ fprintf(ficlog," %.5e",matcov[jj][ll]);
+ fprintf(ficres," %.5e",matcov[jj][ll]);
+ }
+ }else{
+ if(itimes==1){
+ if(mle>=1)
+ printf(" Var(%s%1d%1d)",ca,i,j);
+ fprintf(ficlog," Var(%s%1d%1d)",ca,i,j);
+ fprintf(ficres," Var(%s%1d%1d)",ca,i,j);
+ }else{
+ if(mle>=1)
+ printf(" %.7e",matcov[jj][ll]);
+ fprintf(ficlog," %.7e",matcov[jj][ll]);
+ fprintf(ficres," %.7e",matcov[jj][ll]);
+ }
+ }
+ }
+ } /* end lk */
+ } /* end lj */
+ } /* end li */
+ if(mle>=1)
+ printf("\n");
+ fprintf(ficlog,"\n");
+ fprintf(ficres,"\n");
+ numlinepar++;
+ } /* end k*/
+ } /*end j */
} /* end i */
} /* end itimes */
fflush(ficlog);
fflush(ficres);
- while(fgets(line, MAXLINE, ficpar)) {
- /* If line starts with a # it is a comment */
- if (line[0] == '#') {
- numlinepar++;
- fputs(line,stdout);
- fputs(line,ficparo);
- fputs(line,ficlog);
- continue;
- }else
- break;
- }
-
+ while(fgets(line, MAXLINE, ficpar)) {
+ /* If line starts with a # it is a comment */
+ if (line[0] == '#') {
+ numlinepar++;
+ fputs(line,stdout);
+ fputs(line,ficparo);
+ fputs(line,ficlog);
+ continue;
+ }else
+ break;
+ }
+
/* while((c=getc(ficpar))=='#' && c!= EOF){ */
/* ungetc(c,ficpar); */
/* fgets(line, MAXLINE, ficpar); */
@@ -9282,17 +9465,17 @@ Please run with mle=-1 to get a correct
estepm=0;
if((num_filled=sscanf(line,"agemin=%lf agemax=%lf bage=%lf fage=%lf estepm=%d ftolpl=%lf\n",&ageminpar,&agemaxpar, &bage, &fage, &estepm, &ftolpl)) !=EOF){
-
- if (num_filled != 6) {
- printf("Not 6 parameters in line, for example:agemin=60 agemax=95 bage=55 fage=95 estepm=24 ftolpl=6e-4\n");
- printf("but line=%s\n",line);
- goto end;
- }
- printf("agemin=%lf agemax=%lf bage=%lf fage=%lf estepm=%d ftolpl=%lf\n",ageminpar,agemaxpar, bage, fage, estepm, ftolpl);
- }
- /* ftolpl=6*ftol*1.e5; /\* 6.e-3 make convergences in less than 80 loops for the prevalence limit *\/ */
- /*ftolpl=6.e-4;*/ /* 6.e-3 make convergences in less than 80 loops for the prevalence limit */
-
+
+ if (num_filled != 6) {
+ printf("Error: Not 6 parameters in line, for example:agemin=60 agemax=95 bage=55 fage=95 estepm=24 ftolpl=6e-4\n, your line=%s . Probably you are running an older format.\n",line);
+ fprintf(ficlog,"Error: Not 6 parameters in line, for example:agemin=60 agemax=95 bage=55 fage=95 estepm=24 ftolpl=6e-4\n, your line=%s . Probably you are running an older format.\n",line);
+ goto end;
+ }
+ printf("agemin=%lf agemax=%lf bage=%lf fage=%lf estepm=%d ftolpl=%lf\n",ageminpar,agemaxpar, bage, fage, estepm, ftolpl);
+ }
+ /* ftolpl=6*ftol*1.e5; /\* 6.e-3 make convergences in less than 80 loops for the prevalence limit *\/ */
+ /*ftolpl=6.e-4;*/ /* 6.e-3 make convergences in less than 80 loops for the prevalence limit */
+
/* fscanf(ficpar,"agemin=%lf agemax=%lf bage=%lf fage=%lf estepm=%d ftolpl=%\n",&ageminpar,&agemaxpar, &bage, &fage, &estepm); */
if (estepm==0 || estepm < stepm) estepm=stepm;
if (fage <= 2) {
@@ -9303,7 +9486,7 @@ Please run with mle=-1 to get a correct
fprintf(ficres,"# agemin agemax for life expectancy, bage fage (if mle==0 ie no data nor Max likelihood).\n");
fprintf(ficres,"agemin=%.0f agemax=%.0f bage=%.0f fage=%.0f estepm=%d ftolpl=%e\n",ageminpar,agemaxpar,bage,fage, estepm, ftolpl);
fprintf(ficparo,"agemin=%.0f agemax=%.0f bage=%.0f fage=%.0f estepm=%d, ftolpl=%e\n",ageminpar,agemaxpar,bage,fage, estepm, ftolpl);
-
+
/* Other stuffs, more or less useful */
while((c=getc(ficpar))=='#' && c!= EOF){
ungetc(c,ficpar);
@@ -9360,33 +9543,33 @@ Please run with mle=-1 to get a correct
ungetc(c,ficpar);
fscanf(ficpar,"backcast=%d starting-back-date=%lf/%lf/%lf final-back-date=%lf/%lf/%lf mobil_average=%d\n",&backcast,&jback1,&mback1,&anback1,&jback2,&mback2,&anback2,&mobilavproj);
- fscanf(ficparo,"backcast=%d starting-back-date=%lf/%lf/%lf final-back-date=%lf/%lf/%lf mobil_average=%d\n",&backcast,&jback1,&mback1,&anback1,&jback2,&mback2,&anback2,&mobilavproj);
- fscanf(ficlog,"backcast=%d starting-back-date=%lf/%lf/%lf final-back-date=%lf/%lf/%lf mobil_average=%d\n",&backcast,&jback1,&mback1,&anback1,&jback2,&mback2,&anback2,&mobilavproj);
- fscanf(ficres,"backcast=%d starting-back-date=%lf/%lf/%lf final-back-date=%lf/%lf/%lf mobil_average=%d\n",&backcast,&jback1,&mback1,&anback1,&jback2,&mback2,&anback2,&mobilavproj);
+ fprintf(ficparo,"backcast=%d starting-back-date=%lf/%lf/%lf final-back-date=%lf/%lf/%lf mobil_average=%d\n",backcast,jback1,mback1,anback1,jback2,mback2,anback2,mobilavproj);
+ fprintf(ficlog,"backcast=%d starting-back-date=%lf/%lf/%lf final-back-date=%lf/%lf/%lf mobil_average=%d\n",backcast,jback1,mback1,anback1,jback2,mback2,anback2,mobilavproj);
+ fprintf(ficres,"backcast=%d starting-back-date=%lf/%lf/%lf final-back-date=%lf/%lf/%lf mobil_average=%d\n",backcast,jback1,mback1,anback1,jback2,mback2,anback2,mobilavproj);
/* day and month of proj2 are not used but only year anproj2.*/
- /* freqsummary(fileres, agemin, agemax, s, agev, nlstate, imx,Tvaraff,nbcode, ncodemax,mint,anint); */
+ /* freqsummary(fileres, agemin, agemax, s, agev, nlstate, imx,Tvaraff,nbcode, ncodemax,mint,anint); */
/* ,dateprev1,dateprev2,jprev1, mprev1,anprev1,jprev2, mprev2,anprev2); */
replace_back_to_slash(pathc,pathcd); /* Even gnuplot wants a / */
if(ageminpar == AGEOVERFLOW ||agemaxpar == -AGEOVERFLOW){
- printf("Warning! Error in gnuplot file with ageminpar %f or agemaxpar %f overflow\n\
+ printf("Warning! Error in gnuplot file with ageminpar %f or agemaxpar %f overflow\n\
This is probably because your parameter file doesn't \n contain the exact number of lines (or columns) corresponding to your model line.\n\
Please run with mle=-1 to get a correct covariance matrix.\n",ageminpar,agemaxpar);
- fprintf(ficlog,"Warning! Error in gnuplot file with ageminpar %f or agemaxpar %f overflow\n\
+ fprintf(ficlog,"Warning! Error in gnuplot file with ageminpar %f or agemaxpar %f overflow\n\
This is probably because your parameter file doesn't \n contain the exact number of lines (or columns) corresponding to your model line.\n\
Please run with mle=-1 to get a correct covariance matrix.\n",ageminpar,agemaxpar);
- }else
+ }else{
printinggnuplot(fileresu, optionfilefiname,ageminpar,agemaxpar,fage, prevfcast, backcast, pathc,p);
-
- printinghtml(fileresu,title,datafile, firstpass, lastpass, stepm, weightopt,\
- model,imx,jmin,jmax,jmean,rfileres,popforecast,prevfcast,backcast, estepm, \
- jprev1,mprev1,anprev1,dateprev1,jprev2,mprev2,anprev2,dateprev2);
-
- /*------------ free_vector -------------*/
- /* chdir(path); */
-
+ }
+ printinghtml(fileresu,title,datafile, firstpass, lastpass, stepm, weightopt, \
+ model,imx,jmin,jmax,jmean,rfileres,popforecast,prevfcast,backcast, estepm, \
+ jprev1,mprev1,anprev1,dateprev1,jprev2,mprev2,anprev2,dateprev2);
+
+ /*------------ free_vector -------------*/
+ /* chdir(path); */
+
/* free_ivector(wav,1,imx); */ /* Moved after last prevalence call */
/* free_imatrix(dh,1,lastpass-firstpass+2,1,imx); */
/* free_imatrix(bh,1,lastpass-firstpass+2,1,imx); */
@@ -9397,11 +9580,11 @@ Please run with mle=-1 to get a correct
/*free_matrix(covar,1,NCOVMAX,1,n);*/
fclose(ficparo);
fclose(ficres);
-
-
+
+
/* Other results (useful)*/
-
-
+
+
/*--------------- Prevalence limit (period or stable prevalence) --------------*/
/*#include "prevlim.h"*/ /* Use ficrespl, ficlog */
prlim=matrix(1,nlstate,1,nlstate);
@@ -9413,36 +9596,41 @@ Please run with mle=-1 to get a correct
hPijx(p, bage, fage);
fclose(ficrespij);
- ncovcombmax= pow(2,cptcoveff);
- /*-------------- Variance of one-step probabilities---*/
+ /* ncovcombmax= pow(2,cptcoveff); */
+ /*-------------- Variance of one-step probabilities---*/
k=1;
varprob(optionfilefiname, matcov, p, delti, nlstate, bage, fage,k,Tvar,nbcode, ncodemax,strstart);
- /* Prevalence for each covariates in probs[age][status][cov] */
+ /* Prevalence for each covariates in probs[age][status][cov] */
probs= ma3x(1,AGESUP,1,nlstate+ndeath, 1,ncovcombmax);
for(i=1;i<=AGESUP;i++)
- for(j=1;j<=nlstate;j++)
+ for(j=1;j<=nlstate+ndeath;j++) /* ndeath is useless but a necessity to be compared with mobaverages */
for(k=1;k<=ncovcombmax;k++)
probs[i][j][k]=0.;
- prevalence(probs, ageminpar, agemaxpar, s, agev, nlstate, imx, Tvar, nbcode, ncodemax, mint, anint, dateprev1, dateprev2, firstpass, lastpass);
- if (mobilav!=0 ||mobilavproj !=0 ) {
- mobaverage= ma3x(1, AGESUP,1,nlstate+ndeath, 1,ncovcombmax);
- if (mobilav!=0) {
+ prevalence(probs, ageminpar, agemaxpar, s, agev, nlstate, imx, Tvar, nbcode, ncodemax, mint, anint, dateprev1, dateprev2, firstpass, lastpass);
+ if (mobilav!=0 ||mobilavproj !=0 ) {
+ mobaverages= ma3x(1, AGESUP,1,nlstate+ndeath, 1,ncovcombmax);
+ for(i=1;i<=AGESUP;i++)
+ for(j=1;j<=nlstate;j++)
+ for(k=1;k<=ncovcombmax;k++)
+ mobaverages[i][j][k]=0.;
+ mobaverage=mobaverages;
+ if (mobilav!=0) {
if (movingaverage(probs, ageminpar, agemaxpar, mobaverage, mobilav)!=0){
fprintf(ficlog," Error in movingaverage mobilav=%d\n",mobilav);
printf(" Error in movingaverage mobilav=%d\n",mobilav);
}
- }
- /* /\* Prevalence for each covariates in probs[age][status][cov] *\/ */
- /* prevalence(probs, ageminpar, agemaxpar, s, agev, nlstate, imx, Tvar, nbcode, ncodemax, mint, anint, dateprev1, dateprev2, firstpass, lastpass); */
- else if (mobilavproj !=0) {
+ }
+ /* /\* Prevalence for each covariates in probs[age][status][cov] *\/ */
+ /* prevalence(probs, ageminpar, agemaxpar, s, agev, nlstate, imx, Tvar, nbcode, ncodemax, mint, anint, dateprev1, dateprev2, firstpass, lastpass); */
+ else if (mobilavproj !=0) {
if (movingaverage(probs, ageminpar, agemaxpar, mobaverage, mobilavproj)!=0){
fprintf(ficlog," Error in movingaverage mobilavproj=%d\n",mobilavproj);
printf(" Error in movingaverage mobilavproj=%d\n",mobilavproj);
}
- }
- }/* end if moving average */
-
+ }
+ }/* end if moving average */
+
/*---------- Forecasting ------------------*/
/*if((stepm == 1) && (strcmp(model,".")==0)){*/
if(prevfcast==1){
@@ -9450,60 +9638,36 @@ Please run with mle=-1 to get a correct
prevforecast(fileresu, anproj1, mproj1, jproj1, agemin, agemax, dateprev1, dateprev2, mobilavproj, bage, fage, firstpass, lastpass, anproj2, p, cptcoveff);
}
if(backcast==1){
- ddnewms=matrix(1,nlstate+ndeath,1,nlstate+ndeath);
- ddoldms=matrix(1,nlstate+ndeath,1,nlstate+ndeath);
- ddsavms=matrix(1,nlstate+ndeath,1,nlstate+ndeath);
-
- /*--------------- Back Prevalence limit (period or stable prevalence) --------------*/
- /*#include "prevlim.h"*/ /* Use ficresplb, ficlog */
- bprlim=matrix(1,nlstate,1,nlstate);
- back_prevalence_limit(p, bprlim, ageminpar, agemaxpar, ftolpl, &ncvyear, dateprev1, dateprev2, firstpass, lastpass, mobilavproj);
- fclose(ficresplb);
-
- hBijx(p, bage, fage, mobaverage);
- fclose(ficrespijb);
- free_matrix(bprlim,1,nlstate,1,nlstate); /*here or after loop ? */
-
- /* prevbackforecast(fileresu, anback1, mback1, jback1, agemin, agemax, dateprev1, dateprev2, mobilavproj, bage, fage, firstpass, lastpass, anback2, p, cptcoveff); */
- free_matrix(ddnewms, 1, nlstate+ndeath, 1, nlstate+ndeath);
- free_matrix(ddsavms, 1, nlstate+ndeath, 1, nlstate+ndeath);
- free_matrix(ddoldms, 1, nlstate+ndeath, 1, nlstate+ndeath);
- }
- /* if (mobilav!=0) free_ma3x(mobaverage,1, AGESUP,1,NCOVMAX, 1,NCOVMAX); */
- /* if (mobilavproj!=0) free_ma3x(mobaverage,1, AGESUP,1,NCOVMAX, 1,NCOVMAX); */
-
- /* (popforecast==1) populforecast(fileres, anpyram,mpyram,jpyram, agemin,agemax, dateprev1, dateprev2,mobilav, agedeb, fage, popforecast, popfile, anpyram1,p, i1);*/
- /* } */
- /* else{ */
- /* erreur=108; */
- /* printf("Warning %d!! You can only forecast the prevalences if the optimization\n has been performed with stepm = 1 (month) instead of %d or model=. instead of '%s'\n", erreur, stepm, model); */
- /* fprintf(ficlog,"Warning %d!! You can only forecast the prevalences if the optimization\n has been performed with stepm = 1 (month) instead of %d or model=. instead of '%s'\n", erreur, stepm, model); */
- /* } */
+ ddnewms=matrix(1,nlstate+ndeath,1,nlstate+ndeath);
+ ddoldms=matrix(1,nlstate+ndeath,1,nlstate+ndeath);
+ ddsavms=matrix(1,nlstate+ndeath,1,nlstate+ndeath);
+
+ /*--------------- Back Prevalence limit (period or stable prevalence) --------------*/
+
+ bprlim=matrix(1,nlstate,1,nlstate);
+ back_prevalence_limit(p, bprlim, ageminpar, agemaxpar, ftolpl, &ncvyear, dateprev1, dateprev2, firstpass, lastpass, mobilavproj);
+ fclose(ficresplb);
+
+ /* hBijx(p, bage, fage, mobaverage); */
+ /* fclose(ficrespijb); */
+ free_matrix(bprlim,1,nlstate,1,nlstate); /*here or after loop ? */
+
+ /* prevbackforecast(fileresu, anback1, mback1, jback1, agemin, agemax, dateprev1, dateprev2, mobilavproj,
+ bage, fage, firstpass, lastpass, anback2, p, cptcoveff); */
+ free_matrix(ddnewms, 1, nlstate+ndeath, 1, nlstate+ndeath);
+ free_matrix(ddsavms, 1, nlstate+ndeath, 1, nlstate+ndeath);
+ free_matrix(ddoldms, 1, nlstate+ndeath, 1, nlstate+ndeath);
+ }
/* ------ Other prevalence ratios------------ */
- /* Computes prevalence between agemin (i.e minimal age computed) and no more ageminpar */
-
- /* prevalence(probs, agemin, agemax, s, agev, nlstate, imx, Tvar, nbcode, ncodemax, mint, anint, dateprev1, dateprev2, firstpass, lastpass); */
- /* printf("ageminpar=%f, agemax=%f, s[lastpass][imx]=%d, agev[lastpass][imx]=%f, nlstate=%d, imx=%d, mint[lastpass][imx]=%f, anint[lastpass][imx]=%f,dateprev1=%f, dateprev2=%f, firstpass=%d, lastpass=%d\n",\
- ageminpar, agemax, s[lastpass][imx], agev[lastpass][imx], nlstate, imx, mint[lastpass][imx],anint[lastpass][imx], dateprev1, dateprev2, firstpass, lastpass);
- */
free_ivector(wav,1,imx);
free_imatrix(dh,1,lastpass-firstpass+2,1,imx);
free_imatrix(bh,1,lastpass-firstpass+2,1,imx);
free_imatrix(mw,1,lastpass-firstpass+2,1,imx);
- /* if (mobilav!=0) { */
- /* mobaverage= ma3x(1, AGESUP,1,NCOVMAX, 1,NCOVMAX); */
- /* if (movingaverage(probs, bage, fage, mobaverage,mobilav)!=0){ */
- /* fprintf(ficlog," Error in movingaverage mobilav=%d\n",mobilav); */
- /* printf(" Error in movingaverage mobilav=%d\n",mobilav); */
- /* } */
- /* } */
-
-
/*---------- Health expectancies, no variances ------------*/
strcpy(filerese,"E_");
@@ -9514,22 +9678,19 @@ Please run with mle=-1 to get a correct
}
printf("Computing Health Expectancies: result on file '%s' ...", filerese);fflush(stdout);
fprintf(ficlog,"Computing Health Expectancies: result on file '%s' ...", filerese);fflush(ficlog);
- /*for(cptcov=1,k=0;cptcov<=i1;cptcov++){
- for(cptcod=1;cptcod<=ncodemax[cptcov];cptcod++){*/
-
+
for (k=1; k <= (int) pow(2,cptcoveff); k++){
- fprintf(ficreseij,"\n#****** ");
- for(j=1;j<=cptcoveff;j++) {
+ fprintf(ficreseij,"\n#****** ");
+ for(j=1;j<=cptcoveff;j++) {
fprintf(ficreseij,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
- }
- fprintf(ficreseij,"******\n");
-
- eij=ma3x(1,nlstate,1,nlstate,(int) bage, (int) fage);
- oldm=oldms;savm=savms;
- evsij(eij, p, nlstate, stepm, (int) bage, (int)fage, oldm, savm, k, estepm, strstart);
+ }
+ fprintf(ficreseij,"******\n");
- free_ma3x(eij,1,nlstate,1,nlstate,(int) bage, (int)fage);
- /*}*/
+ eij=ma3x(1,nlstate,1,nlstate,(int) bage, (int) fage);
+ oldm=oldms;savm=savms;
+ evsij(eij, p, nlstate, stepm, (int) bage, (int)fage, oldm, savm, k, estepm, strstart);
+
+ free_ma3x(eij,1,nlstate,1,nlstate,(int) bage, (int)fage);
}
fclose(ficreseij);
printf("done evsij\n");fflush(stdout);
@@ -9643,7 +9804,7 @@ Please run with mle=-1 to get a correct
prlim[i][i]=mobaverage[(int)age][i][k];
}
}
-
+
fprintf(ficrest," %4.0f %d %d",age, vpopbased, mobilav);
/* fprintf(ficrest," %4.0f %d %d %d %d",age, vpopbased, mobilav,Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]); */ /* to be done */
/* printf(" age %4.0f ",age); */
@@ -9656,7 +9817,7 @@ Please run with mle=-1 to get a correct
epj[nlstate+1] +=epj[j];
}
/* printf(" age %4.0f \n",age); */
-
+
for(i=1, vepp=0.;i <=nlstate;i++)
for(j=1;j <=nlstate;j++)
vepp += vareij[i][j][(int)age];
@@ -9722,12 +9883,13 @@ Please run with mle=-1 to get a correct
fprintf(ficlog,"done variance-covariance of period prevalence\n");fflush(ficlog);
/*---------- End : free ----------------*/
- if (mobilav!=0 ||mobilavproj !=0) free_ma3x(mobaverage,1, AGESUP,1,nlstate+ndeath, 1,ncovcombmax); /* We need to have a squared matrix with prevalence of the dead! */
+ if (mobilav!=0 ||mobilavproj !=0)
+ free_ma3x(mobaverages,1, AGESUP,1,nlstate+ndeath, 1,ncovcombmax); /* We need to have a squared matrix with prevalence of the dead! */
free_ma3x(probs,1,AGESUP,1,nlstate+ndeath, 1,ncovcombmax);
- } /* mle==-3 arrives here for freeing */
- /* endfree:*/
free_matrix(prlim,1,nlstate,1,nlstate); /*here or after loop ? */
free_matrix(pmmij,1,nlstate+ndeath,1,nlstate+ndeath);
+ } /* mle==-3 arrives here for freeing */
+ /* endfree:*/
free_matrix(oldms, 1,nlstate+ndeath,1,nlstate+ndeath);
free_matrix(newms, 1,nlstate+ndeath,1,nlstate+ndeath);
free_matrix(savms, 1,nlstate+ndeath,1,nlstate+ndeath);
@@ -9744,6 +9906,7 @@ Please run with mle=-1 to get a correct
free_ivector(Tvar,1,NCOVMAX);
free_ivector(Tprod,1,NCOVMAX);
free_ivector(Tvaraff,1,NCOVMAX);
+ free_ivector(invalidvarcomb,1,ncovcombmax);
free_ivector(Tage,1,NCOVMAX);
free_imatrix(nbcode,0,NCOVMAX,0,NCOVMAX);