--- imach/src/imach.c 2019/05/09 13:39:37 1.290 +++ imach/src/imach.c 2019/05/20 13:03:18 1.296 @@ -1,6 +1,35 @@ -/* $Id: imach.c,v 1.290 2019/05/09 13:39:37 brouard Exp $ +/* $Id: imach.c,v 1.296 2019/05/20 13:03:18 brouard Exp $ $State: Exp $ $Log: imach.c,v $ + Revision 1.296 2019/05/20 13:03:18 brouard + Summary: Projection syntax simplified + + + We can now start projections, forward or backward, from the mean date + of inteviews up to or down to a number of years of projection: + prevforecast=1 yearsfproj=15.3 mobil_average=0 + or + prevforecast=1 starting-proj-date=1/1/2007 final-proj-date=12/31/2017 mobil_average=0 + or + prevbackcast=1 yearsbproj=12.3 mobil_average=1 + or + prevbackcast=1 starting-back-date=1/10/1999 final-back-date=1/1/1985 mobil_average=1 + + Revision 1.295 2019/05/18 09:52:50 brouard + Summary: doxygen tex bug + + Revision 1.294 2019/05/16 14:54:33 brouard + Summary: There was some wrong lines added + + Revision 1.293 2019/05/09 15:17:34 brouard + *** empty log message *** + + Revision 1.292 2019/05/09 14:17:20 brouard + Summary: Some updates + + Revision 1.291 2019/05/09 13:44:18 brouard + Summary: Before ncovmax + Revision 1.290 2019/05/09 13:39:37 brouard Summary: 0.99r18 unlimited number of individuals @@ -1054,7 +1083,7 @@ typedef struct { #define NINTERVMAX 8 #define NLSTATEMAX 8 /**< Maximum number of live states (for func) */ #define NDEATHMAX 8 /**< Maximum number of dead states (for func) */ -/* #define NCOVMAX 20 */ /**< Maximum number of covariates, including generated covariates V1*V2 */ +#define NCOVMAX 20 /**< Maximum number of covariates, including generated covariates V1*V2 */ #define codtabm(h,k) (1 & (h-1) >> (k-1))+1 /*#define decodtabm(h,k,cptcoveff)= (h <= (1<> (k-1)) & 1) +1 : -1)*/ #define decodtabm(h,k,cptcoveff) (((h-1) >> (k-1)) & 1) +1 @@ -1078,12 +1107,12 @@ typedef struct { #define ODIRSEPARATOR '\\' #endif -/* $Id: imach.c,v 1.290 2019/05/09 13:39:37 brouard Exp $ */ +/* $Id: imach.c,v 1.296 2019/05/20 13:03:18 brouard Exp $ */ /* $State: Exp $ */ #include "version.h" char version[]=__IMACH_VERSION__; char copyright[]="April 2018,INED-EUROREVES-Institut de longevite-Japan Society for the Promotion of Science (Grant-in-Aid for Scientific Research 25293121), Intel Software 2015-2018"; -char fullversion[]="$Revision: 1.290 $ $Date: 2019/05/09 13:39:37 $"; +char fullversion[]="$Revision: 1.296 $ $Date: 2019/05/20 13:03:18 $"; char strstart[80]; char optionfilext[10], optionfilefiname[FILENAMELENGTH]; int erreur=0, nberr=0, nbwarn=0; /* Error number, number of errors number of warnings */ @@ -1247,7 +1276,12 @@ double **pmmij, ***probs; /* Global poin double ***mobaverage, ***mobaverages; /* New global variable */ double *ageexmed,*agecens; double dateintmean=0; + double anprojd, mprojd, jprojd; /* For eventual projections */ + double anprojf, mprojf, jprojf; + double anbackd, mbackd, jbackd; /* For eventual backprojections */ + double anbackf, mbackf, jbackf; + double jintmean,mintmean,aintmean; double *weight; int **s; /* Status */ double *agedc; @@ -2960,8 +2994,8 @@ double **pmij(double **ps, double *cov, ps[ii][ii]=1; } } - - + + /* for(ii=1; ii<= nlstate+ndeath; ii++){ */ /* for(jj=1; jj<= nlstate+ndeath; jj++){ */ /* printf(" pmij ps[%d][%d]=%lf ",ii,jj,ps[ii][jj]); */ @@ -2989,7 +3023,7 @@ double **pmij(double **ps, double *cov, double **out, **pmij(); double sumnew=0.; double agefin; - double k3=0.; /* constant of the w_x diagonal matrixe (in order for B to sum to 1 even for death state) */ + double k3=0.; /* constant of the w_x diagonal matrix (in order for B to sum to 1 even for death state) */ double **dnewm, **dsavm, **doldm; double **bbmij; @@ -3008,7 +3042,7 @@ double **pmij(double **ps, double *cov, /* outputs pmmij which is a stochastic matrix in row */ /* Diag(w_x) */ - /* Problem with prevacurrent which can be zero */ + /* Rescaling the cross-sectional prevalence: Problem with prevacurrent which can be zero */ sumnew=0.; /*for (ii=1;ii<=nlstate+ndeath;ii++){*/ for (ii=1;ii<=nlstate;ii++){ /* Only on live states */ @@ -3035,10 +3069,10 @@ double **pmij(double **ps, double *cov, } /* End doldm, At the end doldm is diag[(w_i)] */ - /* left Product of this diag matrix by pmmij=Px (dnewm=dsavm*doldm) */ - bbmij=matprod2(dnewm, doldm,1,nlstate+ndeath,1,nlstate+ndeath,1,nlstate+ndeath, pmmij); /* Bug Valgrind */ + /* Left product of this diag matrix by pmmij=Px (dnewm=dsavm*doldm): diag[(w_i)*Px */ + bbmij=matprod2(dnewm, doldm,1,nlstate+ndeath,1,nlstate+ndeath,1,nlstate+ndeath, pmmij); /* was a Bug Valgrind */ - /* Diag(Sum_i w^i_x p^ij_x */ + /* Diag(Sum_i w^i_x p^ij_x, should be the prevalence at age x+stepm */ /* w1 p11 + w2 p21 only on live states N1./N..*N11/N1. + N2./N..*N21/N2.=(N11+N21)/N..=N.1/N.. */ for (j=1;j<=nlstate+ndeath;j++){ sumnew=0.; @@ -3056,7 +3090,7 @@ double **pmij(double **ps, double *cov, } /*End ii */ } /* End j, At the end dsavm is diag[1/(w_1p1i+w_2 p2i)] for ALL states even if the sum is only for live states */ - ps=matprod2(ps, dnewm,1,nlstate+ndeath,1,nlstate+ndeath,1,nlstate+ndeath, dsavm); /* Bug Valgrind */ + ps=matprod2(ps, dnewm,1,nlstate+ndeath,1,nlstate+ndeath,1,nlstate+ndeath, dsavm); /* was a Bug Valgrind */ /* ps is now diag[w_i] * Px * diag [1/(w_1p1i+w_2 p2i)] */ /* end bmij */ return ps; /*pointer is unchanged */ @@ -3128,7 +3162,7 @@ double **bpmij(double **ps, double *cov, ps[ii][ii]=1; } } - /* Added for backcast */ /* Transposed matrix too */ + /* Added for prevbcast */ /* Transposed matrix too */ for(jj=1; jj<= nlstate+ndeath; jj++){ s1=0.; for(ii=1; ii<= nlstate+ndeath; ii++){ @@ -3888,7 +3922,7 @@ return -l; /*************** function likelione ***********/ -void likelione(FILE *ficres,double p[], int npar, int nlstate, int *globpri, long *ipmx, double *sw, double *fretone, double (*funcone)(double [])) +void likelione(FILE *ficres,double p[], int npar, int nlstate, int *globpri, long *ipmx, double *sw, double *fretone, double (*func)(double [])) { /* This routine should help understanding what is done with the selection of individuals/waves and @@ -3912,7 +3946,7 @@ void likelione(FILE *ficres,double p[], fprintf(ficresilk," -2*gipw/gsw*weight*ll(total)\n"); } - *fretone=(*funcone)(p); + *fretone=(*func)(p); if(*globpri !=0){ fclose(ficresilk); if (mle ==0) @@ -4961,6 +4995,7 @@ Title=%s
Datafile=%s Firstpass=%d La } } /* end mle=-2 */ dateintmean=dateintsum/k2cpt; + date2dmy(dateintmean,&jintmean,&mintmean,&aintmean); fclose(ficresp); fclose(ficresphtm); @@ -6003,10 +6038,10 @@ void concatwav(int wav[], int **dh, int prlim[i][i]=mobaverage[(int)age][i][ij]; } } - /**< Computes the shifted transition matrix \f$ {}{h}_p^{ij}_x\f$ at horizon h. + /**< Computes the shifted transition matrix \f$ {}{h}_p^{ij}x\f$ at horizon h. */ hpxij(p3mat,nhstepm,age,hstepm,xp,nlstate,stepm,oldm,savm, ij,nres); /* Returns p3mat[i][j][h] for h=0 to nhstepm */ - /**< And for each alive state j, sums over i \f$ w^i_x {}{h}_p^{ij}_x\f$, which are the probability + /**< And for each alive state j, sums over i \f$ w^i_x {}{h}_p^{ij}x\f$, which are the probability * at horizon h in state j including mortality. */ for(j=1; j<= nlstate; j++){ @@ -6796,9 +6831,9 @@ To be simple, these graphs help to under void printinghtml(char fileresu[], char title[], char datafile[], int firstpass, \ int lastpass, int stepm, int weightopt, char model[],\ int imx,int jmin, int jmax, double jmeanint,char rfileres[],\ - int popforecast, int mobilav, int prevfcast, int mobilavproj, int backcast, int estepm , \ - double jprev1, double mprev1,double anprev1, double dateprev1, double dateproj1, double dateback1, \ - double jprev2, double mprev2,double anprev2, double dateprev2, double dateproj2, double dateback2){ + int popforecast, int mobilav, int prevfcast, int mobilavproj, int prevbcast, int estepm , \ + double jprev1, double mprev1,double anprev1, double dateprev1, double dateprojd, double dateback1, \ + double jprev2, double mprev2,double anprev2, double dateprev2, double dateprojf, double dateback2){ int jj1, k1, i1, cpt, k4, nres; fprintf(fichtm,"