/* $Id$
$State$
$Log$
+ Revision 1.325 2022/07/25 14:27:23 brouard
+ Summary: r30
+
+ * imach.c (Module): Error cptcovn instead of nsd in bmij (was
+ coredumped, revealed by Feiuno, thank you.
+
Revision 1.324 2022/07/23 17:44:26 brouard
*** empty log message ***
int k2, l2, j1, z1;
int k=0, l;
int first=1, first1, first2;
+ int nres=0; /* New */
double cv12, mu1, mu2, lc1, lc2, v12, v21, v11, v22,v1,v2, c12, tnalp;
double **dnewm,**doldm;
double *xp;
if (cptcovn<1) {tj=1;ncodemax[1]=1;}
j1=0;
for(j1=1; j1<=tj;j1++){ /* For each valid combination of covariates or only once*/
+ for(nres=1;nres <=1; nres++){ /* For each resultline */
+ /* for(nres=1;nres <=nresult; nres++){ /\* For each resultline *\/ */
if (cptcovn>0) {
fprintf(ficresprob, "\n#********** Variable ");
for (z1=1; z1<=cptcoveff; z1++) fprintf(ficresprob, "V%d=%d ",Tvaraff[z1],nbcode[Tvaraff[z1]][codtabm(j1,z1)]);
cov[2]=age;
if(nagesqr==1)
cov[3]= age*age;
- for (k=1; k<=cptcovn;k++) {
- cov[2+nagesqr+k]=nbcode[Tvar[k]][codtabm(j1,k)];
+ /* for (k=1; k<=cptcovn;k++) { */
+ /* cov[2+nagesqr+k]=nbcode[Tvar[k]][codtabm(j1,k)]; */
+ for (k=1; k<=nsd;k++) { /* For single dummy covariates only */
+ /* Here comes the value of the covariate 'j1' after renumbering k with single dummy covariates */
+ cov[2+nagesqr+TvarsDind[k]]=nbcode[TvarsD[k]][codtabm(j1,k)];
/*cov[2+nagesqr+k]=nbcode[Tvar[k]][codtabm(j1,Tvar[k])];*//* j1 1 2 3 4
* 1 1 1 1 1
* 2 2 1 1 1
/* V2+V1+V4+V3*age Tvar[4]=3 ; V1+V2*age Tvar[2]=2; V1+V1*age Tvar[2]=1, Tage[1]=2 */
/* ) p nbcode[Tvar[Tage[k]]][(1 & (ij-1) >> (k-1))+1] */
/*for (k=1; k<=cptcovage;k++) cov[2+Tage[k]]=cov[2+Tage[k]]*cov[2]; */
- for (k=1; k<=cptcovage;k++)
- cov[2+Tage[k]+nagesqr]=nbcode[Tvar[Tage[k]]][codtabm(ij,k)]*cov[2];
- for (k=1; k<=cptcovprod;k++)
- cov[2+nagesqr+Tprod[k]]=nbcode[Tvard[k][1]][codtabm(ij,k)]*nbcode[Tvard[k][2]][codtabm(ij,k)];
-
-
+ for (k=1; k<=cptcovage;k++){ /* For product with age */
+ if(Dummy[Tage[k]]==2){ /* dummy with age */
+ cov[2+nagesqr+Tage[k]]=nbcode[Tvar[Tage[k]]][codtabm(j1,k)]*cov[2];
+ /* cov[++k1]=nbcode[Tvar[Tage[k]]][codtabm(ij,k)]*cov[2]; */
+ } else if(Dummy[Tage[k]]==3){ /* quantitative with age */
+ cov[2+nagesqr+Tage[k]]=Tqresult[nres][k];
+ /* cov[++k1]=Tqresult[nres][k]; */
+ }
+ /* cov[2+Tage[k]+nagesqr]=nbcode[Tvar[Tage[k]]][codtabm(ij,k)]*cov[2]; */
+ }
+ for (k=1; k<=cptcovprod;k++){/* For product without age */
+ if(Dummy[Tvard[k][1]==0]){
+ if(Dummy[Tvard[k][2]==0]){
+ cov[2+nagesqr+Tprod[k]]=nbcode[Tvard[k][1]][codtabm(j1,k)] * nbcode[Tvard[k][2]][codtabm(j1,k)];
+ /* cov[++k1]=nbcode[Tvard[k][1]][codtabm(ij,k)] * nbcode[Tvard[k][2]][codtabm(ij,k)]; */
+ }else{ /* Should we use the mean of the quantitative variables? */
+ cov[2+nagesqr+Tprod[k]]=nbcode[Tvard[k][1]][codtabm(j1,k)] * Tqresult[nres][k];
+ /* cov[++k1]=nbcode[Tvard[k][1]][codtabm(ij,k)] * Tqresult[nres][k]; */
+ }
+ }else{
+ if(Dummy[Tvard[k][2]==0]){
+ cov[2+nagesqr+Tprod[k]]=nbcode[Tvard[k][2]][codtabm(j1,k)] * Tqinvresult[nres][Tvard[k][1]];
+ /* cov[++k1]=nbcode[Tvard[k][2]][codtabm(ij,k)] * Tqinvresult[nres][Tvard[k][1]]; */
+ }else{
+ cov[2+nagesqr+Tprod[k]]=Tqinvresult[nres][Tvard[k][1]]* Tqinvresult[nres][Tvard[k][2]];
+ /* cov[++k1]=Tqinvresult[nres][Tvard[k][1]]* Tqinvresult[nres][Tvard[k][2]]; */
+ }
+ }
+ /* cov[2+nagesqr+Tprod[k]]=nbcode[Tvard[k][1]][codtabm(ij,k)]*nbcode[Tvard[k][2]][codtabm(ij,k)]; */
+ }
+/* For each age and combination of dummy covariates we slightly move the parameters of delti in order to get the gradient*/
for(theta=1; theta <=npar; theta++){
for(i=1; i<=npar; i++)
xp[i] = x[i] + (i==theta ?delti[theta]:(double)0);
} /* k12 */
} /*l1 */
}/* k1 */
+ } /* loop on nres */
} /* loop on combination of covariates j1 */
free_ma3x(varpij,1,nlstate,1,nlstate+ndeath,(int) bage, (int)fage);
free_matrix(mu,1,(nlstate+ndeath)*(nlstate+ndeath),(int) bage, (int)fage);