- \r
-/*********************** Imach ************************************** \r
- This program computes Healthy Life Expectancies from cross-longitudinal \r
- data. Cross-longitudinal consist in a first survey ("cross") where \r
- individuals from different ages are interviewed on their health status\r
- or degree of disability. At least a second wave of interviews \r
- ("longitudinal") should measure each new individual health status. \r
- Health expectancies are computed from the transistions observed between \r
- waves and are computed for each degree of severity of disability (number\r
- of life states). More degrees you consider, more time is necessary to\r
- reach the Maximum Likelihood of the parameters involved in the model. \r
- The simplest model is the multinomial logistic model where pij is\r
- the probabibility to be observed in state j at the second wave conditional\r
- to be observed in state i at the first wave. Therefore the model is:\r
- log(pij/pii)= aij + bij*age+ cij*sex + etc , where 'age' is age and 'sex' \r
- is a covariate. If you want to have a more complex model than "constant and\r
- age", you should modify the program where the markup \r
- *Covariates have to be included here again* invites you to do it.\r
- More covariates you add, less is the speed of the convergence.\r
-\r
- The advantage that this computer programme claims, comes from that if the \r
- delay between waves is not identical for each individual, or if some \r
- individual missed an interview, the information is not rounded or lost, but\r
- taken into account using an interpolation or extrapolation.\r
- hPijx is the probability to be \r
- observed in state i at age x+h conditional to the observed state i at age \r
- x. The delay 'h' can be split into an exact number (nh*stepm) of \r
- unobserved intermediate states. This elementary transition (by month or \r
- quarter trimester, semester or year) is model as a multinomial logistic. \r
- The hPx matrix is simply the matrix product of nh*stepm elementary matrices\r
- and the contribution of each individual to the likelihood is simply hPijx.\r
+/* $Id$\r
+ Interpolate Markov Chain\r
+\r
+ Short summary of the programme:\r
+ \r
+ This program computes Healthy Life Expectancies from\r
+ cross-longitudinal data. Cross-longitudinal data consist in: -1- a\r
+ first survey ("cross") where individuals from different ages are\r
+ interviewed on their health status or degree of disability (in the\r
+ case of a health survey which is our main interest) -2- at least a\r
+ second wave of interviews ("longitudinal") which measure each change\r
+ (if any) in individual health status. Health expectancies are\r
+ computed from the time spent in each health state according to a\r
+ model. More health states you consider, more time is necessary to reach the\r
+ Maximum Likelihood of the parameters involved in the model. The\r
+ simplest model is the multinomial logistic model where pij is the\r
+ probabibility to be observed in state j at the second wave\r
+ conditional to be observed in state i at the first wave. Therefore\r
+ the model is: log(pij/pii)= aij + bij*age+ cij*sex + etc , where\r
+ 'age' is age and 'sex' is a covariate. If you want to have a more\r
+ complex model than "constant and age", you should modify the program\r
+ where the markup *Covariates have to be included here again* invites\r
+ you to do it. More covariates you add, slower the\r
+ convergence.\r
+\r
+ The advantage of this computer programme, compared to a simple\r
+ multinomial logistic model, is clear when the delay between waves is not\r
+ identical for each individual. Also, if a individual missed an\r
+ intermediate interview, the information is lost, but taken into\r
+ account using an interpolation or extrapolation. \r
+\r
+ hPijx is the probability to be observed in state i at age x+h\r
+ conditional to the observed state i at age x. The delay 'h' can be\r
+ split into an exact number (nh*stepm) of unobserved intermediate\r
+ states. This elementary transition (by month or quarter trimester,\r
+ semester or year) is model as a multinomial logistic. The hPx\r
+ matrix is simply the matrix product of nh*stepm elementary matrices\r
+ and the contribution of each individual to the likelihood is simply\r
+ hPijx.\r
\r
Also this programme outputs the covariance matrix of the parameters but also\r
of the life expectancies. It also computes the prevalence limits. \r
#include <unistd.h>\r
\r
#define MAXLINE 256\r
+#define GNUPLOTPROGRAM "..\\gp37mgw\\wgnuplot"\r
#define FILENAMELENGTH 80\r
/*#define DEBUG*/\r
#define windows\r
double ftolhess; /* Tolerance for computing hessian */\r
\r
/**************** split *************************/\r
-static int split( char *path, char *dirc, char *name )\r
+static int split( char *path, char *dirc, char *name, char *ext, char *finame )\r
{\r
char *s; /* pointer */\r
int l1, l2; /* length counters */\r
\r
l1 = strlen( path ); /* length of path */\r
if ( l1 == 0 ) return( GLOCK_ERROR_NOPATH );\r
+#ifdef windows\r
s = strrchr( path, '\\' ); /* find last / */\r
+#else\r
+ s = strrchr( path, '/' ); /* find last / */\r
+#endif\r
if ( s == NULL ) { /* no directory, so use current */\r
#if defined(__bsd__) /* get current working directory */\r
extern char *getwd( );\r
dirc[l1-l2] = 0; /* add zero */\r
}\r
l1 = strlen( dirc ); /* length of directory */\r
+#ifdef windows\r
if ( dirc[l1-1] != '\\' ) { dirc[l1] = '\\'; dirc[l1+1] = 0; }\r
+#else\r
+ if ( dirc[l1-1] != '/' ) { dirc[l1] = '/'; dirc[l1+1] = 0; }\r
+#endif\r
+ s = strrchr( name, '.' ); /* find last / */\r
+ s++;\r
+ strcpy(ext,s); /* save extension */\r
+ l1= strlen( name);\r
+ l2= strlen( s)+1;\r
+ strncpy( finame, name, l1-l2);\r
+ finame[l1-l2]= 0;\r
return( 0 ); /* we're done */\r
}\r
\r
s2 += x[(i-1)*nlstate*ncovmodel+(j-2)*ncovmodel+nc+(i-1)*(ndeath-1)*ncovmodel]*cov[nc];\r
/*printf("Int j>i s1=%.17e, s2=%.17e %lx %lx\n",s1,s2,s1,s2);*/\r
}\r
- ps[i][j]=(s2);\r
+ ps[i][j]=s2;\r
}\r
}\r
/*ps[3][2]=1;*/\r
/**************** Main Program *****************/\r
/***********************************************/\r
\r
-/*int main(int argc, char *argv[])*/\r
-int main()\r
+int main(int argc, char *argv[])\r
{\r
\r
int i,j, k, n=MAXN,iter,m,size,cptcode, cptcod;\r
char line[MAXLINE], linepar[MAXLINE];\r
char title[MAXLINE];\r
char optionfile[FILENAMELENGTH], datafile[FILENAMELENGTH], filerespl[FILENAMELENGTH], optionfilehtm[FILENAMELENGTH];\r
- char fileres[FILENAMELENGTH], filerespij[FILENAMELENGTH], filereso[FILENAMELENGTH], fileresf[FILENAMELENGTH];\r
+ char optionfilext[10], optionfilefiname[FILENAMELENGTH], optionfilegnuplot[FILENAMELENGTH], plotcmd[FILENAMELENGTH];\r
+ \r
+ char fileres[FILENAMELENGTH], filerespij[FILENAMELENGTH], filereso[FILENAMELENGTH], fileresf[FILENAMELENGTH];;\r
+\r
char filerest[FILENAMELENGTH];\r
char fileregp[FILENAMELENGTH];\r
char popfile[FILENAMELENGTH];\r
double dateprev1, dateprev2,jproj1,mproj1,anproj1,jproj2,mproj2,anproj2,jprojmean,mprojmean,anprojmean, calagedate;\r
double yp,yp1,yp2;\r
\r
- char version[80]="Imach version 64b, May 2001, INED-EUROREVES ";\r
+ char version[80]="Imach version 0.7, February 2002, INED-EUROREVES ";\r
char *alph[]={"a","a","b","c","d","e"}, str[4];\r
\r
\r
gettimeofday(&start_time, (struct timezone*)0); */ /* at first time */\r
\r
\r
- printf("\nIMACH, Version 0.7");\r
- printf("\nEnter the parameter file name: ");\r
-\r
-#ifdef windows\r
- scanf("%s",pathtot);\r
- getcwd(pathcd, size);\r
+ printf("\n%s",version);\r
+ if(argc <=1){\r
+ printf("\nEnter the parameter file name: ");\r
+ scanf("%s",pathtot);\r
+ }\r
+ else{\r
+ strcpy(pathtot,argv[1]);\r
+ }\r
+ /*if(getcwd(pathcd, 80)!= NULL)printf ("Error pathcd\n");*/\r
/*cygwin_split_path(pathtot,path,optionfile);\r
printf("pathtot=%s, path=%s, optionfile=%s\n",pathtot,path,optionfile);*/\r
/* cutv(path,optionfile,pathtot,'\\');*/\r
\r
-split(pathtot, path,optionfile);\r
+ split(pathtot,path,optionfile,optionfilext,optionfilefiname);\r
+ printf("pathtot=%s, path=%s, optionfile=%s optionfilext=%s optionfilefiname=%s\n",pathtot,path,optionfile,optionfilext,optionfilefiname);\r
chdir(path);\r
replace(pathc,path);\r
-#endif\r
-#ifdef unix\r
- scanf("%s",optionfile);\r
-#endif\r
\r
/*-------- arguments in the command line --------*/\r
\r
strcpy(fileres,"r");\r
- strcat(fileres, optionfile);\r
+ strcat(fileres, optionfilefiname);\r
+ strcat(fileres,".txt"); /* Other files have txt extension */\r
\r
/*---------arguments file --------*/\r
\r
}\r
}\r
} \r
+\r
+\r
+ /*for(i=1; i <=m ;i++){ \r
+ for(k=1; k <=cptcovn; k++){\r
+ printf("i=%d k=%d %d %d",i,k,codtab[i][k], cptcoveff);\r
+ }\r
+ printf("\n");\r
+ }\r
+ scanf("%d",i);*/\r
\r
/* Calculates basic frequencies. Computes observed prevalence at single age\r
and prints on file fileres'p'. */\r
bage = agemin;\r
fage = agemax;\r
}\r
-\r
- fprintf(ficres,"# agemin agemax for life expectancy.\n");\r
-\r
+ \r
+ fprintf(ficres,"# agemin agemax for life expectancy, bage fage (if mle==0 ie no data nor Max likelihood).\n");\r
fprintf(ficres,"agemin=%.0f agemax=%.0f bage=%.0f fage=%.0f\n",agemin,agemax,bage,fage);\r
fprintf(ficparo,"agemin=%.0f agemax=%.0f bage=%.0f fage=%.0f\n",agemin,agemax,bage,fage);\r
\r
\r
freqsummary(fileres, agemin, agemax, s, agev, nlstate, imx,Tvar,nbcode, ncodemax,mint,anint,dateprev1,dateprev2);\r
\r
- /*------------ gnuplot -------------*/\r
-chdir(pathcd);\r
- if((ficgp=fopen("graph.plt","w"))==NULL) {\r
- printf("Problem with file graph.gp");goto end;\r
- }\r
+ \r
+ /*------------ gnuplot -------------*/\r
+ /*chdir(pathcd);*/\r
+ strcpy(optionfilegnuplot,optionfilefiname);\r
+ strcat(optionfilegnuplot,".plt");\r
+ if((ficgp=fopen(optionfilegnuplot,"w"))==NULL) {\r
+ printf("Problem with file %s",optionfilegnuplot);goto end;\r
+ }\r
#ifdef windows\r
- fprintf(ficgp,"cd \"%s\" \n",pathc);\r
+ fprintf(ficgp,"cd \"%s\" \n",pathc);\r
#endif\r
m=pow(2,cptcoveff);\r
\r
\r
end:\r
#ifdef windows\r
- chdir(pathcd);\r
+ /* chdir(pathcd);*/\r
#endif \r
- \r
- system("..\\gp37mgw\\wgnuplot graph.plt");\r
+ /*system("wgnuplot graph.plt");*/\r
+ /*system("../gp37mgw/wgnuplot graph.plt");*/\r
+ /*system("cd ../gp37mgw");*/\r
+ /* system("..\\gp37mgw\\wgnuplot graph.plt");*/\r
+ strcpy(plotcmd,GNUPLOTPROGRAM);\r
+ strcat(plotcmd," ");\r
+ strcat(plotcmd,optionfilegnuplot);\r
+ system(plotcmd);\r
\r
#ifdef windows\r
while (z[0] != 'q') {\r
- chdir(pathcd); \r
+ chdir(path); \r
printf("\nType e to edit output files, c to start again, and q for exiting: ");\r
scanf("%s",z);\r
if (z[0] == 'c') system("./imach");\r