--- imach/src/imach.c 2015/04/30 14:45:16 1.189 +++ imach/src/imach.c 2023/04/29 10:43:47 1.351 @@ -1,6 +1,622 @@ -/* $Id: imach.c,v 1.189 2015/04/30 14:45:16 brouard Exp $ +/* $Id: imach.c,v 1.351 2023/04/29 10:43:47 brouard Exp $ $State: Exp $ $Log: imach.c,v $ + Revision 1.351 2023/04/29 10:43:47 brouard + Summary: 099r45 + + Revision 1.350 2023/04/24 11:38:06 brouard + *** empty log message *** + + Revision 1.349 2023/01/31 09:19:37 brouard + Summary: Improvements in models with age*Vn*Vm + + Revision 1.347 2022/09/18 14:36:44 brouard + Summary: version 0.99r42 + + Revision 1.346 2022/09/16 13:52:36 brouard + * src/imach.c (Module): 0.99r41 Was an error when product of timevarying and fixed. Using FixedV[of name] now. Thank you Feinuo + + Revision 1.345 2022/09/16 13:40:11 brouard + Summary: Version 0.99r41 + + * imach.c (Module): 0.99r41 Was an error when product of timevarying and fixed. Using FixedV[of name] now. Thank you Feinuo + + Revision 1.344 2022/09/14 19:33:30 brouard + Summary: version 0.99r40 + + * imach.c (Module): Fixing names of variables in T_ (thanks to Feinuo) + + Revision 1.343 2022/09/14 14:22:16 brouard + Summary: version 0.99r39 + + * imach.c (Module): Version 0.99r39 with colored dummy covariates + (fixed or time varying), using new last columns of + ILK_parameter.txt file. + + Revision 1.342 2022/09/11 19:54:09 brouard + Summary: 0.99r38 + + * imach.c (Module): Adding timevarying products of any kinds, + should work before shifting cotvar from ncovcol+nqv columns in + order to have a correspondance between the column of cotvar and + the id of column. + (Module): Some cleaning and adding covariates in ILK.txt + + Revision 1.341 2022/09/11 07:58:42 brouard + Summary: Version 0.99r38 + + After adding change in cotvar. + + Revision 1.340 2022/09/11 07:53:11 brouard + Summary: Version imach 0.99r37 + + * imach.c (Module): Adding timevarying products of any kinds, + should work before shifting cotvar from ncovcol+nqv columns in + order to have a correspondance between the column of cotvar and + the id of column. + + Revision 1.339 2022/09/09 17:55:22 brouard + Summary: version 0.99r37 + + * imach.c (Module): Many improvements for fixing products of fixed + timevarying as well as fixed * fixed, and test with quantitative + covariate. + + Revision 1.338 2022/09/04 17:40:33 brouard + Summary: 0.99r36 + + * imach.c (Module): Now the easy runs i.e. without result or + model=1+age only did not work. The defautl combination should be 1 + and not 0 because everything hasn't been tranformed yet. + + Revision 1.337 2022/09/02 14:26:02 brouard + Summary: version 0.99r35 + + * src/imach.c: Version 0.99r35 because it outputs same results with + 1+age+V1+V1*age for females and 1+age for females only + (education=1 noweight) + + Revision 1.336 2022/08/31 09:52:36 brouard + *** empty log message *** + + Revision 1.335 2022/08/31 08:23:16 brouard + Summary: improvements... + + Revision 1.334 2022/08/25 09:08:41 brouard + Summary: In progress for quantitative + + Revision 1.333 2022/08/21 09:10:30 brouard + * src/imach.c (Module): Version 0.99r33 A lot of changes in + reassigning covariates: my first idea was that people will always + use the first covariate V1 into the model but in fact they are + producing data with many covariates and can use an equation model + with some of the covariate; it means that in a model V2+V3 instead + of codtabm(k,Tvaraff[j]) which calculates for combination k, for + three covariates (V1, V2, V3) the value of Tvaraff[j], but in fact + the equation model is restricted to two variables only (V2, V3) + and the combination for V2 should be codtabm(k,1) instead of + (codtabm(k,2), and the code should be + codtabm(k,TnsdVar[Tvaraff[j]]. Many many changes have been + made. All of these should be simplified once a day like we did in + hpxij() for example by using precov[nres] which is computed in + decoderesult for each nres of each resultline. Loop should be done + on the equation model globally by distinguishing only product with + age (which are changing with age) and no more on type of + covariates, single dummies, single covariates. + + Revision 1.332 2022/08/21 09:06:25 brouard + Summary: Version 0.99r33 + + * src/imach.c (Module): Version 0.99r33 A lot of changes in + reassigning covariates: my first idea was that people will always + use the first covariate V1 into the model but in fact they are + producing data with many covariates and can use an equation model + with some of the covariate; it means that in a model V2+V3 instead + of codtabm(k,Tvaraff[j]) which calculates for combination k, for + three covariates (V1, V2, V3) the value of Tvaraff[j], but in fact + the equation model is restricted to two variables only (V2, V3) + and the combination for V2 should be codtabm(k,1) instead of + (codtabm(k,2), and the code should be + codtabm(k,TnsdVar[Tvaraff[j]]. Many many changes have been + made. All of these should be simplified once a day like we did in + hpxij() for example by using precov[nres] which is computed in + decoderesult for each nres of each resultline. Loop should be done + on the equation model globally by distinguishing only product with + age (which are changing with age) and no more on type of + covariates, single dummies, single covariates. + + Revision 1.331 2022/08/07 05:40:09 brouard + *** empty log message *** + + Revision 1.330 2022/08/06 07:18:25 brouard + Summary: last 0.99r31 + + * imach.c (Module): Version of imach using partly decoderesult to rebuild xpxij function + + Revision 1.329 2022/08/03 17:29:54 brouard + * imach.c (Module): Many errors in graphs fixed with Vn*age covariates. + + Revision 1.328 2022/07/27 17:40:48 brouard + Summary: valgrind bug fixed by initializing to zero DummyV as well as Tage + + Revision 1.327 2022/07/27 14:47:35 brouard + Summary: Still a problem for one-step probabilities in case of quantitative variables + + Revision 1.326 2022/07/26 17:33:55 brouard + Summary: some test with nres=1 + + 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 *** + + Revision 1.323 2022/07/22 12:30:08 brouard + * imach.c (Module): Output of Wald test in the htm file and not only in the log. + + Revision 1.322 2022/07/22 12:27:48 brouard + * imach.c (Module): Output of Wald test in the htm file and not only in the log. + + Revision 1.321 2022/07/22 12:04:24 brouard + Summary: r28 + + * imach.c (Module): Output of Wald test in the htm file and not only in the log. + + Revision 1.320 2022/06/02 05:10:11 brouard + *** empty log message *** + + Revision 1.319 2022/06/02 04:45:11 brouard + * imach.c (Module): Adding the Wald tests from the log to the main + htm for better display of the maximum likelihood estimators. + + Revision 1.318 2022/05/24 08:10:59 brouard + * imach.c (Module): Some attempts to find a bug of wrong estimates + of confidencce intervals with product in the equation modelC + + Revision 1.317 2022/05/15 15:06:23 brouard + * imach.c (Module): Some minor improvements + + Revision 1.316 2022/05/11 15:11:31 brouard + Summary: r27 + + Revision 1.315 2022/05/11 15:06:32 brouard + *** empty log message *** + + Revision 1.314 2022/04/13 17:43:09 brouard + * imach.c (Module): Adding link to text data files + + Revision 1.313 2022/04/11 15:57:42 brouard + * imach.c (Module): Error in rewriting the 'r' file with yearsfproj or yearsbproj fixed + + Revision 1.312 2022/04/05 21:24:39 brouard + *** empty log message *** + + Revision 1.311 2022/04/05 21:03:51 brouard + Summary: Fixed quantitative covariates + + Fixed covariates (dummy or quantitative) + with missing values have never been allowed but are ERRORS and + program quits. Standard deviations of fixed covariates were + wrongly computed. Mean and standard deviations of time varying + covariates are still not computed. + + Revision 1.310 2022/03/17 08:45:53 brouard + Summary: 99r25 + + Improving detection of errors: result lines should be compatible with + the model. + + Revision 1.309 2021/05/20 12:39:14 brouard + Summary: Version 0.99r24 + + Revision 1.308 2021/03/31 13:11:57 brouard + Summary: Version 0.99r23 + + + * imach.c (Module): Still bugs in the result loop. Thank to Holly Benett + + Revision 1.307 2021/03/08 18:11:32 brouard + Summary: 0.99r22 fixed bug on result: + + Revision 1.306 2021/02/20 15:44:02 brouard + Summary: Version 0.99r21 + + * imach.c (Module): Fix bug on quitting after result lines! + (Module): Version 0.99r21 + + Revision 1.305 2021/02/20 15:28:30 brouard + * imach.c (Module): Fix bug on quitting after result lines! + + Revision 1.304 2021/02/12 11:34:20 brouard + * imach.c (Module): The use of a Windows BOM (huge) file is now an error + + Revision 1.303 2021/02/11 19:50:15 brouard + * (Module): imach.c Someone entered 'results:' instead of 'result:'. Now it is an error which is printed. + + Revision 1.302 2020/02/22 21:00:05 brouard + * (Module): imach.c Update mle=-3 (for computing Life expectancy + and life table from the data without any state) + + Revision 1.301 2019/06/04 13:51:20 brouard + Summary: Error in 'r'parameter file backcast yearsbproj instead of yearsfproj + + Revision 1.300 2019/05/22 19:09:45 brouard + Summary: version 0.99r19 of May 2019 + + Revision 1.299 2019/05/22 18:37:08 brouard + Summary: Cleaned 0.99r19 + + Revision 1.298 2019/05/22 18:19:56 brouard + *** empty log message *** + + Revision 1.297 2019/05/22 17:56:10 brouard + Summary: Fix bug by moving date2dmy and nhstepm which gaefin=-1 + + 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 + + The number n which was limited to 20,000 cases is now unlimited, from firstobs to lastobs. If the number is too for the virtual memory, probably an error will occur. + + Revision 1.289 2018/12/13 09:16:26 brouard + Summary: Bug for young ages (<-30) will be in r17 + + Revision 1.288 2018/05/02 20:58:27 brouard + Summary: Some bugs fixed + + Revision 1.287 2018/05/01 17:57:25 brouard + Summary: Bug fixed by providing frequencies only for non missing covariates + + Revision 1.286 2018/04/27 14:27:04 brouard + Summary: some minor bugs + + Revision 1.285 2018/04/21 21:02:16 brouard + Summary: Some bugs fixed, valgrind tested + + Revision 1.284 2018/04/20 05:22:13 brouard + Summary: Computing mean and stdeviation of fixed quantitative variables + + Revision 1.283 2018/04/19 14:49:16 brouard + Summary: Some minor bugs fixed + + Revision 1.282 2018/02/27 22:50:02 brouard + *** empty log message *** + + Revision 1.281 2018/02/27 19:25:23 brouard + Summary: Adding second argument for quitting + + Revision 1.280 2018/02/21 07:58:13 brouard + Summary: 0.99r15 + + New Makefile with recent VirtualBox 5.26. Bug in sqrt negatve in imach.c + + Revision 1.279 2017/07/20 13:35:01 brouard + Summary: temporary working + + Revision 1.278 2017/07/19 14:09:02 brouard + Summary: Bug for mobil_average=0 and prevforecast fixed(?) + + Revision 1.277 2017/07/17 08:53:49 brouard + Summary: BOM files can be read now + + Revision 1.276 2017/06/30 15:48:31 brouard + Summary: Graphs improvements + + Revision 1.275 2017/06/30 13:39:33 brouard + Summary: Saito's color + + Revision 1.274 2017/06/29 09:47:08 brouard + Summary: Version 0.99r14 + + Revision 1.273 2017/06/27 11:06:02 brouard + Summary: More documentation on projections + + Revision 1.272 2017/06/27 10:22:40 brouard + Summary: Color of backprojection changed from 6 to 5(yellow) + + Revision 1.271 2017/06/27 10:17:50 brouard + Summary: Some bug with rint + + Revision 1.270 2017/05/24 05:45:29 brouard + *** empty log message *** + + Revision 1.269 2017/05/23 08:39:25 brouard + Summary: Code into subroutine, cleanings + + Revision 1.268 2017/05/18 20:09:32 brouard + Summary: backprojection and confidence intervals of backprevalence + + Revision 1.267 2017/05/13 10:25:05 brouard + Summary: temporary save for backprojection + + Revision 1.266 2017/05/13 07:26:12 brouard + Summary: Version 0.99r13 (improvements and bugs fixed) + + Revision 1.265 2017/04/26 16:22:11 brouard + Summary: imach 0.99r13 Some bugs fixed + + Revision 1.264 2017/04/26 06:01:29 brouard + Summary: Labels in graphs + + Revision 1.263 2017/04/24 15:23:15 brouard + Summary: to save + + Revision 1.262 2017/04/18 16:48:12 brouard + *** empty log message *** + + Revision 1.261 2017/04/05 10:14:09 brouard + Summary: Bug in E_ as well as in T_ fixed nres-1 vs k1-1 + + Revision 1.260 2017/04/04 17:46:59 brouard + Summary: Gnuplot indexations fixed (humm) + + Revision 1.259 2017/04/04 13:01:16 brouard + Summary: Some errors to warnings only if date of death is unknown but status is death we could set to pi3 + + Revision 1.258 2017/04/03 10:17:47 brouard + Summary: Version 0.99r12 + + Some cleanings, conformed with updated documentation. + + Revision 1.257 2017/03/29 16:53:30 brouard + Summary: Temp + + Revision 1.256 2017/03/27 05:50:23 brouard + Summary: Temporary + + Revision 1.255 2017/03/08 16:02:28 brouard + Summary: IMaCh version 0.99r10 bugs in gnuplot fixed + + Revision 1.254 2017/03/08 07:13:00 brouard + Summary: Fixing data parameter line + + Revision 1.253 2016/12/15 11:59:41 brouard + Summary: 0.99 in progress + + Revision 1.252 2016/09/15 21:15:37 brouard + *** empty log message *** + + Revision 1.251 2016/09/15 15:01:13 brouard + Summary: not working + + Revision 1.250 2016/09/08 16:07:27 brouard + Summary: continue + + Revision 1.249 2016/09/07 17:14:18 brouard + Summary: Starting values from frequencies + + Revision 1.248 2016/09/07 14:10:18 brouard + *** empty log message *** + + Revision 1.247 2016/09/02 11:11:21 brouard + *** empty log message *** + + Revision 1.246 2016/09/02 08:49:22 brouard + *** empty log message *** + + Revision 1.245 2016/09/02 07:25:01 brouard + *** empty log message *** + + Revision 1.244 2016/09/02 07:17:34 brouard + *** empty log message *** + + Revision 1.243 2016/09/02 06:45:35 brouard + *** empty log message *** + + Revision 1.242 2016/08/30 15:01:20 brouard + Summary: Fixing a lots + + Revision 1.241 2016/08/29 17:17:25 brouard + Summary: gnuplot problem in Back projection to fix + + Revision 1.240 2016/08/29 07:53:18 brouard + Summary: Better + + Revision 1.239 2016/08/26 15:51:03 brouard + Summary: Improvement in Powell output in order to copy and paste + + Author: + + Revision 1.238 2016/08/26 14:23:35 brouard + Summary: Starting tests of 0.99 + + Revision 1.237 2016/08/26 09:20:19 brouard + Summary: to valgrind + + Revision 1.236 2016/08/25 10:50:18 brouard + *** empty log message *** + + Revision 1.235 2016/08/25 06:59:23 brouard + *** empty log message *** + + Revision 1.234 2016/08/23 16:51:20 brouard + *** empty log message *** + + Revision 1.233 2016/08/23 07:40:50 brouard + Summary: not working + + Revision 1.232 2016/08/22 14:20:21 brouard + Summary: not working + + Revision 1.231 2016/08/22 07:17:15 brouard + Summary: not working + + Revision 1.230 2016/08/22 06:55:53 brouard + Summary: Not working + + Revision 1.229 2016/07/23 09:45:53 brouard + Summary: Completing for func too + + Revision 1.228 2016/07/22 17:45:30 brouard + Summary: Fixing some arrays, still debugging + + Revision 1.226 2016/07/12 18:42:34 brouard + Summary: temp + + Revision 1.225 2016/07/12 08:40:03 brouard + Summary: saving but not running + + Revision 1.224 2016/07/01 13:16:01 brouard + Summary: Fixes + + Revision 1.223 2016/02/19 09:23:35 brouard + Summary: temporary + + Revision 1.222 2016/02/17 08:14:50 brouard + Summary: Probably last 0.98 stable version 0.98r6 + + Revision 1.221 2016/02/15 23:35:36 brouard + Summary: minor bug + + Revision 1.219 2016/02/15 00:48:12 brouard + *** empty log message *** + + Revision 1.218 2016/02/12 11:29:23 brouard + Summary: 0.99 Back projections + + Revision 1.217 2015/12/23 17:18:31 brouard + Summary: Experimental backcast + + Revision 1.216 2015/12/18 17:32:11 brouard + Summary: 0.98r4 Warning and status=-2 + + Version 0.98r4 is now: + - displaying an error when status is -1, date of interview unknown and date of death known; + - permitting a status -2 when the vital status is unknown at a known date of right truncation. + Older changes concerning s=-2, dating from 2005 have been supersed. + + Revision 1.215 2015/12/16 08:52:24 brouard + Summary: 0.98r4 working + + Revision 1.214 2015/12/16 06:57:54 brouard + Summary: temporary not working + + Revision 1.213 2015/12/11 18:22:17 brouard + Summary: 0.98r4 + + Revision 1.212 2015/11/21 12:47:24 brouard + Summary: minor typo + + Revision 1.211 2015/11/21 12:41:11 brouard + Summary: 0.98r3 with some graph of projected cross-sectional + + Author: Nicolas Brouard + + Revision 1.210 2015/11/18 17:41:20 brouard + Summary: Start working on projected prevalences Revision 1.209 2015/11/17 22:12:03 brouard + Summary: Adding ftolpl parameter + Author: N Brouard + + We had difficulties to get smoothed confidence intervals. It was due + to the period prevalence which wasn't computed accurately. The inner + parameter ftolpl is now an outer parameter of the .imach parameter + file after estepm. If ftolpl is small 1.e-4 and estepm too, + computation are long. + + Revision 1.208 2015/11/17 14:31:57 brouard + Summary: temporary + + Revision 1.207 2015/10/27 17:36:57 brouard + *** empty log message *** + + Revision 1.206 2015/10/24 07:14:11 brouard + *** empty log message *** + + Revision 1.205 2015/10/23 15:50:53 brouard + Summary: 0.98r3 some clarification for graphs on likelihood contributions + + Revision 1.204 2015/10/01 16:20:26 brouard + Summary: Some new graphs of contribution to likelihood + + Revision 1.203 2015/09/30 17:45:14 brouard + Summary: looking at better estimation of the hessian + + Also a better criteria for convergence to the period prevalence And + therefore adding the number of years needed to converge. (The + prevalence in any alive state shold sum to one + + Revision 1.202 2015/09/22 19:45:16 brouard + Summary: Adding some overall graph on contribution to likelihood. Might change + + Revision 1.201 2015/09/15 17:34:58 brouard + Summary: 0.98r0 + + - Some new graphs like suvival functions + - Some bugs fixed like model=1+age+V2. + + Revision 1.200 2015/09/09 16:53:55 brouard + Summary: Big bug thanks to Flavia + + Even model=1+age+V2. did not work anymore + + Revision 1.199 2015/09/07 14:09:23 brouard + Summary: 0.98q6 changing default small png format for graph to vectorized svg. + + Revision 1.198 2015/09/03 07:14:39 brouard + Summary: 0.98q5 Flavia + + Revision 1.197 2015/09/01 18:24:39 brouard + *** empty log message *** + + Revision 1.196 2015/08/18 23:17:52 brouard + Summary: 0.98q5 + + Revision 1.195 2015/08/18 16:28:39 brouard + Summary: Adding a hack for testing purpose + + After reading the title, ftol and model lines, if the comment line has + a q, starting with #q, the answer at the end of the run is quit. It + permits to run test files in batch with ctest. The former workaround was + $ echo q | imach foo.imach + + Revision 1.194 2015/08/18 13:32:00 brouard + Summary: Adding error when the covariance matrix doesn't contain the exact number of lines required by the model line. + + Revision 1.193 2015/08/04 07:17:42 brouard + Summary: 0.98q4 + + Revision 1.192 2015/07/16 16:49:02 brouard + Summary: Fixing some outputs + + Revision 1.191 2015/07/14 10:00:33 brouard + Summary: Some fixes + + Revision 1.190 2015/05/05 08:51:13 brouard + Summary: Adding digits in output parameters (7 digits instead of 6) + + Fix 1+age+. + Revision 1.189 2015/04/30 14:45:16 brouard Summary: 0.98q2 @@ -406,7 +1022,7 @@ The same imach parameter file can be used but the option for mle should be -3. - Agnès, who wrote this part of the code, tried to keep most of the + Agnès, who wrote this part of the code, tried to keep most of the former routines in order to include the new code within the former code. The output is very simple: only an estimate of the intercept and of @@ -501,24 +1117,27 @@ Short summary of the programme: - This program computes Healthy Life Expectancies from - cross-longitudinal data. Cross-longitudinal data consist in: -1- a - first survey ("cross") where individuals from different ages are - interviewed on their health status or degree of disability (in the - case of a health survey which is our main interest) -2- at least a - second wave of interviews ("longitudinal") which measure each change - (if any) in individual health status. Health expectancies are - computed from the time spent in each health state according to a - model. More health states you consider, more time is necessary to reach the - Maximum Likelihood of the parameters involved in the model. The - simplest model is the multinomial logistic model where pij is the - probability to be observed in state j at the second wave - conditional to be observed in state i at the first wave. Therefore - the model is: log(pij/pii)= aij + bij*age+ cij*sex + etc , where - 'age' is age and 'sex' is a covariate. If you want to have a more - complex model than "constant and age", you should modify the program - where the markup *Covariates have to be included here again* invites - you to do it. More covariates you add, slower the + This program computes Healthy Life Expectancies or State-specific + (if states aren't health statuses) Expectancies from + cross-longitudinal data. Cross-longitudinal data consist in: + + -1- a first survey ("cross") where individuals from different ages + are interviewed on their health status or degree of disability (in + the case of a health survey which is our main interest) + + -2- at least a second wave of interviews ("longitudinal") which + measure each change (if any) in individual health status. Health + expectancies are computed from the time spent in each health state + according to a model. More health states you consider, more time is + necessary to reach the Maximum Likelihood of the parameters involved + in the model. The simplest model is the multinomial logistic model + where pij is the probability to be observed in state j at the second + wave conditional to be observed in state i at the first + wave. Therefore the model is: log(pij/pii)= aij + bij*age+ cij*sex + + etc , where 'age' is age and 'sex' is a covariate. If you want to + have a more complex model than "constant and age", you should modify + the program where the markup *Covariates have to be included here + again* invites you to do it. More covariates you add, slower the convergence. The advantage of this computer programme, compared to a simple @@ -537,10 +1156,58 @@ hPijx. Also this programme outputs the covariance matrix of the parameters but also - of the life expectancies. It also computes the period (stable) prevalence. + of the life expectancies. It also computes the period (stable) prevalence. + +Back prevalence and projections: + + - back_prevalence_limit(double *p, double **bprlim, double ageminpar, + double agemaxpar, double ftolpl, int *ncvyearp, double + dateprev1,double dateprev2, int firstpass, int lastpass, int + mobilavproj) + + Computes the back prevalence limit for any combination of + covariate values k at any age between ageminpar and agemaxpar and + returns it in **bprlim. In the loops, + + - **bprevalim(**bprlim, ***mobaverage, nlstate, *p, age, **oldm, + **savm, **dnewm, **doldm, **dsavm, ftolpl, ncvyearp, k); + + - hBijx Back Probability to be in state i at age x-h being in j at x + Computes for any combination of covariates k and any age between bage and fage + p3mat=ma3x(1,nlstate+ndeath,1, nlstate+ndeath, 0,nhstepm); + oldm=oldms;savm=savms; + + - hbxij(p3mat,nhstepm,agedeb,hstepm,p,nlstate,stepm,oldm,savm, k, nres); + Computes the transition matrix starting at age 'age' over + 'nhstepm*hstepm*stepm' months (i.e. until + age (in years) age+nhstepm*hstepm*stepm/12) by multiplying + nhstepm*hstepm matrices. + + Returns p3mat[i][j][h] after calling + p3mat[i][j][h]=matprod2(newm, + bmij(pmmij,cov,ncovmodel,x,nlstate,prevacurrent, dnewm, doldm, + dsavm,ij),\ 1,nlstate+ndeath,1,nlstate+ndeath,1,nlstate+ndeath, + oldm); + +Important routines + +- func (or funcone), computes logit (pij) distinguishing + o fixed variables (single or product dummies or quantitative); + o varying variables by: + (1) wave (single, product dummies, quantitative), + (2) by age (can be month) age (done), age*age (done), age*Vn where Vn can be: + % fixed dummy (treated) or quantitative (not done because time-consuming); + % varying dummy (not done) or quantitative (not done); +- Tricode which tests the modality of dummy variables (in order to warn with wrong or empty modalities) + and returns the number of efficient covariates cptcoveff and modalities nbcode[Tvar[k]][1]= 0 and nbcode[Tvar[k]][2]= 1 usually. +- printinghtml which outputs results like life expectancy in and from a state for a combination of modalities of dummy variables + o There are 2**cptcoveff combinations of (0,1) for cptcoveff variables. Outputting only combinations with people, éliminating 1 1 if + race White (0 0), Black vs White (1 0), Hispanic (0 1) and 1 1 being meaningless. + + - Authors: Nicolas Brouard (brouard@ined.fr) and Agnès Lièvre (lievre@ined.fr). - Institut national d'études démographiques, Paris. + Authors: Nicolas Brouard (brouard@ined.fr) and Agnès Lièvre (lievre@ined.fr). + Institut national d'études démographiques, Paris. This software have been partly granted by Euro-REVES, a concerted action from the European Union. It is copyrighted identically to a GNU software product, ie programme and @@ -596,14 +1263,21 @@ /* #define DEBUG */ /* #define DEBUGBRENT */ +/* #define DEBUGLINMIN */ +/* #define DEBUGHESS */ +#define DEBUGHESSIJ +/* #define LINMINORIGINAL /\* Don't use loop on scale in linmin (accepting nan) *\/ */ #define POWELL /* Instead of NLOPT */ +#define POWELLNOF3INFF1TEST /* Skip test */ /* #define POWELLORIGINAL /\* Don't use Directest to decide new direction but original Powell test *\/ */ /* #define MNBRAKORIGINAL /\* Don't use mnbrak fix *\/ */ +/* #define FLATSUP *//* Suppresses directions where likelihood is flat */ #include #include #include #include +#include #ifdef _WIN32 #include @@ -649,27 +1323,36 @@ typedef struct { /* #include */ /* #define _(String) gettext (String) */ -#define MAXLINE 1024 /* Was 256. Overflow with 312 with 2 states and 4 covariates. Should be ok */ +#define MAXLINE 16384 /* Was 256 and 1024 and 2048. Overflow with 312 with 2 states and 4 covariates. Should be ok */ #define GNUPLOTPROGRAM "gnuplot" +#define GNUPLOTVERSION 5.1 +double gnuplotversion=GNUPLOTVERSION; /*#define GNUPLOTPROGRAM "..\\gp37mgw\\wgnuplot"*/ -#define FILENAMELENGTH 132 +#define FILENAMELENGTH 256 #define GLOCK_ERROR_NOPATH -1 /* empty path */ #define GLOCK_ERROR_GETCWD -2 /* cannot get cwd */ -#define MAXPARM 128 /**< Maximum number of parameters for the optimization */ +#define MAXPARM 216 /**< Maximum number of parameters for the optimization was 128 */ #define NPARMAX 64 /**< (nlstate+ndeath-1)*nlstate*ncovmodel */ #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 codtabm(h,k) 1 & (h-1) >> (k-1) ; -#define MAXN 20000 +#define NCOVMAX 30 /**< Maximum number of covariates used in the model, including generated covariates V1*V2 or V1*age */ +#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 +/*#define MAXN 20000 */ /* Should by replaced by nobs, real number of observations and unlimited */ #define YEARM 12. /**< Number of months per year */ -#define AGESUP 130 +/* #define AGESUP 130 */ +/* #define AGESUP 150 */ +#define AGESUP 200 +#define AGEINF 0 +#define AGEMARGE 25 /* Marge for agemin and agemax for(iage=agemin-AGEMARGE; iage <= agemax+3+AGEMARGE; iage++) */ #define AGEBASE 40 +#define AGEOVERFLOW 1.e20 #define AGEGOMP 10 /**< Minimal age for Gompertz adjustment */ #ifdef _WIN32 #define DIRSEPARATOR '\\' @@ -681,27 +1364,52 @@ typedef struct { #define ODIRSEPARATOR '\\' #endif -/* $Id: imach.c,v 1.189 2015/04/30 14:45:16 brouard Exp $ */ +/* $Id: imach.c,v 1.351 2023/04/29 10:43:47 brouard Exp $ */ /* $State: Exp $ */ - -char version[]="Imach version 0.98q2, April 2015,INED-EUROREVES-Institut de longevite-Japan Society for the Promotion of Science (Grant-in-Aid for Scientific Research 25293121), Intel Software 2015"; -char fullversion[]="$Revision: 1.189 $ $Date: 2015/04/30 14:45:16 $"; +#include "version.h" +char version[]=__IMACH_VERSION__; +char copyright[]="January 2023,INED-EUROREVES-Institut de longevite-Japan Society for the Promotion of Science (Grant-in-Aid for Scientific Research 25293121), Intel Software 2015-2020, Nihon University 2021-202, INED 2000-2022"; +char fullversion[]="$Revision: 1.351 $ $Date: 2023/04/29 10:43:47 $"; char strstart[80]; char optionfilext[10], optionfilefiname[FILENAMELENGTH]; int erreur=0, nberr=0, nbwarn=0; /* Error number, number of errors number of warnings */ +int debugILK=0; /* debugILK is set by a #d in a comment line */ int nagesqr=0, nforce=0; /* nagesqr=1 if model is including age*age, number of forces */ -/* Number of covariates model=V2+V1+ V3*age+V2*V4 */ -int cptcovn=0; /**< cptcovn number of covariates added in the model (excepting constant and age and age*product) */ -int cptcovt=0; /**< cptcovt number of covariates added in the model (excepting constant and age) */ -int cptcovs=0; /**< cptcovs number of simple covariates V2+V1 =2 */ +/* Number of covariates model (1)=V2+V1+ V3*age+V2*V4 */ +/* Model(2) V1 + V2 + V3 + V8 + V7*V8 + V5*V6 + V8*age + V3*age + age*age */ +int cptcovn=0; /**< cptcovn decodemodel: number of covariates k of the models excluding age*products =6 and age*age but including products */ +int cptcovt=0; /**< cptcovt: total number of covariates of the model (2) nbocc(+)+1 = 8 excepting constant and age and age*age */ +int cptcovs=0; /**< cptcovs number of SIMPLE covariates in the model V2+V1 =2 (dummy or quantit or time varying) */ +int cptcovsnq=0; /**< cptcovsnq number of SIMPLE covariates in the model but non quantitative V2+V1 =2 */ int cptcovage=0; /**< Number of covariates with age: V3*age only =1 */ +int cptcovprodage=0; /**< Number of fixed covariates with age: V3*age or V2*V3*age 1 */ +int cptcovprodvage=0; /**< Number of varying covariates with age: V7*age or V7*V6*age */ +int cptcovdageprod=0; /**< Number of doubleproducts with age, since 0.99r44 only: age*Vn*Vm for gnuplot printing*/ int cptcovprodnoage=0; /**< Number of covariate products without age */ -int cptcoveff=0; /* Total number of covariates to vary for printing results */ +int cptcoveff=0; /* Total number of single dummy covariates (fixed or time varying) to vary for printing results (2**cptcoveff combinations of dummies)(computed in tricode as cptcov) */ +int ncovf=0; /* Total number of effective fixed covariates (dummy or quantitative) in the model */ +int ncovv=0; /* Total number of effective (wave) varying covariates (dummy or quantitative) in the model */ +int ncovvt=0; /* Total number of effective (wave) varying covariates (dummy or quantitative or products [without age]) in the model */ +int ncovvta=0; /* +age*V6 + age*V7+ age*V6*V3 +age*V7*V3 + age*V6*V4 +age*V7*V4 Total number of expandend products [with age]) in the model */ +int ncovta=0; /*age*V3*V2 +age*V2+agev3+ageV4 +age*V6 + age*V7+ age*V6*V3 +age*V7*V3 + age*V6*V4 +age*V7*V4 Total number of expandend products [with age]) in the model */ +int ncova=0; /* Total number of effective (wave and stepm) varying with age covariates (single or product, dummy or quantitative) in the model */ +int ncovva=0; /* +age*V6 + age*V7+ge*V6*V3 +age*V7*V3 + age*V6*V4 +age*V7*V4 Total number of effective (wave and stepm) varying with age covariates (single or product, dummy or quantitative) in the model */ +int nsd=0; /**< Total number of single dummy variables (output) */ +int nsq=0; /**< Total number of single quantitative variables (output) */ +int ncoveff=0; /* Total number of effective fixed dummy covariates in the model */ +int nqfveff=0; /**< nqfveff Number of Quantitative Fixed Variables Effective */ +int ntveff=0; /**< ntveff number of effective time varying variables */ +int nqtveff=0; /**< ntqveff number of effective time varying quantitative variables */ int cptcov=0; /* Working variable */ -int npar=NPARMAX; +int firstobs=1, lastobs=10; /* nobs = lastobs-firstobs+1 declared globally ;*/ +int nobs=10; /* Number of observations in the data lastobs-firstobs */ +int ncovcombmax=NCOVMAX; /* Maximum calculated number of covariate combination = pow(2, cptcoveff) */ +int npar=NPARMAX; /* Number of parameters (nlstate+ndeath-1)*nlstate*ncovmodel; */ int nlstate=2; /* Number of live states */ int ndeath=1; /* Number of dead states */ int ncovmodel=0, ncovcol=0; /* Total number of covariables including constant a12*1 +b12*x ncovmodel=2 */ +int nqv=0, ntv=0, nqtv=0; /* Total number of quantitative variables, time variable (dummy), quantitative and time variable*/ +int ncovcolt=0; /* ncovcolt=ncovcol+nqv+ntv+nqtv; total of covariates in the data, not in the model equation*/ int popbased=0; int *wav; /* Number of waves for this individuual 0 is possible */ @@ -716,12 +1424,16 @@ int **dh; /* dh[mi][i] is number of step int **bh; /* bh[mi][i] is the bias (+ or -) for this individual if the delay between * wave mi and wave mi+1 is not an exact multiple of stepm. */ int countcallfunc=0; /* Count the number of calls to func */ +int selected(int kvar); /* Is covariate kvar selected for printing results */ + double jmean=1; /* Mean space between 2 waves */ double **matprod2(); /* test */ double **oldm, **newm, **savm; /* Working pointers to matrices */ double **oldms, **newms, **savms; /* Fixed working pointers to matrices */ +double **ddnewms, **ddoldms, **ddsavms; /* for freeing later */ + /*FILE *fic ; */ /* Used in readdata only */ -FILE *ficpar, *ficparo,*ficres, *ficresp, *ficrespl, *ficrespij, *ficrest,*ficresf,*ficrespop; +FILE *ficpar, *ficparo,*ficres, *ficresp, *ficresphtm, *ficresphtmfr, *ficrespl, *ficresplb,*ficrespij, *ficrespijb, *ficrest,*ficresf, *ficresfb,*ficrespop; FILE *ficlog, *ficrespow; int globpr=0; /* Global variable for printing or not */ double fretone; /* Only one call to likelihood */ @@ -741,17 +1453,17 @@ FILE *ficrescveij; char filerescve[FILENAMELENGTH]; FILE *ficresvij; char fileresv[FILENAMELENGTH]; -FILE *ficresvpl; -char fileresvpl[FILENAMELENGTH]; + char title[MAXLINE]; -char optionfile[FILENAMELENGTH], datafile[FILENAMELENGTH], filerespl[FILENAMELENGTH]; +char model[MAXLINE]; /**< The model line */ +char optionfile[FILENAMELENGTH], datafile[FILENAMELENGTH], filerespl[FILENAMELENGTH], fileresplb[FILENAMELENGTH]; char plotcmd[FILENAMELENGTH], pplotcmd[FILENAMELENGTH]; char tmpout[FILENAMELENGTH], tmpout2[FILENAMELENGTH]; char command[FILENAMELENGTH]; int outcmd=0; -char fileres[FILENAMELENGTH], filerespij[FILENAMELENGTH], filereso[FILENAMELENGTH], rfileres[FILENAMELENGTH]; - +char fileres[FILENAMELENGTH], filerespij[FILENAMELENGTH], filerespijb[FILENAMELENGTH], filereso[FILENAMELENGTH], rfileres[FILENAMELENGTH]; +char fileresu[FILENAMELENGTH]; /* fileres without r in front */ char filelog[FILENAMELENGTH]; /* Log file */ char filerest[FILENAMELENGTH]; char fileregp[FILENAMELENGTH]; @@ -768,6 +1480,7 @@ extern time_t time(); struct tm start_time, end_time, curr_time, last_time, forecast_time; time_t rstart_time, rend_time, rcurr_time, rlast_time, rforecast_time; /* raw time */ +time_t rlast_btime; /* raw time */ struct tm tm; char strcurr[80], strfor[80]; @@ -781,7 +1494,8 @@ double dval; #define FTOL 1.0e-10 #define NRANSI -#define ITMAX 200 +#define ITMAX 200 +#define ITPOWMAX 20 /* This is now multiplied by the number of parameters */ #define TOL 2.0e-4 @@ -819,25 +1533,192 @@ int estepm; int m,nb; long *num; -int firstpass=0, lastpass=4,*cod, *ncodemax, *Tage,*cens; +int firstpass=0, lastpass=4,*cod, *cens; +int *ncodemax; /* ncodemax[j]= Number of modalities of the j th + covariate for which somebody answered excluding + undefined. Usually 2: 0 and 1. */ +int *ncodemaxwundef; /* ncodemax[j]= Number of modalities of the j th + covariate for which somebody answered including + undefined. Usually 3: -1, 0 and 1. */ double **agev,*moisnais, *annais, *moisdc, *andc,**mint, **anint; -double **pmmij, ***probs; +double **pmmij, ***probs; /* Global pointer */ +double ***mobaverage, ***mobaverages; /* New global variable */ +double **precov; /* New global variable to store for each resultline, values of model covariates given by the resultlines (in order to speed up) */ 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; double **covar; /**< covar[j,i], value of jth covariate for individual i, * covar=matrix(0,NCOVMAX,1,n); * cov[Tage[kk]+2]=covar[Tvar[Tage[kk]]][i]*age; */ +double **coqvar; /* Fixed quantitative covariate nqv */ +double ***cotvar; /* Time varying covariate start at ncovcol + nqv + (1 to ntv) */ +double ***cotqvar; /* Time varying quantitative covariate itqv */ double idx; int **nbcode, *Tvar; /**< model=V2 => Tvar[1]= 2 */ +/* Some documentation */ + /* Design original data + * V1 V2 V3 V4 V5 V6 V7 V8 Weight ddb ddth d1st s1 V9 V10 V11 V12 s2 V9 V10 V11 V12 + * < ncovcol=6 > nqv=2 (V7 V8) dv dv dv qtv dv dv dvv qtv + * ntv=3 nqtv=1 + * cptcovn number of covariates (not including constant and age or age*age) = number of plus sign + 1 = 10+1=11 + * For time varying covariate, quanti or dummies + * cotqvar[wav][iv(1 to nqtv)][i]= [1][12][i]=(V12) quanti + * cotvar[wav][ncovcol+nqv+ iv(1 to nqtv)][i]= [(1 to nqtv)][i]=(V12) quanti + * cotvar[wav][iv(1 to ntv)][i]= [1][1][i]=(V9) dummies at wav 1 + * cotvar[wav][iv(1 to ntv)][i]= [1][2][i]=(V10) dummies at wav 1 + * covar[Vk,i], value of the Vkth fixed covariate dummy or quanti for individual i: + * covar[1][i]= (V1), covar[4][i]=(V4), covar[8][i]=(V8) + * Model V2 + V1 + V3*age + V3 + V5*V6 + V7*V8 + V8*age + V8 + V9 + V9*age + V10 + * k= 1 2 3 4 5 6 7 8 9 10 11 + */ +/* According to the model, more columns can be added to covar by the product of covariates */ +/* ncovcol=1(Males=0 Females=1) nqv=1(raedyrs) ntv=2(withoutiadl=0 withiadl=1, witoutadl=0 withoutadl=1) nqtv=1(bmi) nlstate=3 ndeath=1 + # States 1=Coresidence, 2 Living alone, 3 Institution + # V1=sex, V2=raedyrs Quant Fixed, State=livarnb4..livarnb11, V3=iadl4..iald11, V4=adlw4..adlw11, V5=r4bmi..r11bmi +*/ +/* V5+V4+ V3+V4*V3 +V5*age+V2 +V1*V2+V1*age+V1+V4*V3*age */ +/* kmodel 1 2 3 4 5 6 7 8 9 10 */ +/*Typevar[k]= 0 0 0 2 1 0 2 1 0 3 *//*0 for simple covariate (dummy, quantitative,*/ + /* fixed or varying), 1 for age product, 2 for*/ + /* product without age, 3 for age and double product */ +/*Dummy[k]= 1 0 0 1 3 1 1 2 0 3 *//*Dummy[k] 0=dummy (0 1), 1 quantitative */ + /*(single or product without age), 2 dummy*/ + /* with age product, 3 quant with age product*/ +/*Tvar[k]= 5 4 3 6 5 2 7 1 1 6 */ +/* nsd 1 2 3 */ /* Counting single dummies covar fixed or tv */ +/*TnsdVar[Tvar] 1 2 3 */ +/*Tvaraff[nsd] 4 3 1 */ /* ID of single dummy cova fixed or timevary*/ +/*TvarsD[nsd] 4 3 1 */ /* ID of single dummy cova fixed or timevary*/ +/*TvarsDind[nsd] 2 3 9 */ /* position K of single dummy cova */ +/* nsq 1 2 */ /* Counting single quantit tv */ +/* TvarsQ[k] 5 2 */ /* Number of single quantitative cova */ +/* TvarsQind 1 6 */ /* position K of single quantitative cova */ +/* Tprod[i]=k 1 2 */ /* Position in model of the ith prod without age */ +/* cptcovage 1 2 3 */ /* Counting cov*age in the model equation */ +/* Tage[cptcovage]=k 5 8 10 */ /* Position in the model of ith cov*age */ +/* model="V2+V3+V4+V6+V7+V6*V2+V7*V2+V6*V3+V7*V3+V6*V4+V7*V4+age*V2+age*V3+age*V4+age*V6+age*V7+age*V6*V2+age*V6*V3+age*V7*V3+age*V6*V4+age*V7*V4\r"*/ +/* p Tvard[1][1]@21 = {6, 2, 7, 2, 6, 3, 7, 3, 6, 4, 7, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0}*/ +/* p Tvard[2][1]@21 = {7, 2, 6, 3, 7, 3, 6, 4, 7, 4, 0 } +/* p Tvardk[1][1]@24 = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 2, 7, 2, 6, 3, 7, 3, 6, 4, 7, 4, 0, 0}*/ +/* p Tvardk[1][1]@22 = {0, 0, 0, 0, 0, 0, 0, 0, 6, 2, 7, 2, 6, 3, 7, 3, 6, 4, 7, 4, 0, 0} */ +/* Tvard[1][1]@4={4,3,1,2} V4*V3 V1*V2 */ /* Position in model of the ith prod without age */ +/* Tvardk[4][1]=4;Tvardk[4][2]=3;Tvardk[7][1]=1;Tvardk[7][2]=2 */ /* Variables of a prod at position in the model equation*/ +/* TvarF TvarF[1]=Tvar[6]=2, TvarF[2]=Tvar[7]=7, TvarF[3]=Tvar[9]=1 ID of fixed covariates or product V2, V1*V2, V1 */ +/* TvarFind; TvarFind[1]=6, TvarFind[2]=7, TvarFind[3]=9 *//* Inverse V2(6) is first fixed (single or prod) */ +/* Type */ +/* V 1 2 3 4 5 */ +/* F F V V V */ +/* D Q D D Q */ +/* */ +int *TvarsD; +int *TnsdVar; +int *TvarsDind; +int *TvarsQ; +int *TvarsQind; + +#define MAXRESULTLINESPONE 10+1 +int nresult=0; +int parameterline=0; /* # of the parameter (type) line */ +int TKresult[MAXRESULTLINESPONE]; /* TKresult[nres]=k for each resultline nres give the corresponding combination of dummies */ +int resultmodel[MAXRESULTLINESPONE][NCOVMAX];/* resultmodel[k1]=k3: k1th position in the model corresponds to the k3 position in the resultline */ +int modelresult[MAXRESULTLINESPONE][NCOVMAX];/* modelresult[k3]=k1: k1th position in the model corresponds to the k3 position in the resultline */ +int Tresult[MAXRESULTLINESPONE][NCOVMAX];/* Tresult[nres][result_position]= value of the dummy variable at the result_position in the nres resultline */ +int Tinvresult[MAXRESULTLINESPONE][NCOVMAX];/* Tinvresult[nres][Name of a dummy variable]= value of the variable in the result line */ +double TinvDoQresult[MAXRESULTLINESPONE][NCOVMAX];/* TinvDoQresult[nres][Name of a Dummy or Q variable]= value of the variable in the result line */ +int Tvresult[MAXRESULTLINESPONE][NCOVMAX]; /* Tvresult[nres][result_position]= name of the dummy variable at the result_position in the nres resultline */ +double Tqresult[MAXRESULTLINESPONE][NCOVMAX]; /* Tqresult[nres][result_position]= value of the variable at the result_position in the nres resultline */ +double Tqinvresult[MAXRESULTLINESPONE][NCOVMAX]; /* For quantitative variable , value (output) */ +int Tvqresult[MAXRESULTLINESPONE][NCOVMAX]; /* Tvqresult[nres][result_position]= id of the variable at the result_position in the nres resultline */ + +/* ncovcol=1(Males=0 Females=1) nqv=1(raedyrs) ntv=2(withoutiadl=0 withiadl=1, witoutadl=0 withoutadl=1) nqtv=1(bmi) nlstate=3 ndeath=1 + # States 1=Coresidence, 2 Living alone, 3 Institution + # V1=sex, V2=raedyrs Quant Fixed, State=livarnb4..livarnb11, V3=iadl4..iald11, V4=adlw4..adlw11, V5=r4bmi..r11bmi +*/ +/* int *TDvar; /\**< TDvar[1]=4, TDvarF[2]=3, TDvar[3]=6 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 *\/ */ +int *TvarF; /**< TvarF[1]=Tvar[6]=2, TvarF[2]=Tvar[7]=7, TvarF[3]=Tvar[9]=1 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */ +int *TvarFind; /**< TvarFind[1]=6, TvarFind[2]=7, Tvarind[3]=9 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */ +int *TvarV; /**< TvarV[1]=Tvar[1]=5, TvarV[2]=Tvar[2]=4 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */ +int *TvarVind; /**< TvarVind[1]=1, TvarVind[2]=2 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */ +int *TvarA; /**< TvarA[1]=Tvar[5]=5, TvarA[2]=Tvar[8]=1 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */ +int *TvarAind; /**< TvarindA[1]=5, TvarAind[2]=8 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */ +int *TvarFD; /**< TvarFD[1]=V1 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */ +int *TvarFDind; /* TvarFDind[1]=9 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */ +int *TvarFQ; /* TvarFQ[1]=V2 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */ /* Only simple fixed quantitative variable */ +int *TvarFQind; /* TvarFQind[1]=6 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */ /* Only simple fixed quantitative variable */ +int *TvarVD; /* TvarVD[1]=V5 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */ /* Only simple fixed quantitative variable */ +int *TvarVDind; /* TvarVDind[1]=1 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */ /* Only simple fixed quantitative variable */ +int *TvarVQ; /* TvarVQ[1]=V5 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */ /* Only simple time varying quantitative variable */ +int *TvarVQind; /* TvarVQind[1]=1 in V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */ /* Only simple time varying quantitative variable */ +int *TvarVV; /* We count ncovvt time varying covariates (single or products without age) and put their name into TvarVV */ +int *TvarVVind; /* We count ncovvt time varying covariates (single or products without age) and put their name into TvarVV */ +int *TvarVVA; /* We count ncovvt time varying covariates (single or products with age) and put their name into TvarVVA */ +int *TvarVVAind; /* We count ncovvt time varying covariates (single or products without age) and put their name into TvarVV */ +int *TvarAVVA; /* We count ALL ncovta time varying covariates (single or products with age) and put their name into TvarVVA */ +int *TvarAVVAind; /* We count ALL ncovta time varying covariates (single or products without age) and put their name into TvarVV */ + /*# ID V1 V2 weight birth death 1st s1 V3 V4 V5 2nd s2 */ + /* model V1+V3+age*V1+age*V3+V1*V3 + V1*V3*age */ + /* Tvar={1, 3, 1, 3, 6, 6}, the 6 comes from the fact that there are already V1, V2, V3, V4, V5 native covariates */ + /* TvarVV={3,1,3,1,3}, for V3 and then the product V1*V3 is decomposed into V1 and V3 */ + /* TvarVVind={2,5,5,6,6}, for V3 and then the product V1*V3 is decomposed into V1 and V3 and V1*V3*age into 6,6 */ +int *Tvarsel; /**< Selected covariates for output */ +double *Tvalsel; /**< Selected modality value of covariate for output */ +int *Typevar; /**< 0 for simple covariate (dummy, quantitative, fixed or varying), 1 for age product, 2 for product, 3 age*Vn*Vm */ +int *Fixed; /** Fixed[k] 0=fixed, 1 varying, 2 fixed with age product, 3 varying with age product */ +int *Dummy; /** Dummy[k] 0=dummy (0 1), 1 quantitative (single or product without age), 2 dummy with age product, 3 quant with age product */ +int *DummyV; /** Dummy[v] 0=dummy (0 1), 1 quantitative */ +int *FixedV; /** FixedV[v] 0 fixed, 1 varying */ +int *Tage; +int anyvaryingduminmodel=0; /**< Any varying dummy in Model=1 yes, 0 no, to avoid a loop on waves in freq */ +int *Tmodelind; /** Tmodelind[Tvaraff[3]]=9 for V1 position,Tvaraff[1]@9={4, 3, 1, 0, 0, 0, 0, 0, 0}, model=V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1*/ +int *TmodelInvind; /** Tmodelind[Tvaraff[3]]=9 for V1 position,Tvaraff[1]@9={4, 3, 1, 0, 0, 0, 0, 0, 0}, model=V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1*/ +int *TmodelInvQind; /** Tmodelqind[1]=1 for V5(quantitative varying) position,Tvaraff[1]@9={4, 3, 1, 0, 0, 0, 0, 0, 0}, model=V5+V4+V3+V4*V3+V5*age+V2+V1*V2+V1*age+V1 */ int *Ndum; /** Freq of modality (tricode */ -int **codtab; /**< codtab=imatrix(1,100,1,10); */ -int **Tvard, *Tprod, cptcovprod, *Tvaraff; +/* int **codtab;*/ /**< codtab=imatrix(1,100,1,10); */ +int **Tvard; +int **Tvardk; +int *Tprod;/**< Gives the k position of the k1 product */ +/* Tprod[k1=1]=3(=V1*V4) for V2+V1+V1*V4+age*V3 */ +int *Tposprod; /**< Gives the k1 product from the k position */ + /* if V2+V1+V1*V4+age*V3+V3*V2 TProd[k1=2]=5 (V3*V2) */ + /* Tposprod[k]=k1 , Tposprod[3]=1, Tposprod[5(V3*V2)]=2 (2nd product without age) */ +int cptcovprod, *Tvaraff, *invalidvarcomb; double *lsurv, *lpop, *tpop; +#define FD 1; /* Fixed dummy covariate */ +#define FQ 2; /* Fixed quantitative covariate */ +#define FP 3; /* Fixed product covariate */ +#define FPDD 7; /* Fixed product dummy*dummy covariate */ +#define FPDQ 8; /* Fixed product dummy*quantitative covariate */ +#define FPQQ 9; /* Fixed product quantitative*quantitative covariate */ +#define VD 10; /* Varying dummy covariate */ +#define VQ 11; /* Varying quantitative covariate */ +#define VP 12; /* Varying product covariate */ +#define VPDD 13; /* Varying product dummy*dummy covariate */ +#define VPDQ 14; /* Varying product dummy*quantitative covariate */ +#define VPQQ 15; /* Varying product quantitative*quantitative covariate */ +#define APFD 16; /* Age product * fixed dummy covariate */ +#define APFQ 17; /* Age product * fixed quantitative covariate */ +#define APVD 18; /* Age product * varying dummy covariate */ +#define APVQ 19; /* Age product * varying quantitative covariate */ + +#define FTYPE 1; /* Fixed covariate */ +#define VTYPE 2; /* Varying covariate (loop in wave) */ +#define ATYPE 2; /* Age product covariate (loop in dh within wave)*/ + +struct kmodel{ + int maintype; /* main type */ + int subtype; /* subtype */ +}; +struct kmodel modell[NCOVMAX]; + double ftol=FTOL; /**< Tolerance for computing Max Likelihood */ double ftolhess; /**< Tolerance for computing hessian */ @@ -868,7 +1749,7 @@ static int split( char *path, char *dirc } /* got dirc from getcwd*/ printf(" DIRC = %s \n",dirc); - } else { /* strip direcotry from path */ + } else { /* strip directory from path */ ss++; /* after this, the filename */ l2 = strlen( ss ); /* length of filename */ if ( l2 == 0 ) return( GLOCK_ERROR_NOPATH ); @@ -926,6 +1807,20 @@ char *trimbb(char *out, char *in) return s; } +char *trimbtab(char *out, char *in) +{ /* Trim blanks or tabs in line but keeps first blanks if line starts with blanks */ + char *s; + s=out; + while (*in != '\0'){ + while( (*in == ' ' || *in == '\t')){ /* && *(in+1) != '\0'){*/ + in++; + } + *out++ = *in++; + } + *out='\0'; + return s; +} + /* char *substrchaine(char *out, char *in, char *chain) */ /* { */ /* /\* Substract chain 'chain' from 'in', return and output 'out' *\/ */ @@ -952,19 +1847,19 @@ char *trimbb(char *out, char *in) char *substrchaine(char *out, char *in, char *chain) { /* Substract chain 'chain' from 'in', return and output 'out' */ - /* in="V1+V1*age+age*age+V2", chain="age*age" */ + /* in="V1+V1*age+age*age+V2", chain="+age*age" out="V1+V1*age+V2" */ char *strloc; - strcpy (out, in); - strloc = strstr(out, chain); /* strloc points to out at age*age+V2 */ - printf("Bef strloc=%s chain=%s out=%s \n", strloc, chain, out); + strcpy (out, in); /* out="V1+V1*age+age*age+V2" */ + strloc = strstr(out, chain); /* strloc points to out at "+age*age+V2" */ + printf("Bef strloc=%s chain=%s out=%s \n", strloc, chain, out); /* strloc=+age*age+V2 chain="+age*age", out="V1+V1*age+age*age+V2" */ if(strloc != NULL){ - /* will affect out */ /* strloc+strlenc(chain)=+V2 */ /* Will also work in Unicode */ - memmove(strloc,strloc+strlen(chain), strlen(strloc+strlen(chain))+1); - /* strcpy (strloc, strloc +strlen(chain));*/ + /* will affect out */ /* strloc+strlen(chain)=|+V2 = "V1+V1*age+age*age|+V2" */ /* Will also work in Unicodek */ + memmove(strloc,strloc+strlen(chain), strlen(strloc+strlen(chain))+1); /* move number of bytes corresponding to the length of "+V2" which is 3, plus one is 4 (including the null)*/ + /* equivalent to strcpy (strloc, strloc +strlen(chain)) if no overlap; Copies from "+V2" to V1+V1*age+ */ } - printf("Aft strloc=%s chain=%s in=%s out=%s \n", strloc, chain, in, out); + printf("Aft strloc=%s chain=%s in=%s out=%s \n", strloc, chain, in, out); /* strloc=+V2 chain="+age*age", in="V1+V1*age+age*age+V2", out="V1+V1*age+V2" */ return out; } @@ -972,8 +1867,8 @@ char *substrchaine(char *out, char *in, char *cutl(char *blocc, char *alocc, char *in, char occ) { /* cuts string in into blocc and alocc where blocc ends before FIRST occurence of char 'occ' - and alocc starts after first occurence of char 'occ' : ex cutv(blocc,alocc,"abcdef2ghi2j",'2') - gives blocc="abcdef" and alocc="ghi2j". + and alocc starts after first occurence of char 'occ' : ex cutl(blocc,alocc,"abcdef2ghi2j",'2') + gives alocc="abcdef" and blocc="ghi2j". If occ is not found blocc is null and alocc is equal to in. Returns blocc */ char *s, *t; @@ -1033,21 +1928,43 @@ int nbocc(char *s, char occ) i=0; lg=strlen(s); for(i=0; i<= lg; i++) { - if (s[i] == occ ) j++; + if (s[i] == occ ) j++; } return j; } -/* void cutv(char *u,char *v, char*t, char occ) */ -/* { */ -/* /\* cuts string t into u and v where u ends before last occurence of char 'occ' */ -/* and v starts after last occurence of char 'occ' : ex cutv(u,v,"abcdef2ghi2j",'2') */ -/* gives u="abcdef2ghi" and v="j" *\/ */ -/* int i,lg,j,p=0; */ -/* i=0; */ -/* lg=strlen(t); */ -/* for(j=0; j<=lg-1; j++) { */ -/* if((t[j]!= occ) && (t[j+1]== occ)) p=j+1; */ +int nboccstr(char *textin, char *chain) +{ + /* Counts the number of occurence of "chain" in string textin */ + /* in="+V7*V4+age*V2+age*V3+age*V4" chain="age" */ + char *strloc; + + int i,j=0; + + i=0; + + strloc=textin; /* strloc points to "^+V7*V4+age+..." in textin */ + for(;;) { + strloc= strstr(strloc,chain); /* strloc points to first character of chain in textin if found. Example strloc points^ to "+V7*V4+^age" in textin */ + if(strloc != NULL){ + strloc = strloc+strlen(chain); /* strloc points to "+V7*V4+age^" in textin */ + j++; + }else + break; + } + return j; + +} +/* void cutv(char *u,char *v, char*t, char occ) */ +/* { */ +/* /\* cuts string t into u and v where u ends before last occurence of char 'occ' */ +/* and v starts after last occurence of char 'occ' : ex cutv(u,v,"abcdef2ghi2j",'2') */ +/* gives u="abcdef2ghi" and v="j" *\/ */ +/* int i,lg,j,p=0; */ +/* i=0; */ +/* lg=strlen(t); */ +/* for(j=0; j<=lg-1; j++) { */ +/* if((t[j]!= occ) && (t[j+1]== occ)) p=j+1; */ /* } */ /* for(j=0; j