Announcement

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

  • Adjusted mean difference from mixed model

    Dear Statalisters
    I have a longitudinal dataset with three groups (exposed group, sibling control, community control) and data was collected at two time points (baseline and endline). I want to see how a biomarker changes between the time points across groups adjusted for age, gender weight and height. I intended to do linear mixed model followed by the margins command. I am not sure what estimate to use as my adjusted mean difference when presenting the results; should I use the coefficient from the mixed model or the margins from margins command. Or how do I marry the mixed model output with margins output.

    Thanks,
    Oscar

  • #2
    Well, first of all, you don't have a single adjusted mean difference in this design: you have a difference between exposed and sibling control, and you have another, probably different, difference between exposed and community control. You will need to present those separately. If they are close, then you can ultimately combine them for subsequent work, but you still need to report them separately at first. Or perhaps you are interested in a difference in differences: change in the biomarker over time contrasted across the three groups.

    You don't show example data, nor do you show the code you plan to use for your linear mixed model, so it's hard to give specific advice. But assuming you have a grouping variable that looks something like 1 = exposed, 2 = sibling control, 3 = community control, and a timing variable that looks something like 0 = baseline, 1 = follow-up, then your mixed model is going to look something like this:
    Code:
    mixed outcome_variable ib1.group##i.time c.age i.gender c.weight c.height || person_id_variable:
    (It will be more complicated than that if you are using matched controls.)

    Then for the adjusted mean differences between the exposed group and the two controls at each time would be given by the output from:
    Code:
    margins time, dydx(group)
    And for the adjusted mean differences over time contrasted across the groups:
    Code:
    margins group, dydx(time)
    So your first task is to figure out which adjusted mean difference you are interested in. And then you can choose the corresponding code.

    If you need more specific advice, be sure to provide a clear description of what you are looking for, and be sure to include example data. Do the latter with the -dataex- command. If you are running version 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    Comment


    • #3
      Thanks Clyde,
      Code:
      mixed outcome_variable ib1.group##i.time c.age i.gender c.weight c.height || person_id_variable:
      (It will be more complicated than that if you are using matched controls.)
      I was planning to use this command but then you have brought a very important aspect of matched controls, indeed these control were age matched for sibling (obviously the age bracket was wide on this one) while community controls were age and sex matched.

      Below is example dataset, the main aim of my study is to determine the biomarker changes across the groups over time ultimately how does the exposure status affect the biomarker? Another outcome is to determine association of exposure status to growth (haz variable in the dataset) over time, therefore I have included it in case the commands would be different form the biomarker one.

      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input int pid float(group time) byte gender double(age height weight muac) float biomarker double haz
      5002 1 0 0    8.9288158416748           121.45      21.4     171.5  .9339875 -1.74
      5002 1 1 0   12.6511631011962        146.35001 39.549999       210  .8661785 -1.22
      5003 1 0 0   12.3812456130981 127.449999999999     24.45       171  .9330645 -3.76
      5003 1 1 0   14.1422710418701           143.45 32.900002       224  .8213552 -2.41
      5005 3 0 1   9.62970542907714           108.05      17.5       164   .967803 -4.46
      5005 3 1 1    15.948016166687            127.1 26.799999    200.05  .9185484 -5.87
      5008 3 0 0   13.3778238296508              139      31.8     207.5  .9804992 -2.71
      5008 3 1 0   16.9056091308593              157     57.25       280   .811152  -.87
      5011 1 0 1   10.1498975753784            125.6     23.65       173  .9152811 -2.02
      5011 1 1 1                 13              148 36.599998         .  .8463087 -1.08
      5013 2 0 0   11.4175224304199            129.2      27.5       198  .8547781 -2.74
      5013 2 1 0                 12           154.25 46.400002     185.5  .8498074   .44
      5015 1 0 1   10.2402467727661           126.75      24.9     180.5   .814166  -1.9
      5015 1 1 1   14.1668949127197           154.05 42.425003 240.35001  .9054054 -1.32
      5016 2 0 1   10.7111568450927           132.35     30.95       190  .9122024 -1.38
      5016 2 1 1                 13           153.55        50 260.34998  .8456892  -.34
      5017 3 0 1   6.06502389907836              104     16.25     150.5  .9580838 -2.49
      5017 3 1 1   8.82900142669677            128.5    25.775 180.79999  .8852459  -.53
      5023 1 0 1   9.95824813842773           117.45     19.45     158.5   .985022 -3.16
      5023 1 1 1   13.6826267242431        144.39999     31.75       180  .7910448 -2.18
      5024 1 0 0   9.99657726287841            119.8      21.2     168.5  .8127555 -2.94
      5024 1 1 0                 14        150.10001 43.299999         .  .9078947  -1.4
      5025 3 0 1   8.04448986053466           118.45     20.75       155  .9487847  -1.6
      5025 3 1 1   11.8440494537353            148.2     37.75 200.10001  .9315069   .02
      5027 1 0 0    9.0410680770874           123.85     20.75       161  .9017782 -1.45
      5027 1 1 0   12.8235292434692            155.5      38.5         .  .9333333  -.01
      5028 3 0 0   13.5448322296142           136.05      29.3       188  .8186416 -3.22
      5028 3 1 0                 17            158.7 42.700001         .  .8918919  -.62
      5029 3 0 1   9.19164943695068           115.45     19.75       158 1.0070361 -2.98
      5029 3 1 1   11.0205202102661        131.89999    25.975     169.5  .9226562 -1.68
      5032 1 0 1   9.65434646606445            120.7     27.75       211  .9773071 -2.45
      5032 1 1 1    13.417236328125            138.5        41       230  .8783784 -2.73
      5034 3 0 0   8.15674209594726           119.25     23.25       185   .898469 -1.41
      5034 3 1 0   11.9206562042236            150.5 43.799999       232  .8607595  -.04
      5038 1 0 1   12.4852838516235            133.5      26.8     180.4  .9420881  -2.6
      5038 1 1 1    16.246238708496              161 47.299999       240  .9857143 -1.63
      5040 3 0 1   14.9082822799682            142.6        34       205  .8839663 -3.32
      5040 3 1 1   18.6675777435302            163.5 60.574997       290  .9036145 -1.76
      5042 2 0 1   11.4640655517578            134.5        25       164  .9173623 -1.64
      5042 2 1 1   16.1723670959472            159.5 53.415001       250  .8961039 -1.79
      5044 3 0 0   13.7967147827148           142.65      34.9       221  .8271605 -2.39
      5044 3 1 0   17.5595073699951            158.5 63.025002     289.5  .9574468  -.67
      5046 1 0 0   9.79671478271484           120.75     21.75       178  .9042553 -2.62
      5046 1 1 0   13.5595073699951           146.05 42.400002       230  .8815789 -1.79
      5047 2 0 1   9.23271751403808           110.25        19     172.5        .9 -3.86
      5047 2 1 1   10.9521207809448              133     28.35         .  .9538816 -1.47
      5048 1 0 0    9.0958251953125            119.1     20.35       156  .8070319 -2.28
      5048 1 1 0   12.8673048019409              155 43.049999 210.60001  .7723676  -.11
      5049 1 0 0   9.49828910827636            125.4     20.95     155.5  .9099485 -1.62
      5049 1 1 0   13.3160057067871            152.5 41.700001         .  .9358974  -.74
      5050 3 0 0    10.147159576416           129.25      23.5       171  .7853107  -1.6
      5050 3 1 0   13.9179210662841           153.05      41.5       220   .865423  -.94
      5051 3 0 1   7.70499658584594           120.65      20.5       147  .9329321   -.9
      5051 3 1 1   11.5212039947509              147 33.299999         .  .8854467   .13
      5052 3 0 0   7.48596858978271              116     19.55     165.5  .7359882 -1.35
      5052 3 1 0   11.2585496902465              150        42       230  .8407524    .5
      5053 2 0 1   9.53388118743896            139.7      31.7     198.5  .7934272    .7
      5053 2 1 1   12.9849519729614              157      44.5 230.39999  .9206667   .14
      5054 1 0 1   10.7494869232177            118.9      23.3     175.5  .9659982 -3.44
      5054 1 1 1   13.9890556335449              149        39       231  .8631945 -1.83
      5056 3 0 0   8.41683769226074            110.9      18.9       169   .933804 -3.05
      5056 3 1 0  8.760601997375488              117        20     169.5  .9649123 -2.33
      5057 1 0 1   12.9945240020751            131.2      26.7       174  .8398792 -3.34
      5057 1 1 1   17.6470584869384            156.5 45.900002         .  .8852565 -2.57
      5059 3 0 1   9.80218982696533            123.6     21.55       156     .8384 -2.09
      5059 3 1 1  14.73050594329834              142     32.32         .  .8592858 -3.28
      5063 1 0 0   9.27926063537597           124.55      23.8     180.1  .9281537 -1.56
      5063 1 1 0   13.0998630523681            147.5 38.974998 210.64999  .7948718 -1.34
      5064 3 0 1    7.6447639465332           102.35      17.5       175 1.0360444 -4.16
      5064 3 1 1   11.5294113159179              128      27.6    190.25 2.2307692 -2.63
      5065 1 0 1   9.86242294311523           119.95     21.05     163.5  .8547718 -2.71
      5065 1 1 1   12.9986324310302            140.5 31.799999         . 2.2222223 -2.09
      5066 2 0 1   8.66872024536132           117.55      23.8     181.5  .9202842 -2.25
      5066 2 1 1 12.467852592468262              133 36.650002     210.8         . -2.65
      5067 1 0 1   8.97262191772461           119.55      20.6     155.5   .873385 -2.14
      5067 1 1 1   12.8290014266967        141.85001      31.4         .  .8970588 -1.76
      5069 1 0 1   9.66255950927734           130.95      26.2     181.5  .8446526  -.81
      5069 1 1 1   13.4993162155151        152.10001    40.875 230.14999  .8205128    -1
      5070 1 0 1   9.46269702911377            111.9     17.65     145.5  .9516729 -3.74
      5070 1 1 1   13.4117650985717        140.39999      32.5     180.7  2.142857 -2.47
      5072 3 0 0   7.63107442855835            105.1      14.2       133  .9373777  -3.4
      5072 3 1 0   11.6470584869384              137    28.875 170.85001  2.054054 -1.78
      5074 1 0 1   9.09856224060058              128     21.55       172  .8904448  -.84
      5074 1 1 1   12.9165525436401              138 31.549999    190.05  .9136331 -2.36
      5076 3 0 1   13.6570844650268           142.85      34.6     202.5  .8518258 -2.36
      5076 3 1 1                 17              160    54.125 260.65002  .8137363 -1.98
      5077 1 0 1   9.42710494995117           126.15     22.15     175.5  .8380567  -1.4
      5077 1 1 1   12.2845420837402           146.45      31.5 198.10001  .8509407  -.63
      5078 2 0 0   9.87063694000244            124.9     23.65     180.1  .9319502 -2.03
      5078 2 1 0                 13              150 48.349998 263.79999  .9150327  -.92
      5079 3 0 1   5.25462007522583           102.35     14.75     160.5  .9601197 -1.94
      5079 3 1 1   9.11354351043701        132.79999 24.860001       175  .8486312  -.06
      5080 1 0 1   9.71184158325195           119.15     24.35     182.5 1.0244726 -2.73
      5080 1 1 1   11.0998630523681        137.64999        29       180  .9384615  -.89
      5081 1 0 0   9.08213520050048           108.45     18.05     161.5  .9973214    -4
      5081 1 1 0     11.93980884552           123.45      25.1       189   .925456 -4.02
      5082 1 0 0   9.34770679473877           119.55     21.23     165.5  .9598326 -2.42
      5082 1 1 0   7.01504802703857           136.75      28.4 190.10001   .904908   2.9
      5083 2 0 0   9.54483222961425           114.35     18.95       161  .9460654 -3.42
      5083 2 1 0   11.8850889205932        131.70001        26 180.39999  .8619739 -2.76
      end
      label values group group
      label def group 1 "Exposed", modify
      label def group 2 "Community", modify
      label def group 3 "Sibling", modify
      label values gender sex
      label def sex 0 "Female", modify
      label def sex 1 "Male", modify
      Thanks,
      Oscar

      Comment


      • #4
        OK but you're missing a key variable here: you need a variable that identifies which matched triplet each individual belongs to. If you don't have that variable in your full data set, you are in trouble because you cannot correctly analyze matched data without it.

        I'll assume you have it and it's called triplet.

        Code:
        mixed biomarker i.group##i.time i.age i.gender c.weight c.height || triplet: || pid:
        margins group, dydx(time)
        margins group, dydx(time) pwcompare(effect)
        The first margins command will give you the adjusted mean difference in biomarkers between times 0 and 1 in each group. The second one will give you contrasts among the groups on that adjusted mean difference.

        The handling of the haz variable would be entirely analogous: just replace biomarker by haz.

        Comment


        • #5
          Thanks Clyde,
          This is very helpful. I will check the identifier for matching in the primary dataset.

          Oscar

          Comment


          • #6
            Originally posted by Clyde Schechter View Post
            Well, first of all, you don't have a single adjusted mean difference in this design: you have a difference between exposed and sibling control, and you have another, probably different, difference between exposed and community control. You will need to present those separately. If they are close, then you can ultimately combine them for subsequent work, but you still need to report them separately at first. Or perhaps you are interested in a difference in differences: change in the biomarker over time contrasted across the three groups.

            You don't show example data, nor do you show the code you plan to use for your linear mixed model, so it's hard to give specific advice. But assuming you have a grouping variable that looks something like 1 = exposed, 2 = sibling control, 3 = community control, and a timing variable that looks something like 0 = baseline, 1 = follow-up, then your mixed model is going to look something like this:
            Code:
            mixed outcome_variable ib1.group##i.time c.age i.gender c.weight c.height || person_id_variable:
            (It will be more complicated than that if you are using matched controls.)

            Then for the adjusted mean differences between the exposed group and the two controls at each time would be given by the output from:
            Code:
            margins time, dydx(group)
            And for the adjusted mean differences over time contrasted across the groups:
            Code:
            margins group, dydx(time)
            So your first task is to figure out which adjusted mean difference you are interested in. And then you can choose the corresponding code.

            If you need more specific advice, be sure to provide a clear description of what you are looking for, and be sure to include example data. Do the latter with the -dataex- command. If you are running version 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.
            Dear Clyde,

            I was looking for same solution ans found your answer very useful. However, what if i want to compare four adjusted means for their statistical significance accross groups , would Lincom be useful here ?

            Thanks in advance

            Comment


            • #7
              If you are referring to adjusted mean outcomes in a group##time interaction model like the one discussed in the beginning of this thread, you can use exactly the same code as shown there: it does not depend on the number of groups or number of time periods. It will give you all pairwise comparisons.

              If you are looking for an omnibus test of equality of four means, you will have to say what the four groups you want to compare are. The -test- command will handle it with appropriate syntax, but the syntax will depend on what the particular variables involved are.

              Comment


              • #8
                Many thanks Clyde.

                Comment


                • #9
                  Originally posted by Clyde Schechter View Post
                  If you are referring to adjusted mean outcomes in a group##time interaction model like the one discussed in the beginning of this thread, you can use exactly the same code as shown there: it does not depend on the number of groups or number of time periods. It will give you all pairwise comparisons.

                  If you are looking for an omnibus test of equality of four means, you will have to say what the four groups you want to compare are. The -test- command will handle it with appropriate syntax, but the syntax will depend on what the particular variables involved are.


                  I have a mixed effect model with unequal repeated measures range from time 1 to time 20. However, all subjects have at least two measurements pre-and-post treatment. My outcome and exposure is continous. I have three fixed effect baseline variables and two random effect i.e. subjects and having condition_A at baseline. I have the code

                  Code:
                   xtset ID time_point
                  Code:
                   xtmixed oucome c.exposure##i.time_point i.VAR_1 i.VAR_2 i.VAR_3 || ID: || i.condition_A:
                  i have TWO questions here:

                  1) i want percentage change in outcome as an output so for that i took log of the outcome variable and run the regression model with this log variable to obtain a % change in the dependen variable.


                  Code:
                   g ln_oucome=ln(oucome)
                  and then


                  Code:
                   di (exp(coefficient)-1)*100
                  Am i making sense ?

                  2) I notice with time interaction i can have effect of exposure on outcome at diffrent time points. I dont know how to get average effect of exposure on change in dependent variable. I have upto 20 time_points and with each time points the percentage change increases. So the end result for which i am looking is adjusted percentage change like " per unit increasse in exposure associated with NN % (95% CI NN - NN ) change.

                  Comment


                  • #10
                    With regard to question 1, what you show is correct.

                    With regard to question 2, you can get an average marginal effect of exposure on ln_outcome with the command -margins, dydx(exposure)-. This is equivalent to a semi-elasticity, which you can then transform to an aver percentage change using the same formula you mentioned in your first question.

                    That said, I question your underlying model. From its name, and the way you refer to a person "having it" I infer that condition_A is some dichotomous variable. While it is perfectly legal to use such a variable as a random effect, it rarely makes good statistical sense to do so. With only two values, you are, in effect making inferences from an N of 2 sample of condition_A-space. Such inferences will be very inexact, at best. If this is indeed a dichotomous variable, it would make more sense just to include it as a fixed effect in the model.

                    Finally, -xtmixed- was renamed to -mixed- several versions back. While there is no harm in using the older name, which is still supported, you probably should start using the modern name; at some future time Stata may stop recognizing the older name.

                    Comment

                    Working...
                    X