\r
\r
int nvar;\r
-static int cptcov;\r
-int cptcovn, cptcovage=0, cptcoveff=0;\r
+int cptcovn, cptcovage=0, cptcoveff=0,cptcov;\r
int npar=NPARMAX;\r
int nlstate=2; /* Number of live states */\r
int ndeath=1; /* Number of dead states */\r
\r
int *wav; /* Number of waves for this individuual 0 is possible */\r
int maxwav; /* Maxim number of waves */\r
+int jmin, jmax; /* min, max spacing between 2 waves */\r
int mle, weightopt;\r
int **mw; /* mw[mi][i] is number of the mi wave for this individual */\r
int **dh; /* dh[mi][i] is number of steps between mi,mi+1 for this individual */\r
+double jmean; /* Mean space between 2 waves */\r
double **oldm, **newm, **savm; /* Working pointers to matrices */\r
double **oldms, **newms, **savms; /* Fixed working pointers to matrices */\r
FILE *fic,*ficpar, *ficparo,*ficres, *ficrespl, *ficrespij, *ficrest;\r
cov[2+Tprod[k]]=nbcode[Tvard[k][1]][codtab[ij][Tvard[k][1]]]*nbcode[Tvard[k][2]][codtab[ij][Tvard[k][2]]];\r
\r
/*printf("ij=%d cptcovprod=%d tvar=%d ", ij, cptcovprod, Tvar[1]);*/\r
-\r
/*printf("ij=%d cov[3]=%lf cov[4]=%lf \n",ij, cov[3],cov[4]);*/\r
\r
out=matprod2(newm, pmij(pmmij,cov,ncovmodel,x,nlstate),1,nlstate+ndeath,1,nlstate+ndeath,1,nlstate+ndeath, oldm);\r
/* We are differentiating ll according to initial status */\r
/* for (i=1;i<=npar;i++) printf("%f ", x[i]);*/\r
/*for(i=1;i<imx;i++) \r
-printf(" %d\n",s[4][i]);\r
+ printf(" %d\n",s[4][i]);\r
*/\r
cov[1]=1.;\r
\r
for(k=1; k<=nlstate; k++) ll[k]=0.;\r
for (i=1,ipmx=0, sw=0.; i<=imx; i++){\r
for (k=1; k<=cptcovn;k++) cov[2+k]=covar[Tvar[k]][i];\r
- for(mi=1; mi<= wav[i]-1; mi++){\r
+ for(mi=1; mi<= wav[i]-1; mi++){\r
for (ii=1;ii<=nlstate+ndeath;ii++)\r
for (j=1;j<=nlstate+ndeath;j++) oldm[ii][j]=(ii==j ? 1.0 : 0.0);\r
- for(d=0; d<dh[mi][i]; d++){\r
- newm=savm;\r
- cov[2]=agev[mw[mi][i]][i]+d*stepm/YEARM;\r
- for (kk=1; kk<=cptcovage;kk++) {\r
- cov[Tage[kk]+2]=covar[Tvar[Tage[kk]]][i]*cov[2];\r
- /*printf("%d %d",kk,Tage[kk]);*/\r
- }\r
- /*cov[4]=covar[1][i]*cov[2];scanf("%d", i);*/\r
- /*cov[3]=pow(cov[2],2)/1000.;*/\r
-\r
- out=matprod2(newm,oldm,1,nlstate+ndeath,1,nlstate+ndeath,\r
- 1,nlstate+ndeath,pmij(pmmij,cov,ncovmodel,x,nlstate));\r
- savm=oldm;\r
- oldm=newm;\r
-\r
-\r
+ for(d=0; d<dh[mi][i]; d++){\r
+ newm=savm;\r
+ cov[2]=agev[mw[mi][i]][i]+d*stepm/YEARM;\r
+ for (kk=1; kk<=cptcovage;kk++) {\r
+ cov[Tage[kk]+2]=covar[Tvar[Tage[kk]]][i]*cov[2];\r
+ }\r
+ \r
+ out=matprod2(newm,oldm,1,nlstate+ndeath,1,nlstate+ndeath,\r
+ 1,nlstate+ndeath,pmij(pmmij,cov,ncovmodel,x,nlstate));\r
+ savm=oldm;\r
+ oldm=newm;\r
+ \r
+ \r
} /* end mult */\r
- \r
+ \r
lli=log(out[s[mw[mi][i]][i]][s[mw[mi+1][i]][i]]);\r
/* printf(" %f ",out[s[mw[mi][i]][i]][s[mw[mi+1][i]][i]]);*/\r
ipmx +=1;\r
for(k1=1; k1<=j;k1++){\r
for(i1=1; i1<=ncodemax[k1];i1++){\r
j1++;\r
-\r
+ /*printf("cptcoveff=%d Tvaraff=%d", cptcoveff,Tvaraff[1]);\r
+ scanf("%d", i);*/\r
for (i=-1; i<=nlstate+ndeath; i++) \r
for (jk=-1; jk<=nlstate+ndeath; jk++) \r
for(m=agemin; m <= agemax+3; m++)\r
bool=1;\r
if (cptcovn>0) {\r
for (z1=1; z1<=cptcoveff; z1++) \r
- if (covar[Tvaraff[z1]][i]!= nbcode[Tvaraff[z1]][codtab[j1][z1]]) bool=0;\r
+ if (covar[Tvaraff[z1]][i]!= nbcode[Tvaraff[z1]][codtab[j1][z1]]) \r
+ bool=0;\r
}\r
if (bool==1) {\r
for(m=firstpass; m<=lastpass-1; m++){\r
if (cptcovn>0) {\r
fprintf(ficresp, "\n#********** Variable "); \r
for (z1=1; z1<=cptcoveff; z1++) fprintf(ficresp, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtab[j1][z1]]);\r
- }\r
fprintf(ficresp, "**********\n#");\r
+ }\r
for(i=1; i<=nlstate;i++) \r
fprintf(ficresp, " Age Prev(%d) N(%d) N",i,i);\r
fprintf(ficresp, "\n");\r
*/\r
\r
int i, mi, m;\r
- int j, k=0,jk, ju, jl,jmin=1e+5, jmax=-1;\r
-float sum=0.;\r
-\r
+ /* int j, k=0,jk, ju, jl,jmin=1e+5, jmax=-1;\r
+ double sum=0., jmean=0.;*/\r
+\r
+int j, k=0,jk, ju, jl;\r
+ double sum=0.;\r
+jmin=1e+5;\r
+ jmax=-1;\r
+jmean=0.;\r
for(i=1; i<=imx; i++){\r
mi=0;\r
m=firstpass;\r
else{\r
if (s[mw[mi+1][i]][i] > nlstate) {\r
j= rint(agedc[i]*12-agev[mw[mi][i]][i]*12); \r
- if(j=0) j=1; /* Survives at least one month after exam */\r
+ /*if ((j<0) || (j>28)) printf("j=%d num=%d ",j,i);*/\r
+ if(j==0) j=1; /* Survives at least one month after exam */\r
+ k=k+1;\r
+ if (j >= jmax) jmax=j;\r
+ else if (j <= jmin)jmin=j;\r
+ sum=sum+j;\r
}\r
else{\r
j= rint( (agev[mw[mi+1][i]][i]*12 - agev[mw[mi][i]][i]*12));\r
+ /*if ((j<0) || (j>28)) printf("j=%d num=%d ",j,i);*/\r
k=k+1;\r
if (j >= jmax) jmax=j;\r
else if (j <= jmin)jmin=j;\r
}\r
}\r
}\r
- printf("Delay (in months) between two waves Min=%d Max=%d Mean=%f\n\n ",jmin, jmax,sum/k);\r
+ jmean=sum/k;\r
+ printf("Delay (in months) between two waves Min=%d Max=%d Mean=%f\n\n ",jmin, jmax,jmean);\r
}\r
/*********** Tricode ****************************/\r
void tricode(int *Tvar, int **nbcode, int imx)\r
for (i=1; i<=imx; i++) {\r
ij=(int)(covar[Tvar[j]][i]);\r
Ndum[ij]++; \r
+ /*printf("i=%d ij=%d Ndum[ij]=%d imx=%d",i,ij,Ndum[ij],imx);*/\r
if (ij > cptcode) cptcode=ij; \r
}\r
\r
- /*printf("cptcode=%d cptcovn=%d ",cptcode,cptcovn);*/\r
for (i=0; i<=cptcode; i++) {\r
if(Ndum[i]!=0) ncodemax[j]++;\r
}\r
ij=1; \r
\r
+\r
for (i=1; i<=ncodemax[j]; i++) {\r
for (k=0; k<=19; k++) {\r
if (Ndum[k] != 0) {\r
nbcode[Tvar[j]][ij]=k; \r
- /* printf("ij=%d ",nbcode[Tvar[2]][1]);*/\r
ij++;\r
}\r
if (ij > ncodemax[j]) break; \r
} \r
} \r
} \r
- for (i=1; i<=10; i++) {\r
+\r
+ for (k=0; k<19; k++) Ndum[k]=0;\r
+\r
+ for (i=1; i<=ncovmodel; i++) {\r
ij=Tvar[i];\r
Ndum[ij]++; \r
}\r
+\r
ij=1;\r
- for (i=1; i<=cptcovn; i++) {\r
+ for (i=1; i<=10; i++) {\r
if((Ndum[i]!=0) && (i<=ncov)){\r
- Tvaraff[i]=ij; \r
- ij++;\r
+ Tvaraff[ij]=i; \r
+ ij++;\r
}\r
}\r
\r
- for (j=1; j<=(cptcovn+2*cptcovprod); j++) {\r
- if ((Tvar[j]>= cptcoveff) && (Tvar[j] <=ncov)) cptcoveff=Tvar[j];\r
- /*printf("j=%d %d\n",j,Tvar[j]);*/\r
- }\r
- \r
- /* printf("cptcoveff=%d Tvaraff=%d %d\n",cptcoveff, Tvaraff[1],Tvaraff[2]);\r
- scanf("%d",i);*/\r
+ cptcoveff=ij-1;\r
}\r
\r
/*********** Health Expectancies ****************/\r
int main()\r
{\r
\r
- int i,j, k, n=MAXN,iter,m,size,cptcode, aaa, cptcod;\r
+ int i,j, k, n=MAXN,iter,m,size,cptcode, cptcod;\r
double agedeb, agefin,hf;\r
double agemin=1.e20, agemax=-1.e20;\r
\r
printf("title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\nftol=%e stepm=%d ncov=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d\nmodel=%s\n", title, datafile, lastobs, firstpass,lastpass,ftol, stepm, ncov, nlstate,ndeath, maxwav, mle, weightopt,model);\r
fprintf(ficparo,"title=%s datafile=%s lastobs=%d firstpass=%d lastpass=%d\nftol=%e stepm=%d ncov=%d nlstate=%d ndeath=%d maxwav=%d mle=%d weight=%d\nmodel=%s\n", title, datafile, lastobs, firstpass,lastpass,ftol,stepm,ncov,nlstate,ndeath,maxwav, mle, weightopt,model);\r
\r
- covar=matrix(0,NCOVMAX,1,n); \r
- if (strlen(model)<=1) cptcovn=0;\r
- else {\r
- j=0;\r
- j=nbocc(model,'+');\r
- cptcovn=j+1;\r
- }\r
+ covar=matrix(0,NCOVMAX,1,n); \r
+ cptcovn=0; \r
+ if (strlen(model)>1) cptcovn=nbocc(model,'+')+1;\r
\r
ncovmodel=2+cptcovn;\r
nvar=ncovmodel-1; /* Suppressing age as a basic covariate */\r
cptcovn=j+1;\r
cptcovprod=j1;\r
\r
+ \r
strcpy(modelsav,model); \r
- if (j==0) {\r
- if (j1==0){\r
- cutv(stra,strb,modelsav,'V');\r
- Tvar[1]=atoi(strb);\r
- }\r
- else if (j1==1) {\r
- cutv(stra,strb,modelsav,'*');\r
- Tage[1]=1; cptcovage++;\r
- if (strcmp(stra,"age")==0) {\r
+ if ((strcmp(model,"age")==0) || (strcmp(model,"age*age")==0)){\r
+ printf("Error. Non available option model=%s ",model);\r
+ goto end;\r
+ }\r
+ \r
+ for(i=(j+1); i>=1;i--){\r
+ cutv(stra,strb,modelsav,'+');\r
+ if (nbocc(modelsav,'+')==0) strcpy(strb,modelsav); \r
+ /* printf("i=%d a=%s b=%s sav=%s\n",i, stra,strb,modelsav);*/\r
+ /*scanf("%d",i);*/\r
+ if (strchr(strb,'*')) {\r
+ cutv(strd,strc,strb,'*');\r
+ if (strcmp(strc,"age")==0) {\r
cptcovprod--;\r
- cutv(strd,strc,strb,'V');\r
- Tvar[1]=atoi(strc);\r
+ cutv(strb,stre,strd,'V');\r
+ Tvar[i]=atoi(stre);\r
+ cptcovage++;\r
+ Tage[cptcovage]=i;\r
+ /*printf("stre=%s ", stre);*/\r
}\r
- else if (strcmp(strb,"age")==0) {\r
+ else if (strcmp(strd,"age")==0) {\r
cptcovprod--;\r
- cutv(strd,strc,stra,'V');\r
- Tvar[1]=atoi(strc);\r
+ cutv(strb,stre,strc,'V');\r
+ Tvar[i]=atoi(stre);\r
+ cptcovage++;\r
+ Tage[cptcovage]=i;\r
}\r
else {\r
- cutv(strd,strc,strb,'V');\r
- cutv(stre,strd,stra,'V');\r
- Tvar[1]=ncov+1;\r
+ cutv(strb,stre,strc,'V');\r
+ Tvar[i]=ncov+k1;\r
+ cutv(strb,strc,strd,'V'); \r
+ Tprod[k1]=i;\r
+ Tvard[k1][1]=atoi(strc);\r
+ Tvard[k1][2]=atoi(stre);\r
+ Tvar[cptcovn+k2]=Tvard[k1][1];\r
+ Tvar[cptcovn+k2+1]=Tvard[k1][2]; \r
for (k=1; k<=lastobs;k++) \r
- covar[ncov+1][k]=covar[atoi(strc)][k]*covar[atoi(strd)][k];\r
+ covar[ncov+k1][k]=covar[atoi(stre)][k]*covar[atoi(strc)][k];\r
+ k1++;\r
+ k2=k2+2;\r
}\r
- /*printf("%s %s %s\n", stra,strb,modelsav);\r
-printf("%d ",Tvar[1]);\r
-scanf("%d",i);*/\r
}\r
- }\r
- else {\r
- for(i=j; i>=1;i--){\r
- cutv(stra,strb,modelsav,'+');\r
- /*printf("%s %s %s\n", stra,strb,modelsav);\r
- scanf("%d",i);*/\r
- if (strchr(strb,'*')) {\r
- cutv(strd,strc,strb,'*');\r
- if (strcmp(strc,"age")==0) {\r
- cptcovprod--;\r
- cutv(strb,stre,strd,'V');\r
- Tvar[i+1]=atoi(stre);\r
- cptcovage++;\r
- Tage[cptcovage]=i+1;\r
- printf("stre=%s ", stre);\r
- }\r
- else if (strcmp(strd,"age")==0) {\r
- cptcovprod--;\r
- cutv(strb,stre,strc,'V');\r
- Tvar[i+1]=atoi(stre);\r
- cptcovage++;\r
- Tage[cptcovage]=i+1;\r
- }\r
- else {\r
- cutv(strb,stre,strc,'V');\r
- Tvar[i+1]=ncov+k1;\r
- cutv(strb,strc,strd,'V'); \r
- Tprod[k1]=i+1;\r
- Tvard[k1][1]=atoi(strc);\r
- Tvard[k1][2]=atoi(stre);\r
- Tvar[cptcovn+k2]=Tvard[k1][1];\r
- Tvar[cptcovn+k2+1]=Tvard[k1][2]; \r
- for (k=1; k<=lastobs;k++) \r
- covar[ncov+k1][k]=covar[atoi(stre)][k]*covar[atoi(strc)][k];\r
- k1++;\r
- k2=k2+2;\r
- }\r
- }\r
- else {\r
- cutv(strd,strc,strb,'V');\r
- /* printf("%s %s %s", strd,strc,strb);*/\r
- Tvar[i+1]=atoi(strc);\r
- }\r
- strcpy(modelsav,stra); \r
+ else {\r
+ /*printf("d=%s c=%s b=%s\n", strd,strc,strb);*/\r
+ /* scanf("%d",i);*/\r
+ cutv(strd,strc,strb,'V');\r
+ Tvar[i]=atoi(strc);\r
}\r
- cutv(strd,strc,stra,'V');\r
- Tvar[1]=atoi(strc);\r
+ strcpy(modelsav,stra); \r
+ /*printf("a=%s b=%s sav=%s\n", stra,strb,modelsav);\r
+ scanf("%d",i);*/\r
}\r
- }\r
- /* for (i=1; i<=5; i++)\r
- printf("i=%d %d ",i,Tvar[i]);*/\r
- /* printf("tvar=%d %d cptcovage=%d %d",Tvar[1],Tvar[2],cptcovage,Tage[1]);*/\r
- /*printf("cptcovprod=%d ", cptcovprod);*/\r
- /* scanf("%d ",i);*/\r
+}\r
+ \r
+ /*printf("tvar1=%d tvar2=%d tvar3=%d cptcovage=%d Tage=%d",Tvar[1],Tvar[2],Tvar[3],cptcovage,Tage[1]);\r
+ printf("cptcovprod=%d ", cptcovprod);\r
+ scanf("%d ",i);*/\r
fclose(fic);\r
\r
/* if(mle==1){*/\r
if(agedc[i]>0)\r
if(moisdc[i]!=99 && andc[i]!=9999)\r
agev[m][i]=agedc[i];\r
- else{\r
+ else {\r
+ if (andc[i]!=9999){\r
printf("Warning negative age at death: %d line:%d\n",num[i],i);\r
agev[m][i]=-1;\r
+ }\r
}\r
}\r
else if(s[m][i] !=9){ /* Should no more exist */\r
\r
\r
Tcode=ivector(1,100);\r
- nbcode=imatrix(1,nvar,1,8); \r
+ nbcode=imatrix(0,NCOVMAX,0,NCOVMAX); \r
ncodemax[1]=1;\r
if (cptcovn > 0) tricode(Tvar,nbcode,imx);\r
\r
printf("Problem with index.htm \n");goto end;\r
}\r
\r
- fprintf(fichtm,"<body><ul> Imach, Version 0.64a<hr> <li>Outputs files<br><br>\n\r
+ fprintf(fichtm,"<body><ul> <font size=\"6\">Imach, Version 0.64a </font> <hr size=\"2\" color=\"#EC5E5E\"> \r
+Titre=%s <br>Datafile=%s Firstpass=%d Lastpass=%d Stepm=%d Weight=%d Model=%s<br>\r
+Total number of observations=%d <br>\r
+Interval (in months) between two waves: Min=%d Max=%d Mean=%.2lf<br>\r
+<hr size=\"2\" color=\"#EC5E5E\"> \r
+<li>Outputs files<br><br>\n\r
- Observed prevalence in each state: <a href=\"p%s\">p%s</a> <br>\n\r
- Estimated parameters and the covariance matrix: <a href=\"%s\">%s</a> <br>\r
- Stationary prevalence in each state: <a href=\"pl%s\">pl%s</a> <br>\r
- Life expectancies by age and initial health status: <a href=\"e%s\">e%s</a> <br>\r
- Variances of life expectancies by age and initial health status: <a href=\"v%s\">v%s</a><br>\r
- Health expectancies with their variances: <a href=\"t%s\">t%s</a> <br>\r
- - Standard deviation of stationary prevalences: <a href=\"vpl%s\">vpl%s</a> <br><br>",fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres);\r
+ - Standard deviation of stationary prevalences: <a href=\"vpl%s\">vpl%s</a> <br><br>",title,datafile,firstpass,lastpass,stepm, weightopt,model,imx,jmin,jmax,jmean,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres,fileres);\r
\r
- fprintf(fichtm," <li>Graphs</li>\n<p>");\r
+ fprintf(fichtm," <li>Graphs</li><p>");\r
\r
m=cptcoveff;\r
if (cptcovn < 1) {m=1;ncodemax[1]=1;}\r
for(i1=1; i1<=ncodemax[k1];i1++){\r
j1++;\r
if (cptcovn > 0) {\r
- fprintf(fichtm,"<hr>************ Results for covariates");\r
+ fprintf(fichtm,"<hr size=\"2\" color=\"#EC5E5E\">************ Results for covariates");\r
for (cpt=1; cpt<=cptcoveff;cpt++) \r
fprintf(fichtm," V%d=%d ",Tvaraff[cpt],nbcode[Tvaraff[cpt]][codtab[j1][cpt]]);\r
- fprintf(fichtm," ************\n<hr>");\r
+ fprintf(fichtm," ************\n<hr size=\"2\" color=\"#EC5E5E\">");\r
}\r
fprintf(fichtm,"<br>- Probabilities: pe%s%d.gif<br>\r
<img src=\"pe%s%d.gif\">",strtok(optionfile, "."),j1,strtok(optionfile, "."),j1); \r
#ifdef windows\r
chdir(pathcd);\r
#endif \r
- system("wgnuplot graph.plt");\r
+ /*system("wgnuplot graph.plt");*/\r
+ system("../gp37mgw/wgnuplot graph.plt");\r
\r
#ifdef windows\r
while (z[0] != 'q') {\r