#define ODIRSEPARATOR '\\'
#endif
-char version[80]="Imach version 0.95, May 2003, INED-EUROREVES ";
+char version[80]="Imach version 0.95a, May 2003, INED-EUROREVES ";
int erreur; /* Error number */
int nvar;
int cptcovn=0, cptcovage=0, cptcoveff=0,cptcov;
double **oldm, **newm, **savm; /* Working pointers to matrices */
double **oldms, **newms, **savms; /* Fixed working pointers to matrices */
FILE *fic,*ficpar, *ficparo,*ficres, *ficrespl, *ficrespij, *ficrest,*ficresf,*ficrespop;
-FILE *ficlog;
+FILE *ficlog, *ficrespow;
FILE *ficgp,*ficresprob,*ficpop, *ficresprobcov, *ficresprobcor;
FILE *ficresprobmorprev;
FILE *fichtm; /* Html File */
free((FREE_ARG)(v+nl-NR_END));
}
+/************************ivector *******************************/
+char *cvector(long nl,long nh)
+{
+ char *v;
+ v=(char *) malloc((size_t)((nh-nl+1+NR_END)*sizeof(char)));
+ if (!v) nrerror("allocation failure in cvector");
+ return v-nl+NR_END;
+}
+
+/******************free ivector **************************/
+void free_cvector(char *v, long nl, long nh)
+{
+ free((FREE_ARG)(v+nl-NR_END));
+}
+
/************************ivector *******************************/
int *ivector(long nl,long nh)
{
del=0.0;
printf("\nPowell iter=%d -2*LL=%.12f",*iter,*fret);
fprintf(ficlog,"\nPowell iter=%d -2*LL=%.12f",*iter,*fret);
- for (i=1;i<=n;i++)
+ fprintf(ficrespow,"%d %.12f",*iter,*fret);
+ for (i=1;i<=n;i++) {
printf(" %d %.12f",i, p[i]);
- fprintf(ficlog," %d %.12f",i, p[i]);
+ fprintf(ficlog," %d %.12lf",i, p[i]);
+ fprintf(ficrespow," %.12lf", p[i]);
+ }
printf("\n");
fprintf(ficlog,"\n");
+ fprintf(ficrespow,"\n");
for (i=1;i<=n;i++) {
for (j=1;j<=n;j++) xit[j]=xi[j][i];
fptt=(*fret);
int i,j, iter;
double **xi;
double fret;
+ char filerespow[FILENAMELENGTH];
xi=matrix(1,npar,1,npar);
for (i=1;i<=npar;i++)
for (j=1;j<=npar;j++)
xi[i][j]=(i==j ? 1.0 : 0.0);
printf("Powell\n"); fprintf(ficlog,"Powell\n");
+ strcpy(filerespow,"pow");
+ strcat(filerespow,fileres);
+ if((ficrespow=fopen(filerespow,"w"))==NULL) {
+ printf("Problem with resultfile: %s\n", filerespow);
+ fprintf(ficlog,"Problem with resultfile: %s\n", filerespow);
+ }
+ fprintf(ficrespow,"# Powell\n# iter -2*LL");
+ for (i=1;i<=nlstate;i++)
+ for(j=1;j<=nlstate+ndeath;j++)
+ if(j!=i)fprintf(ficrespow," p%1d%1d",i,j);
+ fprintf(ficrespow,"\n");
powell(p,xi,npar,ftol,&iter,&fret,func);
- printf("\n#Number of iterations = %d, -2 Log likelihood = %.12f\n",iter,func(p));
+ fclose(ficrespow);
+ printf("\n#Number of iterations = %d, -2 Log likelihood = %.12f\n",iter,func(p));
fprintf(ficlog,"\n#Number of iterations = %d, -2 Log likelihood = %.12f \n",iter,func(p));
fprintf(ficres,"#Number of iterations = %d, -2 Log likelihood = %.12f \n",iter,func(p));
fprintf(fichtm," ************\n<hr size=\"2\" color=\"#EC5E5E\">");
}
/* Pij */
- fprintf(fichtm,"<br>- Pij or Conditional probabilities to be observed in state j being in state i %d (stepm) months before: pe%s%d1.png<br>
+ fprintf(fichtm,"<br>- Pij or Conditional probabilities to be observed in state j being in state i, %d (stepm) months before: pe%s%d1.png<br>
<img src=\"pe%s%d1.png\">",stepm,strtok(optionfile, "."),jj1,strtok(optionfile, "."),jj1);
/* Quasi-incidences */
fprintf(fichtm,"<br>- Pij or Conditional probabilities to be observed in state j being in state i %d (stepm) months before but expressed in per year i.e. quasi incidences if stepm is small and probabilities too: pe%s%d2.png<br>
- Health expectancies with their variances (no covariance): <a href=\"t%s\">t%s</a> <br>\n
- Standard deviation of stable prevalences: <a href=\"vpl%s\">vpl%s</a> <br>\n",rfileres,rfileres,fileres,fileres,fileres,fileres,fileres,fileres, estepm, fileres,fileres,fileres,fileres,fileres,fileres);
- if(popforecast==1) fprintf(fichtm,"\n
- - Prevalences forecasting: <a href=\"f%s\">f%s</a> <br>\n
- - Population forecasting (if popforecast=1): <a href=\"pop%s\">pop%s</a> <br>\n
- <br>",fileres,fileres,fileres,fileres);
- else
- fprintf(fichtm,"\n No population forecast: popforecast = %d (instead of 1) or stepm = %d (instead of 1) or model=%s (instead of .)<br><br></li>\n",popforecast, stepm, model);
+/* if(popforecast==1) fprintf(fichtm,"\n */
+/* - Prevalences forecasting: <a href=\"f%s\">f%s</a> <br>\n */
+/* - Population forecasting (if popforecast=1): <a href=\"pop%s\">pop%s</a> <br>\n */
+/* <br>",fileres,fileres,fileres,fileres); */
+/* else */
+/* fprintf(fichtm,"\n No population forecast: popforecast = %d (instead of 1) or stepm = %d (instead of 1) or model=%s (instead of .)<br><br></li>\n",popforecast, stepm, model); */
fprintf(fichtm," <ul><li><b>Graphs</b></li><p>");
m=cptcoveff;
fprintf(fichtm," ************\n<hr size=\"2\" color=\"#EC5E5E\">");
}
for(cpt=1; cpt<=nlstate;cpt++) {
- fprintf(fichtm,"<br>- Observed and stationary prevalence (with confident
+ fprintf(fichtm,"<br>- Observed and period prevalence (with confident
interval) in state (%d): v%s%d%d.png <br>
<img src=\"v%s%d%d.png\">",cpt,strtok(optionfile, "."),cpt,jj1,strtok(optionfile, "."),cpt,jj1);
}
}
}
- /* CV preval stat */
+ /* CV preval stable (period) */
for (k1=1; k1<= m ; k1 ++) {
- for (cpt=1; cpt<nlstate ; cpt ++) {
+ for (cpt=1; cpt<=nlstate ; cpt ++) {
k=3;
fprintf(ficgp,"\nset out \"p%s%d%d.png\" \n",strtok(optionfile, "."),cpt,k1);
fprintf(ficgp,"set xlabel \"Age\" \nset ylabel \"Probability\" \nset ter png small\nset size 0.65,0.65\nplot [%.f:%.f] \"pij%s\" u ($1==%d ? ($3):1/0):($%d/($%d",ageminpar,agemaxpar,fileres,k1,k+cpt+1,k+1);
- for (i=1; i< nlstate ; i ++)
+ for (i=1; i<= nlstate ; i ++)
fprintf(ficgp,"+$%d",k+i+1);
fprintf(ficgp,")) t\"prev(%d,%d)\" w l",cpt,cpt+1);
for (i=1; i<=imx; i++) {
for(m=2; (m<= maxwav); m++) {
- if ((mint[m][i]== 99) && (s[m][i] <= nlstate)){
+ if (((int)mint[m][i]== 99) && (s[m][i] <= nlstate)){
anint[m][i]=9999;
s[m][i]=-1;
}
- if(moisdc[i]==99 && andc[i]==9999 & s[m][i]>nlstate) s[m][i]=-1;
+ if((int)moisdc[i]==99 && (int)andc[i]==9999 && s[m][i]>nlstate){
+ printf("Error! Date of death (month %2d and year %4d) of individual %d on line %d was unknown %d, set an arbitrary year of death\n",(int)moisdc[i],(int)andc[i],num[i],i);
+ fprintf(ficlog,"Error! Date of death (month %2d and year %4d) of individual %d on line %d was unknown %d, set an arbitrary year of death\n",(int)moisdc[i],(int)andc[i],num[i],i);
+ s[m][i]=-1;
+ }
+ if((int)moisdc[i]==99 && (int)andc[i]!=9999 && s[m][i]>nlstate){
+ printf("Warning! Month of death of individual %d on line %d was unknown %2d, we set it to June\n",num[i],i,(int)moisdc[i]);
+ fprintf(ficlog,"Warning! Month of death of individual %d on line %d was unknown %f, we set it to June\n",num[i],i,moisdc[i]);
+ moisdc[i]=6;
+ s[m][i]=-1;
+ }
}
}
if(s[m][i] >0){
if (s[m][i] >= nlstate+1) {
if(agedc[i]>0)
- if(moisdc[i]!=99 && andc[i]!=9999)
+ if((int)moisdc[i]!=99 && (int)andc[i]!=9999)
agev[m][i]=agedc[i];
/*if(moisdc[i]==99 && andc[i]==9999) s[m][i]=-1;*/
else {
- if (andc[i]!=9999){
+ if ((int)andc[i]!=9999){
printf("Warning negative age at death: %d line:%d\n",num[i],i);
fprintf(ficlog,"Warning negative age at death: %d line:%d\n",num[i],i);
agev[m][i]=-1;
years but with the precision of a
month */
agev[m][i]=(mint[m][i]/12.+1./24.+anint[m][i])-(moisnais[i]/12.+1./24.+annais[i]);
- if(mint[m][i]==99 || anint[m][i]==9999)
+ if((int)mint[m][i]==99 || (int)anint[m][i]==9999)
agev[m][i]=1;
else if(agev[m][i] <agemin){
agemin=agev[m][i];
Title=%s <br>Datafile=%s Firstpass=%d Lastpass=%d Stepm=%d Weight=%d Model=%s<br>\n
\n
Total number of observations=%d <br>\n
+Youngest age at first pass %.2f, oldest age %.2f<br>\n
Interval (in months) between two waves: Min=%d Max=%d Mean=%.2lf<br>\n
<hr size=\"2\" color=\"#EC5E5E\">
<ul><li><h4>Parameter files</h4>\n
- Copy of the parameter file: <a href=\"o%s\">o%s</a><br>\n
- Log file of the run: <a href=\"%s\">%s</a><br>\n
- - Gnuplot file name: <a href=\"%s\">%s</a></ul>\n",version,title,datafile,firstpass,lastpass,stepm, weightopt,model,imx,jmin,jmax,jmean,fileres,fileres,filelog,filelog,optionfilegnuplot,optionfilegnuplot);
+ - Gnuplot file name: <a href=\"%s\">%s</a></ul>\n",version,title,datafile,firstpass,lastpass,stepm, weightopt,model,imx,agemin,agemax,jmin,jmax,jmean,fileres,fileres,filelog,filelog,optionfilegnuplot,optionfilegnuplot);
fclose(fichtm);
printinghtml(fileres,title,datafile, firstpass, lastpass, stepm, weightopt,model,imx,jmin,jmax,jmean,rfileres,popforecast,estepm,jprev1,mprev1,anprev1,jprev2,mprev2,anprev2);