Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Plotting growth curve trajectories according to categories of infant feeding scenarios

    Hello, stata community. I would like your help once again,

    I am using mixed effects linear regression to evaluate food consumption as an exposure in the first years of life and child growth at age 5 as an outcome. In this example, I have as an exposure variable food consumption up to the first 3 months of life (cenario - variable with 3 categories) and as an outcome variable, repeated measurements of height for age (Variable z_altidade) in these children up to 5 years of age (however, the amount of measurements per child (id) varies (2-46 measurements).To find out how the scenario variable (food consumption in the first 3 months of life) affects height for age over the years, I did the following step by step:

    *I tested the best function (model fit): linear, quadratic or cubic
    *generate the terms quadratic and cubic age
    gen idade_meses_en2= idade_meses_en^2
    gen idade_meses_en3= idade_meses_en^3

    *linear function
    mixed z_altidade idade_meses_en || id: idade_meses_en , cov(uns) variance
    estat ic
    * AIC: 1674308
    * BIC: 1674376

    * quadratic function
    mixed z_altidade idade_meses_en idade_meses_en2 || id: idade_meses_en, cov(uns) variance
    estat ic
    * AIC: 1673929
    * BIC: 1674008

    * cubic function
    mixed z_altidade idade_meses_en idade_meses_en2 idade_meses_en3 || id: idade_meses_en, cov(uns) variance
    estat ic
    * AIC: 1673912
    * BIC: 1674002

    *model that best fits is the cubic model - lower AIC and BIC values. In this way, I ran the final model considering the quadratic and cubic terms, including interactions between age (idade_meses_en/ idade_meses_en2/ idade_meses_en3) and cenario. I found the following output:


    . mixed z_altidade idade_meses_en2 idade_meses_en3 c.idade_meses_en## i.cenario c.idade_meses_en2## i.cenario c.idade_meses_en3## i.cenario|| id: idade_meses_en, cov(un)
    note: idade_meses_en2 omitted because of collinearity.
    note: idade_meses_en3 omitted because of collinearity.

    Performing EM optimization ...

    Performing gradient-based optimization:
    Iteration 0: log likelihood = -836287.86
    Iteration 1: log likelihood = -836286.06
    Iteration 2: log likelihood = -836286.06

    Computing standard errors ...

    Mixed-effects ML regression Number of obs = 597,237
    Group variable: id Number of groups = 127,422
    Obs per group:
    min = 2
    avg = 4.7
    max = 46
    Wald chi2(11) = 3329.97
    Log likelihood = -836286.06 Prob > chi2 = 0.0000

    -----------------------------------------------------------------------------------------------
    z_altidade | Coefficient Std. err. z P>|z| [95% conf. interval]
    ------------------------------+----------------------------------------------------------------
    idade_meses_en2 | .0007663 .0000795 9.64 0.000 .0006106 .0009221
    idade_meses_en3 | -2.10e-06 1.47e-06 -1.43 0.154 -4.98e-06 7.87e-07
    idade_meses_en | -.0346841 .0010568 -32.82 0.000 -.0367555 -.0326128
    |
    cenario |
    Substitutos do leite materno | -.3389908 .0113932 -29.75 0.000 -.361321 -.3166606
    IA precoce | -.129324 .0185984 -6.95 0.000 -.1657761 -.0928719
    |
    cenario#c.idade_meses_en |
    Substitutos do leite materno | .0657829 .0022711 28.97 0.000 .0613317 .0702342
    IA precoce | .0261245 .0034945 7.48 0.000 .0192754 .0329736
    |
    idade_meses_en2 | 0 (omitted)
    |
    cenario#c.idade_meses_en2 |
    Substitutos do leite materno | -.0027962 .0001651 -16.94 0.000 -.0031199 -.0024726
    IA precoce | -.0011431 .0002284 -5.00 0.000 -.0015908 -.0006954
    |
    idade_meses_en3 | 0 (omitted)
    |
    cenario#c.idade_meses_en3 |
    Substitutos do leite materno | .0000361 2.97e-06 12.16 0.000 .0000303 .000042
    IA precoce | .0000136 3.71e-06 3.66 0.000 6.30e-06 .0000208
    |
    _cons | .2197004 .005296 41.48 0.000 .2093204 .2300803
    -----------------------------------------------------------------------------------------------

    ------------------------------------------------------------------------------
    Random-effects parameters | Estimate Std. err. [95% conf. interval]
    -----------------------------+------------------------------------------------
    id: Unstructured |
    var(idade_meses_en) | .0059077 .00007 .0057722 .0060465
    var(_cons) | 1.669051 .0085306 1.652415 1.685855
    cov(idade_meses_en,_cons) | -.0586498 .0006555 -.0599346 -.057365
    -----------------------------+------------------------------------------------
    var(Residual) | .5247229 .0012235 .5223304 .5271263
    ------------------------------------------------------------------------------
    LR test vs. linear model: chi2(3) = 3.7e+05 Prob > chi2 = 0.0000

    Note: LR test is conservative and provided only for reference.


    It is known that the interpretation is not so literal and that graphic representation can help in the interpretation of findings. Furthermore, I am interested in showing the results of this model at specific ages. To do this, I used the margins and marginsplot commands, but I think they don't work well because the cenario categories appear as a linear function over time, with the model that best fits being the cubic model. How can I do this? Should I then plot the interaction of scenario with cubic age? The graph below shows the result of the syntax used.

    margins i.cenario, at(idade_meses_en=(0(6)60)) vsquish
    marginsplot, name(modelo_teste1, replace) x(idade_meses_en) noci


    What I would like: model growth curves for the height/age index (y) at specific ages (x), considering categories of the cenario variable.

    I use version 17 of Stata. I greatly appreciate your help
    Here's a snippet of the database as an example


    ----------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input long id byte sexo_ca int ano_acomp_ca float(idade_ca idade_meses_ca cenario alt peso idade_en ano_acomp_en imc_calc idade_meses_en z_altidade seq_CAEN2 max_CAEN2 idade_meses_en2 idade_meses_en3)
    10576959 0 2017  .05749487  .6899384 1   54     4  .07939767 2017 13.717422   .952772   2.604984  1  6   .9077745  .8649022
    10576959 0 2017  .05749487  .6899384 1   59 5.925  .24640657 2017 17.020971  2.956879   .9491886  2  6   8.743133 25.852385
    10576959 0 2017  .05749487  .6899384 1   66     7   .4791239 2018 16.069788  5.749487   .8883988  3  6    33.0566  190.0585
    10576959 0 2017  .05749487  .6899384 1   69     8   .5968515 2018 16.803192  7.162218   .7397134  4  6   51.29736  367.4029
    10576959 0 2017  .05749487  .6899384 1   73    10   .8651608 2018 18.765247  10.38193   .6152673  5  6  107.78445 1119.0106
    10576959 0 2017  .05749487  .6899384 1   75    10  1.1334702 2018 17.777779 13.601643 -.08274923  6  6   185.0047  2516.368
    11055885 1 2016  .16974674 2.0369608 0   62  6.55  .25188228 2016 17.039543  3.022587  .27920705  1  5   9.136034  27.61446
    11055885 1 2016  .16974674 2.0369608 0   65     7   .3422314 2016 16.568047  4.106776   .5353787  2  5   16.86561  69.26329
    11055885 1 2016  .16974674 2.0369608 0   66   7.3   .4188912 2016 16.758495  5.026694  .04612643  3  5   25.26765 127.01274
    11055885 1 2016  .16974674 2.0369608 0   66   7.3   .5010267 2016 16.758495  6.012321  -.7585881  4  5     36.148 217.33334
    11055885 1 2016  .16974674 2.0369608 0   69   7.6   .5722108 2016 15.963033  6.866529   .6430932  5  5   47.14923  323.7516
    11532240 1 2016  .06297057  .7556468 1   58  5.19  .12594114 2016 15.428062 1.5112936   1.682775  1  6  2.2840085 3.4518075
    11532240 1 2016  .06297057  .7556468 1   59 11.65   .1943874 2016 33.467392 2.3326488  .28748262  2  6    5.44125 12.692526
    11532240 1 2016  .06297057  .7556468 1   62   6.5  .25188228 2016  16.90947  3.022587  .27920705  3  6   9.136034  27.61446
    11532240 1 2016  .06297057  .7556468 1   66  8.14    .386037 2016 18.686869 4.6324434  1.0159707  4  6   21.45953  99.41006
    11532240 1 2016  .06297057  .7556468 1   75 11.17   .7556468 2017  19.85778  9.067762  1.3512913  5  6   82.22431  745.5905
    11532240 1 2016  .06297057  .7556468 1   81    14  1.0622861 2017  21.33821 12.747434   2.209877  6  6  162.49707 2071.4207
    11673070 1 2016 .013689253 .16427104 0   50  3.36 .013689253 2016     13.44 .16427104  .06116878  1  2 .026984975 .00443285
    11673070 1 2016 .013689253 .16427104 0   80  11.7  1.0841889 2017  18.28125 13.010267  1.2701492  2  2  169.26706 2202.2097
    17647115 0 2015  .12594114 1.5112936 0 57.8   5.3  .12594114 2015 15.864275 1.5112936  2.1045804  1  2  2.2840085 3.4518075
    17647115 0 2015  .12594114 1.5112936 0   62   6.1  .20807666 2015 15.868886   2.49692  2.4225495  2  2   6.234609  15.56732
    27974818 1 2015  .09034908 1.0841889 0   49  2.32  .09034908 2015  9.662641 1.0841889  -2.940797  1  5  1.1754657 1.2744268
    27974818 1 2015  .09034908 1.0841889 0   55   5.2   .2053388 2015 17.190083 2.4640656  -1.712049  2  5   6.071619 14.960867
    27974818 1 2015  .09034908 1.0841889 0   61  7.26   .3641342 2015 19.510885   4.36961 -1.3869892  3  5   19.09349   83.4311
    27974818 1 2015  .09034908 1.0841889 0   61  7.23   .4517454 2015  19.43026  5.420945 -2.3218367  4  5   29.38664 159.30336
    27974818 1 2015  .09034908 1.0841889 0   68  9.65  .58590007 2015 20.869377  7.030801  -.5363694  5  5   49.43216  347.5477
    29640336 1 2016   .1889117 2.2669406 2   74 10.45   .9226557 2017 19.083273  11.07187 -.23131172  1  6  122.58628 1357.2593
    29640336 1 2016   .1889117 2.2669406 2   83 12.03  1.4592744 2018 17.462622 17.511293   .6632237  2  6   306.6454  5369.757
    29640336 1 2016   .1889117 2.2669406 2   85 13.56   1.670089 2018 18.768167  20.04107   .2844399  3  6   401.6444  8049.384
    29640336 1 2016   .1889117 2.2669406 2   97  16.3  2.2997947 2018 17.323837 27.597536  2.2812006  4  6    761.624 21018.945
    29640336 1 2016   .1889117 2.2669406 2   98  17.6   2.587269 2019 18.325699  31.04723  1.5428514  5  6   963.9305  29927.37
    29640336 1 2016   .1889117 2.2669406 2   98  18.1   2.691307 2019 18.846315  32.29569  1.3168868  6  6  1043.0115 33684.773
    32832552 0 2015 .027378507  .3285421 0   49  3.43 .027378507 2015 14.285714  .3285421 -.07929426  1  4   .1079399  .0354628
    32832552 0 2015 .027378507  .3285421 0   50     4  .08487337 2015        16 1.0184804 -1.8867936  2  4  1.0373024 1.0564722
    32832552 0 2015 .027378507  .3285421 0   57  4.85   .1889117 2015  14.92767 2.2669406 -.03305185  3  4   5.139019 11.649852
    32832552 0 2015 .027378507  .3285421 0   57  6.15   .3367556 2015 18.928902 4.0410676 -2.3515866  4  4  16.330227 65.991554
    33695767 1 2019  .03011636  .3613963 0   50  3.56  .03011636 2019     14.24  .3613963  .06116878  1  5  .13060729   .047201
    33695767 1 2019  .03011636  .3613963 0 51.5 5.112  .10130048 2019   19.2742 1.2156057 -1.6564716  2  5  1.4776973 1.7962973
    33695767 1 2019  .03011636  .3613963 0 51.5 5.112   .1670089 2019   19.2742 2.0041068  -3.461639  3  5  4.0164437  8.049382
    33695767 1 2019  .03011636  .3613963 0 57.5  6.59   .2984257 2019  19.93195  3.581109 -1.9219668  4  5   12.82434  45.92536
    33695767 1 2019  .03011636  .3613963 0   71  9.43   .8104038 2019 18.706606  9.724846  -.4318246  5  5   94.57262  919.7042
    33718216 0 2015  .13141684  1.577002 0   51  3.97  .13141684 2015  15.26336  1.577002  -1.375079  1  2  2.4869354 3.9219024
    33718216 0 2015  .13141684  1.577002 0   59  5.46  .29021218 2015 15.685148  3.482546  -.3814132  2  2   12.12813  42.23677
    34955417 0 2016  .03011636  .3613963 0   51  3.94  .03011636 2016  15.14802  .3613963   .9944171  1  4  .13060729   .047201
    34955417 0 2016  .03011636  .3613963 0   57   5.2   .1505818 2016 16.004925 1.8069816   1.695209  2  4   3.265182  5.900125
    34955417 0 2016  .03011636  .3613963 0   70   8.6   .6324435 2016 17.551022  7.589323  1.1716125  3  4   57.59782  437.1284
    34955417 0 2016  .03011636  .3613963 0   80    10   1.486653 2017    15.625 17.839836  .11547854  4  4   318.2598  5677.702
    36421115 0 2018  .12046544 1.4455853 0   54  4.34  .12046544 2018 14.883403 1.4455853  .16006504  1  4  2.0897167  3.020864
    36421115 0 2018  .12046544 1.4455853 0   58  5.39  .25735798 2018 16.022593  3.088296  -.8564585  2  4   9.537572 29.454844
    36421115 0 2018  .12046544 1.4455853 0   70 10.82   .8870637 2019  22.08163 10.644764  -.6005127  3  4    113.311 1206.1688
    36421115 0 2018  .12046544 1.4455853 0   74    12  1.1170431 2019 21.913805 13.404518  -.4630341  4  4   179.6811 2408.5386
    37565537 1 2017   .1615332 1.9383984 1   60   5.3  .26009583 2017 14.722222   3.12115  -.6990924  1  2   9.741577 30.404924
    37565537 1 2017   .1615332 1.9383984 1   71   7.1  .55852157 2018 14.084507  6.702259  1.5775474  2  2   44.92028 301.06732
    39098684 1 2016  .10677618  1.281314 1   46   2.6  .10677618 2016 12.287334  1.281314  -4.481988  1  2   1.641766  2.103618
    39098684 1 2016  .10677618  1.281314 1   49 44.95    .238193 2016 187.21367  2.858316  -4.711346  2  2   8.169971  23.35236
    39121618 1 2016   .2108145  2.529774 0   59   5.6   .2108145 2016 16.087332  2.529774  .28748262  1  9   6.399757 16.189941
    39121618 1 2016   .2108145  2.529774 0   63   6.6   .3258042 2016 16.628874  3.909651   .7683568  2  9   15.28537  59.76046
    39121618 1 2016   .2108145  2.529774 0   67   7.5   .4791239 2016 16.707508  5.749487  .51971906  3  9    33.0566  190.0585
    39121618 1 2016   .2108145  2.529774 0   69   8.1   .5722108 2016 17.013233  6.866529   .6430932  4  9   47.14923  323.7516
    39121618 1 2016   .2108145  2.529774 0   70   8.7   .6899384 2016 17.755102  8.279261 -.27177352  5  9   68.54616  567.5115
    39121618 1 2016   .2108145  2.529774 0   70   9.2   .7665982 2016 18.775509  9.199179  -.8776035  6  9   84.62489  778.4795
    39121618 1 2016   .2108145  2.529774 0   74  9.95   .8678987 2016 18.170197 10.414784   .3145875  7  9  108.46774 1129.6681
    39121618 1 2016   .2108145  2.529774 0   76  9.95   .9582478 2016 17.226454 11.498974   .6273015  8  9   132.2264  1520.468
    39121618 1 2016   .2108145  2.529774 0   77  10.3  1.0349076 2016 17.372238  12.41889   .5265452  9  9  154.22885 1915.3513
    39223276 1 2018  .07939767   .952772 0   53  4.35  .07939767 2018 15.485938   .952772  1.6458665  1  2   .9077745  .8649022
    39223276 1 2018  .07939767   .952772 0 56.5  6.45   .2327173 2018 20.205183  2.792608  -.9622246  2  2   7.798658 21.778593
    40501789 1 2017  .11772759  1.412731 2   53   4.4  .12320329 2017 15.663938 1.4784395  -.8858762  1  3  2.1857831  3.231548
    40501789 1 2017  .11772759  1.412731 2   60     7   .3778234 2017 19.444445  4.533881 -1.8675812  2  3   20.55608  93.19881
    40501789 1 2017  .11772759  1.412731 2   60   8.2   .4490075 2017 22.777777  5.388091  -2.795429  3  3   29.03152 156.42447
    40863444 0 2019 .019164955 .22997946 0   51     3 .019164955 2019 11.534025 .22997946   .9944171  1  5  .05289055 .01216374
    40863444 0 2019 .019164955 .22997946 0   56     5  .13689254 2019 15.943877 1.6427104  1.1834943  2  5  2.6984975 4.4328504
    40863444 0 2019 .019164955 .22997946 0   62   5.6   .3258042 2019 14.568158  3.909651   1.043723  3  5   15.28537  59.76046
    40863444 0 2019 .019164955 .22997946 0   66   7.1  .54757017 2019 16.299356  6.570842    .118645  4  5   43.17596 283.70242
    40863444 0 2019 .019164955 .22997946 0   68   7.5   .6516085 2019 16.219723  7.819302   .3078144  5  5   61.14148 478.08365
    40886644 0 2018  .06297057  .7556468 0   53  4.21  .06297057 2018  14.98754  .7556468  2.0681286  1  4   .5710021  .4314759
    40886644 0 2018  .06297057  .7556468 0   62  6.06  .28199863 2018 15.764828 3.3839836   1.043723  2  4  11.451345  38.75116
    40886644 0 2018  .06297057  .7556468 0   64  7.37   .3969884 2018 17.993164   4.76386   .8824854  3  4  22.694365 108.11278
    40886644 0 2018  .06297057  .7556468 0   68  8.25   .5557837 2018 17.841696  6.669404  1.0010984  4  4   44.48095 296.66144
    52379999 0 2016  .23545517  2.825462 0   57     4  .23545517 2016  12.31148  2.825462 -.03305185  1 22   7.983236  22.55633
    52379999 0 2016  .23545517  2.825462 0   60   5.1   .3915127 2016 14.166666  4.698152  -.9655557  2 22  22.072634 103.70058
    52379999 0 2016  .23545517  2.825462 0   62  5.32   .4845996 2016  13.83975  5.815195  -.9155464  3 22  33.816494  196.6495
    52379999 0 2016  .23545517  2.825462 0   68   6.1   .6433949 2016  13.19204  7.720739   .3078144  4 22   59.60982  460.2318
    52379999 0 2016  .23545517  2.825462 0   69 70.35   .9637235 2017 147.76308 11.564682 -1.4959625  5 22  133.74187 1546.6823
    52379999 0 2016  .23545517  2.825462 0   74   8.4  1.3114306 2017 15.339664 15.737167 -1.2813606  6 22  247.65843 3897.4424
    52379999 0 2016  .23545517  2.825462 0   78   8.6   1.486653 2017 14.135438 17.839836  -.5865136  7 22   318.2598  5677.702
    52379999 0 2016  .23545517  2.825462 0   84   8.9  1.9000684 2018 12.613379  22.80082 -.19357643  8 22  519.87744 11853.633
    52379999 0 2016  .23545517  2.825462 0   83   9.8   2.017796 2018 14.225577  24.21355  -.8416084  9 22  586.29614 14196.312
    52379999 0 2016  .23545517  2.825462 0   87   9.8  2.2669404 2018  12.94755 27.203285  -.3794459 10 22   740.0187  20130.94
    52379999 0 2016  .23545517  2.825462 0   86    10   2.554415 2018 13.520823 30.652977 -1.3256345 11 22    939.605  28801.69
    52379999 0 2016  .23545517  2.825462 0   89    10   2.666667 2018  12.62467        32   -.879957 12 22       1024     32768
    52379999 0 2016  .23545517  2.825462 0   89    10  2.7460644 2019  12.62467 32.952774   -.879957 13 22  1085.8854 35782.934
    52379999 0 2016  .23545517  2.825462 0   89    10   2.806297 2019  12.62467 33.675564 -1.0684968 14 22  1134.0436  38189.56
    52379999 0 2016  .23545517  2.825462 0   89  10.5   2.902122 2019 13.255902 34.825462 -1.2489586 15 22  1212.8129  42236.77
    52379999 0 2016  .23545517  2.825462 0   89  10.9   2.973306 2019 13.760888 35.679672  -1.422331 16 22   1273.039  45421.61
    52379999 0 2016  .23545517  2.825462 0   90    11   3.148528 2019 13.580247  37.78234  -1.489887 17 22  1427.5052  53934.49
    52379999 0 2016  .23545517  2.825462 0   93    11   3.326489 2019 12.718233  39.91787 -1.0379856 18 22   1593.436  63606.57
    52379999 0 2016  .23545517  2.825462 0   93  10.5   3.397673 2019 12.140132  40.77208 -1.1928927 19 22   1662.362  67777.95
    52379999 0 2016  .23545517  2.825462 0   92    11  3.4770706 2019  12.99622  41.72485 -1.5909727 20 22  1740.9628  72641.41
    52379999 0 2016  .23545517  2.825462 0   94  10.9  3.5674195 2019 12.335898  42.80904 -1.2407924 21 22  1832.6135  78452.42
    52379999 0 2016  .23545517  2.825462 0   95  10.6   3.649555 2019 11.745152  43.79466 -1.1394521 22 22  1917.9724  83996.95
    end
    label values sexo_ca sexo
    label def sexo 0 "feminino", modify
    label def sexo 1 "masculino", modify
    label values cenario cenario
    label def cenario 0 "LM exclusivo", modify
    label def cenario 1 "Substitutos do leite materno", modify
    label def cenario 2 "IA precoce", modify
    ------------------ copy up to and including the previous line ------------------





    Attached Files
    Last edited by Andressa Freire; 27 Nov 2023, 12:44.

  • #2
    You did not use factor-variable notation correctly in your regression. Your error was creating the new variables gen idade_meses_en2= idade_meses_en^2 and gen idade_meses_en3= idade_meses_en^3. When you do this, -margins- does not recognize that idad_meses_en2 is supposed to be the square of idad_meses_en, and that idad_meses_en3 is supposed to be the square. After all, -margins- does not go back and scan your code to see how those variables were created! So it thinks these are just two unrelated variables and treats them accordingly. So you have to go back and redo your regression correctly:
    Code:
    mixed z_altidade c.idade_meses_en##c.idade_meses_en##c.idade_meses_en///
        || id: c.idade_meses_en##c.idade_meses_en##c.idade_meses_en, cov(uns) variance
    If you do that, -margins- will give you the kind of plot you are looking for.

    Note that you should also have random slopes for the quadratic and cubic terms in idade_messes_en, not just the linear term. Otherwise you are constraining those higher order coefficients to be constant across persons, which is a very bizarre kind of constraint. Now, because you are also introducing more random slope terms into the model, you might encounter a large number of iterations or even a convergence failure with -cov(uns)- as that matrix will be pretty large. If this happens, consider simplifying the model by using a lower-dimensional covariance structure such as, perhaps, exchangeable.
    Last edited by Clyde Schechter; 28 Nov 2023, 12:40.

    Comment


    • #3
      Hello, Clyde. Thank you so much for your help.

      I re-ran this analysis with your observations and generated these results. I have some doubts...

      *I tested the best function (model fit): linear, quadratic or cubic

      *linear function
      mixed z_altidade idade_meses_en || id: idade_meses_en , cov(uns) variance
      estat ic
      * AIC: 1674308
      * BIC: 1674376

      * quadratic function
      mixed z_altidade c.idade_meses_en##c.idade_meses_en || id: c.idade_meses_en##c.idade_meses_en, cov(uns) variance
      estat ic
      * AIC: 1659490
      * BIC: 1659603

      * cubic function
      mixed z_altidade c.idade_meses_en##c.idade_meses_en##c.idade_meses_ en || id: c.idade_meses_en##c.idade_meses_en##c.idade_meses_ en, cov(ex) variance
      estat ic
      * AIC: 2031621
      * BIC: 2031688

      Doubts:
      - does running the cubic model with a different covariance structure than the linear and quadratic models change the AIC and BIC values a lot?
      - If it is to test the best model, do I have to standardize the same covariance structure for everyone?
      - I ask this because after this phase of testing the best model, the best was the quadratic one (the previous time it was cubic, but that's ok, the command contained errors)




      *model that best fits is the quadratic model - lower AIC and BIC values.

      mixed z_altidade c.idade_meses_en##c.idade_meses_en##i.cenario || id: c.idade_meses_en##c.idade_meses_en, cov(ex) variance
      *did not run using cov (ex)

      I ran this final model considering the "cenario" variable:

      mixed z_altidade c.idade_meses_en##c.idade_meses_en##i.cenario || id: c.idade_meses_en##c.idade_meses_en, cov(uns) variance

      margins i.cenario, at(idade_meses_en=(0(6)60))
      marginsplot, title("Escore Z de altura-para-idade, segundo aleitamento e idade em meses", size(medium)) ytitle("Altura-para-idade (escores Z)") ylabel(, angle(0)) xtitle("Idade (meses)") xlabel(0(12)60) graphregion(color(white)) bgcolor(white) legend(col(3) region(lstyle(none))) plot1opts(m(Oh) lp(dash)) plot2opts(m(Oh) lp(dash)) plot3opts(m(Oh) lp(dash)) noci recast(line) name(modelo_teste2, replace) yline(0)



      Performing EM optimization ...

      Performing gradient-based optimization:
      Iteration 0: log likelihood = -833501.59
      Iteration 1: log likelihood = -830630.36 (not concave)
      Iteration 2: log likelihood = -830543.17 (not concave)
      Iteration 3: log likelihood = -830145.55 (not concave)
      Iteration 4: log likelihood = -829499.7
      Iteration 5: log likelihood = -829277.04
      Iteration 6: log likelihood = -829266.86
      Iteration 7: log likelihood = -829266.83

      Computing standard errors ...

      Mixed-effects ML regression Number of obs = 597,237
      Group variable: id Number of groups = 127,422
      Obs per group:
      min = 2
      avg = 4.7
      max = 46
      Wald chi2(8) = 2477.67
      Log likelihood = -829266.83 Prob > chi2 = 0.0000

      ------------------------------------------------------------------------------------------
      > -----------------
      z_altidade | Coefficient Std. err. z P>|z| [95
      > % con
      > f. interval]
      ------------------------------------------+-----------------------------------------------
      > -----------------
      idade_meses_en | -.0363922 .0008706 -41.80 0.000 -.03
      > 80985
      > -.0346858
      |
      c.idade_meses_en#c.idade_meses_en | .0008394 .0000302 27.75 0.000 .00
      > 07801
      > .0008986
      |
      cenario |
      Substitutos do leite materno | -.3051966 .0115034 -26.53 0.000 -.32
      > 77429
      > -.2826502
      IA precoce | -.1085399 .0185572 -5.85 0.000 -.14
      > 49114
      > -.0721684
      |
      cenario#c.idade_meses_en |
      Substitutos do leite materno | .0498085 .0018337 27.16 0.000 .04
      > 62145
      > .0534025
      IA precoce | .0183328 .002864 6.40 0.000 .01
      > 27196
      > .0239461
      |
      cenario#c.idade_meses_en#c.idade_meses_en |
      Substitutos do leite materno | -.0012331 .0000625 -19.72 0.000 -.00
      > 13557
      > -.0011106
      IA precoce | -.0005045 .0000927 -5.44 0.000 -.00
      > 06862
      > -.0003227
      |
      _cons | .2267284 .0054175 41.85 0.000 .21
      > 61102
      > .2373465
      ------------------------------------------------------------------------------------------
      > -----------------

      ------------------------------------------------------------------------------
      Random-effects parameters | Estimate Std. err. [95% conf. interval]
      -----------------------------+------------------------------------------------
      id: Unstructured |
      var(idade_meses_en) | .0260088 .0003003 .0254269 .026604
      var(c.idade_meses_en# |
      c.idade_meses_en) | .0000172 3.82e-07 .0000164 .0000179
      var(_cons) | 1.992113 .0095976 1.97339 2.011013
      cov(idade_meses_en, |
      c.idade_meses_en# |
      c.idade_meses_en) | -.0006519 .0000108 -.000673 -.0006308
      cov(idade_meses_en,_cons) | -.1422723 .0011441 -.1445146 -.14003
      cov(c.idade_meses_en# |
      c.idade_meses_en, |
      _cons) | .003035 . . .
      -----------------------------+------------------------------------------------
      var(Residual) | .4824281 .0011705 .4801394 .4847277
      ------------------------------------------------------------------------------
      LR test vs. linear model: chi2(6) = 3.8e+05 Prob > chi2 = 0.0000

      Note: LR test is conservative and provided only for reference.



      The graphical representation makes sense for me, especially regarding the exclusive category (Attached are graph and log file)

      Do you and our Statalist colleagues have any observations? Am I on the right path of analysis?
      Attached Files
      Last edited by Andressa Freire; 01 Dec 2023, 09:34.

      Comment


      • #4
        - does running the cubic model with a different covariance structure than the linear and quadratic models change the AIC and BIC values a lot?

        It is hard to say what the effect on AIC and BIC would be. On the one hand, you are adding an additional cubic term to the model, which will both improve the log likelihood, but also increase the parameters penalty. But you are also reducing the number of parameters in the covariance structure by going from unstructured to exchangeable, for which you also will suffer some loss of fit. So you have two effects going in opposite directions. I have no intuition about which would win out, other than to say that I think it would depend a great deal on the specific data set.

        In any case, to the extent you are ever willing to rely on using AIC to select your model, I think this situation is just as good as any other. Unlike likelihood ratio tests which are only valid for comparing nested models, the AIC can compare any kind of different models provided all of them have been fit to the same data. (So, make sure that your estimation sample is the same for all of these models. When you added the cenario variable, you might have reduced the estimation sample because any observation with a missing value for cenario would drop out. Just check that this didn't happen. If it did, then you have to start over, and add -if !missing(cenario)- to the command for the model that didn't include cenario.)

        Comment


        • #5
          Thank you very much, Clyde Schechter. The "cenario" variable is not missing, but your comment is something that I will always keep in mind in other databases. After your suggestions, I ran some models to compare the results, familiarize myself with this type of analysis and practice.

          In my database I test some outcomes such as height/age z-score (example from opening the topic), bmi/age z-score. My concern is that when I tested this same basis using the bmi/age z-score, I had completely different graphical results just by changing the covariance structure in the final model, which left me unsure whether I was doing this analysis correctly (summary of the codes and graphs attached). Furthermore, the generated curves do not look like BMI curves, which increases my chances of constructing the syntax incorrectly.

          *I tested the best function (model fit): linear, quadratic or cubic

          *linear function
          mixed z_imcidade c.idade_meses_en || id: c.idade_meses_en , cov(uns) variance
          estat ic
          * AIC: 1860851
          * BIC: 1860920

          *quadratic function
          mixed z_imcidade c.idade_meses_en##c.idade_meses_en || id: c.idade_meses_en##c.idade_meses_en, cov(uns) variance
          estat ic
          * AIC: 1840288
          * BIC: 1840403

          *cubic function
          mixed z_imcidade c.idade_meses_en##c.idade_meses_en##c.idade_meses_ en || id: c.idade_meses_en##c.idade_meses_en##c.idade_meses_ en, cov(uns) variance
          estat ic
          * AIC: 1824210
          * BIC: 1824256

          *model that best fits is the cubic model - lower AIC and BIC values.

          *final model
          mixed z_imcidade c.idade_meses_en##c.idade_meses_en##c.idade_meses_ en##i.cenario || id: c.idade_meses_en##c.idade_meses_en##c.idade_meses_ en, cov(uns) variance

          margins i.cenario, at(idade_meses_en=(0(6)60))
          marginsplot, title("Escore Z de imc-para-idade, segundo cenario e meses de idade", size(medium)) ytitle("imc-para-idade (escores Z)") ylabel(, angle(0)) xtitle("Idade (meses)") xlabel(0(12)60) graphregion(color(white)) bgcolor(white) legend(ring(0) col(1) position(5) bmargin(large) region(lstyle(none))) plot1opts(m(Oh) lpattern(solid) lcolor(black)) plot2opts(m(Oh) lpattern(dash) lcolor(black)) plot3opts(m(Oh) lpattern(shortdash) lcolor(black)) noci recast(line) name(modelo_imc_menor3m_pb, replace) yline(0, lcolor(gs8))

          Code:
          Performing EM optimization ...
          
          Performing gradient-based optimization:
          Iteration 0:   log likelihood = -922866.16  
          Iteration 1:   log likelihood = -915756.39  (not concave)
          Iteration 2:   log likelihood = -913980.51  
          Iteration 3:   log likelihood = -912045.83  
          Iteration 4:   log likelihood = -911567.91  
          Iteration 5:   log likelihood = -911437.22  
          Iteration 6:   log likelihood = -911410.97  
          Iteration 7:   log likelihood = -911410.77  
          Iteration 8:   log likelihood = -911410.77  
          
          Computing standard errors ...
          
          Mixed-effects ML regression                     Number of obs     =    757,518
          Group variable: id                              Number of groups  =    148,284
                                                          Obs per group:
                                                                        min =          2
                                                                        avg =        5.1
                                                                        max =         44
                                                          Wald chi2(11)     =   10575.81
          Log likelihood = -911410.77                     Prob > chi2       =     0.0000
          
          ----------------------------------------------------------------------------------------------------------------------------
                                                          z_imcidade | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
          -----------------------------------------------------------+----------------------------------------------------------------
                                                      idade_meses_en |  -.0316145   .0012392   -25.51   0.000    -.0340432   -.0291858
                                                                     |
                                   c.idade_meses_en#c.idade_meses_en |   .0044579   .0000959    46.48   0.000     .0042699    .0046458
                                                                     |
                  c.idade_meses_en#c.idade_meses_en#c.idade_meses_en |  -.0001027   1.97e-06   -52.22   0.000    -.0001066   -.0000989
                                                                     |
                                                             cenario |
                                       Substitutos do leite materno  |  -.2666626   .0097445   -27.37   0.000    -.2857615   -.2475636
                                                         IA precoce  |  -.2019122   .0156418   -12.91   0.000    -.2325696   -.1712549
                                                                     |
                                            cenario#c.idade_meses_en |
                                       Substitutos do leite materno  |   .0563446   .0026293    21.43   0.000     .0511913    .0614978
                                                         IA precoce  |   .0793783    .004055    19.58   0.000     .0714305     .087326
                                                                     |
                           cenario#c.idade_meses_en#c.idade_meses_en |
                                       Substitutos do leite materno  |  -.0026912      .0002   -13.46   0.000    -.0030832   -.0022993
                                                         IA precoce  |  -.0045326   .0002945   -15.39   0.000    -.0051098   -.0039555
                                                                     |
          cenario#c.idade_meses_en#c.idade_meses_en#c.idade_meses_en |
                                       Substitutos do leite materno  |   .0000388   4.04e-06     9.61   0.000     .0000309    .0000467
                                                         IA precoce  |   .0000734   5.73e-06    12.81   0.000     .0000622    .0000846
                                                                     |
                                                               _cons |   .3023013   .0045408    66.58   0.000     .2934016    .3112011
          ----------------------------------------------------------------------------------------------------------------------------
          
          ------------------------------------------------------------------------------
            Random-effects parameters  |   Estimate   Std. err.     [95% conf. interval]
          -----------------------------+------------------------------------------------
          id: Unstructured             |
                   var(idade_meses_en) |   .0607705    .000693      .0594272    .0621441
                 var(c.idade_meses_en# |
                     c.idade_meses_en) |    .000255   4.55e-06      .0002462    .0002641
                 var(c.idade_meses_en# |
                     c.idade_meses_en# |
                     c.idade_meses_en) |   7.76e-08   2.05e-09      7.37e-08    8.17e-08
                            var(_cons) |   1.366257   .0081426       1.35039    1.382309
                   cov(idade_meses_en, |
                     c.idade_meses_en# |
                     c.idade_meses_en) |  -.0037602   .0000553     -.0038685   -.0036519
                   cov(idade_meses_en, |
                     c.idade_meses_en# |
                     c.idade_meses_en# |
                     c.idade_meses_en) |   .0000623   1.17e-06        .00006    .0000646
             cov(idade_meses_en,_cons) |  -.1463256   .0019351     -.1501183   -.1425328
                 cov(c.idade_meses_en# |
                     c.idade_meses_en, |
                     c.idade_meses_en# |
                     c.idade_meses_en# |
                     c.idade_meses_en) |  -4.40e-06   9.67e-08     -4.59e-06   -4.21e-06
                 cov(c.idade_meses_en# |
                     c.idade_meses_en, |
                                _cons) |   .0067353   .0001413      .0064584    .0070123
                 cov(c.idade_meses_en# |
                     c.idade_meses_en# |
                     c.idade_meses_en, |
                                _cons) |  -.0000964   2.81e-06     -.0001019   -.0000909
          -----------------------------+------------------------------------------------
                         var(Residual) |    .313879   .0007019      .3125063    .3152578
          ------------------------------------------------------------------------------
          LR test vs. linear model: chi2(10) = 5.6e+05              Prob > chi2 = 0.0000
          
          Note: LR test is conservative and provided only for reference.


          *changing for cov(ex)
          mixed z_imcidade c.idade_meses_en##c.idade_meses_en##c.idade_meses_ en##i.cenario || id: c.idade_meses_en##c.idade_meses_en##c.idade_meses_ en, cov(uns) variance

          margins i.cenario, at(idade_meses_en=(0(6)60))
          marginsplot, title("Escore Z de imc-para-idade, segundo cenario e meses de idade", size(medium)) ytitle("imc-para-idade (escores Z)") ylabel(, angle(0)) xtitle("Idade (meses)") xlabel(0(12)60) graphregion(color(white)) bgcolor(white) legend(ring(0) col(1) position(5) bmargin(large) region(lstyle(none))) plot1opts(m(Oh) lpattern(solid) lcolor(black)) plot2opts(m(Oh) lpattern(dash) lcolor(black)) plot3opts(m(Oh) lpattern(shortdash) lcolor(black)) noci recast(line) name(modelo_imc_menor3m_pb2, replace) yline(0, lcolor(gs8))

          Code:
          Performing EM optimization ...
          
          Performing gradient-based optimization:
          Iteration 0:   log likelihood = -1184406.9  (not concave)
          Iteration 1:   log likelihood = -1175724.8  (not concave)
          Iteration 2:   log likelihood = -1175696.4  
          Iteration 3:   log likelihood = -1175391.4  (not concave)
          Iteration 4:   log likelihood = -1175036.1  
          Iteration 5:   log likelihood = -1174969.9  
          Iteration 6:   log likelihood = -1174968.6  
          Iteration 7:   log likelihood = -1174968.6  
          Iteration 8:   log likelihood = -1174968.6  
          Iteration 9:   log likelihood = -1174968.6  
          Iteration 10:  log likelihood = -1174968.6  
          
          Computing standard errors ...
          
          Mixed-effects ML regression                     Number of obs     =    757,518
          Group variable: id                              Number of groups  =    148,284
                                                          Obs per group:
                                                                        min =          2
                                                                        avg =        5.1
                                                                        max =         44
                                                          Wald chi2(11)     =    9463.11
          Log likelihood = -1174968.6                     Prob > chi2       =     0.0000
          
          ----------------------------------------------------------------------------------------------------------------------------
                                                          z_imcidade | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
          -----------------------------------------------------------+----------------------------------------------------------------
                                                      idade_meses_en |   .0045754   .0011989     3.82   0.000     .0022257    .0069252
                                                                     |
                                   c.idade_meses_en#c.idade_meses_en |   .0013301   .0000953    13.95   0.000     .0011432     .001517
                                                                     |
                  c.idade_meses_en#c.idade_meses_en#c.idade_meses_en |  -.0000319   2.38e-06   -13.42   0.000    -.0000366   -.0000273
                                                                     |
                                                             cenario |
                                       Substitutos do leite materno  |  -.2362497    .008617   -27.42   0.000    -.2531387   -.2193608
                                                         IA precoce  |   -.199354    .013971   -14.27   0.000    -.2267368   -.1719713
                                                                     |
                                            cenario#c.idade_meses_en |
                                       Substitutos do leite materno  |   .0458798   .0025505    17.99   0.000     .0408809    .0508787
                                                         IA precoce  |   .0785571   .0036362    21.60   0.000     .0714304    .0856839
                                                                     |
                           cenario#c.idade_meses_en#c.idade_meses_en |
                                       Substitutos do leite materno  |  -.0019896   .0001949   -10.21   0.000    -.0023717   -.0016076
                                                         IA precoce  |  -.0042658   .0002457   -17.36   0.000    -.0047473   -.0037843
                                                                     |
          cenario#c.idade_meses_en#c.idade_meses_en#c.idade_meses_en |
                                       Substitutos do leite materno  |   .0000275   4.70e-06     5.84   0.000     .0000182    .0000367
                                                         IA precoce  |   .0000645   5.49e-06    11.74   0.000     .0000537    .0000752
                                                                     |
                                                               _cons |   .2080677   .0038722    53.73   0.000     .2004783    .2156571
          ----------------------------------------------------------------------------------------------------------------------------
          
          ------------------------------------------------------------------------------
            Random-effects parameters  |   Estimate   Std. err.     [95% conf. interval]
          -----------------------------+------------------------------------------------
          id: Exchangeable             |
               var(ida~s_en.._cons)(1) |   1.06e-08   5.14e-10      9.68e-09    1.17e-08
               cov(ida~s_en.._cons)(1) |   1.06e-08          .             .           .
          -----------------------------+------------------------------------------------
                         var(Residual) |   1.205653   .0020185      1.201703    1.209616
          ------------------------------------------------------------------------------
          LR test vs. linear model: chi2(2) = 35625.19              Prob > chi2 = 0.0000
          (1) idade_meses_en c.idade_meses_en#c.idade_meses_en c.idade_meses_en#c.idade_meses_en#c.idade_meses_en _cons
          
          Note: LR test is conservative and provided only for reference.

          Reading other posts here, I saw that other colleagues generate cubic splines with the rc_spline and mkspline packages, specifically for modeling growth curves. So I decided to test this new syntax.


          Code:
          rc_spline idade_meses_en, knots(2 6 12 24 58)
          mixed z_imcidade idade_meses_en c._S*##i.cenario || id: _Sidade_meses_en1 _Sidade_meses_en2 _Sidade_meses_en3 _Sidade_meses_en4 , cov (ex) variance
          margins i.cenario, at(c.idade_meses_en=(0(6)60))
          marginsplot, title("Escore Z de imc-para-idade, segundo cenario e meses de idade", size(medium)) ytitle("imc-para-idade (escores Z)") ylabel(, angle(0)) xtitle("Idade (meses)") xlabel(0(12)60) graphregion(color(white)) bgcolor(white) legend(ring(0) col(1) position(5) bmargin(large) region(lstyle(none))) plot1opts(m(Oh) lpattern(solid) lcolor(black)) plot2opts(m(Oh) lpattern(dash) lcolor(black)) plot3opts(m(Oh) lpattern(shortdash) lcolor(black)) noci recast(line) name(modelo_imc_menor3m_pb3, replace) yline(0, lcolor(gs8))
          
           mixed z_imcidade idade_meses_en c._S*##i.cenario || id: _Sidade_meses_en1 _Sidade_meses_en2 _Sidade_meses_en3 _Sidade_meses_en4 , c
          > ov (ex) variance
          note: _Sidade_meses_en1 omitted because of collinearity.
          
          Performing EM optimization ...
          
          Performing gradient-based optimization:
          Iteration 0:   log likelihood = -1063836.2  
          Iteration 1:   log likelihood = -1061276.9  
          Iteration 2:   log likelihood = -1061250.5  
          Iteration 3:   log likelihood = -1061249.4  
          Iteration 4:   log likelihood = -1061249.4  
          
          Computing standard errors ...
          
          Mixed-effects ML regression                     Number of obs     =    757,518
          Group variable: id                              Number of groups  =    148,284
                                                          Obs per group:
                                                                        min =          2
                                                                        avg =        5.1
                                                                        max =         44
                                                          Wald chi2(14)     =    7814.56
          Log likelihood = -1061249.4                     Prob > chi2       =     0.0000
          
          -----------------------------------------------------------------------------------------------
                             z_imcidade | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
          ------------------------------+----------------------------------------------------------------
                         idade_meses_en |  -.0258663   .0009965   -25.96   0.000    -.0278194   -.0239133
                      _Sidade_meses_en1 |          0  (omitted)
                      _Sidade_meses_en2 |   2.849046   .0518307    54.97   0.000      2.74746    2.950632
                      _Sidade_meses_en3 |  -5.855007   .1071976   -54.62   0.000     -6.06511   -5.644903
                      _Sidade_meses_en4 |    3.65152    .074432    49.06   0.000     3.505636    3.797404
                                        |
                                cenario |
          Substitutos do leite materno  |   -.202386    .007168   -28.23   0.000    -.2164351    -.188337
                            IA precoce  |  -.1067189   .0125906    -8.48   0.000     -.131396   -.0820418
                                        |
            cenario#c._Sidade_meses_en1 |
          Substitutos do leite materno  |   .0297944   .0021624    13.78   0.000     .0255561    .0340326
                            IA precoce  |   .0394746   .0035218    11.21   0.000      .032572    .0463772
                                        |
            cenario#c._Sidade_meses_en2 |
          Substitutos do leite materno  |  -.3025613    .108913    -2.78   0.005    -.5160268   -.0890959
                            IA precoce  |  -.7894956   .1662547    -4.75   0.000    -1.115349   -.4636423
                                        |
            cenario#c._Sidade_meses_en3 |
          Substitutos do leite materno  |   .2979308    .222974     1.34   0.181    -.1390902    .7349519
                            IA precoce  |   1.164523   .3330385     3.50   0.000     .5117795    1.817266
                                        |
            cenario#c._Sidade_meses_en4 |
          Substitutos do leite materno  |   .1076489   .1514081     0.71   0.477    -.1891055    .4044034
                            IA precoce  |  -.3061516   .2143424    -1.43   0.153     -.726255    .1139518
                                        |
                                  _cons |   .3050519   .0031472    96.93   0.000     .2988835    .3112203
          -----------------------------------------------------------------------------------------------
          
          ------------------------------------------------------------------------------
            Random-effects parameters  |   Estimate   Std. err.     [95% conf. interval]
          -----------------------------+------------------------------------------------
          id: Exchangeable             |
               var(_Sidad~1.._cons)(1) |   .0211051   .0002235      .0206716    .0215478
               cov(_Sidad~1.._cons)(1) |  -.0018219   .0003846     -.0025757   -.0010682
          -----------------------------+------------------------------------------------
                         var(Residual) |   .6346027   .0013486       .631965    .6372514
          ------------------------------------------------------------------------------
          LR test vs. linear model: chi2(2) = 2.6e+05               Prob > chi2 = 0.0000
          (1) _Sidade_meses_en1 _Sidade_meses_en2 _Sidade_meses_en3 _Sidade_meses_en4 _cons
          
          Note: LR test is conservative and provided only for reference.
          
          . margins i.cenario, at(c.idade_meses_en=(0(6)60))
          
          Predictive margins                                     Number of obs = 757,518
          
          Expression: Linear prediction, fixed portion, predict()
          1._at:  idade_meses_en =  0
          2._at:  idade_meses_en =  6
          3._at:  idade_meses_en = 12
          4._at:  idade_meses_en = 18
          5._at:  idade_meses_en = 24
          6._at:  idade_meses_en = 30
          7._at:  idade_meses_en = 36
          8._at:  idade_meses_en = 42
          9._at:  idade_meses_en = 48
          10._at: idade_meses_en = 54
          11._at: idade_meses_en = 60
          
          --------------------------------------------------------------------------------------------------
                                           |            Delta-method
                                           |     Margin   std. err.      z    P>|z|     [95% conf. interval]
          ---------------------------------+----------------------------------------------------------------
                               _at#cenario |
                           1#LM exclusivo  |          .  (not estimable)
           1#Substitutos do leite materno  |          .  (not estimable)
                             1#IA precoce  |          .  (not estimable)
                           2#LM exclusivo  |          .  (not estimable)
           2#Substitutos do leite materno  |          .  (not estimable)
                             2#IA precoce  |          .  (not estimable)
                           3#LM exclusivo  |          .  (not estimable)
           3#Substitutos do leite materno  |          .  (not estimable)
                             3#IA precoce  |          .  (not estimable)
                           4#LM exclusivo  |          .  (not estimable)
           4#Substitutos do leite materno  |          .  (not estimable)
                             4#IA precoce  |          .  (not estimable)
                           5#LM exclusivo  |          .  (not estimable)
           5#Substitutos do leite materno  |          .  (not estimable)
                             5#IA precoce  |          .  (not estimable)
                           6#LM exclusivo  |          .  (not estimable)
           6#Substitutos do leite materno  |          .  (not estimable)
                             6#IA precoce  |          .  (not estimable)
                           7#LM exclusivo  |          .  (not estimable)
           7#Substitutos do leite materno  |          .  (not estimable)
                             7#IA precoce  |          .  (not estimable)
                           8#LM exclusivo  |          .  (not estimable)
           8#Substitutos do leite materno  |          .  (not estimable)
                             8#IA precoce  |          .  (not estimable)
                           9#LM exclusivo  |          .  (not estimable)
           9#Substitutos do leite materno  |          .  (not estimable)
                             9#IA precoce  |          .  (not estimable)
                          10#LM exclusivo  |          .  (not estimable)
          10#Substitutos do leite materno  |          .  (not estimable)
                            10#IA precoce  |          .  (not estimable)
                          11#LM exclusivo  |          .  (not estimable)
          11#Substitutos do leite materno  |          .  (not estimable)
                            11#IA precoce  |          .  (not estimable)
          --------------------------------------------------------------------------------------------------
          I used rc_spline and not mkspline here because I would like to model the curve at specific ages, which I put in knots. However, as you can see, when I use margins it goes wrong.

          where could I be going wrong?
          I saw Maarten Buis' posts, I would like to know your opinion too, in addition to other colleagues, if possible, please. I appreciate any help you give me

          Maarten Buis
          Clyde Schechter
          Attached Files
          Last edited by Andressa Freire; 05 Dec 2023, 05:57.

          Comment


          • #6
            You cannot use -margins- after -rcspline- (nor -mkspline-) because -margins- does not know that the various spline variables are actually functions of the idade_meses_en variable: it treats them as if they were unrelated.

            Fernando Rios has written a program, f_able, available from SSC, that, I believe can handle this kind of situation, though I personally have not used it and cannot say more about that.

            Comment

            Working...
            X