Announcement

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

  • interacction mixed model repeat measure

    Hello, first of all thank you very much !!
    I need to create the interaction between group and age45, is it correct to do it in the following way? Thank you, best regards

    xtmixed rootascmax time group#age45 || id:


    clear
    input float id byte time float(calci0 rootascmax age45 sex Ao40 raphe group)
    1 1 0 41 1 0 1 0 1
    1 2 0 40.9 1 0 1 0 1
    2 1 0 35.88 1 0 0 1 1
    2 2 0 37.22 1 0 0 1 1
    3 1 1 40.79 0 0 1 1 0
    3 2 1 41 0 0 1 1 0
    4 1 1 45.87 0 0 1 1 0
    4 2 1 46 0 0 1 1 0
    5 1 1 45.31 0 0 1 1 1
    5 2 1 45.28 0 0 1 1 1
    6 1 1 . 0 0 . 1 0
    6 2 1 . 0 0 . 1 0
    7 1 1 39.29 0 0 0 0 1
    7 2 1 39.36 0 0 0 0 1
    8 1 0 40.26 1 0 1 1 0
    8 2 0 41.76 1 0 1 1 0
    9 1 1 41.15 0 0 1 1 1
    9 2 1 41.5 0 0 1 1 1
    10 1 0 37.5 0 1 0 1 1
    10 2 0 37.5 0 1 0 1 1
    11 1 0 38.7 1 0 0 1 1
    11 2 0 39.34 1 0 0 1 1
    12 1 0 40.8 0 0 1 1 1
    12 2 0 40.92 0 0 1 1 1
    13 1 0 35.4 1 0 0 1 0
    13 2 0 36.17 1 0 0 1 0
    14 1 1 41.55 0 0 1 1 0
    14 2 1 42 0 0 1 1 0
    15 1 1 42.84 0 0 1 1 0
    15 2 1 43.29 0 0 1 1 0
    16 1 0 43.79 1 0 1 1 1
    16 2 0 43.8 1 0 1 1 1
    17 1 0 39.94 0 0 0 0 1
    17 2 0 39.45 0 0 0 0 1
    18 1 1 45.19 0 0 1 1 0
    18 2 1 45.81 0 0 1 1 0
    19 1 1 44.73 0 0 1 1 0
    19 2 1 45.69 0 0 1 1 0
    20 1 1 48.25 0 0 1 1 1
    20 2 1 48.58 0 0 1 1 1
    21 1 1 39.72 0 1 0 1 1
    21 2 1 39.84 0 1 0 1 1
    22 1 0 48.79 0 1 1 0 0
    22 2 0 48.93 0 1 1 0 0
    23 1 1 35.63 0 0 0 1 1
    23 2 1 . 0 0 0 1 1
    24 1 1 33.89 0 0 0 1 1
    24 2 1 32.18 0 0 0 1 1
    25 1 1 49.85 0 0 1 1 0
    25 2 1 49.9 0 0 1 1 0
    26 1 0 38.33 1 0 0 1 1
    26 2 0 39.3 1 0 0 1 1
    27 1 0 44.7 1 0 1 0 0
    27 2 0 47.44 1 0 1 0 0
    28 1 0 47.7 1 0 1 1 1
    28 2 0 48.65 1 0 1 1 1
    29 1 1 51.05 0 0 1 1 0
    29 2 1 50.82 0 0 1 1 0
    30 1 0 34.5 1 1 0 1 0
    30 2 0 38.2 1 1 0 1 0
    31 1 1 43.69 0 0 1 1 1
    31 2 1 43.91 0 0 1 1 1
    32 1 1 41.11 0 0 1 1 0
    32 2 1 42.81 0 0 1 1 0
    33 1 1 38.59 0 0 0 1 0
    33 2 1 39 0 0 0 1 0
    34 1 0 40.82 0 1 1 0 0
    34 2 0 42.02 0 1 1 0 0
    35 1 1 42.25 0 0 1 1 0
    35 2 1 42.44 0 0 1 1 0
    36 1 1 34.26 0 1 0 1 0
    36 2 1 35.06 0 1 0 1 0
    37 1 0 32.37 1 1 0 1 0
    37 2 0 33.43 1 1 0 1 0
    38 1 0 37.28 1 0 0 1 1
    38 2 0 36.52 1 0 0 1 1
    39 1 0 30.99 1 0 0 1 0
    39 2 0 31 1 0 0 1 0
    40 1 1 37.4 0 0 0 1 0
    40 2 1 37 0 0 0 1 0
    41 1 1 35.17 0 0 0 1 0
    41 2 1 34.57 0 0 0 1 0
    42 1 0 44.29 1 0 1 1 0
    42 2 0 44.82 1 0 1 1 0
    43 1 0 35.42 1 1 0 0 0
    43 2 0 37.73 1 1 0 0 0
    44 1 0 35.32 1 0 0 0 1
    44 2 0 35.15 1 0 0 0 1
    45 1 1 41.75 0 0 1 0 1
    45 2 1 42.2 0 0 1 0 1
    46 1 0 43.2 0 1 1 1 0
    46 2 0 43.6 0 1 1 1 0
    47 1 0 39.4 1 0 0 1 1
    47 2 0 39.3 1 0 0 1 1
    48 1 0 37.1 0 1 0 1 1
    48 2 0 37.7 0 1 0 1 1
    49 1 1 38.23 0 0 0 1 0
    49 2 1 38.27 0 0 0 1 0
    50 1 1 41.41 0 0 1 1 1
    50 2 1 41.4 0 0 1 1 1
    end
    label values calci0 calci0
    label def calci0 0 "Score <= 0", modify
    label def calci0 1 "Score > 0", modify
    label values age45 age45
    label def age45 0 "Age >=45", modify
    label def age45 1 "Age < 45", modify
    label values sex sex
    label def sex 0 "Men", modify
    label def sex 1 "Women", modify
    label values Ao40 Ao40
    label def Ao40 0 "Ao < 40", modify
    label def Ao40 1 "Ao >=40", modify
    label values raphe raphe
    label def raphe 0 "No Raphe", modify
    label def raphe 1 "Raphe", modify
    label values group group
    label def group 0 "Placebo", modify
    label def group 1 "Atorvastatina", modify
    [/CODE]

  • #2
    Augusto, hi.

    If you are fitting a random intercept model, this would be an approach:


    Code:
    xtmixed rootascmax  i.group i.time i.age45 i.group#i.age45 || id:
    Assumptions/structure:
    1. Time is a categorical variable
    2. The model contains both main and interaction effects

    Comment


    • #3
      It depends on the experimental/observational design underlying your data.

      Your group variable is evidently a treatment-group variable, and it is constant within id. But each id is observed twice, at times 1 and 2. What is unclear is whether the two times correspond to pre-treatment and post-treatment observations, or whether the participant was receiving the same treatment at both occasions. I'm assuming, though you do not say as much, that you are looking to identify whether the atorvastatin treatment is equally effective in both age groups.

      If time 1 represents a pre-treatment observation, and then at time 2 they are given either a placebo or atorvastatin, then the way to handle this would be:
      Code:
      gen byte on_active_treatment = (time == 2) & (group == "Atorvastatina":group)
      mixed rootascmax i.on_active_treatment##i.age45 || id:
      The coefficient of the 1.on_active_treatment#1.age45 term will then be your estimate of the difference between the effect of active treatment on rootascmax and that of placebo among those age <45 and those age >= 45.

      If, however, your participants either received placebo at both times or received atorvastatina at both times, then you have a different design, and the analysis would be:
      Code:
      mixed rootascmax i.group##i.age45 || id:
      In this case, the coefficient of 1.group#1.age45 will be your estimate of the difference between those age < 45 and those age >= 45 in the difference in expected rootascmax between the placebo and atorvastatina groups.

      Note that the command previously called -xtmixed- has been renamed -mixed- (since version 13). Stata still accepts -xtmixed-, but may or may not continue to do so in future versions. Also note the use of the ## notation, rather than #. This makes it easier to specifically estimate the interaction effect itself. (It can also be done with the # notation, but it requires more commands and is somewhat complicated.)

      Added: crossed with #2. Note that the use of i.group i.age45 and i.group#i.age45 is equivalent to using i.group##i.age45. But these are different from i.group#i.age45 without i.group and i.age45. Do read -help fvvarlist-.
      Last edited by Clyde Schechter; 08 Jun 2023, 12:04.

      Comment


      • #4
        Thank you very much to both. The patients in the 2 moments have taken an atorvastatin group and another placebo group. The diameter of the aorta is measured at 2 points in time. What we want to have is a p value of interaction of the atorvastatin group and those under 45 years of age. So the correct model would be: ? mixed rootascmax mixto i.group##i.age45 || identificación:

        Comment


        • #5
          The patients in the 2 moments have taken an atorvastatin group and another placebo group.
          It is not clear to me how this decides between the two designs I distinguished in #3. At time 1, what were the patients in each group taking?

          mixed rootascmax mixto i.group##i.age45 || identificación:
          You have now introduced a new variable, mixto. What is it?

          Comment


          • #6
            One group of patients was given atorvastatin and the other placebo. The measurement of the diameter of the aorta was taken at 2 moments of time and that difference in the response variable. We want to see the interaction between taking atorvastatin and age < 45 years.
            mixed rootascmax i.group##i.age45 || id:

            Comment


            • #7
              So I interpret your response as follows:
              1. There are two study groups, placebo and atorvastatin.
              2. The atorvastatin group received atorvastatin at both times.
              3. The placebo group received placebo at both times.
              So this would be a repeated-measures study to compare a treated and untreated group without pre-treatment baseline measurements.

              On these assumptions, yes, -mixed rootascmax i.group##i.age45 || id:- is the way to go.

              Comment


              • #8
                Thanks a lot for everything

                Comment


                • #9

                  Hello Clyde I apologize for so much inconvenience. I don't understand why there is so much difference in both models. When I create the interaction variable. mixed rootascmax i.group#i.age45 || id: Performing EM optimization: Performing gradient-based optimization: Iteration 0: log likelihood = -867.82953 Iteration 1: log likelihood = -867.82953 Computing standard errors: Mixed-effects ML regression Number of obs = 376 Group variable: id Number of groups = 189 Obs per group: min = 1 avg = 2.0 max = 2 Wald chi2(3) = 30.84 Log likelihood = -867.82953 Prob > chi2 = 0.0000 ----------------------------------------------------------------------------------------- rootascmax | Coef. Std. Err. z P>|z| [95% Conf. Interval] ------------------------+---------------------------------------------------------------- group#age45 | Placebo#Age < 45 | -4.663137 .8613514 -5.41 0.000 -6.351355 -2.974919 Atorvastatina#Age >=45 | -1.418631 .8564527 -1.66 0.098 -3.097248 .2599849 Atorvastatina#Age < 45 | -2.379694 .8426898 -2.82 0.005 -4.031336 -.7280522 | _cons | 43.06357 .5958717 72.27 0.000 41.89568 44.23146 ----------------------------------------------------------------------------------------- ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ id: Identity | var(_cons) | 16.90052 1.791217 13.73044 20.80249 -----------------------------+------------------------------------------------ var(Residual) | .9951468 .1029273 .8125461 1.218783 ------------------------------------------------------------------------------ LR test vs. linear model: chibar2(01) = 415.22 Prob >= chibar2 = 0.0000 gen inter_groupage45=group*age45 mixed rootascmax inter_groupage45 || id: Performing EM optimization: Performing gradient-based optimization: Iteration 0: log likelihood = -881.96047 Iteration 1: log likelihood = -881.96047 Computing standard errors: Mixed-effects ML regression Number of obs = 376 Group variable: id Number of groups = 189 Obs per group: min = 1 avg = 2.0 max = 2 Wald chi2(1) = 0.31 Log likelihood = -881.96047 Prob > chi2 = 0.5782 ---------------------------------------------------------------------------------- rootascmax | Coef. Std. Err. z P>|z| [95% Conf. Interval] -----------------+---------------------------------------------------------------- inter_groupage45 | -.4148131 .7461125 -0.56 0.578 -1.877167 1.04754 _cons | 41.09869 .3799502 108.17 0.000 40.354 41.84338 ---------------------------------------------------------------------------------- ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ id: Identity | var(_cons) | 19.70616 2.079908 16.02363 24.23499 -----------------------------+------------------------------------------------ var(Residual) | .9952134 .1029411 .8125895 1.218881 ------------------------------------------------------------------------------ LR test vs. linear model: chibar2(01) = 441.13 Prob >= chibar2 = 0.0000

                  Comment


                  • #10

                    Sorry for my previous post that the model is not understood. Hello Clyde I apologize for so much inconvenience. I don't understand why there is so much difference in both models. When I create the interaction variable. Attached word file. Thanks
                    Attached Files

                    Comment


                    • #11
                      As you noted, what you posted in #5 is unreadable. The solution, however, is to do it using code delimiters. If you are not familiar with code delimiters and how to use them, please read the Forum FAQ, with special attention to #12.

                      Attachments, in general, are discouraged here. Some of us, including me, will not download or open attachments from people we do not know. This is especially the case for Microsoft Word documents, which are capable of containing active malware.

                      Please try again.

                      Comment


                      • #12

                        Hi Clyde, if I do the interaction manually I get different results. What is the cause of that ? mixed rootascmax i.group##i.age45 || id:

                        gen inter_groupage45=group*age45

                        mixed rootascmax inter_groupage45 || id:

                        Comment


                        • #13
                          Those are not the same thing at all. Remember that i.group##i.age45 expands to i.group i.age45 and i.group#i.age45. Your homebrew interaction term inter_groupage45 corresponds only to i.group#i.age45.

                          Comment

                          Working...
                          X