version 1.265, 2017/04/26 16:22:11
|
version 1.267, 2017/05/13 10:25:05
|
Line 1
|
Line 1
|
/* $Id$ |
/* $Id$ |
$State$ |
$State$ |
$Log$ |
$Log$ |
|
Revision 1.267 2017/05/13 10:25:05 brouard |
|
Summary: temporary save for backprojection |
|
|
|
Revision 1.266 2017/05/13 07:26:12 brouard |
|
Summary: Version 0.99r13 (improvements and bugs fixed) |
|
|
Revision 1.265 2017/04/26 16:22:11 brouard |
Revision 1.265 2017/04/26 16:22:11 brouard |
Summary: imach 0.99r13 Some bugs fixed |
Summary: imach 0.99r13 Some bugs fixed |
|
|
Line 815 Back prevalence and projections:
|
Line 821 Back prevalence and projections:
|
p3mat=ma3x(1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm); |
p3mat=ma3x(1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm); |
oldm=oldms;savm=savms; |
oldm=oldms;savm=savms; |
|
|
- hbxij(p3mat,nhstepm,agedeb,hstepm,p,nlstate,stepm,oldm,savm, k); |
- hbxij(p3mat,nhstepm,agedeb,hstepm,p,nlstate,stepm,oldm,savm, k, nres); |
Computes the transition matrix starting at age 'age' over |
Computes the transition matrix starting at age 'age' over |
'nhstepm*hstepm*stepm' months (i.e. until |
'nhstepm*hstepm*stepm' months (i.e. until |
age (in years) age+nhstepm*hstepm*stepm/12) by multiplying |
age (in years) age+nhstepm*hstepm*stepm/12) by multiplying |
Line 2657 Earliest age to start was %d-%d=%d, ncvl
|
Line 2663 Earliest age to start was %d-%d=%d, ncvl
|
max=vector(1,nlstate); |
max=vector(1,nlstate); |
meandiff=vector(1,nlstate); |
meandiff=vector(1,nlstate); |
|
|
dnewm=ddnewms; doldm=ddoldms; dsavm=ddsavms; |
dnewm=ddnewms; doldm=ddoldms; dsavm=ddsavms; |
oldm=oldms; savm=savms; |
oldm=oldms; savm=savms; |
|
|
/* Starting with matrix unity */ |
/* Starting with matrix unity */ |
for (ii=1;ii<=nlstate+ndeath;ii++) |
for (ii=1;ii<=nlstate+ndeath;ii++) |
for (j=1;j<=nlstate+ndeath;j++){ |
for (j=1;j<=nlstate+ndeath;j++){ |
oldm[ii][j]=(ii==j ? 1.0 : 0.0); |
oldm[ii][j]=(ii==j ? 1.0 : 0.0); |
} |
} |
|
|
Line 2736 Earliest age to start was %d-%d=%d, ncvl
|
Line 2742 Earliest age to start was %d-%d=%d, ncvl
|
/* out=matprod2(newm,oldm,1,nlstate+ndeath,1,nlstate+ndeath,1,nlstate+ndeath, bmij(pmmij,cov,ncovmodel,x,nlstate,prevacurrent, ageminpar, agemaxpar, dnewm, doldm, dsavm,ij)); /\* Bug Valgrind *\/ */ |
/* out=matprod2(newm,oldm,1,nlstate+ndeath,1,nlstate+ndeath,1,nlstate+ndeath, bmij(pmmij,cov,ncovmodel,x,nlstate,prevacurrent, ageminpar, agemaxpar, dnewm, doldm, dsavm,ij)); /\* Bug Valgrind *\/ */ |
/* out=matprod2(newm,oldm,1,nlstate+ndeath,1,nlstate+ndeath,1,nlstate+ndeath, bmij(pmmij,cov,ncovmodel,x,nlstate,prevacurrent, dnewm, doldm, dsavm,ij)); /\* Bug Valgrind *\/ */ |
/* out=matprod2(newm,oldm,1,nlstate+ndeath,1,nlstate+ndeath,1,nlstate+ndeath, bmij(pmmij,cov,ncovmodel,x,nlstate,prevacurrent, dnewm, doldm, dsavm,ij)); /\* Bug Valgrind *\/ */ |
out=matprod2(newm,oldm,1,nlstate+ndeath,1,nlstate+ndeath,1,nlstate+ndeath, bmij(pmmij,cov,ncovmodel,x,nlstate,prevacurrent,ij)); /* Bug Valgrind */ |
out=matprod2(newm,oldm,1,nlstate+ndeath,1,nlstate+ndeath,1,nlstate+ndeath, bmij(pmmij,cov,ncovmodel,x,nlstate,prevacurrent,ij)); /* Bug Valgrind */ |
|
/* if((int)age == 70){ */ |
|
/* printf(" Backward prevalim age=%d agefin=%d \n", (int) age, (int) agefin); */ |
|
/* for(i=1; i<=nlstate+ndeath; i++) { */ |
|
/* printf("%d newm= ",i); */ |
|
/* for(j=1;j<=nlstate+ndeath;j++) { */ |
|
/* printf("%f ",newm[i][j]); */ |
|
/* } */ |
|
/* printf("oldm * "); */ |
|
/* for(j=1;j<=nlstate+ndeath;j++) { */ |
|
/* printf("%f ",oldm[i][j]); */ |
|
/* } */ |
|
/* printf(" pmmij "); */ |
|
/* for(j=1;j<=nlstate+ndeath;j++) { */ |
|
/* printf("%f ",pmmij[i][j]); */ |
|
/* } */ |
|
/* printf("\n"); */ |
|
/* } */ |
|
/* } */ |
savm=oldm; |
savm=oldm; |
oldm=newm; |
oldm=newm; |
|
|
for(j=1; j<=nlstate; j++){ |
for(j=1; j<=nlstate; j++){ |
max[j]=0.; |
max[j]=0.; |
min[j]=1.; |
min[j]=1.; |
Line 2788 Oldest age to start was %d-%d=%d, ncvloo
|
Line 2813 Oldest age to start was %d-%d=%d, ncvloo
|
double **pmij(double **ps, double *cov, int ncovmodel, double *x, int nlstate ) |
double **pmij(double **ps, double *cov, int ncovmodel, double *x, int nlstate ) |
{ |
{ |
/* According to parameters values stored in x and the covariate's values stored in cov, |
/* According to parameters values stored in x and the covariate's values stored in cov, |
computes the probability to be observed in state j being in state i by appying the |
computes the probability to be observed in state j (after stepm years) being in state i by appying the |
model to the ncovmodel covariates (including constant and age). |
model to the ncovmodel covariates (including constant and age). |
lnpijopii=ln(pij/pii)= aij+bij*age+cij*v1+dij*v2+... = sum_nc=1^ncovmodel xij(nc)*cov[nc] |
lnpijopii=ln(pij/pii)= aij+bij*age+cij*v1+dij*v2+... = sum_nc=1^ncovmodel xij(nc)*cov[nc] |
and, according on how parameters are entered, the position of the coefficient xij(nc) of the |
and, according on how parameters are entered, the position of the coefficient xij(nc) of the |
Line 2797 double **pmij(double **ps, double *cov,
|
Line 2822 double **pmij(double **ps, double *cov,
|
j>=i nc + ((i-1)*(nlstate+ndeath-1)+(j-2))*ncovmodel |
j>=i nc + ((i-1)*(nlstate+ndeath-1)+(j-2))*ncovmodel |
Computes ln(pij/pii) (lnpijopii), deduces pij/pii by exponentiation, |
Computes ln(pij/pii) (lnpijopii), deduces pij/pii by exponentiation, |
sums on j different of i to get 1-pii/pii, deduces pii, and then all pij. |
sums on j different of i to get 1-pii/pii, deduces pii, and then all pij. |
Outputs ps[i][j] the probability to be observed in j being in j according to |
Outputs ps[i][j] or probability to be observed in j being in i according to |
the values of the covariates cov[nc] and corresponding parameter values x[nc+shiftij] |
the values of the covariates cov[nc] and corresponding parameter values x[nc+shiftij] |
|
Sum on j ps[i][j] should equal to 1. |
*/ |
*/ |
double s1, lnpijopii; |
double s1, lnpijopii; |
/*double t34;*/ |
/*double t34;*/ |
Line 2862 double **pmij(double **ps, double *cov,
|
Line 2888 double **pmij(double **ps, double *cov,
|
/* |
/* |
for(i=1; i<= npar; i++) printf("%f ",x[i]); |
for(i=1; i<= npar; i++) printf("%f ",x[i]); |
goto end;*/ |
goto end;*/ |
return ps; |
return ps; /* Pointer is unchanged since its call */ |
} |
} |
|
|
/*************** backward transition probabilities ***************/ |
/*************** backward transition probabilities ***************/ |
Line 2871 double **pmij(double **ps, double *cov,
|
Line 2897 double **pmij(double **ps, double *cov,
|
/* double **bmij(double **ps, double *cov, int ncovmodel, double *x, int nlstate, double ***prevacurrent, double ***dnewm, double **doldm, double **dsavm, int ij ) */ |
/* double **bmij(double **ps, double *cov, int ncovmodel, double *x, int nlstate, double ***prevacurrent, double ***dnewm, double **doldm, double **dsavm, int ij ) */ |
double **bmij(double **ps, double *cov, int ncovmodel, double *x, int nlstate, double ***prevacurrent, int ij ) |
double **bmij(double **ps, double *cov, int ncovmodel, double *x, int nlstate, double ***prevacurrent, int ij ) |
{ |
{ |
/* Computes the backward probability at age agefin and covariate ij |
/* Computes the backward probability at age agefin and covariate combination ij. In fact cov is already filled and x too. |
* and returns in **ps as well as **bmij. |
* Call to pmij(cov and x), call to cross prevalence, sums and inverses, left multiply, and returns in **ps as well as **bmij. |
*/ |
*/ |
int i, ii, j,k; |
int i, ii, j,k; |
|
|
Line 2889 double **pmij(double **ps, double *cov,
|
Line 2915 double **pmij(double **ps, double *cov,
|
|
|
agefin=cov[2]; |
agefin=cov[2]; |
/* bmij *//* age is cov[2], ij is included in cov, but we need for |
/* bmij *//* age is cov[2], ij is included in cov, but we need for |
the observed prevalence (with this covariate ij) */ |
the observed prevalence (with this covariate ij) at beginning of transition */ |
dsavm=pmij(pmmij,cov,ncovmodel,x,nlstate); |
/* dsavm=pmij(pmmij,cov,ncovmodel,x,nlstate); */ |
|
pmmij=pmij(pmmij,cov,ncovmodel,x,nlstate); /*This is forward probability from agefin to agefin + stepm */ |
|
/* outputs pmmij which is a stochastic matrix */ |
/* We do have the matrix Px in savm and we need pij */ |
/* We do have the matrix Px in savm and we need pij */ |
for (j=1;j<=nlstate+ndeath;j++){ |
for (j=1;j<=nlstate+ndeath;j++){ |
sumnew=0.; /* w1 p11 + w2 p21 only on live states */ |
sumnew=0.; /* w1 p11 + w2 p21 only on live states N1./N..*N11/N1. + N2./N..*N21/N2.=(N11+N21)/N..=N.1/N.. */ |
for (ii=1;ii<=nlstate;ii++){ |
for (ii=1;ii<=nlstate;ii++){ |
sumnew+=dsavm[ii][j]*prevacurrent[(int)agefin][ii][ij]; |
/* sumnew+=dsavm[ii][j]*prevacurrent[(int)agefin][ii][ij]; */ |
|
sumnew+=pmmij[ii][j]*prevacurrent[(int)agefin][ii][ij]; /* Yes prevalence at beginning of transition */ |
} /* sumnew is (N11+N21)/N..= N.1/N.. = sum on i of w_i pij */ |
} /* sumnew is (N11+N21)/N..= N.1/N.. = sum on i of w_i pij */ |
for (ii=1;ii<=nlstate+ndeath;ii++){ |
if(sumnew >= 1.e-10){ |
if(sumnew >= 1.e-10){ |
for (ii=1;ii<=nlstate+ndeath;ii++){ |
/* if(agefin >= agemaxpar && agefin <= agemaxpar+stepm/YEARM){ */ |
/* if(agefin >= agemaxpar && agefin <= agemaxpar+stepm/YEARM){ */ |
/* doldm[ii][j]=(ii==j ? 1./sumnew : 0.0); */ |
/* doldm[ii][j]=(ii==j ? 1./sumnew : 0.0); */ |
/* }else if(agefin >= agemaxpar+stepm/YEARM){ */ |
/* }else if(agefin >= agemaxpar+stepm/YEARM){ */ |
/* doldm[ii][j]=(ii==j ? 1./sumnew : 0.0); */ |
/* doldm[ii][j]=(ii==j ? 1./sumnew : 0.0); */ |
/* }else */ |
/* }else */ |
doldm[ii][j]=(ii==j ? 1./sumnew : 0.0); |
doldm[ii][j]=(ii==j ? 1./sumnew : 0.0); |
}else{ |
} /*End ii */ |
; |
}else{ /* We put the identity matrix */ |
/* printf("ii=%d, i=%d, doldm=%lf dsavm=%lf, probs=%lf, sumnew=%lf,agefin=%d\n",ii,j,doldm[ii][j],dsavm[ii][j],prevacurrent[(int)agefin][ii][ij],sumnew, (int)agefin); */ |
for (ii=1;ii<=nlstate+ndeath;ii++){ |
} |
doldm[ii][j]=(ii==j ? 1. : 0.0); |
} /*End ii */ |
} /*End ii */ |
} /* End j, At the end doldm is diag[1/(w_1p1i+w_2 p2i)] */ |
/* printf("Problem internal bmij A: sum_i w_i*p_ij=N.j/N.. <1.e-10 i=%d, j=%d, sumnew=%lf,agefin=%d\n",ii,j,sumnew, (int)agefin); */ |
/* left Product of this diag matrix by dsavm=Px (newm=dsavm*doldm) */ |
} |
bbmij=matprod2(dnewm, dsavm,1,nlstate+ndeath,1,nlstate+ndeath,1,nlstate+ndeath, doldm); /* Bug Valgrind */ |
} /* End j, At the end doldm is diag[1/(w_1p1i+w_2 p2i)] or identity*/ |
|
/* left Product of this diag matrix by dsavm=Px (dnewm=dsavm*doldm) */ |
|
/* bbmij=matprod2(dnewm, dsavm,1,nlstate+ndeath,1,nlstate+ndeath,1,nlstate+ndeath, doldm); /\* Bug Valgrind *\/ */ |
|
bbmij=matprod2(dnewm, pmmij,1,nlstate+ndeath,1,nlstate+ndeath,1,nlstate+ndeath, doldm); /* Bug Valgrind */ |
/* dsavm=doldm; /\* dsavm is now diag [1/(w_1p1i+w_2 p2i)] but can be overwritten*\/ */ |
/* dsavm=doldm; /\* dsavm is now diag [1/(w_1p1i+w_2 p2i)] but can be overwritten*\/ */ |
/* doldm=dnewm; /\* doldm is now Px * diag [1/(w_1p1i+w_2 p2i)] *\/ */ |
/* doldm=dnewm; /\* doldm is now Px * diag [1/(w_1p1i+w_2 p2i)] *\/ */ |
/* dnewm=dsavm; /\* doldm is now Px * diag [1/(w_1p1i+w_2 p2i)] *\/ */ |
/* dnewm=dsavm; /\* doldm is now Px * diag [1/(w_1p1i+w_2 p2i)] *\/ */ |
/* left Product of this matrix by diag matrix of prevalences (savm) */ |
/* left Product of this matrix by diag matrix of prevalences (savm) */ |
for (j=1;j<=nlstate+ndeath;j++){ |
for (j=1;j<=nlstate+ndeath;j++){ |
|
sumnew=0.; |
for (ii=1;ii<=nlstate+ndeath;ii++){ |
for (ii=1;ii<=nlstate+ndeath;ii++){ |
|
sumnew+=prevacurrent[(int)agefin][ii][ij]; |
dsavm[ii][j]=(ii==j ? prevacurrent[(int)agefin][ii][ij] : 0.0); |
dsavm[ii][j]=(ii==j ? prevacurrent[(int)agefin][ii][ij] : 0.0); |
} |
} |
} /* End j, At the end oldm is diag[1/(w_1p1i+w_2 p2i)] */ |
/* if(sumnew <0.9){ */ |
ps=matprod2(doldm, dsavm,1,nlstate+ndeath,1,nlstate+ndeath,1,nlstate+ndeath, dnewm); /* Bug Valgrind */ |
/* printf("Problem internal bmij B: sum on i wi <0.9: j=%d, sum_i wi=%lf,agefin=%d\n",j,sumnew, (int)agefin); */ |
|
/* } */ |
|
} /* End j, At the end dsavm is diag[(w_i)] */ |
|
/* What if dsavm doesn't sum ii to 1? */ |
|
/* ps=matprod2(doldm, dsavm,1,nlstate+ndeath,1,nlstate+ndeath,1,nlstate+ndeath, dnewm); /\* Bug Valgrind *\/ */ |
|
ps=matprod2(ps, dsavm,1,nlstate+ndeath,1,nlstate+ndeath,1,nlstate+ndeath, dnewm); /* Bug Valgrind */ |
/* newm or out is now diag[w_i] * Px * diag [1/(w_1p1i+w_2 p2i)] */ |
/* newm or out is now diag[w_i] * Px * diag [1/(w_1p1i+w_2 p2i)] */ |
/* end bmij */ |
/* end bmij */ |
return ps; |
return ps; /*pointer is unchanged */ |
} |
} |
/*************** transition probabilities ***************/ |
/*************** transition probabilities ***************/ |
|
|
Line 3138 double ***hpxij(double ***po, int nhstep
|
Line 3177 double ***hpxij(double ***po, int nhstep
|
} |
} |
for(i=1; i<=nlstate+ndeath; i++) |
for(i=1; i<=nlstate+ndeath; i++) |
for(j=1;j<=nlstate+ndeath;j++) { |
for(j=1;j<=nlstate+ndeath;j++) { |
po[i][j][h]=newm[i][j]; |
po[i][j][h]=newm[i][j]; |
/*if(h==nhstepm) printf("po[%d][%d][%d]=%f ",i,j,h,po[i][j][h]);*/ |
/*if(h==nhstepm) printf("po[%d][%d][%d]=%f ",i,j,h,po[i][j][h]);*/ |
} |
} |
/*printf("h=%d ",h);*/ |
/*printf("h=%d ",h);*/ |
} /* end h */ |
} /* end h */ |
/* printf("\n H=%d \n",h); */ |
/* printf("\n H=%d \n",h); */ |
return po; |
return po; |
} |
} |
|
|
/************* Higher Back Matrix Product ***************/ |
/************* Higher Back Matrix Product ***************/ |
/* double ***hbxij(double ***po, int nhstepm, double age, int hstepm, double *x, double ***prevacurrent, int nlstate, int stepm, double **oldm, double **savm, double **dnewm, double **doldm, double **dsavm, int ij ) */ |
/* double ***hbxij(double ***po, int nhstepm, double age, int hstepm, double *x, double ***prevacurrent, int nlstate, int stepm, double **oldm, double **savm, double **dnewm, double **doldm, double **dsavm, int ij ) */ |
double ***hbxij(double ***po, int nhstepm, double age, int hstepm, double *x, double ***prevacurrent, int nlstate, int stepm, int ij ) |
double ***hbxij(double ***po, int nhstepm, double age, int hstepm, double *x, double ***prevacurrent, int nlstate, int stepm, int ij, int nres ) |
{ |
{ |
/* Computes the transition matrix starting at age 'age' over |
/* For a combination of dummy covariate ij, computes the transition matrix starting at age 'age' over |
'nhstepm*hstepm*stepm' months (i.e. until |
'nhstepm*hstepm*stepm' months (i.e. until |
age (in years) age+nhstepm*hstepm*stepm/12) by multiplying |
age (in years) age+nhstepm*hstepm*stepm/12) by multiplying |
nhstepm*hstepm matrices. |
nhstepm*hstepm matrices. |
Line 3159 double ***hbxij(double ***po, int nhstep
|
Line 3198 double ***hbxij(double ***po, int nhstep
|
(typically every 2 years instead of every month which is too big |
(typically every 2 years instead of every month which is too big |
for the memory). |
for the memory). |
Model is determined by parameters x and covariates have to be |
Model is determined by parameters x and covariates have to be |
included manually here. |
included manually here. Then we use a call to bmij(x and cov) |
|
The addresss of po (p3mat allocated to the dimension of nhstepm) should be stored for output |
*/ |
*/ |
|
|
int i, j, d, h, k; |
int i, j, d, h, k; |
double **out, cov[NCOVMAX+1]; |
double **out, cov[NCOVMAX+1], **bmij(); |
double **newm; |
double **newm, ***newmm; |
double agexact; |
double agexact; |
double agebegin, ageend; |
double agebegin, ageend; |
double **oldm, **savm; |
double **oldm, **savm; |
|
|
oldm=oldms;savm=savms; |
newmm=po; /* To be saved */ |
|
oldm=oldms;savm=savms; /* Global pointers */ |
/* Hstepm could be zero and should return the unit matrix */ |
/* Hstepm could be zero and should return the unit matrix */ |
for (i=1;i<=nlstate+ndeath;i++) |
for (i=1;i<=nlstate+ndeath;i++) |
for (j=1;j<=nlstate+ndeath;j++){ |
for (j=1;j<=nlstate+ndeath;j++){ |
Line 3183 double ***hbxij(double ***po, int nhstep
|
Line 3223 double ***hbxij(double ***po, int nhstep
|
newm=savm; |
newm=savm; |
/* Covariates have to be included here again */ |
/* Covariates have to be included here again */ |
cov[1]=1.; |
cov[1]=1.; |
agexact=age-((h-1)*hstepm + (d-1))*stepm/YEARM; /* age just before transition */ |
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 *\/ */ |
/* agexact=age+((h-1)*hstepm + (d-1))*stepm/YEARM; /\* age just before transition *\/ */ |
cov[2]=agexact; |
cov[2]=agexact; |
if(nagesqr==1) |
if(nagesqr==1) |
cov[3]= agexact*agexact; |
cov[3]= agexact*agexact; |
for (k=1; k<=cptcovn;k++) |
for (k=1; k<=cptcovn;k++){ |
cov[2+nagesqr+k]=nbcode[Tvar[k]][codtabm(ij,k)]; |
/* cov[2+nagesqr+k]=nbcode[Tvar[k]][codtabm(ij,k)]; */ |
/* cov[2+nagesqr+k]=nbcode[Tvar[k]][codtabm(ij,Tvar[k])]; */ |
/* /\* cov[2+nagesqr+k]=nbcode[Tvar[k]][codtabm(ij,Tvar[k])]; *\/ */ |
for (k=1; k<=cptcovage;k++) /* Should start at cptcovn+1 */ |
cov[2+nagesqr+TvarsDind[k]]=nbcode[TvarsD[k]][codtabm(ij,k)]; |
/* cov[2+Tage[k]]=cov[2+Tage[k]]*cov[2]; */ |
/* printf("hbxij Dummy agexact=%.0f combi=%d k=%d TvarsD[%d]=V%d TvarsDind[%d]=%d nbcode=%d cov[%d]=%lf codtabm(%d,Tvar[%d])=%d \n",agexact,ij,k, k, TvarsD[k],k,TvarsDind[k],nbcode[TvarsD[k]][codtabm(ij,k)],2+nagesqr+TvarsDind[k],cov[2+nagesqr+TvarsDind[k]], ij, k, codtabm(ij,k)); */ |
cov[2+nagesqr+Tage[k]]=nbcode[Tvar[Tage[k]]][codtabm(ij,k)]*cov[2]; |
} |
/* cov[2+nagesqr+Tage[k]]=nbcode[Tvar[Tage[k]]][codtabm(ij,Tvar[Tage[k]])]*cov[2]; */ |
for (k=1; k<=nsq;k++) { /* For single varying covariates only */ |
for (k=1; k<=cptcovprod;k++) /* Useless because included in cptcovn */ |
/* Here comes the value of quantitative after renumbering k with single quantitative covariates */ |
|
cov[2+nagesqr+TvarsQind[k]]=Tqresult[nres][k]; |
|
/* printf("hPxij Quantitative k=%d TvarsQind[%d]=%d, TvarsQ[%d]=V%d,Tqresult[%d][%d]=%f\n",k,k,TvarsQind[k],k,TvarsQ[k],nres,k,Tqresult[nres][k]); */ |
|
} |
|
for (k=1; k<=cptcovage;k++){ /* Should start at cptcovn+1 */ |
|
if(Dummy[Tvar[Tage[k]]]){ |
|
cov[2+nagesqr+Tage[k]]=nbcode[Tvar[Tage[k]]][codtabm(ij,k)]*cov[2]; |
|
} else{ |
|
cov[2+nagesqr+Tage[k]]=Tqresult[nres][k]; |
|
} |
|
/* printf("hBxij Age combi=%d k=%d Tage[%d]=V%d Tqresult[%d][%d]=%f\n",ij,k,k,Tage[k],nres,k,Tqresult[nres][k]); */ |
|
} |
|
for (k=1; k<=cptcovprod;k++){ /* Useless because included in cptcovn */ |
cov[2+nagesqr+Tprod[k]]=nbcode[Tvard[k][1]][codtabm(ij,k)]*nbcode[Tvard[k][2]][codtabm(ij,k)]; |
cov[2+nagesqr+Tprod[k]]=nbcode[Tvard[k][1]][codtabm(ij,k)]*nbcode[Tvard[k][2]][codtabm(ij,k)]; |
/* cov[2+nagesqr+Tprod[k]]=nbcode[Tvard[k][1]][codtabm(ij,Tvard[k][1])]*nbcode[Tvard[k][2]][codtabm(ij,Tvard[k][2])]; */ |
} |
|
|
|
|
/*printf("hxi cptcov=%d cptcode=%d\n",cptcov,cptcode);*/ |
/*printf("hxi cptcov=%d cptcode=%d\n",cptcov,cptcode);*/ |
/*printf("h=%d d=%d age=%f cov=%f\n",h,d,age,cov[2]);*/ |
/*printf("h=%d d=%d age=%f cov=%f\n",h,d,age,cov[2]);*/ |
|
|
/* Careful transposed matrix */ |
/* Careful transposed matrix */ |
/* age is in cov[2] */ |
/* age is in cov[2], prevacurrent at beginning of transition. */ |
/* out=matprod2(newm, bmij(pmmij,cov,ncovmodel,x,nlstate,prevacurrent, dnewm, doldm, dsavm,ij),\ */ |
/* out=matprod2(newm, bmij(pmmij,cov,ncovmodel,x,nlstate,prevacurrent, dnewm, doldm, dsavm,ij),\ */ |
/* 1,nlstate+ndeath,1,nlstate+ndeath,1,nlstate+ndeath, oldm); */ |
/* 1,nlstate+ndeath,1,nlstate+ndeath,1,nlstate+ndeath, oldm); */ |
out=matprod2(newm, bmij(pmmij,cov,ncovmodel,x,nlstate,prevacurrent,ij),\ |
out=matprod2(newm, bmij(pmmij,cov,ncovmodel,x,nlstate,prevacurrent,ij),\ |
Line 4947 void prevalence(double ***probs, double
|
Line 4998 void prevalence(double ***probs, double
|
} else{ |
} else{ |
if(first==1){ |
if(first==1){ |
first=0; |
first=0; |
printf("Warning Observed prevalence probs[%d][%d][%d]=%lf because of lack of cases\nSee others in log file...\n",jk,i,j1,probs[i][jk][j1]); |
printf("Warning Observed prevalence doesn't sum to 1 for state %d: probs[%d][%d][%d]=%lf because of lack of cases\nSee others in log file...\n",jk,i,jk, j1,probs[i][jk][j1]); |
|
fprintf(ficlog,"Warning Observed prevalence doesn't sum to 1 for state %d: probs[%d][%d][%d]=%lf because of lack of cases\nSee others in log file...\n",jk,i,jk, j1,probs[i][jk][j1]); |
|
}else{ |
|
fprintf(ficlog,"Warning Observed prevalence doesn't sum to 1 for state %d: probs[%d][%d][%d]=%lf because of lack of cases\nSee others in log file...\n",jk,i,jk, j1,probs[i][jk][j1]); |
} |
} |
} |
} |
} |
} |
Line 6185 void varprob(char optionfilefiname[], do
|
Line 6239 void varprob(char optionfilefiname[], do
|
fprintf(fichtm,"\n<li><h4> Computing and drawing one step probabilities with their confidence intervals</h4></li>\n"); |
fprintf(fichtm,"\n<li><h4> Computing and drawing one step probabilities with their confidence intervals</h4></li>\n"); |
fprintf(fichtm,"\n"); |
fprintf(fichtm,"\n"); |
|
|
fprintf(fichtm,"\n<li><h4> <a href=\"%s\">Matrix of variance-covariance of one-step probabilities (drawings)</a></h4> this page is important in order to visualize confidence intervals and especially correlation between disability and recovery, or more generally, way in and way back.</li>\n",optionfilehtmcov); |
fprintf(fichtm,"\n<li><h4> <a href=\"%s\">Matrix of variance-covariance of one-step probabilities (drawings)</a></h4> this page is important in order to visualize confidence intervals and especially correlation between disability and recovery, or more generally, way in and way back. %s</li>\n",optionfilehtmcov,optionfilehtmcov); |
fprintf(fichtmcov,"Current page is file <a href=\"%s\">%s</a><br>\n\n<h4>Matrix of variance-covariance of pairs of step probabilities</h4>\n",optionfilehtmcov, optionfilehtmcov); |
fprintf(fichtmcov,"Current page is file <a href=\"%s\">%s</a><br>\n\n<h4>Matrix of variance-covariance of pairs of step probabilities</h4>\n",optionfilehtmcov, optionfilehtmcov); |
fprintf(fichtmcov,"\nEllipsoids of confidence centered on point (p<inf>ij</inf>, p<inf>kl</inf>) are estimated \ |
fprintf(fichtmcov,"\nEllipsoids of confidence centered on point (p<inf>ij</inf>, p<inf>kl</inf>) are estimated \ |
and drawn. It helps understanding how is the covariance between two incidences.\ |
and drawn. It helps understanding how is the covariance between two incidences.\ |
Line 6402 To be simple, these graphs help to under
|
Line 6456 To be simple, these graphs help to under
|
fprintf(ficgp,"\nset parametric;unset label"); |
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 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(ficgp,"\nset ter svg size 640, 480"); |
fprintf(fichtmcov,"\n<br>Ellipsoids of confidence cov(p%1d%1d,p%1d%1d) expressed in year<sup>-1</sup>\ |
fprintf(fichtmcov,"\n<p><br>Ellipsoids of confidence cov(p%1d%1d,p%1d%1d) expressed in year<sup>-1</sup>\ |
:<a href=\"%s_%d%1d%1d-%1d%1d.svg\"> \ |
:<a href=\"%s_%d%1d%1d-%1d%1d.svg\"> \ |
%s_%d%1d%1d-%1d%1d.svg</A>, ",k1,l1,k2,l2,\ |
%s_%d%1d%1d-%1d%1d.svg</A>, ",k1,l1,k2,l2,\ |
subdirf2(optionfilefiname,"VARPIJGR_"), j1,k1,l1,k2,l2, \ |
subdirf2(optionfilefiname,"VARPIJGR_"), j1,k1,l1,k2,l2, \ |
Line 6413 To be simple, these graphs help to under
|
Line 6467 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,"\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,"\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", \ |
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), \ |
mu1,std,v11,sqrt(lc1),v12,sqrt(fabs(lc2)), \ |
mu2,std,v21,sqrt(lc1),v22,sqrt(lc2)); |
mu2,std,v21,sqrt(lc1),v22,sqrt(fabs(lc2))); /* For gnuplot only */ |
}else{ |
}else{ |
first=0; |
first=0; |
fprintf(fichtmcov," %d (%.3f),",(int) age, c12); |
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,"\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,"\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", \ |
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), \ |
mu1,std,v11,sqrt(lc1),v12,sqrt(fabs(lc2)), \ |
mu2,std,v21,sqrt(lc1),v22,sqrt(lc2)); |
mu2,std,v21,sqrt(lc1),v22,sqrt(fabs(lc2))); |
}/* if first */ |
}/* if first */ |
} /* age mod 5 */ |
} /* age mod 5 */ |
} /* end loop age */ |
} /* end loop age */ |
Line 6713 true period expectancies (those weighted
|
Line 6767 true period expectancies (those weighted
|
} |
} |
|
|
/******************* Gnuplot file **************/ |
/******************* Gnuplot file **************/ |
void printinggnuplot(char fileresu[], char optionfilefiname[], double ageminpar, double agemaxpar, double fage , int prevfcast, int backcast, char pathc[], double p[]){ |
void printinggnuplot(char fileresu[], char optionfilefiname[], double ageminpar, double agemaxpar, double fage , int prevfcast, int backcast, char pathc[], double p[], int offyear){ |
|
|
char dirfileres[132],optfileres[132]; |
char dirfileres[132],optfileres[132]; |
char gplotcondition[132], gplotlabel[132]; |
char gplotcondition[132], gplotlabel[132]; |
Line 6723 void printinggnuplot(char fileresu[], ch
|
Line 6777 void printinggnuplot(char fileresu[], ch
|
int vpopbased; |
int vpopbased; |
int ioffset; /* variable offset for columns */ |
int ioffset; /* variable offset for columns */ |
int nres=0; /* Index of resultline */ |
int nres=0; /* Index of resultline */ |
|
int istart=1; /* For starting graphs in projections */ |
|
|
/* if((ficgp=fopen(optionfilegnuplot,"a"))==NULL) { */ |
/* if((ficgp=fopen(optionfilegnuplot,"a"))==NULL) { */ |
/* printf("Problem with file %s",optionfilegnuplot); */ |
/* printf("Problem with file %s",optionfilegnuplot); */ |
Line 7253 set ter svg size 640, 480\nunset log y\n
|
Line 7308 set ter svg size 640, 480\nunset log y\n
|
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 xlabel \"Age\" \nset ylabel \"Prevalence\" \n\ |
fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Prevalence\" \n\ |
set ter svg size 640, 480\nunset log y\nplot [%.f:%.f] ", ageminpar, agemaxpar); |
set ter svg size 640, 480\nunset log y\nplot [%.f:%.f] ", ageminpar, agemaxpar); |
for (i=1; i<= nlstate+1 ; i ++){ /* nlstate +1 p11 p21 p.1 */ |
|
|
/* for (i=1; i<= nlstate+1 ; i ++){ /\* nlstate +1 p11 p21 p.1 *\/ */ |
|
istart=nlstate+1; /* Could be one if by state, but nlstate+1 is w.i projection only */ |
|
/*istart=1;*/ /* Could be one if by state, but nlstate+1 is w.i projection only */ |
|
for (i=istart; 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*/ |
/*# 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 */ |
/*# 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*/ |
/*# 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 */ |
/*# 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 */ |
if(i==1){ |
if(i==istart){ |
fprintf(ficgp,"\"%s\"",subdirf2(fileresu,"F_")); |
fprintf(ficgp,"\"%s\"",subdirf2(fileresu,"F_")); |
}else{ |
}else{ |
fprintf(ficgp,",\\\n '' "); |
fprintf(ficgp,",\\\n '' "); |
Line 7270 set ter svg size 640, 480\nunset log y\n
|
Line 7329 set ter svg size 640, 480\nunset log y\n
|
/*# V1 = 1 yearproj age p11 p21 p31 p.1 p12 p22 p32 p.2 p13 p23 p33 p.3 p14 p24 p34 p.4*/ |
/*# 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 */ |
/*# 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 */ |
fprintf(ficgp," u %d:(", ioffset); |
fprintf(ficgp," u %d:(", ioffset); |
if(i==nlstate+1) |
if(i==nlstate+1){ |
fprintf(ficgp," $%d/(1.-$%d)) t 'pw.%d' with line ", \ |
fprintf(ficgp," $%d/(1.-$%d)):5 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 ", \ |
|
offyear, \ |
ioffset+(cpt-1)*(nlstate+1)+1+(i-1), ioffset+1+(i-1)+(nlstate+1)*nlstate,cpt ); |
ioffset+(cpt-1)*(nlstate+1)+1+(i-1), ioffset+1+(i-1)+(nlstate+1)*nlstate,cpt ); |
else |
}else |
fprintf(ficgp," $%d/(1.-$%d)) t 'p%d%d' with line ", \ |
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 ); |
ioffset+(cpt-1)*(nlstate+1)+1+(i-1), ioffset+1+(i-1)+(nlstate+1)*nlstate,i,cpt ); |
}else{ /* more than 2 covariates */ |
}else{ /* more than 2 covariates */ |
Line 7305 set ter svg size 640, 480\nunset log y\n
|
Line 7369 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 */ |
/*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*/ |
/* '' 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){ |
if(i==nlstate+1){ |
fprintf(ficgp,"%s ? $%d/(1.-$%d) : 1/0) t 'p.%d' with line ", gplotcondition, \ |
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,",\\\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,cpt ); |
ioffset+(cpt-1)*(nlstate+1)+1+(i-1), ioffset+1+(i-1)+(nlstate+1)*nlstate,cpt ); |
|
/* '' 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{ |
}else{ |
fprintf(ficgp,"%s ? $%d/(1.-$%d) : 1/0) t 'p%d%d' with line ", gplotcondition, \ |
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 ); |
ioffset+(cpt-1)*(nlstate+1)+1+(i-1), ioffset +1+(i-1)+(nlstate+1)*nlstate,i,cpt ); |
Line 7526 set ter svg size 640, 480\nunset log y\n
|
Line 7596 set ter svg size 640, 480\nunset log y\n
|
int mobilavrange, mob; |
int mobilavrange, mob; |
int iage=0; |
int iage=0; |
|
|
double sum=0.; |
double sum=0., sumr=0.; |
double age; |
double age; |
double *sumnewp, *sumnewm; |
double *sumnewp, *sumnewm, *sumnewmr; |
double *agemingood, *agemaxgood; /* Currently identical for all covariates */ |
double *agemingood, *agemaxgood; |
|
double *agemingoodr, *agemaxgoodr; |
|
|
|
|
/* modcovmax=2*cptcoveff;/\* Max number of modalities. We suppose */ |
/* modcovmax=2*cptcoveff;/\* Max number of modalities. We suppose */ |
Line 7537 set ter svg size 640, 480\nunset log y\n
|
Line 7608 set ter svg size 640, 480\nunset log y\n
|
|
|
sumnewp = vector(1,ncovcombmax); |
sumnewp = vector(1,ncovcombmax); |
sumnewm = vector(1,ncovcombmax); |
sumnewm = vector(1,ncovcombmax); |
|
sumnewmr = vector(1,ncovcombmax); |
agemingood = vector(1,ncovcombmax); |
agemingood = vector(1,ncovcombmax); |
|
agemingoodr = vector(1,ncovcombmax); |
agemaxgood = vector(1,ncovcombmax); |
agemaxgood = vector(1,ncovcombmax); |
|
agemaxgoodr = vector(1,ncovcombmax); |
|
|
for (cptcod=1;cptcod<=ncovcombmax;cptcod++){ |
for (cptcod=1;cptcod<=ncovcombmax;cptcod++){ |
sumnewm[cptcod]=0.; |
sumnewm[cptcod]=0.; sumnewmr[cptcod]=0.; |
sumnewp[cptcod]=0.; |
sumnewp[cptcod]=0.; |
agemingood[cptcod]=0; |
agemingood[cptcod]=0, agemingoodr[cptcod]=0; |
agemaxgood[cptcod]=0; |
agemaxgood[cptcod]=0, agemaxgoodr[cptcod]=0; |
} |
} |
if (cptcovn<1) ncovcombmax=1; /* At least 1 pass */ |
if (cptcovn<1) ncovcombmax=1; /* At least 1 pass */ |
|
|
if(mobilav==1||mobilav ==3 ||mobilav==5 ||mobilav== 7){ |
if(mobilav==-1 || mobilav==1||mobilav ==3 ||mobilav==5 ||mobilav== 7){ |
if(mobilav==1) mobilavrange=5; /* default */ |
if(mobilav==1 || mobilav==-1) mobilavrange=5; /* default */ |
else mobilavrange=mobilav; |
else mobilavrange=mobilav; |
for (age=bage; age<=fage; age++) |
for (age=bage; age<=fage; age++) |
for (i=1; i<=nlstate;i++) |
for (i=1; i<=nlstate;i++) |
Line 7561 set ter svg size 640, 480\nunset log y\n
|
Line 7635 set ter svg size 640, 480\nunset log y\n
|
*/ |
*/ |
for (mob=3;mob <=mobilavrange;mob=mob+2){ |
for (mob=3;mob <=mobilavrange;mob=mob+2){ |
for (age=bage+(mob-1)/2; age<=fage-(mob-1)/2; age++){ |
for (age=bage+(mob-1)/2; age<=fage-(mob-1)/2; age++){ |
for (i=1; i<=nlstate;i++){ |
for (cptcod=1;cptcod<=ncovcombmax;cptcod++){ |
for (cptcod=1;cptcod<=ncovcombmax;cptcod++){ |
sumnewm[cptcod]=0.; |
|
for (i=1; i<=nlstate;i++){ |
mobaverage[(int)age][i][cptcod] =probs[(int)age][i][cptcod]; |
mobaverage[(int)age][i][cptcod] =probs[(int)age][i][cptcod]; |
for (cpt=1;cpt<=(mob-1)/2;cpt++){ |
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] +=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; |
mobaverage[(int)age][i][cptcod]=mobaverage[(int)age][i][cptcod]/mob; |
} |
sumnewm[cptcod]+=mobaverage[(int)age][i][cptcod]; |
} |
} /* end i */ |
|
if(sumnewm[cptcod] >1.e-3) mobaverage[(int)age][i][cptcod]=mobaverage[(int)age][i][cptcod]/sumnewm[cptcod]; /* Rescaling to sum one */ |
|
} /* end cptcod */ |
}/* end age */ |
}/* end age */ |
}/* end mob */ |
}/* end mob */ |
}else |
}else{ |
|
printf("Error internal in movingaverage, mobilav=%d.\n",mobilav); |
return -1; |
return -1; |
for (cptcod=1;cptcod<=ncovcombmax;cptcod++){ |
} |
|
|
|
for (cptcod=1;cptcod<=ncovcombmax;cptcod++){ /* for each combination */ |
/* for (age=bage+(mob-1)/2; age<=fage-(mob-1)/2; age++){ */ |
/* for (age=bage+(mob-1)/2; age<=fage-(mob-1)/2; age++){ */ |
if(invalidvarcomb[cptcod]){ |
if(invalidvarcomb[cptcod]){ |
printf("\nCombination (%d) ignored because no cases \n",cptcod); |
printf("\nCombination (%d) ignored because no cases \n",cptcod); |
continue; |
continue; |
} |
} |
|
|
agemingood[cptcod]=fage-(mob-1)/2; |
for (age=fage-(mob-1)/2; age>=bage+(mob-1)/2; age--){ /*looking for the youngest and oldest good age */ |
for (age=fage-(mob-1)/2; age>=bage; age--){/* From oldest to youngest, finding the youngest wrong */ |
|
sumnewm[cptcod]=0.; |
sumnewm[cptcod]=0.; |
|
sumnewmr[cptcod]=0.; |
for (i=1; i<=nlstate;i++){ |
for (i=1; i<=nlstate;i++){ |
sumnewm[cptcod]+=mobaverage[(int)age][i][cptcod]; |
sumnewm[cptcod]+=mobaverage[(int)age][i][cptcod]; |
|
sumnewmr[cptcod]+=probs[(int)age][i][cptcod]; |
|
} |
|
if(fabs(sumnewmr[cptcod] - 1.) <= 1.e-3) { /* good without smoothing */ |
|
agemingoodr[cptcod]=age; |
} |
} |
if(fabs(sumnewm[cptcod] - 1.) <= 1.e-3) { /* good */ |
if(fabs(sumnewm[cptcod] - 1.) <= 1.e-3) { /* good */ |
agemingood[cptcod]=age; |
agemingood[cptcod]=age; |
}else{ /* bad */ |
} |
for (i=1; i<=nlstate;i++){ |
} /* age */ |
mobaverage[(int)age][i][cptcod]=mobaverage[(int)agemingood[cptcod]][i][cptcod]; |
for (age=bage+(mob-1)/2; age<=fage-(mob-1)/2; age++){ /*looking for the youngest and oldest good age */ |
} /* i */ |
|
} /* end bad */ |
|
}/* age */ |
|
sum=0.; |
|
for (i=1; i<=nlstate;i++){ |
|
sum+=mobaverage[(int)agemingood[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 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.; |
sumnewm[cptcod]=0.; |
|
sumnewmr[cptcod]=0.; |
for (i=1; i<=nlstate;i++){ |
for (i=1; i<=nlstate;i++){ |
sumnewm[cptcod]+=mobaverage[(int)age][i][cptcod]; |
sumnewm[cptcod]+=mobaverage[(int)age][i][cptcod]; |
|
sumnewmr[cptcod]+=probs[(int)age][i][cptcod]; |
|
} |
|
if(fabs(sumnewmr[cptcod] - 1.) <= 1.e-3) { /* good without smoothing */ |
|
agemaxgoodr[cptcod]=age; |
} |
} |
if(fabs(sumnewm[cptcod] - 1.) <= 1.e-3) { /* good */ |
if(fabs(sumnewm[cptcod] - 1.) <= 1.e-3) { /* good */ |
agemaxgood[cptcod]=age; |
agemaxgood[cptcod]=age; |
}else{ /* bad */ |
} |
for (i=1; i<=nlstate;i++){ |
} /* age */ |
mobaverage[(int)age][i][cptcod]=mobaverage[(int)agemaxgood[cptcod]][i][cptcod]; |
/* Thus we have agemingood and agemaxgood as well as goodr for raw (preobs) */ |
} /* i */ |
/* but they will change */ |
|
for (age=fage-(mob-1)/2; age>=bage; age--){/* From oldest to youngest, filling up to the youngest */ |
|
sumnewm[cptcod]=0.; |
|
sumnewmr[cptcod]=0.; |
|
for (i=1; i<=nlstate;i++){ |
|
sumnewm[cptcod]+=mobaverage[(int)age][i][cptcod]; |
|
sumnewmr[cptcod]+=probs[(int)age][i][cptcod]; |
|
} |
|
if(mobilav==-1){ /* Forcing raw ages if good else agemingood */ |
|
if(fabs(sumnewmr[cptcod] - 1.) <= 1.e-3) { /* good without smoothing */ |
|
agemaxgoodr[cptcod]=age; /* age min */ |
|
for (i=1; i<=nlstate;i++) |
|
mobaverage[(int)age][i][cptcod]=probs[(int)age][i][cptcod]; |
|
}else{ /* bad we change the value with the values of good ages */ |
|
for (i=1; i<=nlstate;i++){ |
|
mobaverage[(int)age][i][cptcod]=mobaverage[(int)agemaxgoodr[cptcod]][i][cptcod]; |
|
} /* i */ |
|
} /* end bad */ |
|
}else{ |
|
if(fabs(sumnewm[cptcod] - 1.) <= 1.e-3) { /* good */ |
|
agemaxgood[cptcod]=age; |
|
}else{ /* bad we change the value with the values of good ages */ |
|
for (i=1; i<=nlstate;i++){ |
|
mobaverage[(int)age][i][cptcod]=mobaverage[(int)agemaxgood[cptcod]][i][cptcod]; |
|
} /* i */ |
|
} /* end bad */ |
|
}/* end else */ |
|
sum=0.;sumr=0.; |
|
for (i=1; i<=nlstate;i++){ |
|
sum+=mobaverage[(int)age][i][cptcod]; |
|
sumr+=probs[(int)age][i][cptcod]; |
|
} |
|
if(fabs(sum - 1.) > 1.e-3) { /* bad */ |
|
printf("Moving average A1: For this combination of covariate cptcod=%d, we can't get a smoothed prevalence which sums to one (%f) at any descending age! age=%d, could you increase bage=%d\n",cptcod,sumr, (int)age, bage); |
|
} /* end bad */ |
|
/* else{ /\* We found some ages summing to one, we will smooth the oldest *\/ */ |
|
if(fabs(sumr - 1.) > 1.e-3) { /* bad */ |
|
printf("Moving average A2: For this combination of covariate cptcod=%d, the raw prevalence doesn't sums to one (%f) even with smoothed values at young ages! age=%d, could you increase bage=%d\n",cptcod,sumr, (int)age, bage); |
} /* end bad */ |
} /* end bad */ |
}/* age */ |
}/* age */ |
sum=0.; |
|
for (i=1; i<=nlstate;i++){ |
for (age=bage+(mob-1)/2; age<=fage; age++){/* From youngest, finding the oldest wrong */ |
sum+=mobaverage[(int)agemaxgood[cptcod]][i][cptcod]; |
sumnewm[cptcod]=0.; |
} |
sumnewmr[cptcod]=0.; |
if(fabs(sum - 1.) > 1.e-3) { /* bad */ |
for (i=1; i<=nlstate;i++){ |
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); |
sumnewm[cptcod]+=mobaverage[(int)age][i][cptcod]; |
/* for (i=1; i<=nlstate;i++){ */ |
sumnewmr[cptcod]+=probs[(int)age][i][cptcod]; |
/* mobaverage[(int)age][i][cptcod]=mobaverage[(int)agemingood[cptcod]][i][cptcod]; */ |
} |
/* } /\* i *\/ */ |
if(mobilav==-1){ /* Forcing raw ages if good else agemingood */ |
} /* end bad */ |
if(fabs(sumnewmr[cptcod] - 1.) <= 1.e-3) { /* good */ |
|
agemingoodr[cptcod]=age; |
|
for (i=1; i<=nlstate;i++) |
|
mobaverage[(int)age][i][cptcod]=probs[(int)age][i][cptcod]; |
|
}else{ /* bad we change the value with the values of good ages */ |
|
for (i=1; i<=nlstate;i++){ |
|
mobaverage[(int)age][i][cptcod]=mobaverage[(int)agemingoodr[cptcod]][i][cptcod]; |
|
} /* i */ |
|
} /* end bad */ |
|
}else{ |
|
if(fabs(sumnewm[cptcod] - 1.) <= 1.e-3) { /* good */ |
|
agemingood[cptcod]=age; |
|
}else{ /* bad */ |
|
for (i=1; i<=nlstate;i++){ |
|
mobaverage[(int)age][i][cptcod]=mobaverage[(int)agemingood[cptcod]][i][cptcod]; |
|
} /* i */ |
|
} /* end bad */ |
|
}/* end else */ |
|
sum=0.;sumr=0.; |
|
for (i=1; i<=nlstate;i++){ |
|
sum+=mobaverage[(int)age][i][cptcod]; |
|
sumr+=mobaverage[(int)age][i][cptcod]; |
|
} |
|
if(fabs(sum - 1.) > 1.e-3) { /* bad */ |
|
printf("Moving average B1: For this combination of covariate cptcod=%d, we can't get a smoothed prevalence which sums to one (%f) at any descending age! age=%d, could you decrease fage=%d?\n",cptcod, sum, (int) age, fage); |
|
} /* end bad */ |
|
/* else{ /\* We found some ages summing to one, we will smooth the oldest *\/ */ |
|
if(fabs(sumr - 1.) > 1.e-3) { /* bad */ |
|
printf("Moving average B2: For this combination of covariate cptcod=%d, the raw prevalence doesn't sums to one (%f) even with smoothed values at young ages! age=%d, could you increase fage=%d\n",cptcod,sumr, (int)age, fage); |
|
} /* end bad */ |
|
}/* age */ |
|
|
|
|
for (age=bage; age<=fage; age++){ |
for (age=bage; age<=fage; age++){ |
/* printf("%d %d ", cptcod, (int)age); */ |
/* printf("%d %d ", cptcod, (int)age); */ |
Line 7646 set ter svg size 640, 480\nunset log y\n
|
Line 7786 set ter svg size 640, 480\nunset log y\n
|
} |
} |
/* printf("\n"); */ |
/* printf("\n"); */ |
/* } */ |
/* } */ |
|
|
/* brutal averaging */ |
/* brutal averaging */ |
for (i=1; i<=nlstate;i++){ |
/* for (i=1; i<=nlstate;i++){ */ |
for (age=1; age<=bage; age++){ |
/* for (age=1; age<=bage; age++){ */ |
mobaverage[(int)age][i][cptcod]=mobaverage[(int)agemingood[cptcod]][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]); */ |
/* /\* 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++){ |
/* for (age=fage; age<=AGESUP; age++){ */ |
mobaverage[(int)age][i][cptcod]=mobaverage[(int)agemaxgood[cptcod]][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]); */ |
/* /\* printf("age=%d i=%d cptcod=%d mobaverage=%.4f \n",(int)age,i, cptcod, mobaverage[(int)age][i][cptcod]); *\/ */ |
} |
/* } */ |
} /* end i status */ |
/* } /\* end i status *\/ */ |
for (i=nlstate+1; i<=nlstate+ndeath;i++){ |
/* for (i=nlstate+1; i<=nlstate+ndeath;i++){ */ |
for (age=1; age<=AGESUP; age++){ |
/* for (age=1; age<=AGESUP; age++){ */ |
/*printf("i=%d, age=%d, cptcod=%d\n",i, (int)age, cptcod);*/ |
/* /\*printf("i=%d, age=%d, cptcod=%d\n",i, (int)age, cptcod);*\/ */ |
mobaverage[(int)age][i][cptcod]=0.; |
/* mobaverage[(int)age][i][cptcod]=0.; */ |
} |
/* } */ |
} |
/* } */ |
}/* end cptcod */ |
}/* end cptcod */ |
free_vector(sumnewm,1, ncovcombmax); |
free_vector(agemaxgoodr,1, ncovcombmax); |
free_vector(sumnewp,1, ncovcombmax); |
|
free_vector(agemaxgood,1, ncovcombmax); |
free_vector(agemaxgood,1, ncovcombmax); |
free_vector(agemingood,1, ncovcombmax); |
free_vector(agemingood,1, ncovcombmax); |
|
free_vector(agemingoodr,1, ncovcombmax); |
|
free_vector(sumnewmr,1, ncovcombmax); |
|
free_vector(sumnewm,1, ncovcombmax); |
|
free_vector(sumnewp,1, ncovcombmax); |
return 0; |
return 0; |
}/* End movingaverage */ |
}/* End movingaverage */ |
|
|
|
|
/************** Forecasting ******************/ |
/************** 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 bage, double fage, int firstpass, int lastpass, double anproj2, double p[], int cptcoveff){ |
/* proj1, year, month, day of starting projection |
/* proj1, year, month, day of starting projection |
agemin, agemax range of age |
agemin, agemax range of age |
dateprev1 dateprev2 range of dates during which prevalence is computed |
dateprev1 dateprev2 range of dates during which prevalence is computed |
anproj2 year of en of projection (same day and month as proj1). |
anproj2 year of en of projection (same day and month as proj1). |
*/ |
*/ |
int yearp, stepsize, hstepm, nhstepm, j, k, cptcod, i, h, i1, k4, nres=0; |
int yearp, stepsize, hstepm, nhstepm, j, k, cptcod, i, h, i1, k4, nres=0; |
double agec; /* generic age */ |
double agec; /* generic age */ |
double agelim, ppij, yp,yp1,yp2,jprojmean,mprojmean,anprojmean; |
double agelim, ppij, yp,yp1,yp2,jprojmean,mprojmean,anprojmean; |
double *popeffectif,*popcount; |
double *popeffectif,*popcount; |
Line 7774 set ter svg size 640, 480\nunset log y\n
|
Line 7918 set ter svg size 640, 480\nunset log y\n
|
for(j=1; j<=nlstate+ndeath;j++) { |
for(j=1; j<=nlstate+ndeath;j++) { |
ppij=0.; |
ppij=0.; |
for(i=1; i<=nlstate;i++) { |
for(i=1; i<=nlstate;i++) { |
if (mobilav==1) |
/* if (mobilav>=1) */ |
ppij=ppij+p3mat[i][j][h]*mobaverage[(int)agec][i][k]; |
ppij=ppij+p3mat[i][j][h]*mobaverage[(int)agec][i][k]; |
else { |
/* else { */ /* even if mobilav==-1 we use mobaverage */ |
ppij=ppij+p3mat[i][j][h]*probs[(int)(agec)][i][k]; |
/* ppij=ppij+p3mat[i][j][h]*probs[(int)(agec)][i][k]; */ |
} |
/* } */ |
if (h*hstepm/YEARM*stepm== yearp) { |
if (h*hstepm/YEARM*stepm== yearp) { |
fprintf(ficresf," %.3f", p3mat[i][j][h]); |
fprintf(ficresf," %.3f", p3mat[i][j][h]); |
} |
} |
Line 7790 set ter svg size 640, 480\nunset log y\n
|
Line 7934 set ter svg size 640, 480\nunset log y\n
|
} /* end h */ |
} /* end h */ |
free_ma3x(p3mat,1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm); |
free_ma3x(p3mat,1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm); |
} /* end agec */ |
} /* end agec */ |
|
/* diffyear=(int) anproj1+yearp-ageminpar-1; */ |
|
/*printf("Prevforecast %d+%d-%d=diffyear=%d\n",(int) anproj1, (int)yearp,(int)ageminpar,(int) anproj1-(int)ageminpar);*/ |
} /* end yearp */ |
} /* end yearp */ |
} /* end k */ |
} /* end k */ |
|
|
Line 7800 set ter svg size 640, 480\nunset log y\n
|
Line 7946 set ter svg size 640, 480\nunset log y\n
|
} |
} |
|
|
/* /\************** Back Forecasting ******************\/ */ |
/* /\************** Back Forecasting ******************\/ */ |
/* void prevbackforecast(char fileres[], 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){ */ |
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 */ |
/* back1, year, month, day of starting backection |
/* agemin, agemax range of age */ |
agemin, agemax range of age |
/* dateprev1 dateprev2 range of dates during which prevalence is computed */ |
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 en of backection (same day and month as back1). |
/* *\/ */ |
*/ |
/* int yearp, stepsize, hstepm, nhstepm, j, k, cptcod, i, h, i1; */ |
int yearp, stepsize, hstepm, nhstepm, j, k, cptcod, i, h, i1, k4, nres=0; |
/* double agec; /\* generic age *\/ */ |
double agec; /* generic age */ |
/* double agelim, ppij, yp,yp1,yp2,jprojmean,mprojmean,anprojmean; */ |
double agelim, ppij, yp,yp1,yp2,jprojmean,mprojmean,anprojmean; |
/* double *popeffectif,*popcount; */ |
double *popeffectif,*popcount; |
/* double ***p3mat; */ |
double ***p3mat; |
/* /\* double ***mobaverage; *\/ */ |
/* double ***mobaverage; */ |
/* char fileresfb[FILENAMELENGTH]; */ |
char fileresfb[FILENAMELENGTH]; |
|
|
/* agelim=AGESUP; */ |
agelim=AGESUP; |
/* /\* Compute observed prevalence between dateprev1 and dateprev2 by counting the number of people */ |
/* Compute observed prevalence between dateprev1 and dateprev2 by counting the number of people |
/* in each health status at the date of interview (if between dateprev1 and dateprev2). */ |
in each health status at the date of interview (if between dateprev1 and dateprev2). |
/* We still use firstpass and lastpass as another selection. */ |
We still use firstpass and lastpass as another selection. |
/* *\/ */ |
*/ |
/* /\* freqsummary(fileres, agemin, agemax, s, agev, nlstate, imx,Tvaraff,nbcode, ncodemax,mint,anint,strstart,\ *\/ */ |
/* freqsummary(fileres, agemin, agemax, s, agev, nlstate, imx,Tvaraff,nbcode, ncodemax,mint,anint,strstart,\ */ |
/* /\* firstpass, lastpass, stepm, weightopt, model); *\/ */ |
/* firstpass, lastpass, stepm, weightopt, model); */ |
/* prevalence(probs, ageminpar, agemax, s, agev, nlstate, imx, Tvar, nbcode, ncodemax, mint, anint, dateprev1, dateprev2, firstpass, lastpass); */ |
|
|
/*Do we need to compute prevalence again?*/ |
/* strcpy(fileresfb,"FB_"); */ |
|
/* strcat(fileresfb,fileresu); */ |
/* prevalence(probs, ageminpar, agemax, s, agev, nlstate, imx, Tvar, nbcode, ncodemax, mint, anint, dateprev1, dateprev2, firstpass, lastpass); */ |
/* if((ficresfb=fopen(fileresfb,"w"))==NULL) { */ |
|
/* printf("Problem with back forecast resultfile: %s\n", fileresfb); */ |
|
/* fprintf(ficlog,"Problem with back forecast resultfile: %s\n", fileresfb); */ |
|
/* } */ |
|
/* printf("Computing back forecasting: result on file '%s', please wait... \n", fileresfb); */ |
|
/* fprintf(ficlog,"Computing back forecasting: result on file '%s', please wait... \n", fileresfb); */ |
|
|
|
/* if (cptcoveff==0) ncodemax[cptcoveff]=1; */ |
|
|
|
/* /\* if (mobilav!=0) { *\/ */ |
|
/* /\* mobaverage= ma3x(1, AGESUP,1,NCOVMAX, 1,NCOVMAX); *\/ */ |
|
/* /\* if (movingaverage(probs, ageminpar, fage, mobaverage,mobilav)!=0){ *\/ */ |
|
/* /\* fprintf(ficlog," Error in movingaverage mobilav=%d\n",mobilav); *\/ */ |
|
/* /\* printf(" Error in movingaverage mobilav=%d\n",mobilav); *\/ */ |
|
/* /\* } *\/ */ |
|
/* /\* } *\/ */ |
|
|
|
/* stepsize=(int) (stepm+YEARM-1)/YEARM; */ |
|
/* if (stepm<=12) stepsize=1; */ |
|
/* if(estepm < stepm){ */ |
|
/* printf ("Problem %d lower than %d\n",estepm, stepm); */ |
|
/* } */ |
|
/* else hstepm=estepm; */ |
|
|
|
/* hstepm=hstepm/stepm; */ |
|
/* yp1=modf(dateintmean,&yp);/\* extracts integral of datemean in yp and */ |
|
/* fractional in yp1 *\/ */ |
|
/* anprojmean=yp; */ |
|
/* yp2=modf((yp1*12),&yp); */ |
|
/* mprojmean=yp; */ |
|
/* yp1=modf((yp2*30.5),&yp); */ |
|
/* jprojmean=yp; */ |
|
/* if(jprojmean==0) jprojmean=1; */ |
|
/* if(mprojmean==0) jprojmean=1; */ |
|
|
|
/* i1=cptcoveff; */ |
|
/* if (cptcovn < 1){i1=1;} */ |
|
|
|
/* fprintf(ficresfb,"# Mean day of interviews %.lf/%.lf/%.lf (%.2f) between %.2f and %.2f \n",jprojmean,mprojmean,anprojmean,dateintmean,dateprev1,dateprev2); */ |
strcpy(fileresfb,"FB_"); |
|
strcat(fileresfb,fileresu); |
|
if((ficresfb=fopen(fileresfb,"w"))==NULL) { |
|
printf("Problem with back forecast resultfile: %s\n", fileresfb); |
|
fprintf(ficlog,"Problem with back forecast resultfile: %s\n", fileresfb); |
|
} |
|
printf("\nComputing back forecasting: result on file '%s', please wait... \n", fileresfb); |
|
fprintf(ficlog,"\nComputing back forecasting: result on file '%s', please wait... \n", fileresfb); |
|
|
/* fprintf(ficresfb,"#****** Routine prevbackforecast **\n"); */ |
if (cptcoveff==0) ncodemax[cptcoveff]=1; |
|
|
/* /\* if (h==(int)(YEARM*yearp)){ *\/ */ |
|
/* for(cptcov=1, k=0;cptcov<=i1;cptcov++){ */ |
stepsize=(int) (stepm+YEARM-1)/YEARM; |
/* for(cptcod=1;cptcod<=ncodemax[cptcoveff];cptcod++){ */ |
if (stepm<=12) stepsize=1; |
/* k=k+1; */ |
if(estepm < stepm){ |
/* fprintf(ficresfb,"\n#****** hbijx=probability over h years, hp.jx is weighted by observed prev \n#"); */ |
printf ("Problem %d lower than %d\n",estepm, stepm); |
/* for(j=1;j<=cptcoveff;j++) { */ |
} |
/* fprintf(ficresfb," V%d (=) %d",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]); */ |
else hstepm=estepm; |
/* } */ |
|
/* fprintf(ficresfb," yearbproj age"); */ |
hstepm=hstepm/stepm; |
/* for(j=1; j<=nlstate+ndeath;j++){ */ |
yp1=modf(dateintmean,&yp);/* extracts integral of datemean in yp and |
/* for(i=1; i<=nlstate;i++) */ |
fractional in yp1 */ |
/* fprintf(ficresfb," p%d%d",i,j); */ |
anprojmean=yp; |
/* fprintf(ficresfb," p.%d",j); */ |
yp2=modf((yp1*12),&yp); |
/* } */ |
mprojmean=yp; |
/* for (yearp=0; yearp>=(anback2-anback1);yearp -=stepsize) { */ |
yp1=modf((yp2*30.5),&yp); |
/* /\* for (yearp=0; yearp<=(anproj2-anproj1);yearp +=stepsize) { *\/ */ |
jprojmean=yp; |
/* fprintf(ficresfb,"\n"); */ |
if(jprojmean==0) jprojmean=1; |
/* fprintf(ficresfb,"\n# Back Forecasting at date %.lf/%.lf/%.lf ",jback1,mback1,anback1+yearp); */ |
if(mprojmean==0) jprojmean=1; |
/* for (agec=fage; agec>=(ageminpar-1); agec--){ */ |
|
/* nhstepm=(int) rint((agelim-agec)*YEARM/stepm); */ |
i1=pow(2,cptcoveff); |
/* nhstepm = nhstepm/hstepm; */ |
if (cptcovn < 1){i1=1;} |
/* p3mat=ma3x(1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm); */ |
|
/* oldm=oldms;savm=savms; */ |
fprintf(ficresfb,"# Mean day of interviews %.lf/%.lf/%.lf (%.2f) between %.2f and %.2f \n",jprojmean,mprojmean,anprojmean,dateintmean,dateprev1,dateprev2); |
/* hbxij(p3mat,nhstepm,agec,hstepm,p,prevacurrent,nlstate,stepm,oldm,savm,oldm,savm, dnewm, doldm, dsavm, k); */ |
|
/* for (h=0; h<=nhstepm; h++){ */ |
fprintf(ficresfb,"#****** Routine prevbackforecast **\n"); |
/* if (h*hstepm/YEARM*stepm ==yearp) { */ |
|
/* fprintf(ficresfb,"\n"); */ |
/* if (h==(int)(YEARM*yearp)){ */ |
/* for(j=1;j<=cptcoveff;j++) */ |
/* for(cptcov=1, k=0;cptcov<=i1;cptcov++){ */ |
/* fprintf(ficresfb,"%d %d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]); */ |
/* for(cptcod=1;cptcod<=ncodemax[cptcoveff];cptcod++){ */ |
/* fprintf(ficresfb,"%.f %.f ",anback1+yearp,agec+h*hstepm/YEARM*stepm); */ |
/* k=k+1; */ |
/* } */ |
for(nres=1; nres <= nresult; nres++) /* For each resultline */ |
/* for(j=1; j<=nlstate+ndeath;j++) { */ |
for(k=1; k<=i1;k++){ |
/* ppij=0.; */ |
if(i1 != 1 && TKresult[nres]!= k) |
/* for(i=1; i<=nlstate;i++) { */ |
continue; |
/* if (mobilav==1) */ |
if(invalidvarcomb[k]){ |
/* ppij=ppij+p3mat[i][j][h]*mobaverage[(int)agec][i][cptcod]; */ |
printf("\nCombination (%d) projection ignored because no cases \n",k); |
/* else { */ |
continue; |
/* ppij=ppij+p3mat[i][j][h]*probs[(int)(agec)][i][cptcod]; */ |
} |
/* } */ |
fprintf(ficresfb,"\n#****** hbijx=probability over h years, hp.jx is weighted by observed prev \n#"); |
/* if (h*hstepm/YEARM*stepm== yearp) { */ |
for(j=1;j<=cptcoveff;j++) { |
/* fprintf(ficresfb," %.3f", p3mat[i][j][h]); */ |
fprintf(ficresfb," V%d (=) %d",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]); |
/* } */ |
} |
/* } /\* end i *\/ */ |
for (k4=1; k4<= nsq; k4++){ /* For each selected (single) quantitative value */ |
/* if (h*hstepm/YEARM*stepm==yearp) { */ |
fprintf(ficresf," V%d=%f ",Tvqresult[nres][k4],Tqresult[nres][k4]); |
/* fprintf(ficresfb," %.3f", ppij); */ |
} |
/* } */ |
fprintf(ficresfb," yearbproj age"); |
/* }/\* end j *\/ */ |
for(j=1; j<=nlstate+ndeath;j++){ |
/* } /\* end h *\/ */ |
for(i=1; i<=nlstate;i++) |
/* free_ma3x(p3mat,1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm); */ |
fprintf(ficresfb," p%d%d",i,j); |
/* } /\* end agec *\/ */ |
fprintf(ficresfb," p.%d",j); |
/* } /\* end yearp *\/ */ |
} |
/* } /\* end cptcod *\/ */ |
for (yearp=0; yearp>=(anback2-anback1);yearp -=stepsize) { |
/* } /\* end cptcov *\/ */ |
/* for (yearp=0; yearp<=(anproj2-anproj1);yearp +=stepsize) { */ |
|
fprintf(ficresfb,"\n"); |
/* /\* if (mobilav!=0) free_ma3x(mobaverage,1, AGESUP,1,NCOVMAX, 1,NCOVMAX); *\/ */ |
fprintf(ficresfb,"\n# Back Forecasting at date %.lf/%.lf/%.lf ",jback1,mback1,anback1+yearp); |
|
/* for (agec=fage; agec>=(ageminpar-1); agec--){ */ |
/* fclose(ficresfb); */ |
/* nhstepm=(int) rint((agelim-agec)*YEARM/stepm); */ |
/* printf("End of Computing Back forecasting \n"); */ |
for (agec=fage; agec>=fage-20; agec--){ /* testing up to 10 */ |
/* fprintf(ficlog,"End of Computing Back forecasting\n"); */ |
nhstepm=(int) rint((agelim-agec)*YEARM/stepm); |
|
nhstepm = nhstepm/hstepm; |
|
p3mat=ma3x(1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm); |
|
oldm=oldms;savm=savms; |
|
hbxij(p3mat,nhstepm,agec,hstepm,p,prevacurrent,nlstate,stepm, k, nres); |
|
|
|
for (h=0; h<=nhstepm; h++){ |
|
if (h*hstepm/YEARM*stepm ==yearp) { |
|
fprintf(ficresfb,"\n"); |
|
for(j=1;j<=cptcoveff;j++) |
|
fprintf(ficresfb,"%d %d ",Tvaraff[j],nbcode[Tvaraff[j]][codtabm(k,j)]); |
|
fprintf(ficresfb,"%.f %.f ",anback1+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][k]; |
|
/* else { */ |
|
/* ppij=ppij+p3mat[i][j][h]*probs[(int)(agec)][i][k]; */ |
|
/* } */ |
|
if (h*hstepm/YEARM*stepm== yearp) { |
|
fprintf(ficresfb," %.3f", p3mat[i][j][h]); |
|
} |
|
} /* end i */ |
|
if (h*hstepm/YEARM*stepm==yearp) { |
|
fprintf(ficresfb," %.3f", ppij); |
|
} |
|
}/* end j */ |
|
} /* end h */ |
|
free_ma3x(p3mat,1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm); |
|
} /* end agec */ |
|
} /* end yearp */ |
|
} /* end k */ |
|
|
|
/* if (mobilav!=0) free_ma3x(mobaverage,1, AGESUP,1,NCOVMAX, 1,NCOVMAX); */ |
|
|
|
fclose(ficresfb); |
|
printf("End of Computing Back forecasting \n"); |
|
fprintf(ficlog,"End of Computing Back forecasting\n"); |
|
|
/* } */ |
} |
|
|
/************** Forecasting *****not tested NB*************/ |
/************** 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){ */ |
/* 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){ */ |
Line 9771 int back_prevalence_limit(double *p, dou
|
Line 9926 int back_prevalence_limit(double *p, dou
|
}else{ |
}else{ |
/* bprevalim(bprlim, probs, nlstate, p, age, oldm, savm, dnewm, doldm, dsavm, 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,nres); |
bprevalim(bprlim, probs, nlstate, p, age, ftolpl, ncvyearp, k,nres); |
|
/* printf("TOTOT\n"); */ |
|
/* exit(1); */ |
} |
} |
fprintf(ficresplb,"%.0f ",age ); |
fprintf(ficresplb,"%.0f ",age ); |
for(j=1;j<=cptcoveff;j++) |
for(j=1;j<=cptcoveff;j++) |
Line 9929 int hPijx(double *p, int bage, int fage)
|
Line 10086 int hPijx(double *p, int bage, int fage)
|
|
|
/* nhstepm=nhstepm*YEARM; aff par mois*/ |
/* nhstepm=nhstepm*YEARM; aff par mois*/ |
|
|
p3mat=ma3x(1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm); |
p3mat=ma3x(1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm); /* We can't have it at an upper level because of nhstepm */ |
|
/* and memory limitations if stepm is small */ |
|
|
/* oldm=oldms;savm=savms; */ |
/* oldm=oldms;savm=savms; */ |
/* hbxij(p3mat,nhstepm,agedeb,hstepm,p,nlstate,stepm,oldm,savm, k); */ |
/* hbxij(p3mat,nhstepm,agedeb,hstepm,p,nlstate,stepm,oldm,savm, k); */ |
hbxij(p3mat,nhstepm,agedeb,hstepm,p,prevacurrent,nlstate,stepm, k); |
hbxij(p3mat,nhstepm,agedeb,hstepm,p,prevacurrent,nlstate,stepm, k, nres); |
/* hbxij(p3mat,nhstepm,agedeb,hstepm,p,prevacurrent,nlstate,stepm,oldm,savm, dnewm, doldm, dsavm, k); */ |
/* hbxij(p3mat,nhstepm,agedeb,hstepm,p,prevacurrent,nlstate,stepm,oldm,savm, dnewm, doldm, dsavm, k); */ |
fprintf(ficrespijb,"# Cov Agex agex-h hbijx with i,j="); |
fprintf(ficrespijb,"# Cov Agex agex-h hbijx with i,j="); |
for(i=1; i<=nlstate;i++) |
for(i=1; i<=nlstate;i++) |
Line 11492 Please run with mle=-1 to get a correct
|
Line 11651 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\ |
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); |
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); |
printinggnuplot(fileresu, optionfilefiname,ageminpar,agemaxpar,fage, prevfcast, backcast, pathc,p, (int)anproj1-(int)ageminpar); |
} |
} |
printinghtml(fileresu,title,datafile, firstpass, lastpass, stepm, weightopt, \ |
printinghtml(fileresu,title,datafile, firstpass, lastpass, stepm, weightopt, \ |
model,imx,jmin,jmax,jmean,rfileres,popforecast,mobilav,prevfcast,mobilavproj,backcast, estepm, \ |
model,imx,jmin,jmax,jmean,rfileres,popforecast,mobilav,prevfcast,mobilavproj,backcast, estepm, \ |
Line 11554 Please run with mle=-1 to get a correct
|
Line 11713 Please run with mle=-1 to get a correct
|
printf(" Error in movingaverage mobilav=%d\n",mobilav); |
printf(" Error in movingaverage mobilav=%d\n",mobilav); |
} |
} |
} |
} |
/* /\* Prevalence for each covariates in probs[age][status][cov] *\/ */ |
/* else if(mobilavproj==-1){ /\* Forcing raw observed prevalences *\/ */ |
/* prevalence(probs, ageminpar, agemaxpar, s, agev, nlstate, imx, Tvar, nbcode, ncodemax, mint, anint, dateprev1, dateprev2, firstpass, lastpass); */ |
/* 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"); |
printf("Movingaveraging projected observed prevalence\n"); |
fprintf(ficlog,"Movingaveraging projected observed prevalence\n"); |
fprintf(ficlog,"Movingaveraging projected observed prevalence\n"); |
Line 11587 Please run with mle=-1 to get a correct
|
Line 11752 Please run with mle=-1 to get a correct
|
fclose(ficrespijb); |
fclose(ficrespijb); |
free_matrix(bprlim,1,nlstate,1,nlstate); /*here or after loop ? */ |
free_matrix(bprlim,1,nlstate,1,nlstate); /*here or after loop ? */ |
|
|
/* prevbackforecast(fileresu, anback1, mback1, jback1, agemin, agemax, dateprev1, dateprev2, mobilavproj, |
prevbackforecast(fileresu, mobaverage, anback1, mback1, jback1, agemin, agemax, dateprev1, dateprev2, mobilavproj, |
bage, fage, firstpass, lastpass, anback2, p, cptcoveff); */ |
bage, fage, firstpass, lastpass, anback2, p, cptcoveff); |
free_matrix(ddnewms, 1, nlstate+ndeath, 1, nlstate+ndeath); |
free_matrix(ddnewms, 1, nlstate+ndeath, 1, nlstate+ndeath); |
free_matrix(ddsavms, 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(ddoldms, 1, nlstate+ndeath, 1, nlstate+ndeath); |