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
+ 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
}\r
}\r
\r
-/*************** transition probabilities **********/ \r
+/*************** transition probabilities ***************/ \r
\r
double **pmij(double **ps, double *cov, int ncovmodel, double *x, int nlstate )\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
+\r
for(i=1; i<= nlstate; i++){\r
s1=0;\r
for(j=1; j<i; j++)\r
}\r
}\r
\r
+\r
/* for(ii=1; ii<= nlstate+ndeath; ii++){\r
for(jj=1; jj<= nlstate+ndeath; jj++){\r
printf("%lf ",ps[ii][jj]);\r
cov[1]=1.;\r
cov[2]=age+((h-1)*hstepm + (d-1))*stepm/YEARM;\r
for (k=1; k<=cptcovn;k++) cov[2+k]=nbcode[Tvar[k]][codtab[ij][Tvar[k]]];\r
-for (k=1; k<=cptcovage;k++)\r
+ for (k=1; k<=cptcovage;k++)\r
cov[2+Tage[k]]=cov[2+Tage[k]]*cov[2];\r
- for (k=1; k<=cptcovprod;k++)\r
+ for (k=1; k<=cptcovprod;k++)\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
\r
void lubksb(double **a, int npar, int *indx, double b[]) ;\r
void ludcmp(double **a, int npar, int *indx, double *d) ;\r
\r
-\r
hess=matrix(1,npar,1,npar);\r
\r
printf("\nCalculation of the hessian matrix. Wait...\n");\r
printf("%d",i);fflush(stdout);\r
hess[i][i]=hessii(p,ftolhess,i,delti);\r
/*printf(" %f ",p[i]);*/\r
+ /*printf(" %lf ",hess[i][i]);*/\r
}\r
-\r
+ \r
for (i=1;i<=npar;i++) {\r
for (j=1;j<=npar;j++) {\r
if (j>i) { \r
printf(".%d%d",i,j);fflush(stdout);\r
hess[i][j]=hessij(p,delti,i,j);\r
- hess[j][i]=hess[i][j];\r
+ hess[j][i]=hess[i][j]; \r
+ /*printf(" %lf ",hess[i][j]);*/\r
}\r
}\r
}\r
}\r
}\r
delti[theta]=delts;\r
- return res;\r
+ return res; \r
\r
}\r
\r
if (j >= jmax) jmax=j;\r
if (j <= jmin) jmin=j;\r
sum=sum+j;\r
- if (j<0) printf("j=%d num=%d ",j,i); \r
+ /* if (j<10) printf("j=%d num=%d ",j,i); */\r
}\r
}\r
else{\r
k=k+1;\r
if (j >= jmax) jmax=j;\r
else if (j <= jmin)jmin=j;\r
+ /* if (j<10) printf("j=%d jmin=%d num=%d ",j,jmin,i); */\r
sum=sum+j;\r
}\r
jk= j/stepm;\r
}\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
+ }\r
/*********** Tricode ****************************/\r
void tricode(int *Tvar, int **nbcode, int imx)\r
{\r
\r
for (k=0; k<19; k++) Ndum[k]=0;\r
\r
- for (i=1; i<=ncovmodel; i++) {\r
+ for (i=1; i<=ncovmodel-2; i++) {\r
ij=Tvar[i];\r
Ndum[ij]++; \r
}\r
double **dnewm,**doldm;\r
int i, j, nhstepm, hstepm, h;\r
int k, cptcode;\r
- double *xp;\r
+ double *xp;\r
double **gp, **gm;\r
double ***gradg, ***trgradg;\r
double ***p3mat;\r
int ju,jl, mi;\r
int i1,j1, k1,k2,k3,jk,aa,bb, stepsize, ij;\r
int jnais,jdc,jint4,jint1,jint2,jint3,**outcome,**adl,*tab;\r
- \r
+ \r
int hstepm, nhstepm;\r
double bage, fage, age, agelim, agebase;\r
double ftolpl=FTOL;\r
fprintf(ficparo,"\n");\r
}\r
\r
- npar= (nlstate+ndeath-1)*nlstate*ncovmodel;\r
+ npar= (nlstate+ndeath-1)*nlstate*ncovmodel;\r
+\r
p=param[1][1];\r
\r
/* Reads comments: lines beginning with '#' */\r
tab=ivector(1,NCOVMAX);\r
ncodemax=ivector(1,8);\r
\r
- i=1; \r
+ i=1;\r
while (fgets(line, MAXLINE, fic) != NULL) {\r
if ((i >= firstobs) && (i <=lastobs)) {\r
\r
cutv(stra, strb,line,' '); covar[j][i]=(double)(atoi(strb)); strcpy(line,stra);\r
} \r
num[i]=atol(stra);\r
-\r
- /*printf("%d %.lf %.lf %.lf %.lf/%.lf %.lf/%.lf %.lf/%.lf %d %.lf/%.lf %d %.lf/%.lf %d %.lf/%.lf %d\n",num[i],(covar[1][i]), (covar[2][i]), (weight[i]), (moisnais[i]), (annais[i]), (moisdc[i]), (andc[i]), (mint[1][i]), (anint[1][i]), (s[1][i]), (mint[2][i]), (anint[2][i]), (s[2][i]), (mint[3][i]), (anint[3][i]), (s[3][i]), (mint[4][i]), (anint[4][i]), (s[4][i]));*/\r
+ \r
+ /*if((s[2][i]==2) && (s[3][i]==-1)&&(s[4][i]==9)){\r
+ printf("%d %.lf %.lf %.lf %.lf/%.lf %.lf/%.lf %.lf/%.lf %d %.lf/%.lf %d %.lf/%.lf %d %.lf/%.lf %d\n",num[i],(covar[1][i]), (covar[2][i]),weight[i], (moisnais[i]), (annais[i]), (moisdc[i]), (andc[i]), (mint[1][i]), (anint[1][i]), (s[1][i]), (mint[2][i]), (anint[2][i]), (s[2][i]), (mint[3][i]), (anint[3][i]), (s[3][i]), (mint[4][i]), (anint[4][i]), (s[4][i])); ij=ij+1;}*/\r
\r
i=i+1;\r
}\r
} \r
-\r
- /*scanf("%d",i);*/\r
+ /* printf("ii=%d", ij);\r
+ scanf("%d",i);*/\r
imx=i-1; /* Number of individuals */\r
\r
+ /* for (i=1; i<=imx; i++){\r
+ if ((s[1][i]==3) && (s[2][i]==2)) s[2][i]=3;\r
+ if ((s[2][i]==3) && (s[3][i]==2)) s[3][i]=3;\r
+ if ((s[3][i]==3) && (s[4][i]==2)) s[4][i]=3;\r
+ }\r
+ for (i=1; i<=imx; i++) printf("%d %.lf %.lf %.lf %.lf/%.lf %.lf/%.lf %.lf/%.lf %d %.lf/%.lf %d %.lf/%.lf %d %.lf/%.lf %d\n",num[i],(covar[1][i]), (covar[2][i]), (weight[i]), (moisnais[i]), (annais[i]), (moisdc[i]), (andc[i]), (mint[1][i]), (anint[1][i]), (s[1][i]), (mint[2][i]), (anint[2][i]), (s[2][i]), (mint[3][i]), (anint[3][i]), (s[3][i]), (mint[4][i]), (anint[4][i]), (s[4][i]));*/\r
+\r
/* Calculation of the number of parameter from char model*/\r
Tvar=ivector(1,15); \r
Tprod=ivector(1,15); \r
}\r
/*-calculation of age at interview from date of interview and age at death -*/\r
agev=matrix(1,maxwav,1,imx);\r
+\r
+ for (i=1; i<=imx; i++) \r
+ for(m=2; (m<= maxwav); m++)\r
+ if ((mint[m][i]== 99) && (s[m][i] <= nlstate)){\r
+ anint[m][i]=9999;\r
+ s[m][i]=-1;\r
+ }\r
\r
for (i=1; i<=imx; i++) {\r
agedc[i]=(moisdc[i]/12.+andc[i])-(moisnais[i]/12.+annais[i]);\r
newms= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */\r
savms= matrix(1,nlstate+ndeath,1,nlstate+ndeath); /* creation */\r
oldm=oldms; newm=newms; savm=savms; /* Keeps fixed addresses to free */\r
- \r
+ \r
/* For Powell, parameters are in a vector p[] starting at p[1]\r
so we point p on param[1][1] so that p[1] maps on param[1][1][1] */\r
p=param[1][1]; /* *(*(*(param +1)+1)+0) */\r
/*printf("Total time was %d uSec.\n", total_usecs);*/\r
/*------ End -----------*/\r
\r
+\r
end:\r
#ifdef windows\r
chdir(pathcd);\r