--- imach/src/imach.c 2017/05/18 20:09:32 1.268
+++ imach/src/imach.c 2018/04/19 14:49:16 1.283
@@ -1,6 +1,53 @@
-/* $Id: imach.c,v 1.268 2017/05/18 20:09:32 brouard Exp $
+/* $Id: imach.c,v 1.283 2018/04/19 14:49:16 brouard Exp $
$State: Exp $
$Log: imach.c,v $
+ Revision 1.283 2018/04/19 14:49:16 brouard
+ Summary: Some minor bugs fixed
+
+ Revision 1.282 2018/02/27 22:50:02 brouard
+ *** empty log message ***
+
+ Revision 1.281 2018/02/27 19:25:23 brouard
+ Summary: Adding second argument for quitting
+
+ Revision 1.280 2018/02/21 07:58:13 brouard
+ Summary: 0.99r15
+
+ New Makefile with recent VirtualBox 5.26. Bug in sqrt negatve in imach.c
+
+ Revision 1.279 2017/07/20 13:35:01 brouard
+ Summary: temporary working
+
+ Revision 1.278 2017/07/19 14:09:02 brouard
+ Summary: Bug for mobil_average=0 and prevforecast fixed(?)
+
+ Revision 1.277 2017/07/17 08:53:49 brouard
+ Summary: BOM files can be read now
+
+ Revision 1.276 2017/06/30 15:48:31 brouard
+ Summary: Graphs improvements
+
+ Revision 1.275 2017/06/30 13:39:33 brouard
+ Summary: Saito's color
+
+ Revision 1.274 2017/06/29 09:47:08 brouard
+ Summary: Version 0.99r14
+
+ Revision 1.273 2017/06/27 11:06:02 brouard
+ Summary: More documentation on projections
+
+ Revision 1.272 2017/06/27 10:22:40 brouard
+ Summary: Color of backprojection changed from 6 to 5(yellow)
+
+ Revision 1.271 2017/06/27 10:17:50 brouard
+ Summary: Some bug with rint
+
+ Revision 1.270 2017/05/24 05:45:29 brouard
+ *** empty log message ***
+
+ Revision 1.269 2017/05/23 08:39:25 brouard
+ Summary: Code into subroutine, cleanings
+
Revision 1.268 2017/05/18 20:09:32 brouard
Summary: backprojection and confidence intervals of backprevalence
@@ -1007,12 +1054,12 @@ typedef struct {
#define ODIRSEPARATOR '\\'
#endif
-/* $Id: imach.c,v 1.268 2017/05/18 20:09:32 brouard Exp $ */
+/* $Id: imach.c,v 1.283 2018/04/19 14:49:16 brouard Exp $ */
/* $State: Exp $ */
#include "version.h"
char version[]=__IMACH_VERSION__;
-char copyright[]="February 2016,INED-EUROREVES-Institut de longevite-Japan Society for the Promotion of Science (Grant-in-Aid for Scientific Research 25293121), Intel Software 2015-2018";
-char fullversion[]="$Revision: 1.268 $ $Date: 2017/05/18 20:09:32 $";
+char copyright[]="April 2018,INED-EUROREVES-Institut de longevite-Japan Society for the Promotion of Science (Grant-in-Aid for Scientific Research 25293121), Intel Software 2015-2018";
+char fullversion[]="$Revision: 1.283 $ $Date: 2018/04/19 14:49:16 $";
char strstart[80];
char optionfilext[10], optionfilefiname[FILENAMELENGTH];
int erreur=0, nberr=0, nbwarn=0; /* Error number, number of errors number of warnings */
@@ -1084,10 +1131,7 @@ FILE *ficrescveij;
char filerescve[FILENAMELENGTH];
FILE *ficresvij;
char fileresv[FILENAMELENGTH];
-FILE *ficresvpl;
-char fileresvpl[FILENAMELENGTH];
-FILE *ficresvbl;
-char fileresvbl[FILENAMELENGTH];
+
char title[MAXLINE];
char model[MAXLINE]; /**< The model line */
char optionfile[FILENAMELENGTH], datafile[FILENAMELENGTH], filerespl[FILENAMELENGTH], fileresplb[FILENAMELENGTH];
@@ -2489,15 +2533,18 @@ void powell(double p[], double **xi, int
double **prevalim(double **prlim, int nlstate, double x[], double age, double **oldm, double **savm, double ftolpl, int *ncvyear, int ij, int nres)
{
- /* Computes the prevalence limit in each live state at age x and for covariate combination ij
- (and selected quantitative values in nres)
- by left multiplying the unit
- matrix by transitions matrix until convergence is reached with precision ftolpl */
- /* Wx= Wx-1 Px-1= Wx-2 Px-2 Px-1 = Wx-n Px-n ... Px-2 Px-1 I */
- /* Wx is row vector: population in state 1, population in state 2, population dead */
- /* or prevalence in state 1, prevalence in state 2, 0 */
- /* newm is the matrix after multiplications, its rows are identical at a factor */
- /* Initial matrix pimij */
+ /**< Computes the prevalence limit in each live state at age x and for covariate combination ij
+ * (and selected quantitative values in nres)
+ * by left multiplying the unit
+ * matrix by transitions matrix until convergence is reached with precision ftolpl
+ * Wx= Wx-1 Px-1= Wx-2 Px-2 Px-1 = Wx-n Px-n ... Px-2 Px-1 I
+ * Wx is row vector: population in state 1, population in state 2, population dead
+ * or prevalence in state 1, prevalence in state 2, 0
+ * newm is the matrix after multiplications, its rows are identical at a factor.
+ * Inputs are the parameter, age, a tolerance for the prevalence limit ftolpl.
+ * Output is prlim.
+ * Initial matrix pimij
+ */
/* {0.85204250825084937, 0.13044499163996345, 0.017512500109187184, */
/* 0.090851990222114765, 0.88271245433047185, 0.026435555447413338, */
/* 0, 0 , 1} */
@@ -2932,14 +2979,15 @@ double **pmij(double **ps, double *cov,
/* Diag(w_x) */
/* Problem with prevacurrent which can be zero */
sumnew=0.;
- /* for (ii=1;ii<=nlstate+ndeath;ii++){ */
+ /*for (ii=1;ii<=nlstate+ndeath;ii++){*/
for (ii=1;ii<=nlstate;ii++){ /* Only on live states */
+ /* printf(" agefin=%d, ii=%d, ij=%d, prev=%f\n",(int)agefin,ii, ij, prevacurrent[(int)agefin][ii][ij]); */
sumnew+=prevacurrent[(int)agefin][ii][ij];
}
if(sumnew >0.01){ /* At least some value in the prevalence */
for (ii=1;ii<=nlstate+ndeath;ii++){
for (j=1;j<=nlstate+ndeath;j++)
- doldm[ii][j]=(ii==j ? prevacurrent[(int)agefin][ii][ij]/sumnew : 0.0);
+ doldm[ii][j]=(ii==j ? prevacurrent[(int)agefin][ii][ij]/sumnew : 0.0);
}
}else{
for (ii=1;ii<=nlstate+ndeath;ii++){
@@ -3239,7 +3287,7 @@ double ***hbxij(double ***po, int nhstep
newm=savm;
/* Covariates have to be included here again */
cov[1]=1.;
- agexact=age-((h-1)*hstepm + (d))*stepm/YEARM; /* age just before transition, d or d-1? */
+ agexact=age-( (h-1)*hstepm + (d) )*stepm/YEARM; /* age just before transition, d or d-1? */
/* agexact=age+((h-1)*hstepm + (d-1))*stepm/YEARM; /\* age just before transition *\/ */
cov[2]=agexact;
if(nagesqr==1)
@@ -3841,7 +3889,7 @@ void likelione(FILE *ficres,double p[],
else if(mle >=1)
fprintf(fichtm,"\n
File of contributions to the likelihood computed with optimized parameters mle = %d.",mle);
fprintf(fichtm," You should at least run with mle >= 1 to get starting values corresponding to the optimized parameters in order to visualize the real contribution of each individual/wave: %s
\n",subdirf(fileresilk),subdirf(fileresilk));
-
+ fprintf(fichtm,"\n
Equation of the model: model=1+age+%s
\n",model);
for (k=1; k<= nlstate ; k++) {
fprintf(fichtm,"
- Probability p%dj by origin %d and destination j. Dot's sizes are related to corresponding weight: %s-p%dj.png
\
@@ -4323,7 +4371,7 @@ void freqsummary(char fileres[], double
double ***freq; /* Frequencies */
double *x, *y, a=0.,b=0.,r=1., sa=0., sb=0.; /* for regression, y=b+m*x and r is the correlation coefficient */
int no=0, linreg(int ifi, int ila, int *no, const double x[], const double y[], double* a, double* b, double* r, double* sa, double * sb);
- double *meanq;
+ double *meanq, *idq;
double **meanqt;
double *pp, **prop, *posprop, *pospropt;
double pos=0., posproptt=0., pospropta=0., k2, dateintsum=0,k2cpt=0;
@@ -4336,6 +4384,7 @@ void freqsummary(char fileres[], double
pospropt=vector(1,nlstate); /* Counting the number of transition starting from a live state */
/* prop=matrix(1,nlstate,iagemin,iagemax+3); */
meanq=vector(1,nqfveff); /* Number of Quantitative Fixed Variables Effective */
+ idq=vector(1,nqfveff); /* Number of Quantitative Fixed Variables Effective */
meanqt=matrix(1,lastpass,1,nqtveff);
strcpy(fileresp,"P_");
strcat(fileresp,fileresu);
@@ -4444,13 +4493,15 @@ Title=%s
Datafile=%s Firstpass=%d La
posprop[i]=0;
pospropt[i]=0;
}
- /* for (z1=1; z1<= nqfveff; z1++) { */
- /* meanq[z1]+=0.; */
+ for (z1=1; z1<= nqfveff; z1++) { /* zeroing for each combination j1 as well as for the total */
+ idq[z1]+=0.;
+ meanq[z1]+=0.;
+ }
+ /* for (z1=1; z1<= nqtveff; z1++) { */
/* for(m=1;m<=lastpass;m++){ */
- /* meanqt[m][z1]=0.; */
- /* } */
- /* } */
-
+ /* meanqt[m][z1]=0.; */
+ /* } */
+ /* } */
/* dateintsum=0; */
/* k2cpt=0; */
@@ -4460,7 +4511,7 @@ Title=%s
Datafile=%s Firstpass=%d La
if(j !=0){
if(anyvaryingduminmodel==0){ /* If All fixed covariates */
if (cptcoveff >0) { /* Filter is here: Must be looked at for model=V1+V2+V3+V4 */
- /* for (z1=1; z1<= nqfveff; z1++) { */
+ /* for (z1=1; z1<= nqfveff; z1++) { */
/* meanq[z1]+=coqvar[Tvar[z1]][iind]; /\* Computes mean of quantitative with selected filter *\/ */
/* } */
for (z1=1; z1<=cptcoveff; z1++) { /* loops on covariates in the model */
@@ -4526,6 +4577,11 @@ Title=%s
Datafile=%s Firstpass=%d La
/* freq[s[m][iind]][s[m+1][iind]][(int)((agebegin+ageend)/2.)] += weight[iind]; */
freq[s[m][iind]][s[m+1][iind]][iagemax+3] += weight[iind]; /* Total is in iagemax+3 *//* At age of beginning of transition, where status is known */
}
+ for (z1=1; z1<= nqfveff; z1++) {
+ idq[z1]++;
+ meanq[z1]+=covar[ncovcol+z1][iind]; /* *weight[iind];*/ /* Computes mean of quantitative with selected filter */
+ /* meanq[z1]+=coqvar[Tvar[z1]][iind]; /\* Computes mean of quantitative with selected filter *\/ */
+ }
} /* end if between passes */
if ((agev[m][iind]>1) && (agev[m][iind]< (iagemax+3)) && (anint[m][iind]!=9999) && (mint[m][iind]!=99) && (j==0)) {
dateintsum=dateintsum+k2; /* on all covariates ?*/
@@ -4573,6 +4629,19 @@ Title=%s
Datafile=%s Firstpass=%d La
fprintf(ficresphtmfr, "**********\n");
fprintf(ficlog, "**********\n");
}
+ /*
+ Printing means of quantitative variables if any
+ */
+ for (z1=1; z1<= nqfveff; z1++) {
+ fprintf(ficresphtmfr,"V quantitative id %d, number of idividuals= %f, sum=%f", z1, idq[z1], meanq[z1]);
+ fprintf(ficresphtmfr,", mean=%f
\n",meanq[z1]/idq[z1]);
+ }
+ /* for (z1=1; z1<= nqtveff; z1++) { */
+ /* for(m=1;m<=lastpass;m++){ */
+ /* fprintf(ficresphtmfr,"V quantitative id %d, pass id=%d, mean=%f
\n", z1, m, meanqt[m][z1]); */
+ /* } */
+ /* } */
+
fprintf(ficresphtm,"
");
if((cptcoveff==0 && nj==1)|| nj==2 ) /* no covariate and first pass */
fprintf(ficresp, " Age");
@@ -4853,6 +4922,7 @@ Title=%s
Datafile=%s Firstpass=%d La
fclose(ficresp);
fclose(ficresphtm);
fclose(ficresphtmfr);
+ free_vector(idq,1,nqfveff);
free_vector(meanq,1,nqfveff);
free_matrix(meanqt,1,lastpass,1,nqtveff);
free_vector(x, iagemin-AGEMARGE, iagemax+4+AGEMARGE);
@@ -5463,7 +5533,7 @@ void concatwav(int wav[], int **dh, int
/* hstepm beeing the number of stepms, if hstepm=1 the length of hstepm is stepm.
nhstepm is the number of hstepm from age to agelim
nstepm is the number of stepm from age to agelin.
- Look at hpijx to understand the reason of that which relies in memory size
+ Look at hpijx to understand the reason which relies in memory size consideration
and note for a fixed period like estepm months */
/* We decided (b) to get a life expectancy respecting the most precise curvature of the
survival function given by stepm (the optimization length). Unfortunately it
@@ -5694,7 +5764,8 @@ void concatwav(int wav[], int **dh, int
/* if((int)age==70)printf("i=%2d,j=%2d,h=%2d,age=%3d,%9.4f,%9.4f,%9.4f\n",i,j,h,(int)age,p3mat[i][j][h],hf,eij[i][j][(int)age]);*/
}
-
+
+ /* Standard deviation of expectancies ij */
fprintf(ficresstdeij,"%3.0f",age );
for(i=1; i<=nlstate;i++){
eip=0.;
@@ -5709,6 +5780,7 @@ void concatwav(int wav[], int **dh, int
}
fprintf(ficresstdeij,"\n");
+ /* Variance of expectancies ij */
fprintf(ficrescveij,"%3.0f",age );
for(i=1; i<=nlstate;i++)
for(j=1; j<=nlstate;j++){
@@ -5742,10 +5814,11 @@ void concatwav(int wav[], int **dh, int
/************ Variance ******************/
void varevsij(char optionfilefiname[], double ***vareij, double **matcov, double x[], double delti[], int nlstate, int stepm, double bage, double fage, double **oldm, double **savm, double **prlim, double ftolpl, int *ncvyearp, int ij, int estepm, int cptcov, int cptcod, int popbased, int mobilav, char strstart[], int nres)
{
- /* Variance of health expectancies */
- /* double **prevalim(double **prlim, int nlstate, double *xp, double age, double **oldm, double ** savm,double ftolpl);*/
- /* double **newm;*/
- /* int movingaverage(double ***probs, double bage,double fage, double ***mobaverage, int mobilav)*/
+ /** Variance of health expectancies
+ * double **prevalim(double **prlim, int nlstate, double *xp, double age, double **oldm, double ** savm,double ftolpl);
+ * double **newm;
+ * int movingaverage(double ***probs, double bage,double fage, double ***mobaverage, int mobilav)
+ */
/* int movingaverage(); */
double **dnewm,**doldm;
@@ -5753,11 +5826,11 @@ void concatwav(int wav[], int **dh, int
int i, j, nhstepm, hstepm, h, nstepm ;
int k;
double *xp;
- double **gp, **gm; /* for var eij */
- double ***gradg, ***trgradg; /*for var eij */
- double **gradgp, **trgradgp; /* for var p point j */
- double *gpp, *gmp; /* for var p point j */
- double **varppt; /* for var p point j nlstate to nlstate+ndeath */
+ double **gp, **gm; /**< for var eij */
+ double ***gradg, ***trgradg; /**< for var eij */
+ double **gradgp, **trgradgp; /**< for var p point j */
+ double *gpp, *gmp; /**< for var p point j */
+ double **varppt; /**< for var p point j nlstate to nlstate+ndeath */
double ***p3mat;
double age,agelim, hf;
/* double ***mobaverage; */
@@ -5818,7 +5891,7 @@ void concatwav(int wav[], int **dh, int
/* fprintf(fichtm, "#Local time at start: %s", strstart);*/
fprintf(fichtm,"\n Computing probabilities of dying over estepm months as a weighted average (i.e global mortality independent of initial healh state)
\n");
fprintf(fichtm,"\n
%s
\n",digitp);
- /* } */
+
varppt = matrix(nlstate+1,nlstate+ndeath,nlstate+1,nlstate+ndeath);
pstamp(ficresvij);
fprintf(ficresvij,"# Variance and covariance of health expectancies e.j \n# (weighted average of eij where weights are ");
@@ -5873,9 +5946,12 @@ void concatwav(int wav[], int **dh, int
for(i=1; i<=npar; i++){ /* Computes gradient x + delta*/
xp[i] = x[i] + (i==theta ?delti[theta]:0);
}
-
+ /**< Computes the prevalence limit with parameter theta shifted of delta up to ftolpl precision and
+ * returns into prlim .
+ */
prevalim(prlim,nlstate,xp,age,oldm,savm,ftolpl,ncvyearp,ij, nres);
-
+
+ /* If popbased = 1 we use crossection prevalences. Previous step is useless but prlim is created */
if (popbased==1) {
if(mobilav ==0){
for(i=1; i<=nlstate;i++)
@@ -5885,23 +5961,28 @@ void concatwav(int wav[], int **dh, int
prlim[i][i]=mobaverage[(int)age][i][ij];
}
}
-
- hpxij(p3mat,nhstepm,age,hstepm,xp,nlstate,stepm,oldm,savm, ij,nres); /* Returns p3mat[i][j][h] for h=1 to nhstepm */
+ /**< Computes the shifted transition matrix \f$ {}{h}_p^{ij}_x\f$ at horizon h.
+ */
+ hpxij(p3mat,nhstepm,age,hstepm,xp,nlstate,stepm,oldm,savm, ij,nres); /* Returns p3mat[i][j][h] for h=0 to nhstepm */
+ /**< And for each alive state j, sums over i \f$ w^i_x {}{h}_p^{ij}_x\f$, which are the probability
+ * at horizon h in state j including mortality.
+ */
for(j=1; j<= nlstate; j++){
for(h=0; h<=nhstepm; h++){
for(i=1, gp[h][j]=0.;i<=nlstate;i++)
gp[h][j] += prlim[i][i]*p3mat[i][j][h];
}
}
- /* Next for computing probability of death (h=1 means
+ /* Next for computing shifted+ probability of death (h=1 means
computed over hstepm matrices product = hstepm*stepm months)
- as a weighted average of prlim.
+ as a weighted average of prlim(i) * p(i,j) p.3=w1*p13 + w2*p23 .
*/
for(j=nlstate+1;j<=nlstate+ndeath;j++){
for(i=1,gpp[j]=0.; i<= nlstate; i++)
gpp[j] += prlim[i][i]*p3mat[i][j][1];
- }
- /* end probability of death */
+ }
+
+ /* Again with minus shift */
for(i=1; i<=npar; i++) /* Computes gradient x - delta */
xp[i] = x[i] - (i==theta ?delti[theta]:0);
@@ -5934,19 +6015,23 @@ void concatwav(int wav[], int **dh, int
for(i=1,gmp[j]=0.; i<= nlstate; i++)
gmp[j] += prlim[i][i]*p3mat[i][j][1];
}
- /* end probability of death */
-
+ /* end shifting computations */
+
+ /**< Computing gradient matrix at horizon h
+ */
for(j=1; j<= nlstate; j++) /* vareij */
for(h=0; h<=nhstepm; h++){
gradg[h][theta][j]= (gp[h][j]-gm[h][j])/2./delti[theta];
}
-
- for(j=nlstate+1; j<= nlstate+ndeath; j++){ /* var mu */
+ /**< Gradient of overall mortality p.3 (or p.j)
+ */
+ for(j=nlstate+1; j<= nlstate+ndeath; j++){ /* var mu mortality from j */
gradgp[theta][j]= (gpp[j]-gmp[j])/2./delti[theta];
}
} /* End theta */
-
+
+ /* We got the gradient matrix for each theta and state j */
trgradg =ma3x(0,nhstepm,1,nlstate,1,npar); /* veij */
for(h=0; h<=nhstepm; h++) /* veij */
@@ -5957,13 +6042,19 @@ void concatwav(int wav[], int **dh, int
for(j=nlstate+1; j<=nlstate+ndeath;j++) /* mu */
for(theta=1; theta <=npar; theta++)
trgradgp[j][theta]=gradgp[theta][j];
-
+ /**< as well as its transposed matrix
+ */
hf=hstepm*stepm/YEARM; /* Duration of hstepm expressed in year unit. */
for(i=1;i<=nlstate;i++)
for(j=1;j<=nlstate;j++)
vareij[i][j][(int)age] =0.;
-
+
+ /* Computing trgradg by matcov by gradg at age and summing over h
+ * and k (nhstepm) formula 15 of article
+ * Lievre-Brouard-Heathcote
+ */
+
for(h=0;h<=nhstepm;h++){
for(k=0;k<=nhstepm;k++){
matprod2(dnewm,trgradg[h],1,nlstate,1,npar,1,npar,matcov);
@@ -5974,7 +6065,11 @@ void concatwav(int wav[], int **dh, int
}
}
- /* pptj */
+ /* pptj is p.3 or p.j = trgradgp by cov by gradgp, variance of
+ * p.j overall mortality formula 49 but computed directly because
+ * we compute the grad (wix pijx) instead of grad (pijx),even if
+ * wix is independent of theta.
+ */
matprod2(dnewmp,trgradgp,nlstate+1,nlstate+ndeath,1,npar,1,npar,matcov);
matprod2(doldmp,dnewmp,nlstate+1,nlstate+ndeath,1,npar,nlstate+1,nlstate+ndeath,gradgp);
for(j=nlstate+1;j<=nlstate+ndeath;j++)
@@ -6062,7 +6157,7 @@ void concatwav(int wav[], int **dh, int
} /* end varevsij */
/************ Variance of prevlim ******************/
- void varprevlim(char fileres[], double **varpl, double **matcov, double x[], double delti[], int nlstate, int stepm, double bage, double fage, double **oldm, double **savm, double **prlim, double ftolpl, int *ncvyearp, int ij, char strstart[], int nres)
+ void varprevlim(char fileresvpl[], FILE *ficresvpl, double **varpl, double **matcov, double x[], double delti[], int nlstate, int stepm, double bage, double fage, double **oldm, double **savm, double **prlim, double ftolpl, int *ncvyearp, int ij, char strstart[], int nres)
{
/* Variance of prevalence limit for each state ij using current parameters x[] and estimates of neighbourhood give by delti*/
/* double **prevalim(double **prlim, int nlstate, double *xp, double age, double **oldm, double **savm,double ftolpl);*/
@@ -6187,7 +6282,7 @@ void concatwav(int wav[], int **dh, int
/************ Variance of backprevalence limit ******************/
- void varbrevlim(char fileres[], double **varbpl, double **matcov, double x[], double delti[], int nlstate, int stepm, double bage, double fage, double **oldm, double **savm, double **bprlim, double ftolpl, int mobilavproj, int *ncvyearp, int ij, char strstart[], int nres)
+ void varbrevlim(char fileresvbl[], FILE *ficresvbl, double **varbpl, double **matcov, double x[], double delti[], int nlstate, int stepm, double bage, double fage, double **oldm, double **savm, double **bprlim, double ftolpl, int mobilavproj, int *ncvyearp, int ij, char strstart[], int nres)
{
/* Variance of backward prevalence limit for each state ij using current parameters x[] and estimates of neighbourhood give by delti*/
/* double **prevalim(double **prlim, int nlstate, double *xp, double age, double **oldm, double **savm,double ftolpl);*/
@@ -6583,7 +6678,12 @@ To be simple, these graphs help to under
}
/* Eigen vectors */
- v11=(1./sqrt(1+(v1-lc1)*(v1-lc1)/cv12/cv12));
+ if(1+(v1-lc1)*(v1-lc1)/cv12/cv12 <1.e-5){
+ printf(" Error sqrt of a negative number: %lf\n",1+(v1-lc1)*(v1-lc1)/cv12/cv12);
+ fprintf(ficlog," Error sqrt of a negative number: %lf\n",1+(v1-lc1)*(v1-lc1)/cv12/cv12);
+ v11=(1./sqrt(fabs(1+(v1-lc1)*(v1-lc1)/cv12/cv12)));
+ }else
+ v11=(1./sqrt(1+(v1-lc1)*(v1-lc1)/cv12/cv12));
/*v21=sqrt(1.-v11*v11); *//* error */
v21=(lc1-v1)/cv12*v11;
v12=-v21;
@@ -6614,8 +6714,8 @@ To be simple, these graphs help to under
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(fabs(lc2)), \
- mu2,std,v21,sqrt(lc1),v22,sqrt(fabs(lc2))); /* For gnuplot only */
+ mu1,std,v11,sqrt(fabs(lc1)),v12,sqrt(fabs(lc2)), \
+ mu2,std,v21,sqrt(fabs(lc1)),v22,sqrt(fabs(lc2))); /* For gnuplot only */
}else{
first=0;
fprintf(fichtmcov," %d (%.3f),",(int) age, c12);
@@ -6652,8 +6752,8 @@ void printinghtml(char fileresu[], char
int lastpass, int stepm, int weightopt, char model[],\
int imx,int jmin, int jmax, double jmeanint,char rfileres[],\
int popforecast, int mobilav, int prevfcast, int mobilavproj, int backcast, int estepm , \
- double jprev1, double mprev1,double anprev1, double dateprev1, \
- double jprev2, double mprev2,double anprev2, double dateprev2){
+ double jprev1, double mprev1,double anprev1, double dateprev1, double dateproj1, double dateback1, \
+ double jprev2, double mprev2,double anprev2, double dateprev2, double dateproj2, double dateback2){
int jj1, k1, i1, cpt, k4, nres;
fprintf(fichtm,"- Result files (first order: no variance)\n \
@@ -6790,7 +6890,7 @@ divided by h: hPij
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-%d.svg
", cpt, nlstate, cpt, subdirf2(optionfilefiname,"LIJT_"),cpt,k1,nres,subdirf2(optionfilefiname,"LIJT_"),cpt,k1,nres,subdirf2(optionfilefiname,"LIJT_"),cpt,k1,nres);
+ %s_%d-%d-%d.svg
", cpt, nlstate, cpt, subdirf2(optionfilefiname,"LIJT_"),cpt,k1,nres,subdirf2(optionfilefiname,"LIJT_"),cpt,k1,nres,subdirf2(optionfilefiname,"LIJT_"),cpt,k1,nres);
}
/* Period (stable) prevalence in each health state */
for(cpt=1; cpt<=nlstate;cpt++){
@@ -6807,15 +6907,18 @@ divided by h: hPij
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 and mobil_average=%d) up to period (stable) prevalence in state %d. Or probability to be in state %d being in an observed weighted state (from 1 to %d). %s_%d-%d-%d.svg
\
-", dateprev1, dateprev2, mobilavproj, cpt, cpt, nlstate, subdirf2(optionfilefiname,"PROJ_"),cpt,k1,nres,subdirf2(optionfilefiname,"PROJ_"),cpt,k1,nres,subdirf2(optionfilefiname,"PROJ_"),cpt,k1,nres);
+ fprintf(fichtm,"
\n- Projection of cross-sectional prevalence (estimated with cases observed from %.1f to %.1f and mobil_average=%d), from year %.1f up to year %.1f tending to period (stable) prevalence in state %d. Or probability to be in state %d being in an observed weighted state (from 1 to %d). %s_%d-%d-%d.svg
\
+", dateprev1, dateprev2, mobilavproj, dateproj1, dateproj2, cpt, cpt, nlstate, subdirf2(optionfilefiname,"PROJ_"),cpt,k1,nres,subdirf2(optionfilefiname,"PROJ_"),cpt,k1,nres,subdirf2(optionfilefiname,"PROJ_"),cpt,k1,nres);
}
}
if(backcast==1){
/* Back projection of prevalence up to stable (mixed) back-prevalence in each health state */
for(cpt=1; cpt<=nlstate;cpt++){
- fprintf(fichtm,"
\n- Back projection of cross-sectional prevalence (estimated with cases observed from %.1f to %.1f and mobil_average=%d) up to stable (mixed) back prevalence in state %d. Or probability to have been in an state %d, knowing that the person was in either state (1 or %d) with weights corresponding to observed prevalence at different ages. %s_%d-%d-%d.svg
\
-", dateprev1, dateprev2, mobilavproj, cpt, cpt, nlstate, subdirf2(optionfilefiname,"PROJB_"),cpt,k1,nres,subdirf2(optionfilefiname,"PROJB_"),cpt,k1,nres,subdirf2(optionfilefiname,"PROJB_"),cpt,k1,nres);
+ fprintf(fichtm,"
\n- Back projection of cross-sectional prevalence (estimated with cases observed from %.1f to %.1f and mobil_average=%d), \
+ from year %.1f up to year %.1f (probably close to stable [mixed] back prevalence in state %d (randomness in cross-sectional prevalence is not taken into \
+ account but can visually be appreciated). Or probability to have been in an state %d, knowing that the person was in either state (1 or %d) \
+with weights corresponding to observed prevalence at different ages. %s_%d-%d-%d.svg
\
+ ", dateprev1, dateprev2, mobilavproj, dateback1, dateback2, cpt, cpt, nlstate, subdirf2(optionfilefiname,"PROJB_"),cpt,k1,nres,subdirf2(optionfilefiname,"PROJB_"),cpt,k1,nres,subdirf2(optionfilefiname,"PROJB_"),cpt,k1,nres);
}
}
@@ -6921,7 +7024,7 @@ true period expectancies (those weighted
}
/******************* Gnuplot file **************/
-void printinggnuplot(char fileresu[], char optionfilefiname[], double ageminpar, double agemaxpar, double fage , int prevfcast, int backcast, char pathc[], double p[], int offyear, int offbyear){
+void printinggnuplot(char fileresu[], char optionfilefiname[], double ageminpar, double agemaxpar, double bage, double fage , int prevfcast, int backcast, char pathc[], double p[], int offyear, int offbyear){
char dirfileres[132],optfileres[132];
char gplotcondition[132], gplotlabel[132];
@@ -6930,6 +7033,8 @@ void printinggnuplot(char fileresu[], ch
int ng=0;
int vpopbased;
int ioffset; /* variable offset for columns */
+ int iyearc=1; /* variable column for year of projection */
+ int iagec=1; /* variable column for age of projection */
int nres=0; /* Index of resultline */
int istart=1; /* For starting graphs in projections */
@@ -6943,6 +7048,20 @@ void printinggnuplot(char fileresu[], ch
/*#endif */
m=pow(2,cptcoveff);
+ /* diagram of the model */
+ fprintf(ficgp,"\n#Diagram of the model \n");
+ fprintf(ficgp,"\ndelta=0.03;delta2=0.07;unset arrow;\n");
+ fprintf(ficgp,"yoff=(%d > 2? 0:1);\n",nlstate);
+ fprintf(ficgp,"\n#Peripheral arrows\nset for [i=1:%d] for [j=1:%d] arrow i*10+j from cos(pi*((1-(%d/2)*2./%d)/2+(i-1)*2./%d))-(i!=j?(i-j)/abs(i-j)*delta:0), yoff +sin(pi*((1-(%d/2)*2./%d)/2+(i-1)*2./%d)) + (i!=j?(i-j)/abs(i-j)*delta:0) rto -0.95*(cos(pi*((1-(%d/2)*2./%d)/2+(i-1)*2./%d))+(i!=j?(i-j)/abs(i-j)*delta:0) - cos(pi*((1-(%d/2)*2./%d)/2+(j-1)*2./%d)) + (i!=j?(i-j)/abs(i-j)*delta2:0)), -0.95*(sin(pi*((1-(%d/2)*2./%d)/2+(i-1)*2./%d)) + (i!=j?(i-j)/abs(i-j)*delta:0) - sin(pi*((1-(%d/2)*2./%d)/2+(j-1)*2./%d))+( i!=j?(i-j)/abs(i-j)*delta2:0)) ls (i < j? 1:2)\n",nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate);
+
+ fprintf(ficgp,"\n#Centripete arrows (turning in other direction (1-i) instead of (i-1)) \nset for [i=1:%d] arrow (%d+1)*10+i from cos(pi*((1-(%d/2)*2./%d)/2+(1-i)*2./%d))-(i!=j?(i-j)/abs(i-j)*delta:0), yoff +sin(pi*((1-(%d/2)*2./%d)/2+(1-i)*2./%d)) + (i!=j?(i-j)/abs(i-j)*delta:0) rto -0.80*(cos(pi*((1-(%d/2)*2./%d)/2+(1-i)*2./%d))+(i!=j?(i-j)/abs(i-j)*delta:0) ), -0.80*(sin(pi*((1-(%d/2)*2./%d)/2+(1-i)*2./%d)) + (i!=j?(i-j)/abs(i-j)*delta:0) + yoff ) ls 4\n",nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate);
+ fprintf(ficgp,"\n#show arrow\nunset label\n");
+ fprintf(ficgp,"\n#States labels, starting from 2 (2-i) instead of (1-i), was (i-1)\nset for [i=1:%d] label i sprintf(\"State %%d\",i) center at cos(pi*((1-(%d/2)*2./%d)/2+(2-i)*2./%d)), yoff+sin(pi*((1-(%d/2)*2./%d)/2+(2-i)*2./%d)) font \"helvetica, 16\" tc rgbcolor \"blue\"\n",nlstate,nlstate,nlstate,nlstate,nlstate,nlstate,nlstate);
+ fprintf(ficgp,"\nset label %d+1 sprintf(\"State %%d\",%d+1) center at 0.,0. font \"helvetica, 16\" tc rgbcolor \"red\"\n",nlstate,nlstate);
+ fprintf(ficgp,"\n#show label\nunset border;unset xtics; unset ytics;\n");
+ fprintf(ficgp,"\n\nset ter svg size 640, 480;set out \"%s_.svg\" \n",subdirf2(optionfilefiname,"D_"));
+ fprintf(ficgp,"unset log y; plot [-1.2:1.2][yoff-1.2:1.2] 1/0 not; set out;reset;\n");
+
/* Contribution to likelihood */
/* Plot the probability implied in the likelihood */
fprintf(ficgp,"\n# Contributions to the Likelihood, mle >=1. For mle=4 no interpolation, pure matrix products.\n#\n");
@@ -7012,7 +7131,8 @@ void printinggnuplot(char fileresu[], ch
fprintf(ficgp,"\nset out \"%s_%d-%d-%d.svg\" \n",subdirf2(optionfilefiname,"V_"),cpt,k1,nres);
fprintf(ficgp,"\n#set out \"V_%s_%d-%d-%d.svg\" \n",optionfilefiname,cpt,k1,nres);
- fprintf(ficgp,"set label \"Alive state %d %s\" at graph 0.98,0.5 center rotate font \"Helvetica,12\"\n",cpt,gplotlabel);
+ /* fprintf(ficgp,"set label \"Alive state %d %s\" at graph 0.98,0.5 center rotate font \"Helvetica,12\"\n",cpt,gplotlabel); */
+ fprintf(ficgp,"set title \"Alive state %d %s\" font \"Helvetica,12\"\n",cpt,gplotlabel);
fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability\" \nset ter svg size 640, 480\nplot [%.f:%.f] \"%s\" every :::%d::%d u 1:($2==%d ? $3:1/0) \"%%lf %%lf",ageminpar,fage,subdirf2(fileresu,"VPL_"),nres-1,nres-1,nres);
/* fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability\" \nset ter svg size 640, 480\nplot [%.f:%.f] \"%s\" every :::%d::%d u 1:($2==%d ? $3:1/0) \"%%lf %%lf",ageminpar,fage,subdirf2(fileresu,"VPL_"),k1-1,k1-1,nres); */
/* k1-1 error should be nres-1*/
@@ -7034,7 +7154,7 @@ void printinggnuplot(char fileresu[], ch
fprintf(ficgp,"\" t\"\" w l lt 1,\"%s\" u 1:((",subdirf2(fileresu,"P_"));
if(cptcoveff ==0){
- fprintf(ficgp,"$%d)) t 'Observed prevalence in state %d' with line lt 3", 2+(cpt-1), cpt );
+ fprintf(ficgp,"$%d)) t 'Observed prevalence in state %d' with line lt 3", 2+3*(cpt-1), cpt );
}else{
kl=0;
for (k=1; k<=cptcoveff; k++){ /* For each combination of covariate */
@@ -7092,20 +7212,21 @@ void printinggnuplot(char fileresu[], ch
if (i==cpt) fprintf(ficgp," %%lf (%%lf)");
else fprintf(ficgp," %%*lf (%%*lf)");
}
- fprintf(ficgp,"\" t\"Backward (stable) prevalence\" w l lt 0,\"%s\" every :::%d::%d u 1:($2==%d ? $3+1.96*$4 : 1/0) \"%%lf %%lf",subdirf2(fileresu,"VBL_"),nres-1,nres-1,nres);
+ fprintf(ficgp,"\" t\"Backward (stable) prevalence\" w l lt 6 dt 3,\"%s\" every :::%d::%d u 1:($2==%d ? $3+1.96*$4 : 1/0) \"%%lf %%lf",subdirf2(fileresu,"VBL_"),nres-1,nres-1,nres);
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==%d ? $3-1.96*$4 : 1/0) \"%%lf %%lf",subdirf2(fileresu,"VBL_"),nres-1,nres-1,nres);
+ fprintf(ficgp,"\" t\"95%% CI\" w l lt 4,\"%s\" every :::%d::%d u 1:($2==%d ? $3-1.96*$4 : 1/0) \"%%lf %%lf",subdirf2(fileresu,"VBL_"),nres-1,nres-1,nres);
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");
+ fprintf(ficgp,"\" t\"\" w l lt 4");
} /* end if backprojcast */
} /* end if backcast */
- fprintf(ficgp,"\nset out ;unset label;\n");
+ /* fprintf(ficgp,"\nset out ;unset label;\n"); */
+ fprintf(ficgp,"\nset out ;unset title;\n");
} /* nres */
} /* k1 */
} /* cpt */
@@ -7503,24 +7624,22 @@ set ter svg size 640, 480\nunset log y\n
/*# 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)):5 t 'pw.%d' with line lc variable ", \
+ fprintf(ficgp," $%d/(1.-$%d)):1 t 'pw.%d' with line lc variable ", \
ioffset+(cpt-1)*(nlstate+1)+1+(i-1), ioffset+1+(i-1)+(nlstate+1)*nlstate,cpt );
fprintf(ficgp,",\\\n '' ");
fprintf(ficgp," u %d:(",ioffset);
- fprintf(ficgp," (($5-$6) == %d ) ? $%d/(1.-$%d) : 1/0):5 with labels center not ", \
+ fprintf(ficgp," (($1-$2) == %d ) ? $%d/(1.-$%d) : 1/0):1 with labels center not ", \
offyear, \
ioffset+(cpt-1)*(nlstate+1)+1+(i-1), ioffset+1+(i-1)+(nlstate+1)*nlstate );
}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 */
- }
+ ioffset=2*cptcoveff+2; /* Age is in 4 or 6 or etc.*/
+ /*# 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 */
+ iyearc=ioffset-1;
+ iagec=ioffset;
fprintf(ficgp," u %d:(",ioffset);
kl=0;
strcpy(gplotcondition,"(");
@@ -7542,13 +7661,13 @@ set ter svg size 640, 480\nunset log y\n
/*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):5 t 'p.%d' with line lc variable", gplotcondition, \
- ioffset+(cpt-1)*(nlstate+1)+1+(i-1), ioffset+1+(i-1)+(nlstate+1)*nlstate,cpt );
+ fprintf(ficgp,"%s ? $%d/(1.-$%d) : 1/0):%d t 'p.%d' with line lc variable", gplotcondition, \
+ ioffset+(cpt-1)*(nlstate+1)+1+(i-1), ioffset+1+(i-1)+(nlstate+1)*nlstate,iyearc, cpt );
fprintf(ficgp,",\\\n '' ");
- fprintf(ficgp," u %d:(",ioffset);
- fprintf(ficgp,"%s && (($5-$6) == %d ) ? $%d/(1.-$%d) : 1/0):5 with labels center not ", gplotcondition, \
- offyear, \
- ioffset+(cpt-1)*(nlstate+1)+1+(i-1), ioffset+1+(i-1)+(nlstate+1)*nlstate );
+ fprintf(ficgp," u %d:(",iagec);
+ fprintf(ficgp,"%s && (($%d-$%d) == %d ) ? $%d/(1.-$%d) : 1/0):%d with labels center not ", gplotcondition, \
+ iyearc, iagec, offyear, \
+ ioffset+(cpt-1)*(nlstate+1)+1+(i-1), ioffset+1+(i-1)+(nlstate+1)*nlstate, iyearc );
/* '' u 6:(($1==1 && $2==0 && $3==2 && $4==0) && (($5-$6) == 1947) ? $10/(1.-$22) : 1/0):5 with labels center boxed not*/
}else{
fprintf(ficgp,"%s ? $%d/(1.-$%d) : 1/0) t 'p%d%d' with line ", gplotcondition, \
@@ -7618,24 +7737,22 @@ set ter svg size 640, 480\nunset log y\n
/*# 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)):5 t 'bw%d' with line lc variable ", \
+ fprintf(ficgp," $%d/(1.-$%d)):1 t 'bw%d' with line lc variable ", \
ioffset+(cpt-1)*(nlstate+1)+1+(i-1), ioffset+1+(i-1)+(nlstate+1)*nlstate,cpt );
fprintf(ficgp,",\\\n '' ");
fprintf(ficgp," u %d:(",ioffset);
- fprintf(ficgp," (($5-$6) == %d ) ? $%d : 1/0):5 with labels center not ", \
+ fprintf(ficgp," (($1-$2) == %d ) ? $%d : 1/0):1 with labels center not ", \
offbyear, \
ioffset+(cpt-1)*(nlstate+1)+1+(i-1) );
}else
fprintf(ficgp," $%d/(1.-$%d)) t 'b%d%d' with line ", \
ioffset+(cpt-1)*(nlstate+1)+1+(i-1), ioffset+1+(i-1)+(nlstate+1)*nlstate,cpt,i );
}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 */
- }
+ ioffset=2*cptcoveff+2; /* Age is in 4 or 6 or etc.*/
+ /*# 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 */
+ iyearc=ioffset-1;
+ iagec=ioffset;
fprintf(ficgp," u %d:(",ioffset);
kl=0;
strcpy(gplotcondition,"(");
@@ -7657,14 +7774,14 @@ set ter svg size 640, 480\nunset log y\n
/*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/0):5 t 'bw%d' with line lc variable", gplotcondition, \
- ioffset+(cpt-1)*(nlstate+1)+1+(i-1),cpt );
+ fprintf(ficgp,"%s ? $%d : 1/0):%d t 'bw%d' with line lc variable", gplotcondition, \
+ ioffset+(cpt-1)*(nlstate+1)+1+(i-1),iyearc,cpt );
fprintf(ficgp,",\\\n '' ");
- fprintf(ficgp," u %d:(",ioffset);
+ fprintf(ficgp," u %d:(",iagec);
/* fprintf(ficgp,"%s && (($5-$6) == %d ) ? $%d/(1.-$%d) : 1/0):5 with labels center not ", gplotcondition, \ */
- fprintf(ficgp,"%s && (($5-$6) == %d ) ? $%d : 1/0):5 with labels center not ", gplotcondition, \
- offbyear, \
- ioffset+(cpt-1)*(nlstate+1)+1+(i-1) );
+ fprintf(ficgp,"%s && (($%d-$%d) == %d ) ? $%d : 1/0):%d with labels center not ", gplotcondition, \
+ iyearc,iagec,offbyear, \
+ ioffset+(cpt-1)*(nlstate+1)+1+(i-1), iyearc );
/* '' u 6:(($1==1 && $2==0 && $3==2 && $4==0) && (($5-$6) == 1947) ? $10/(1.-$22) : 1/0):5 with labels center boxed not*/
}else{
/* fprintf(ficgp,"%s ? $%d/(1.-$%d) : 1/0) t 'p%d%d' with line ", gplotcondition, \ */
@@ -7723,7 +7840,7 @@ set ter svg size 640, 480\nunset log y\n
continue;
fprintf(ficgp,"\n\n# Combination of dummy k1=%d which is ",k1);
strcpy(gplotlabel,"(");
- sprintf(gplotlabel+strlen(gplotlabel)," Dummy combination %d ",k1);
+ /*sprintf(gplotlabel+strlen(gplotlabel)," Dummy combination %d ",k1);*/
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 */
@@ -7740,7 +7857,9 @@ set ter svg size 640, 480\nunset log y\n
strcpy(gplotlabel+strlen(gplotlabel),")");
fprintf(ficgp,"\n#\n");
fprintf(ficgp,"\nset out \"%s_%d-%d-%d.svg\" ",subdirf2(optionfilefiname,"PE_"),k1,ng,nres);
- fprintf(ficgp,"\nset label \"%s\" at graph 0.98,0.5 center rotate font \"Helvetica,12\"\n",gplotlabel);
+ fprintf(ficgp,"\nset key outside ");
+ /* fprintf(ficgp,"\nset label \"%s\" at graph 1.2,0.5 center rotate font \"Helvetica,12\"\n",gplotlabel); */
+ fprintf(ficgp,"\nset title \"%s\" font \"Helvetica,12\"\n",gplotlabel);
fprintf(ficgp,"\nset ter svg size 640, 480 ");
if (ng==1){
fprintf(ficgp,"\nset ylabel \"Value of the logit of the model\"\n"); /* exp(a12+b12*x) could be nice */
@@ -7860,12 +7979,12 @@ set ter svg size 640, 480\nunset log y\n
}
fprintf(ficgp,")");
if(ng ==2)
- fprintf(ficgp," t \"p%d%d\" ", k2,k);
+ fprintf(ficgp," w l lw 2 lt (%d*%d+%d)%%%d+1 dt %d t \"p%d%d\" ", nlstate+ndeath, k2, k, nlstate+ndeath, k2, k2,k);
else /* ng= 3 */
- fprintf(ficgp," t \"i%d%d\" ", k2,k);
+ fprintf(ficgp," w l lw 2 lt (%d*%d+%d)%%%d+1 dt %d t \"i%d%d\" ", nlstate+ndeath, k2, k, nlstate+ndeath, k2, k2,k);
}else{ /* end ng <> 1 */
if( k !=k2) /* logit p11 is hard to draw */
- fprintf(ficgp," t \"logit(p%d%d)\" ", k2,k);
+ fprintf(ficgp," w l lw 2 lt (%d*%d+%d)%%%d+1 dt %d t \"logit(p%d%d)\" ", nlstate+ndeath, k2, k, nlstate+ndeath, k2, k2,k);
}
if ((k+k2)!= (nlstate*2+ndeath) && ng != 1)
fprintf(ficgp,",");
@@ -7874,7 +7993,8 @@ set ter svg size 640, 480\nunset log y\n
i=i+ncovmodel;
} /* end k */
} /* end k2 */
- fprintf(ficgp,"\n set out; unset label;\n");
+ /* fprintf(ficgp,"\n set out; unset label;set key default;\n"); */
+ fprintf(ficgp,"\n set out; unset title;set key default;\n");
} /* end k1 */
} /* end ng */
/* avoid: */
@@ -7898,8 +8018,8 @@ set ter svg size 640, 480\nunset log y\n
double *agemingoodr, *agemaxgoodr;
- /* modcovmax=2*cptcoveff;/\* Max number of modalities. We suppose */
- /* a covariate has 2 modalities, should be equal to ncovcombmax *\/ */
+ /* 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);
@@ -8112,7 +8232,7 @@ set ter svg size 640, 480\nunset log y\n
/************** Forecasting ******************/
-void prevforecast(char fileres[], double anproj1, double mproj1, double jproj1, double ageminpar, double agemax, double dateprev1, double dateprev2, int mobilav, double bage, double fage, int firstpass, int lastpass, double anproj2, double p[], int cptcoveff){
+ void prevforecast(char fileres[], double anproj1, double mproj1, double jproj1, double ageminpar, double agemax, double dateprev1, double dateprev2, int mobilav, double ***prev, double bage, double fage, int firstpass, int lastpass, double anproj2, double p[], int cptcoveff){
/* proj1, year, month, day of starting projection
agemin, agemax range of age
dateprev1 dateprev2 range of dates during which prevalence is computed
@@ -8151,7 +8271,12 @@ void prevforecast(char fileres[], double
if(estepm < stepm){
printf ("Problem %d lower than %d\n",estepm, stepm);
}
- else hstepm=estepm;
+ else{
+ hstepm=estepm;
+ }
+ if(estepm > stepm){ /* Yes every two year */
+ stepsize=2;
+ }
hstepm=hstepm/stepm;
yp1=modf(dateintmean,&yp);/* extracts integral of datemean in yp and
@@ -8196,7 +8321,8 @@ void prevforecast(char fileres[], double
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--){
+ /* for (agec=fage; agec>=(ageminpar-1); agec--){ */
+ for (agec=fage; agec>=(bage); agec--){
nhstepm=(int) rint((agelim-agec)*YEARM/stepm);
nhstepm = nhstepm/hstepm;
p3mat=ma3x(1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);
@@ -8217,11 +8343,11 @@ void prevforecast(char fileres[], double
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][k];
- /* else { */ /* even if mobilav==-1 we use mobaverage */
- /* ppij=ppij+p3mat[i][j][h]*probs[(int)(agec)][i][k]; */
- /* } */
+ if (mobilav>=1)
+ ppij=ppij+p3mat[i][j][h]*prev[(int)agec][i][k];
+ else { /* even if mobilav==-1 we use mobaverage, probs may not sums to 1 */
+ ppij=ppij+p3mat[i][j][h]*probs[(int)(agec)][i][k];
+ }
fprintf(ficresf," %.3f", p3mat[i][j][h]);
} /* end i */
fprintf(ficresf," %.3f", ppij);
@@ -8239,12 +8365,13 @@ void prevforecast(char fileres[], double
}
-/* /\************** Back Forecasting ******************\/ */
-void prevbackforecast(char fileres[], double ***prevacurrent, double anback1, double mback1, double jback1, double ageminpar, double agemax, double dateprev1, double dateprev2, int mobilav, double bage, double fage, int firstpass, int lastpass, double anback2, double p[], int cptcoveff){
+/************** Back Forecasting ******************/
+ void prevbackforecast(char fileres[], double ***prevacurrent, double anback1, double mback1, double jback1, double ageminpar, double agemax, double dateprev1, double dateprev2, int mobilav, double bage, double fage, int firstpass, int lastpass, double anback2, double p[], int cptcoveff){
/* back1, year, month, day of starting backection
agemin, agemax range of age
dateprev1 dateprev2 range of dates during which prevalence is computed
- anback2 year of en of backection (same day and month as back1).
+ anback2 year of end of backprojection (same day and month as back1).
+ prevacurrent and prev are prevalences.
*/
int yearp, stepsize, hstepm, nhstepm, j, k, cptcod, i, h, i1, k4, nres=0;
double agec; /* generic age */
@@ -8283,7 +8410,12 @@ void prevbackforecast(char fileres[], do
if(estepm < stepm){
printf ("Problem %d lower than %d\n",estepm, stepm);
}
- else hstepm=estepm;
+ else{
+ hstepm=estepm;
+ }
+ if(estepm >= stepm){ /* Yes every two year */
+ stepsize=2;
+ }
hstepm=hstepm/stepm;
yp1=modf(dateintmean,&yp);/* extracts integral of datemean in yp and
@@ -8304,10 +8436,6 @@ void prevbackforecast(char fileres[], do
fprintf(ficresfb,"#****** Routine prevbackforecast **\n");
- /* if (h==(int)(YEARM*yearp)){ */
- /* for(cptcov=1, k=0;cptcov<=i1;cptcov++){ */
- /* for(cptcod=1;cptcod<=ncodemax[cptcoveff];cptcod++){ */
- /* k=k+1; */
for(nres=1; nres <= nresult; nres++) /* For each resultline */
for(k=1; k<=i1;k++){
if(i1 != 1 && TKresult[nres]!= k)
@@ -8333,16 +8461,16 @@ void prevbackforecast(char fileres[], do
/* for (yearp=0; yearp<=(anproj2-anproj1);yearp +=stepsize) { */
fprintf(ficresfb,"\n");
fprintf(ficresfb,"\n# Back Forecasting at date %.lf/%.lf/%.lf ",jback1,mback1,anback1+yearp);
- printf("\n# Back Forecasting at date %.lf/%.lf/%.lf ",jback1,mback1,anback1+yearp);
- /* for (agec=fage; agec>=(ageminpar-1); agec--){ */
- /* nhstepm=(int) rint((agelim-agec)*YEARM/stepm); */
- for (agec=bage; agec<=agemax-1; agec++){ /* testing */
+ /* printf("\n# Back Forecasting at date %.lf/%.lf/%.lf ",jback1,mback1,anback1+yearp); */
+ /* for (agec=bage; agec<=agemax-1; agec++){ /\* testing *\/ */
+ for (agec=bage; agec<=fage; agec++){ /* testing */
/* We compute bij at age agec over nhstepm, nhstepm decreases when agec increases because of agemax;*/
- nhstepm=(int) rint((agec-agelim)*YEARM/stepm);
+ nhstepm=(int) (agec-agelim) *YEARM/stepm;/* nhstepm=(int) rint((agec-agelim)*YEARM/stepm);*/
nhstepm = nhstepm/hstepm;
p3mat=ma3x(1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm);
oldm=oldms;savm=savms;
/* computes hbxij at age agec over 1 to nhstepm */
+ /* printf("####prevbackforecast debug agec=%.2f nhstepm=%d\n",agec, nhstepm);fflush(stdout); */
hbxij(p3mat,nhstepm,agec,hstepm,p,prevacurrent,nlstate,stepm, k, nres);
/* hpxij(p3mat,nhstepm,agec,hstepm,p, nlstate,stepm,oldm,savm, k,nres); */
/* Then we print p3mat for h corresponding to the right agec+h*stepms=yearp */
@@ -8360,8 +8488,10 @@ void prevbackforecast(char fileres[], do
ppij=0.;ppi=0.;
for(j=1; j<=nlstate;j++) {
/* if (mobilav==1) */
- ppij=ppij+p3mat[i][j][h]*mobaverage[(int)agec][j][k];
- ppi=ppi+mobaverage[(int)agec][j][k];
+ ppij=ppij+p3mat[i][j][h]*prevacurrent[(int)agec][j][k];
+ ppi=ppi+prevacurrent[(int)agec][j][k];
+ /* ppij=ppij+p3mat[i][j][h]*mobaverage[(int)agec][j][k]; */
+ /* ppi=ppi+mobaverage[(int)agec][j][k]; */
/* else { */
/* ppij=ppij+p3mat[i][j][h]*probs[(int)(agec)][i][k]; */
/* } */
@@ -8386,6 +8516,123 @@ void prevbackforecast(char fileres[], do
}
+/* Variance of prevalence limit: varprlim */
+ void varprlim(char fileresu[], int nresult, double ***prevacurrent, int mobilavproj, double bage, double fage, double **prlim, int *ncvyearp, double ftolpl, double p[], double **matcov, double *delti, int stepm, int cptcoveff){
+ /*------- Variance of period (stable) prevalence------*/
+
+ char fileresvpl[FILENAMELENGTH];
+ FILE *ficresvpl;
+ double **oldm, **savm;
+ double **varpl; /* Variances of prevalence limits by age */
+ int i1, k, nres, j ;
+
+ strcpy(fileresvpl,"VPL_");
+ strcat(fileresvpl,fileresu);
+ if((ficresvpl=fopen(fileresvpl,"w"))==NULL) {
+ printf("Problem with variance of period (stable) prevalence resultfile: %s\n", fileresvpl);
+ exit(0);
+ }
+ printf("Computing Variance-covariance of period (stable) prevalence: file '%s' ...", fileresvpl);fflush(stdout);
+ fprintf(ficlog, "Computing Variance-covariance of period (stable) prevalence: file '%s' ...", fileresvpl);fflush(ficlog);
+
+ /*for(cptcov=1,k=0;cptcov<=i1;cptcov++){
+ for(cptcod=1;cptcod<=ncodemax[cptcov];cptcod++){*/
+
+ i1=pow(2,cptcoveff);
+ if (cptcovn < 1){i1=1;}
+
+ for(nres=1; nres <= nresult; nres++) /* For each resultline */
+ for(k=1; k<=i1;k++){
+ if(i1 != 1 && TKresult[nres]!= k)
+ continue;
+ fprintf(ficresvpl,"\n#****** ");
+ printf("\n#****** ");
+ fprintf(ficlog,"\n#****** ");
+ for(j=1;j<=cptcoveff;j++) {
+ fprintf(ficresvpl,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
+ fprintf(ficlog,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
+ printf("V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
+ }
+ for (j=1; j<= nsq; j++){ /* For each selected (single) quantitative value */
+ printf(" V%d=%f ",Tvqresult[nres][j],Tqresult[nres][j]);
+ fprintf(ficresvpl," V%d=%f ",Tvqresult[nres][j],Tqresult[nres][j]);
+ fprintf(ficlog," V%d=%f ",Tvqresult[nres][j],Tqresult[nres][j]);
+ }
+ fprintf(ficresvpl,"******\n");
+ printf("******\n");
+ fprintf(ficlog,"******\n");
+
+ varpl=matrix(1,nlstate,(int) bage, (int) fage);
+ oldm=oldms;savm=savms;
+ varprevlim(fileresvpl, ficresvpl, varpl, matcov, p, delti, nlstate, stepm, (int) bage, (int) fage, oldm, savm, prlim, ftolpl, ncvyearp, k, strstart, nres);
+ free_matrix(varpl,1,nlstate,(int) bage, (int)fage);
+ /*}*/
+ }
+
+ fclose(ficresvpl);
+ printf("done variance-covariance of period prevalence\n");fflush(stdout);
+ fprintf(ficlog,"done variance-covariance of period prevalence\n");fflush(ficlog);
+
+ }
+/* Variance of back prevalence: varbprlim */
+ void varbprlim(char fileresu[], int nresult, double ***prevacurrent, int mobilavproj, double bage, double fage, double **bprlim, int *ncvyearp, double ftolpl, double p[], double **matcov, double *delti, int stepm, int cptcoveff){
+ /*------- Variance of back (stable) prevalence------*/
+
+ char fileresvbl[FILENAMELENGTH];
+ FILE *ficresvbl;
+
+ double **oldm, **savm;
+ double **varbpl; /* Variances of back prevalence limits by age */
+ int i1, k, nres, j ;
+
+ strcpy(fileresvbl,"VBL_");
+ strcat(fileresvbl,fileresu);
+ if((ficresvbl=fopen(fileresvbl,"w"))==NULL) {
+ printf("Problem with variance of back (stable) prevalence resultfile: %s\n", fileresvbl);
+ exit(0);
+ }
+ printf("Computing Variance-covariance of back (stable) prevalence: file '%s' ...", fileresvbl);fflush(stdout);
+ fprintf(ficlog, "Computing Variance-covariance of back (stable) prevalence: file '%s' ...", fileresvbl);fflush(ficlog);
+
+
+ i1=pow(2,cptcoveff);
+ if (cptcovn < 1){i1=1;}
+
+ for(nres=1; nres <= nresult; nres++) /* For each resultline */
+ for(k=1; k<=i1;k++){
+ if(i1 != 1 && TKresult[nres]!= k)
+ continue;
+ fprintf(ficresvbl,"\n#****** ");
+ printf("\n#****** ");
+ fprintf(ficlog,"\n#****** ");
+ for(j=1;j<=cptcoveff;j++) {
+ fprintf(ficresvbl,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
+ fprintf(ficlog,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
+ printf("V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
+ }
+ for (j=1; j<= nsq; j++){ /* For each selected (single) quantitative value */
+ printf(" V%d=%f ",Tvqresult[nres][j],Tqresult[nres][j]);
+ fprintf(ficresvbl," V%d=%f ",Tvqresult[nres][j],Tqresult[nres][j]);
+ fprintf(ficlog," V%d=%f ",Tvqresult[nres][j],Tqresult[nres][j]);
+ }
+ fprintf(ficresvbl,"******\n");
+ printf("******\n");
+ fprintf(ficlog,"******\n");
+
+ varbpl=matrix(1,nlstate,(int) bage, (int) fage);
+ oldm=oldms;savm=savms;
+
+ varbrevlim(fileresvbl, ficresvbl, varbpl, matcov, p, delti, nlstate, stepm, (int) bage, (int) fage, oldm, savm, bprlim, ftolpl, mobilavproj, ncvyearp, k, strstart, nres);
+ free_matrix(varbpl,1,nlstate,(int) bage, (int)fage);
+ /*}*/
+ }
+
+ fclose(ficresvbl);
+ printf("done variance-covariance of back prevalence\n");fflush(stdout);
+ fprintf(ficlog,"done variance-covariance of back prevalence\n");fflush(ficlog);
+
+ } /* End of varbprlim */
+
/************** Forecasting *****not tested NB*************/
/* void populforecast(char fileres[], double anpyram,double mpyram,double jpyram,double ageminpar, double agemax,double dateprev1, double dateprev2s, int mobilav, double agedeb, double fage, int popforecast, char popfile[], double anpyram1,double p[], int i2){ */
@@ -10442,7 +10689,9 @@ int main(int argc, char *argv[])
int vpopbased=0;
int nres=0;
int endishere=0;
-
+ int noffset=0;
+ int ncurrv=0; /* Temporary variable */
+
char ca[32], cb[32];
/* FILE *fichtm; *//* Html File */
/* FILE *ficgp;*/ /*Gnuplot File */
@@ -10494,11 +10743,12 @@ int main(int argc, char *argv[])
double *delti; /* Scale */
double ***eij, ***vareij;
double **varpl; /* Variances of prevalence limits by age */
- double **varbpl; /* Variances of back prevalence limits by age */
+
double *epj, vepp;
- double dateprev1, dateprev2,jproj1=1,mproj1=1,anproj1=2000,jproj2=1,mproj2=1,anproj2=2000;
- double jback1=1,mback1=1,anback1=2000,jback2=1,mback2=1,anback2=2000;
+ double dateprev1, dateprev2;
+ double jproj1=1,mproj1=1,anproj1=2000,jproj2=1,mproj2=1,anproj2=2000, dateproj1=0, dateproj2=0;
+ double jback1=1,mback1=1,anback1=2000,jback2=1,mback2=1,anback2=2000, dateback1=0, dateback2=0;
double **ximort;
char *alph[]={"a","a","b","c","d","e"}, str[4]="1234";
@@ -10576,8 +10826,13 @@ int main(int argc, char *argv[])
if(pathr[0] == '\0') break; /* Dirty */
}
}
+ else if (argc<=2){
+ strcpy(pathtot,argv[1]);
+ }
else{
strcpy(pathtot,argv[1]);
+ strcpy(z,argv[2]);
+ printf("\nargv[2]=%s z=%c\n",argv[2],z[0]);
}
/*if(getcwd(pathcd, MAXLINE)!= NULL)printf ("Error pathcd\n");*/
/*cygwin_split_path(pathtot,path,optionfile);
@@ -10655,8 +10910,6 @@ int main(int argc, char *argv[])
exit(70);
}
-
-
strcpy(filereso,"o");
strcat(filereso,fileresu);
if((ficparo=fopen(filereso,"w"))==NULL) { /* opened on subdirectory */
@@ -10665,17 +10918,52 @@ int main(int argc, char *argv[])
fflush(ficlog);
goto end;
}
+ /*-------- Rewriting parameter file ----------*/
+ strcpy(rfileres,"r"); /* "Rparameterfile */
+ strcat(rfileres,optionfilefiname); /* Parameter file first name */
+ strcat(rfileres,"."); /* */
+ strcat(rfileres,optionfilext); /* Other files have txt extension */
+ if((ficres =fopen(rfileres,"w"))==NULL) {
+ printf("Problem writing new parameter file: %s\n", rfileres);goto end;
+ fprintf(ficlog,"Problem writing new parameter file: %s\n", rfileres);goto end;
+ fflush(ficlog);
+ goto end;
+ }
+ fprintf(ficres,"#IMaCh %s\n",version);
+
/* Reads comments: lines beginning with '#' */
numlinepar=0;
-
- /* First parameter line */
+ /* Is it a BOM UTF-8 Windows file? */
+ /* First parameter line */
while(fgets(line, MAXLINE, ficpar)) {
+ noffset=0;
+ if( line[0] == (char)0xEF && line[1] == (char)0xBB) /* EF BB BF */
+ {
+ noffset=noffset+3;
+ printf("# File is an UTF8 Bom.\n"); // 0xBF
+ }
+ else if( line[0] == (char)0xFE && line[1] == (char)0xFF)
+ {
+ noffset=noffset+2;
+ printf("# File is an UTF16BE BOM file\n");
+ }
+ else if( line[0] == 0 && line[1] == 0)
+ {
+ if( line[2] == (char)0xFE && line[3] == (char)0xFF){
+ noffset=noffset+4;
+ printf("# File is an UTF16BE BOM file\n");
+ }
+ } else{
+ ;/*printf(" Not a BOM file\n");*/
+ }
+
/* If line starts with a # it is a comment */
- if (line[0] == '#') {
+ if (line[noffset] == '#') {
numlinepar++;
fputs(line,stdout);
fputs(line,ficparo);
+ fputs(line,ficres);
fputs(line,ficlog);
continue;
}else
@@ -10685,18 +10973,24 @@ int main(int argc, char *argv[])
title, datafile, &lastobs, &firstpass,&lastpass)) !=EOF){
if (num_filled != 5) {
printf("Should be 5 parameters\n");
+ fprintf(ficlog,"Should be 5 parameters\n");
}
numlinepar++;
printf("title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\n", title, datafile, lastobs, firstpass,lastpass);
+ fprintf(ficparo,"title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\n", title, datafile, lastobs, firstpass,lastpass);
+ fprintf(ficres,"title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\n", title, datafile, lastobs, firstpass,lastpass);
+ fprintf(ficlog,"title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\n", title, datafile, lastobs, firstpass,lastpass);
}
/* Second parameter line */
while(fgets(line, MAXLINE, ficpar)) {
- /* If line starts with a # it is a comment */
+ /* while(fscanf(ficpar,"%[^\n]", line)) { */
+ /* If line starts with a # it is a comment. Strangely fgets reads the EOL and fputs doesn't */
if (line[0] == '#') {
numlinepar++;
- fputs(line,stdout);
- fputs(line,ficparo);
- fputs(line,ficlog);
+ printf("%s",line);
+ fprintf(ficres,"%s",line);
+ fprintf(ficparo,"%s",line);
+ fprintf(ficlog,"%s",line);
continue;
}else
break;
@@ -10706,8 +11000,13 @@ int main(int argc, char *argv[])
if (num_filled != 11) {
printf("Not 11 parameters, for example:ftol=1.e-8 stepm=12 ncovcol=2 nqv=1 ntv=2 nqtv=1 nlstate=2 ndeath=1 maxwav=3 mle=1 weight=1\n");
printf("but line=%s\n",line);
+ fprintf(ficlog,"Not 11 parameters, for example:ftol=1.e-8 stepm=12 ncovcol=2 nqv=1 ntv=2 nqtv=1 nlstate=2 ndeath=1 maxwav=3 mle=1 weight=1\n");
+ fprintf(ficlog,"but line=%s\n",line);
}
printf("ftol=%e stepm=%d ncovcol=%d nqv=%d ntv=%d nqtv=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d\n",ftol, stepm, ncovcol, nqv, ntv, nqtv, nlstate, ndeath, maxwav, mle, weightopt);
+ fprintf(ficparo,"ftol=%e stepm=%d ncovcol=%d nqv=%d ntv=%d nqtv=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d\n",ftol, stepm, ncovcol, nqv, ntv, nqtv, nlstate, ndeath, maxwav, mle, weightopt);
+ fprintf(ficres,"ftol=%e stepm=%d ncovcol=%d nqv=%d ntv=%d nqtv=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d\n",ftol, stepm, ncovcol, nqv, ntv, nqtv, nlstate, ndeath, maxwav, mle, weightopt);
+ fprintf(ficlog,"ftol=%e stepm=%d ncovcol=%d nqv=%d ntv=%d nqtv=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d\n",ftol, stepm, ncovcol, nqv, ntv, nqtv, nlstate, ndeath, maxwav, mle, weightopt);
}
/* ftolpl=6*ftol*1.e5; /\* 6.e-3 make convergences in less than 80 loops for the prevalence limit *\/ */
/*ftolpl=6.e-4; *//* 6.e-3 make convergences in less than 80 loops for the prevalence limit */
@@ -10716,22 +11015,18 @@ int main(int argc, char *argv[])
/* If line starts with a # it is a comment */
if (line[0] == '#') {
numlinepar++;
- fputs(line,stdout);
- fputs(line,ficparo);
- fputs(line,ficlog);
+ printf("%s",line);
+ fprintf(ficres,"%s",line);
+ fprintf(ficparo,"%s",line);
+ fprintf(ficlog,"%s",line);
continue;
}else
break;
}
if((num_filled=sscanf(line,"model=1+age%[^.\n]", model)) !=EOF){
- if (num_filled == 0){
- printf("ERROR %d: Model should be at minimum 'model=1+age.' WITHOUT space:'%s'\n",num_filled, line);
- fprintf(ficlog,"ERROR %d: Model should be at minimum 'model=1+age.' WITHOUT space:'%s'\n",num_filled, line);
- model[0]='\0';
- goto end;
- } else if (num_filled != 1){
- printf("ERROR %d: Model should be at minimum 'model=1+age.' %s\n",num_filled, line);
- fprintf(ficlog,"ERROR %d: Model should be at minimum 'model=1+age.' %s\n",num_filled, line);
+ if (num_filled != 1){
+ printf("ERROR %d: Model should be at minimum 'model=1+age' %s\n",num_filled, line);
+ fprintf(ficlog,"ERROR %d: Model should be at minimum 'model=1+age' %s\n",num_filled, line);
model[0]='\0';
goto end;
}
@@ -10744,20 +11039,23 @@ int main(int argc, char *argv[])
}
/* printf(" model=1+age%s modeltemp= %s, model=%s\n",model, modeltemp, model);fflush(stdout); */
printf("model=1+age+%s\n",model);fflush(stdout);
+ fprintf(ficparo,"model=1+age+%s\n",model);fflush(stdout);
+ fprintf(ficres,"model=1+age+%s\n",model);fflush(stdout);
+ fprintf(ficlog,"model=1+age+%s\n",model);fflush(stdout);
}
/* fscanf(ficpar,"title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\nftol=%lf stepm=%d ncovcol=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d model=1+age+%s\n",title, datafile, &lastobs, &firstpass,&lastpass,&ftol, &stepm, &ncovcol, &nlstate,&ndeath, &maxwav, &mle, &weightopt,model); */
/* numlinepar=numlinepar+3; /\* In general *\/ */
/* printf("title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\nftol=%e stepm=%d ncovcol=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d\nmodel=1+age+%s\n", title, datafile, lastobs, firstpass,lastpass,ftol, stepm, ncovcol, nlstate,ndeath, maxwav, mle, weightopt,model); */
- fprintf(ficparo,"title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\nftol=%e stepm=%d ncovcol=%d nqv=%d ntv=%d nqtv=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d\nmodel=1+age+%s.\n", title, datafile, lastobs, firstpass,lastpass,ftol,stepm,ncovcol, nqv, ntv, nqtv, nlstate,ndeath,maxwav, mle, weightopt,model);
- fprintf(ficlog,"title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\nftol=%e stepm=%d ncovcol=%d nqv=%d ntv=%d nqtv=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d\nmodel=1+age+%s.\n", title, datafile, lastobs, firstpass,lastpass,ftol,stepm,ncovcol, nqv, ntv, nqtv, nlstate,ndeath,maxwav, mle, weightopt,model);
+ /* fprintf(ficparo,"title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\nftol=%e stepm=%d ncovcol=%d nqv=%d ntv=%d nqtv=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d\nmodel=1+age+%s.\n", title, datafile, lastobs, firstpass,lastpass,ftol,stepm,ncovcol, nqv, ntv, nqtv, nlstate,ndeath,maxwav, mle, weightopt,model); */
+ /* fprintf(ficlog,"title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\nftol=%e stepm=%d ncovcol=%d nqv=%d ntv=%d nqtv=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d\nmodel=1+age+%s.\n", title, datafile, lastobs, firstpass,lastpass,ftol,stepm,ncovcol, nqv, ntv, nqtv, nlstate,ndeath,maxwav, mle, weightopt,model); */
fflush(ficlog);
/* if(model[0]=='#'|| model[0]== '\0'){ */
if(model[0]=='#'){
- printf("Error in 'model' line: model should start with 'model=1+age+' and end with '.' \n \
- 'model=1+age+.' or 'model=1+age+V1.' or 'model=1+age+age*age+V1+V1*age.' or \n \
- 'model=1+age+V1+V2.' or 'model=1+age+V1+V2+V1*V2.' etc. \n"); \
+ printf("Error in 'model' line: model should start with 'model=1+age+' and end without space \n \
+ 'model=1+age+' or 'model=1+age+V1.' or 'model=1+age+age*age+V1+V1*age' or \n \
+ 'model=1+age+V1+V2' or 'model=1+age+V1+V2+V1*V2' etc. \n"); \
if(mle != -1){
- printf("Fix the model line and run imach with mle=-1 to get a correct template of the parameter file.\n");
+ printf("Fix the model line and run imach with mle=-1 to get a correct template of the parameter vectors and subdiagonal covariance matrix.\n");
exit(1);
}
}
@@ -10979,16 +11277,6 @@ Please run with mle=-1 to get a correct
fflush(ficlog);
- /*-------- Rewriting parameter file ----------*/
- strcpy(rfileres,"r"); /* "Rparameterfile */
- strcat(rfileres,optionfilefiname); /* Parameter file first name*/
- strcat(rfileres,"."); /* */
- strcat(rfileres,optionfilext); /* Other files have txt extension */
- if((ficres =fopen(rfileres,"w"))==NULL) {
- printf("Problem writing new parameter file: %s\n", rfileres);goto end;
- fprintf(ficlog,"Problem writing new parameter file: %s\n", rfileres);goto end;
- }
- fprintf(ficres,"#%s\n",version);
} /* End of mle != -3 */
/* Main data
@@ -11326,10 +11614,31 @@ Title=%s
Datafile=%s Firstpass=%d La
firstpass, lastpass, stepm, weightopt, model);
fprintf(fichtm,"\n");
- fprintf(fichtm,"
Total number of observations=%d
\n\
+ fprintf(fichtm,"Parameter line 2
- Tolerance for the convergence of the likelihood: ftol=%f \n
- Interval for the elementary matrix (in month): stepm=%d",\
+ ftol, stepm);
+ fprintf(fichtm,"\n
- Number of fixed dummy covariates: ncovcol=%d ", ncovcol);
+ ncurrv=1;
+ for(i=ncurrv; i <=ncovcol; i++) fprintf(fichtm,"V%d ", i);
+ fprintf(fichtm,"\n
- Number of fixed quantitative variables: nqv=%d ", nqv);
+ ncurrv=i;
+ for(i=ncurrv; i <=ncurrv-1+nqv; i++) fprintf(fichtm,"V%d ", i);
+ fprintf(fichtm,"\n
- Number of time varying (wave varying) covariates: ntv=%d ", ntv);
+ ncurrv=i;
+ for(i=ncurrv; i <=ncurrv-1+ntv; i++) fprintf(fichtm,"V%d ", i);
+ fprintf(fichtm,"\n
- Number of quantitative time varying covariates: nqtv=%d ", nqtv);
+ ncurrv=i;
+ for(i=ncurrv; i <=ncurrv-1+nqtv; i++) fprintf(fichtm,"V%d ", i);
+ fprintf(fichtm,"\n
- Weights column \n
Number of alive states: nlstate=%d
Number of death states (not really implemented): ndeath=%d \n - Number of waves: maxwav=%d \n
- Parameter for maximization (1), using parameter values (0), for design of parameters and variance-covariance matrix: mle=%d \n
- Does the weight column be taken into account (1), or not (0): weight=%d
\n", \
+ nlstate, ndeath, maxwav, mle, weightopt);
+
+ fprintf(fichtm," Diagram of states %s_.svg
\n\
+", subdirf2(optionfilefiname,"D_"),subdirf2(optionfilefiname,"D_"),subdirf2(optionfilefiname,"D_"));
+
+
+ fprintf(fichtm,"\nSome descriptive statistics
\n
Total number of observations=%d
\n\
Youngest age at first (selected) pass %.2f, oldest age %.2f
\n\
Interval (in months) between two waves: Min=%d Max=%d Mean=%.2lf
\n",\
- imx,agemin,agemax,jmin,jmax,jmean);
+ 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 */
@@ -11601,7 +11910,7 @@ Please run with mle=-1 to get a correct
printf("\n");
/*--------- results files --------------*/
- fprintf(ficres,"title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\nftol=%e stepm=%d ncovcol=%d nqv=%d ntv=%d nqtv=%d nlstate=%d ndeath=%d maxwav=%d mle= 0 weight=%d\nmodel=1+age+%s.\n", title, datafile, lastobs, firstpass,lastpass,ftol, stepm, ncovcol, nqv, ntv, nqtv, nlstate, ndeath, maxwav, weightopt,model);
+ /* fprintf(ficres,"title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\nftol=%e stepm=%d ncovcol=%d nqv=%d ntv=%d nqtv=%d nlstate=%d ndeath=%d maxwav=%d mle= 0 weight=%d\nmodel=1+age+%s.\n", title, datafile, lastobs, firstpass,lastpass,ftol, stepm, ncovcol, nqv, ntv, nqtv, nlstate, ndeath, maxwav, weightopt,model); */
fprintf(ficres,"# Parameters nlstate*nlstate*ncov a12*1 + b12 * age + ...\n");
@@ -11889,6 +12198,9 @@ Please run with mle=-1 to get a correct
fprintf(ficlog,"prevforecast=%d starting-proj-date=%.lf/%.lf/%.lf final-proj-date=%.lf/%.lf/%.lf mobil_average=%d\n",prevfcast,jproj1,mproj1,anproj1,jproj2,mproj2,anproj2,mobilavproj);
fprintf(ficres,"prevforecast=%d starting-proj-date=%.lf/%.lf/%.lf final-proj-date=%.lf/%.lf/%.lf mobil_average=%d\n",prevfcast,jproj1,mproj1,anproj1,jproj2,mproj2,anproj2,mobilavproj);
/* day and month of proj2 are not used but only year anproj2.*/
+ dateproj1=anproj1+(mproj1-1)/12.+(jproj1-1)/365.;
+ dateproj2=anproj2+(mproj2-1)/12.+(jproj2-1)/365.;
+
}
break;
case 12:
@@ -11904,6 +12216,8 @@ Please run with mle=-1 to get a correct
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.*/
+ dateback1=anback1+(mback1-1)/12.+(jback1-1)/365.;
+ dateback2=anback2+(mback2-1)/12.+(jback2-1)/365.;
}
break;
case 13:
@@ -11954,11 +12268,12 @@ Please run with mle=-1 to get a correct
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{
- printinggnuplot(fileresu, optionfilefiname,ageminpar,agemaxpar,fage, prevfcast, backcast, pathc,p, (int)anproj1-(int)agemin, (int)anback1-(int)agemax+1);
+ /* printinggnuplot(fileresu, optionfilefiname,ageminpar,agemaxpar,fage, prevfcast, backcast, pathc,p, (int)anproj1-(int)agemin, (int)anback1-(int)agemax+1); */
+ printinggnuplot(fileresu, optionfilefiname,ageminpar,agemaxpar,bage, fage, prevfcast, backcast, pathc,p, (int)anproj1-bage, (int)anback1-fage);
}
printinghtml(fileresu,title,datafile, firstpass, lastpass, stepm, weightopt, \
model,imx,jmin,jmax,jmean,rfileres,popforecast,mobilav,prevfcast,mobilavproj,backcast, estepm, \
- jprev1,mprev1,anprev1,dateprev1,jprev2,mprev2,anprev2,dateprev2);
+ jprev1,mprev1,anprev1,dateprev1, dateproj1, dateback1,jprev2,mprev2,anprev2,dateprev2,dateproj2, dateback2);
/*------------ free_vector -------------*/
/* chdir(path); */
@@ -11994,16 +12309,17 @@ Please run with mle=-1 to get a correct
k=1;
varprob(optionfilefiname, matcov, p, delti, nlstate, bage, fage,k,Tvar,nbcode, ncodemax,strstart);
- /* Prevalence for each covariates in probs[age][status][cov] */
- probs= ma3x(1,AGESUP,1,nlstate+ndeath, 1,ncovcombmax);
- for(i=1;i<=AGESUP;i++)
+ /* Prevalence for each covariate combination in probs[age][status][cov] */
+ probs= ma3x(AGEINF,AGESUP,1,nlstate+ndeath, 1,ncovcombmax);
+ for(i=AGEINF;i<=AGESUP;i++)
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);
+ 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++)
+ mobaverages= ma3x(AGEINF, AGESUP,1,nlstate+ndeath, 1,ncovcombmax);
+ for(i=AGEINF;i<=AGESUP;i++)
for(j=1;j<=nlstate+ndeath;j++)
for(k=1;k<=ncovcombmax;k++)
mobaverages[i][j][k]=0.;
@@ -12015,31 +12331,27 @@ Please run with mle=-1 to get a correct
fprintf(ficlog," Error in movingaverage mobilav=%d\n",mobilav);
printf(" Error in movingaverage mobilav=%d\n",mobilav);
}
- }
- /* else if(mobilavproj==-1){ /\* Forcing raw observed prevalences *\/ */
- /* for(i=1;i<=AGESUP;i++) */
- /* for(j=1;j<=nlstate;j++) */
- /* for(k=1;k<=ncovcombmax;k++) */
- /* mobaverages[i][j][k]=probs[i][j][k]; */
- /* /\* /\\* 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) {
+ } else if (mobilavproj !=0) {
printf("Movingaveraging projected observed prevalence\n");
fprintf(ficlog,"Movingaveraging projected observed prevalence\n");
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);
}
+ }else{
+ printf("Internal error moving average\n");
+ fflush(stdout);
+ exit(1);
}
}/* end if moving average */
/*---------- Forecasting ------------------*/
- /*if((stepm == 1) && (strcmp(model,".")==0)){*/
if(prevfcast==1){
/* if(stepm ==1){*/
- prevforecast(fileresu, anproj1, mproj1, jproj1, agemin, agemax, dateprev1, dateprev2, mobilavproj, bage, fage, firstpass, lastpass, anproj2, p, cptcoveff);
+ prevforecast(fileresu, anproj1, mproj1, jproj1, agemin, agemax, dateprev1, dateprev2, mobilavproj, mobaverage, bage, fage, firstpass, lastpass, anproj2, p, cptcoveff);
}
+
+ /* Backcasting */
if(backcast==1){
ddnewms=matrix(1,nlstate+ndeath,1,nlstate+ndeath);
ddoldms=matrix(1,nlstate+ndeath,1,nlstate+ndeath);
@@ -12048,71 +12360,23 @@ Please run with mle=-1 to get a correct
/*--------------- 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, mobaverage, anback1, mback1, jback1, agemin, agemax, dateprev1, dateprev2, mobilavproj,
- bage, fage, firstpass, lastpass, anback2, p, cptcoveff);
+ prevbackforecast(fileresu, mobaverage, anback1, mback1, jback1, agemin, agemax, dateprev1, dateprev2,
+ mobilavproj, bage, fage, firstpass, lastpass, anback2, p, cptcoveff);
+ varbprlim(fileresu, nresult, mobaverage, mobilavproj, bage, fage, bprlim, &ncvyear, ftolpl, p, matcov, delti, stepm, cptcoveff);
- /*------- Variance of back (stable) prevalence------*/
- strcpy(fileresvbl,"VBL_");
- strcat(fileresvbl,fileresu);
- if((ficresvbl=fopen(fileresvbl,"w"))==NULL) {
- printf("Problem with variance of back (stable) prevalence resultfile: %s\n", fileresvbl);
- exit(0);
- }
- printf("Computing Variance-covariance of back (stable) prevalence: file '%s' ...", fileresvbl);fflush(stdout);
- fprintf(ficlog, "Computing Variance-covariance of back (stable) prevalence: file '%s' ...", fileresvbl);fflush(ficlog);
-
- /*for(cptcov=1,k=0;cptcov<=i1;cptcov++){
- for(cptcod=1;cptcod<=ncodemax[cptcov];cptcod++){*/
-
- i1=pow(2,cptcoveff);
- if (cptcovn < 1){i1=1;}
-
- for(nres=1; nres <= nresult; nres++) /* For each resultline */
- for(k=1; k<=i1;k++){
- if(i1 != 1 && TKresult[nres]!= k)
- continue;
- fprintf(ficresvbl,"\n#****** ");
- printf("\n#****** ");
- fprintf(ficlog,"\n#****** ");
- for(j=1;j<=cptcoveff;j++) {
- fprintf(ficresvbl,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
- fprintf(ficlog,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
- printf("V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
- }
- for (j=1; j<= nsq; j++){ /* For each selected (single) quantitative value */
- printf(" V%d=%f ",Tvqresult[nres][j],Tqresult[nres][j]);
- fprintf(ficresvbl," V%d=%f ",Tvqresult[nres][j],Tqresult[nres][j]);
- fprintf(ficlog," V%d=%f ",Tvqresult[nres][j],Tqresult[nres][j]);
- }
- fprintf(ficresvbl,"******\n");
- printf("******\n");
- fprintf(ficlog,"******\n");
-
- varbpl=matrix(1,nlstate,(int) bage, (int) fage);
- oldm=oldms;savm=savms;
-
- varbrevlim(fileres, varbpl, matcov, p, delti, nlstate, stepm, (int) bage, (int) fage, oldm, savm, bprlim, ftolpl, mobilavproj, &ncvyear, k, strstart, nres);
- free_matrix(varbpl,1,nlstate,(int) bage, (int)fage);
- /*}*/
- }
-
- fclose(ficresvbl);
- printf("done variance-covariance of back prevalence\n");fflush(stdout);
- fprintf(ficlog,"done variance-covariance of back prevalence\n");fflush(ficlog);
-
+ free_matrix(bprlim,1,nlstate,1,nlstate); /*here or after loop ? */
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);
- }
- free_matrix(bprlim,1,nlstate,1,nlstate); /*here or after loop ? */
+ } /* end Backcasting */
/* ------ Other prevalence ratios------------ */
@@ -12165,10 +12429,10 @@ Please run with mle=-1 to get a correct
fclose(ficreseij);
printf("done evsij\n");fflush(stdout);
fprintf(ficlog,"done evsij\n");fflush(ficlog);
+
/*---------- State-specific expectancies and variances ------------*/
-
strcpy(filerest,"T_");
strcat(filerest,fileresu);
if((ficrest=fopen(filerest,"w"))==NULL) {
@@ -12177,8 +12441,6 @@ Please run with mle=-1 to get a correct
}
printf("Computing Total Life expectancies with their standard errors: file '%s' ...\n", filerest); fflush(stdout);
fprintf(ficlog,"Computing Total Life expectancies with their standard errors: file '%s' ...\n", filerest); fflush(ficlog);
-
-
strcpy(fileresstde,"STDE_");
strcat(fileresstde,fileresu);
if((ficresstdeij=fopen(fileresstde,"w"))==NULL) {
@@ -12206,9 +12468,6 @@ Please run with mle=-1 to get a correct
printf(" Computing Variance-covariance of State-specific Expectancies: file '%s' ... ", fileresv);fflush(stdout);
fprintf(ficlog," Computing Variance-covariance of State-specific Expectancies: file '%s' ... ", fileresv);fflush(ficlog);
- /*for(cptcov=1,k=0;cptcov<=i1;cptcov++){
- for(cptcod=1;cptcod<=ncodemax[cptcov];cptcod++){*/
-
i1=pow(2,cptcoveff); /* Number of combination of dummy covariates */
if (cptcovn < 1){i1=1;}
@@ -12270,7 +12529,7 @@ Please run with mle=-1 to get a correct
vareij=ma3x(1,nlstate,1,nlstate,(int) bage, (int) fage);
pstamp(ficrest);
-
+ epj=vector(1,nlstate+1);
for(vpopbased=0; vpopbased <= popbased; vpopbased++){ /* Done for vpopbased=0 and vpopbased=1 if popbased==1*/
oldm=oldms;savm=savms; /* ZZ Segmentation fault */
cptcod= 0; /* To be deleted */
@@ -12286,7 +12545,6 @@ Please run with mle=-1 to get a correct
for (i=1;i<=nlstate;i++) fprintf(ficrest,"e.%d (std) ",i);
fprintf(ficrest,"\n");
/* printf("Which p?\n"); for(i=1;i<=npar;i++)printf("p[i=%d]=%lf,",i,p[i]);printf("\n"); */
- epj=vector(1,nlstate+1);
printf("Computing age specific period (stable) prevalences in each health state \n");
fprintf(ficlog,"Computing age specific period (stable) prevalences in each health state \n");
for(age=bage; age <=fage ;age++){
@@ -12324,66 +12582,19 @@ Please run with mle=-1 to get a correct
fprintf(ficrest,"\n");
}
} /* End vpopbased */
+ free_vector(epj,1,nlstate+1);
free_ma3x(eij,1,nlstate,1,nlstate,(int) bage, (int)fage);
free_ma3x(vareij,1,nlstate,1,nlstate,(int) bage, (int)fage);
- free_vector(epj,1,nlstate+1);
printf("done selection\n");fflush(stdout);
fprintf(ficlog,"done selection\n");fflush(ficlog);
- /*}*/
} /* End k selection */
printf("done State-specific expectancies\n");fflush(stdout);
fprintf(ficlog,"done State-specific expectancies\n");fflush(ficlog);
- /*------- Variance of period (stable) prevalence------*/
-
- strcpy(fileresvpl,"VPL_");
- strcat(fileresvpl,fileresu);
- if((ficresvpl=fopen(fileresvpl,"w"))==NULL) {
- printf("Problem with variance of period (stable) prevalence resultfile: %s\n", fileresvpl);
- exit(0);
- }
- printf("Computing Variance-covariance of period (stable) prevalence: file '%s' ...", fileresvpl);fflush(stdout);
- fprintf(ficlog, "Computing Variance-covariance of period (stable) prevalence: file '%s' ...", fileresvpl);fflush(ficlog);
-
- /*for(cptcov=1,k=0;cptcov<=i1;cptcov++){
- for(cptcod=1;cptcod<=ncodemax[cptcov];cptcod++){*/
-
- i1=pow(2,cptcoveff);
- if (cptcovn < 1){i1=1;}
-
- for(nres=1; nres <= nresult; nres++) /* For each resultline */
- for(k=1; k<=i1;k++){
- if(i1 != 1 && TKresult[nres]!= k)
- continue;
- fprintf(ficresvpl,"\n#****** ");
- printf("\n#****** ");
- fprintf(ficlog,"\n#****** ");
- for(j=1;j<=cptcoveff;j++) {
- fprintf(ficresvpl,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
- fprintf(ficlog,"V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
- printf("V%d=%d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]);
- }
- for (j=1; j<= nsq; j++){ /* For each selected (single) quantitative value */
- printf(" V%d=%f ",Tvqresult[nres][j],Tqresult[nres][j]);
- fprintf(ficresvpl," V%d=%f ",Tvqresult[nres][j],Tqresult[nres][j]);
- fprintf(ficlog," V%d=%f ",Tvqresult[nres][j],Tqresult[nres][j]);
- }
- fprintf(ficresvpl,"******\n");
- printf("******\n");
- fprintf(ficlog,"******\n");
-
- varpl=matrix(1,nlstate,(int) bage, (int) fage);
- oldm=oldms;savm=savms;
- varprevlim(fileres, varpl, matcov, p, delti, nlstate, stepm, (int) bage, (int) fage, oldm, savm, prlim, ftolpl, &ncvyear, k, strstart, nres);
- free_matrix(varpl,1,nlstate,(int) bage, (int)fage);
- /*}*/
- }
-
- fclose(ficresvpl);
- printf("done variance-covariance of period prevalence\n");fflush(stdout);
- fprintf(ficlog,"done variance-covariance of period prevalence\n");fflush(ficlog);
+ /* variance-covariance of period prevalence*/
+ varprlim(fileresu, nresult, mobaverage, mobilavproj, bage, fage, prlim, &ncvyear, ftolpl, p, matcov, delti, stepm, cptcoveff);
free_vector(weight,1,n);
@@ -12402,8 +12613,8 @@ Please run with mle=-1 to get a correct
/*---------- End : free ----------------*/
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);
+ free_ma3x(mobaverages,AGEINF, AGESUP,1,nlstate+ndeath, 1,ncovcombmax); /* We need to have a squared matrix with prevalence of the dead! */
+ free_ma3x(probs,AGEINF,AGESUP,1,nlstate+ndeath, 1,ncovcombmax);
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 */
@@ -12420,6 +12631,7 @@ Please run with mle=-1 to get a correct
/*free_vector(delti,1,npar);*/
free_ma3x(delti3,1,nlstate,1, nlstate+ndeath-1,1,ncovmodel);
free_matrix(agev,1,maxwav,1,imx);
+ free_ma3x(paramstart,1,nlstate,1, nlstate+ndeath-1,1,ncovmodel);
free_ma3x(param,1,nlstate,1, nlstate+ndeath-1,1,ncovmodel);
free_ivector(ncodemax,1,NCOVMAX);
@@ -12496,6 +12708,8 @@ Please run with mle=-1 to get a correct
fclose(ficlog);
/*------ End -----------*/
+
+/* Executes gnuplot */
printf("Before Current directory %s!\n",pathcd);
#ifdef WIN32
@@ -12564,4 +12778,6 @@ end:
printf("\nType q for exiting: "); fflush(stdout);
scanf("%s",z);
}
+ printf("End\n");
+ exit(0);
}