version 1.142, 2014/01/26 03:57:36
|
version 1.144, 2014/02/10 22:17:31
|
Line 1
|
Line 1
|
/* $Id$ |
/* $Id$ |
$State$ |
$State$ |
$Log$ |
$Log$ |
|
Revision 1.144 2014/02/10 22:17:31 brouard |
|
*** empty log message *** |
|
|
|
Revision 1.143 2014/01/26 09:45:38 brouard |
|
Summary: Version 0.98nR (to be improved, but gives same optimization results as 0.98k. Nice, promising |
|
|
|
* imach.c (Module): Trying to merge old staffs together while being at Tokyo. Not tested... |
|
(Module): Version 0.98nR Running ok, but output format still only works for three covariates. |
|
|
Revision 1.142 2014/01/26 03:57:36 brouard |
Revision 1.142 2014/01/26 03:57:36 brouard |
Summary: gnuplot changed plot w l 1 has to be changed to plot w l lt 2 |
Summary: gnuplot changed plot w l 1 has to be changed to plot w l lt 2 |
|
|
Line 423 extern int errno;
|
Line 432 extern int errno;
|
#define GLOCK_ERROR_NOPATH -1 /* empty path */ |
#define GLOCK_ERROR_NOPATH -1 /* empty path */ |
#define GLOCK_ERROR_GETCWD -2 /* cannot get cwd */ |
#define GLOCK_ERROR_GETCWD -2 /* cannot get cwd */ |
|
|
#define MAXPARM 128 /* Maximum number of parameters for the optimization */ |
#define MAXPARM 128 /**< Maximum number of parameters for the optimization */ |
#define NPARMAX 64 /* (nlstate+ndeath-1)*nlstate*ncovmodel */ |
#define NPARMAX 64 /**< (nlstate+ndeath-1)*nlstate*ncovmodel */ |
|
|
#define NINTERVMAX 8 |
#define NINTERVMAX 8 |
#define NLSTATEMAX 8 /* Maximum number of live states (for func) */ |
#define NLSTATEMAX 8 /**< Maximum number of live states (for func) */ |
#define NDEATHMAX 8 /* Maximum number of dead states (for func) */ |
#define NDEATHMAX 8 /**< Maximum number of dead states (for func) */ |
#define NCOVMAX 20 /* Maximum number of covariates */ |
#define NCOVMAX 20 /**< Maximum number of covariates, including generated covariates V1*V2 */ |
#define MAXN 20000 |
#define MAXN 20000 |
#define YEARM 12. /* Number of months per year */ |
#define YEARM 12. /**< Number of months per year */ |
#define AGESUP 130 |
#define AGESUP 130 |
#define AGEBASE 40 |
#define AGEBASE 40 |
#define AGEGOMP 10. /* Minimal age for Gompertz adjustment */ |
#define AGEGOMP 10. /**< Minimal age for Gompertz adjustment */ |
#ifdef UNIX |
#ifdef UNIX |
#define DIRSEPARATOR '/' |
#define DIRSEPARATOR '/' |
#define CHARSEPARATOR "/" |
#define CHARSEPARATOR "/" |
Line 448 extern int errno;
|
Line 457 extern int errno;
|
/* $Id$ */ |
/* $Id$ */ |
/* $State$ */ |
/* $State$ */ |
|
|
char version[]="Imach version 0.98nR, January 2014,INED-EUROREVES-Institut de longevite-Japan Society for the Promotion of Science (Grant-in-Aid for Scientific Research 25293121)"; |
char version[]="Imach version 0.98nR2, January 2014,INED-EUROREVES-Institut de longevite-Japan Society for the Promotion of Science (Grant-in-Aid for Scientific Research 25293121)"; |
char fullversion[]="$Revision$ $Date$"; |
char fullversion[]="$Revision$ $Date$"; |
char strstart[80]; |
char strstart[80]; |
char optionfilext[10], optionfilefiname[FILENAMELENGTH]; |
char optionfilext[10], optionfilefiname[FILENAMELENGTH]; |
Line 582 int **codtab; /**< codtab=imatrix(1,100,
|
Line 591 int **codtab; /**< codtab=imatrix(1,100,
|
int **Tvard, *Tprod, cptcovprod, *Tvaraff; |
int **Tvard, *Tprod, cptcovprod, *Tvaraff; |
double *lsurv, *lpop, *tpop; |
double *lsurv, *lpop, *tpop; |
|
|
double ftol=FTOL; /* Tolerance for computing Max Likelihood */ |
double ftol=FTOL; /**< Tolerance for computing Max Likelihood */ |
double ftolhess; /* Tolerance for computing hessian */ |
double ftolhess; /**< Tolerance for computing hessian */ |
|
|
/**************** split *************************/ |
/**************** split *************************/ |
static int split( char *path, char *dirc, char *name, char *ext, char *finame ) |
static int split( char *path, char *dirc, char *name, char *ext, char *finame ) |
Line 2203 void freqsummary(char fileres[], int ia
|
Line 2212 void freqsummary(char fileres[], int ia
|
|
|
first=1; |
first=1; |
|
|
for(k1=1; k1<=j;k1++){ |
for(k1=1; k1<=j ; k1++){ /* Loop on covariates */ |
for(i1=1; i1<=ncodemax[k1];i1++){ |
for(i1=1; i1<=ncodemax[k1];i1++){ /* Now it is 2 */ |
j1++; |
j1++; |
/*printf("cptcoveff=%d Tvaraff=%d", cptcoveff,Tvaraff[1]); |
/*printf("cptcoveff=%d Tvaraff=%d", cptcoveff,Tvaraff[1]); |
scanf("%d", i);*/ |
scanf("%d", i);*/ |
Line 2212 void freqsummary(char fileres[], int ia
|
Line 2221 void freqsummary(char fileres[], int ia
|
for (jk=-5; jk<=nlstate+ndeath; jk++) |
for (jk=-5; jk<=nlstate+ndeath; jk++) |
for(m=iagemin; m <= iagemax+3; m++) |
for(m=iagemin; m <= iagemax+3; m++) |
freq[i][jk][m]=0; |
freq[i][jk][m]=0; |
|
|
for (i=1; i<=nlstate; i++) |
for (i=1; i<=nlstate; i++) |
for(m=iagemin; m <= iagemax+3; m++) |
for(m=iagemin; m <= iagemax+3; m++) |
prop[i][m]=0; |
prop[i][m]=0; |
|
|
dateintsum=0; |
dateintsum=0; |
k2cpt=0; |
k2cpt=0; |
for (i=1; i<=imx; i++) { |
for (i=1; i<=imx; i++) { |
bool=1; |
bool=1; |
if (cptcovn>0) { |
if (cptcovn>0) { /* Filter is here: Must be looked at for model=V1+V2+V3+V4 */ |
for (z1=1; z1<=cptcoveff; z1++) |
for (z1=1; z1<=cptcoveff; z1++) |
if (covar[Tvaraff[z1]][i]!= nbcode[Tvaraff[z1]][codtab[j1][z1]]) |
if (covar[Tvaraff[z1]][i]!= nbcode[Tvaraff[z1]][codtab[j1][z1]]){ |
bool=0; |
bool=0; |
|
printf("bool=%d i=%d, z1=%d, i1=%d, Tvaraff[%d]=%d, covar[Tvarff][%d]=%2f, codtab[%d][%d]=%d, nbcode[Tvaraff][codtab[%d][%d]=%d, j1=%d\n", |
|
bool,i,z1, i1, z1, Tvaraff[z1],i,covar[Tvaraff[z1]][i],j1,z1,codtab[j1][z1], |
|
j1,z1,nbcode[Tvaraff[z1]][codtab[j1][z1]],j1); |
|
/* For j1=7 in V1+V2+V3+V4 = 0 1 1 0 and codtab[7][3]=1 and nbcde[3][?]=1*/ |
|
} |
} |
} |
|
|
if (bool==1){ |
if (bool==1){ |
for(m=firstpass; m<=lastpass; m++){ |
for(m=firstpass; m<=lastpass; m++){ |
k2=anint[m][i]+(mint[m][i]/12.); |
k2=anint[m][i]+(mint[m][i]/12.); |
Line 2253 void freqsummary(char fileres[], int ia
|
Line 2268 void freqsummary(char fileres[], int ia
|
fprintf(ficresp, "\n#********** Variable "); |
fprintf(ficresp, "\n#********** Variable "); |
for (z1=1; z1<=cptcoveff; z1++) fprintf(ficresp, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtab[j1][z1]]); |
for (z1=1; z1<=cptcoveff; z1++) fprintf(ficresp, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtab[j1][z1]]); |
fprintf(ficresp, "**********\n#"); |
fprintf(ficresp, "**********\n#"); |
|
fprintf(ficlog, "\n#********** Variable "); |
|
for (z1=1; z1<=cptcoveff; z1++) fprintf(ficlog, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtab[j1][z1]]); |
|
fprintf(ficlog, "**********\n#"); |
} |
} |
for(i=1; i<=nlstate;i++) |
for(i=1; i<=nlstate;i++) |
fprintf(ficresp, " Age Prev(%d) N(%d) N",i,i); |
fprintf(ficresp, " Age Prev(%d) N(%d) N",i,i); |
Line 2564 void concatwav(int wav[], int **dh, int
|
Line 2582 void concatwav(int wav[], int **dh, int
|
/*********** Tricode ****************************/ |
/*********** Tricode ****************************/ |
void tricode(int *Tvar, int **nbcode, int imx) |
void tricode(int *Tvar, int **nbcode, int imx) |
{ |
{ |
/* Uses cptcovn+2*cptcovprod as the number of covariates */ |
/**< Uses cptcovn+2*cptcovprod as the number of covariates */ |
/* Tvar[i]=atoi(stre); /* find 'n' in Vn and stores in Tvar. If model=V2+V1 Tvar[1]=2 and Tvar[2]=1 */ |
/* Tvar[i]=atoi(stre); find 'n' in Vn and stores in Tvar. If model=V2+V1 Tvar[1]=2 and Tvar[2]=1 |
|
/* Boring subroutine which should only output nbcode[Tvar[j]][k] |
|
/* nbcode[Tvar[j][1]= |
|
*/ |
|
|
int Ndum[20],ij=1, k=0, j=0, i=0, maxncov=NCOVMAX; |
int Ndum[20],ij=1, k=0, j=0, i=0, maxncov=NCOVMAX; |
int modmaxcovj=0; /* Modality max of covariates j */ |
int modmaxcovj=0; /* Modality max of covariates j */ |
cptcoveff=0; |
cptcoveff=0; |
|
|
for (k=0; k<maxncov; k++) Ndum[k]=0; |
for (k=0; k < maxncov; k++) Ndum[k]=0; |
for (k=1; k<=7; k++) ncodemax[k]=0; /* Horrible constant again */ |
for (k=1; k <= maxncov; k++) ncodemax[k]=0; /* Horrible constant again replaced by NCOVMAX */ |
|
|
for (j=1; j<=(cptcovn+2*cptcovprod); j++) { /* For each covariate j */ |
for (j=1; j<=(cptcovn+2*cptcovprod); j++) { /* For each covariate j */ |
for (i=1; i<=imx; i++) { /*reads the data file to get the maximum value of the |
for (i=1; i<=imx; i++) { /*reads the data file to get the maximum value of the |
Line 2626 void tricode(int *Tvar, int **nbcode, in
|
Line 2647 void tricode(int *Tvar, int **nbcode, in
|
} |
} |
} |
} |
ij--; |
ij--; |
cptcoveff=ij; /*Number of simple covariates*/ |
cptcoveff=ij; /*Number of total covariates*/ |
} |
} |
|
|
/*********** Health Expectancies ****************/ |
/*********** Health Expectancies ****************/ |
Line 5411 run imach with mle=-1 to get a correct t
|
Line 5432 run imach with mle=-1 to get a correct t
|
anint=matrix(1,maxwav,1,n); |
anint=matrix(1,maxwav,1,n); |
s=imatrix(1,maxwav+1,1,n); /* s[i][j] health state for wave i and individual j */ |
s=imatrix(1,maxwav+1,1,n); /* s[i][j] health state for wave i and individual j */ |
tab=ivector(1,NCOVMAX); |
tab=ivector(1,NCOVMAX); |
ncodemax=ivector(1,8); /* hard coded ? */ |
ncodemax=ivector(1,NCOVMAX); /* Number of code per covariate; if O and 1 only, 2**ncov; V1+V2+V3+V4=>16 */ |
|
|
/* Reads data from file datafile */ |
/* Reads data from file datafile */ |
if (readdata(datafile, firstobs, lastobs, &imx)==1) |
if (readdata(datafile, firstobs, lastobs, &imx)==1) |
Line 5490 run imach with mle=-1 to get a correct t
|
Line 5511 run imach with mle=-1 to get a correct t
|
ncodemax[1]=1; |
ncodemax[1]=1; |
if (cptcovn > 0) tricode(Tvar,nbcode,imx); |
if (cptcovn > 0) tricode(Tvar,nbcode,imx); |
|
|
codtab=imatrix(1,100,1,10); /* Cross tabulation to get the order of |
codtab=imatrix(1,100,1,10); /**< codtab[h,k]=( (h-1) - mod(k-1,2**(k-1) )/2**(k-1) |
the estimations*/ |
*/ |
h=0; |
h=0; |
m=pow(2,cptcoveff); |
m=pow(2,cptcoveff); |
|
|
for(k=1;k<=cptcoveff; k++){ /* scans any effective covariate */ |
for(k=1;k<=cptcoveff; k++){ /* scans any effective covariate */ |
for(i=1; i <=(m/pow(2,k));i++){ /* i=1 to 8/1=8; i=1 to 8/2=4; i=1 to 8/8=1 */ |
for(i=1; i <=pow(2,cptcoveff-k);i++){ /* i=1 to 8/1=8; i=1 to 8/2=4; i=1 to 8/8=1 */ |
for(j=1; j <= ncodemax[k]; j++){ /* For each modality of this covariate */ |
for(j=1; j <= ncodemax[k]; j++){ /* For each modality of this covariate ncodemax=2*/ |
for(cpt=1; cpt <=(m/pow(2,cptcoveff+1-k)); cpt++){ /* cpt=1 to 8/2**(3+1-1 or 3+1-3) =1 or 4 */ |
for(cpt=1; cpt <=pow(2,k-1); cpt++){ /* cpt=1 to 8/2**(3+1-1 or 3+1-3) =1 or 4 */ |
h++; |
h++; |
if (h>m) |
if (h>m) |
h=1; |
h=1; |
|
/**< codtab(h,k) k = codtab[h,k]=( (h-1) - mod(k-1,2**(k-1) )/2**(k-1) + 1 |
|
* h 1 2 3 4 |
|
*______________________________ |
|
* 1 i=1 1 i=1 1 i=1 1 i=1 1 |
|
* 2 2 1 1 1 |
|
* 3 i=2 1 2 1 1 |
|
* 4 2 2 1 1 |
|
* 5 i=3 1 i=2 1 2 1 |
|
* 6 2 1 2 1 |
|
* 7 i=4 1 2 2 1 |
|
* 8 2 2 2 1 |
|
* 9 i=5 1 i=3 1 i=2 1 1 |
|
* 10 2 1 1 1 |
|
* 11 i=6 1 2 1 1 |
|
* 12 2 2 1 1 |
|
* 13 i=7 1 i=4 1 2 1 |
|
* 14 2 1 2 1 |
|
* 15 i=8 1 2 2 1 |
|
* 16 2 2 2 1 |
|
*/ |
codtab[h][k]=j; |
codtab[h][k]=j; |
codtab[h][Tvar[k]]=j; |
codtab[h][Tvar[k]]=j; |
printf("h=%d k=%d j=%d codtab[h][k]=%d Tvar[k]=%d codtab[h][Tvar[k]]=%d \n",h, k,j,codtab[h][k],Tvar[k],codtab[h][Tvar[k]]); |
printf("h=%d k=%d j=%d codtab[h][k]=%d Tvar[k]=%d codtab[h][Tvar[k]]=%d \n",h, k,j,codtab[h][k],Tvar[k],codtab[h][Tvar[k]]); |
Line 6081 Interval (in months) between two waves:
|
Line 6122 Interval (in months) between two waves:
|
agebase=ageminpar; |
agebase=ageminpar; |
agelim=agemaxpar; |
agelim=agemaxpar; |
ftolpl=1.e-10; |
ftolpl=1.e-10; |
i1=cptcoveff; |
i1=pow(2,cptcoveff); |
if (cptcovn < 1){i1=1;} |
if (cptcovn < 1){i1=1;} |
|
|
for(cptcov=1,k=0;cptcov<=i1;cptcov++){ |
for(cptcov=1,k=0;cptcov<=i1;cptcov++){ |
for(cptcod=1;cptcod<=ncodemax[cptcov];cptcod++){ |
//for(cptcod=1;cptcod<=ncodemax[cptcov];cptcod++){ |
k=k+1; |
k=k+1; |
/* to clean */ |
/* to clean */ |
printf("cptcov=%d cptcod=%d codtab=%d nbcode=%d\n",cptcov, cptcod,codtab[cptcod][cptcov],nbcode); |
//printf("cptcov=%d cptcod=%d codtab=%d\n",cptcov, cptcod,codtab[cptcod][cptcov]); |
fprintf(ficrespl,"\n#******"); |
fprintf(ficrespl,"\n#******"); |
printf("\n#******"); |
printf("\n#******"); |
fprintf(ficlog,"\n#******"); |
fprintf(ficlog,"\n#******"); |
Line 6109 Interval (in months) between two waves:
|
Line 6150 Interval (in months) between two waves:
|
for(i=1; i<=nlstate;i++) |
for(i=1; i<=nlstate;i++) |
fprintf(ficrespl," %.5f", prlim[i][i]); |
fprintf(ficrespl," %.5f", prlim[i][i]); |
fprintf(ficrespl,"\n"); |
fprintf(ficrespl,"\n"); |
} |
} /* Age */ |
} |
/* was end of cptcod */ |
} |
} /* cptcov */ |
fclose(ficrespl); |
fclose(ficrespl); |
|
|
/*------------- h Pij x at various ages ------------*/ |
/*------------- h Pij x at various ages ------------*/ |