Announcement

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

  • Mixed effect model

    Hi Stata experts,

    I have a longitudinal dataset with outcome recorded at 8 timepoints and exposure recorded at just 4 timepoints. How to build a mixed effect model with just baseline predictor values and outcome values at all timepoints? I appreciate your help. Thank you so much!!

  • #2
    Can we do this by converting dataset in wideformat? Or is it possible to carry out in long format?

    Comment


    • #3
      Anjana:
      the issue here is that you have missing values for 4 out of 8 timepoints.
      As such, if you keep -exposure- in the dataset in -long- format, all the observations with missing values in any variable will be omitted (listwise deletion, you know).
      I do not get how -reshape- from -long- to -wide- can do the trick, also considering that panel data commands work at their best when data are in -long- format.
      Kind regards,
      Carlo
      (StataNow 18.5)

      Comment


      • #4
        Thank you so much for the response, Carlo! I appreciate it. Can you please let me know how to generate the below graph?

        Comment


        • #5
          Can you please let me know how to plot this graph in Stata?

          Comment


          • #6
            The below graph: x axis would be our predictor var only at baseline and y axis would be values of outcome, the 4 lines would be our timepoints for our outcome variable.
            Attached Files

            Comment


            • #7
              Anjana:
              see the [G2] graph twoway scatteri entry in Stata .pdf manual.
              Kind regards,
              Carlo
              (StataNow 18.5)

              Comment


              • #8
                Hi Carlo,

                Can we plot these twoway graphs with multiple imputation estimates? Thank you so much!!

                Kind regards,
                Anjana

                Comment


                • #9
                  Anjana:
                  when you go -mi- you obtain different fully imputed datasets (in addition to the original one plagued with missing values). Hence, you can have as many graphs as the number of your datasets, as you can see from the following toy-example:
                  Code:
                  . webuse mheart5
                  (Fictional heart attack data)
                  
                  . mi set mlong
                  
                  . mi register imputed age bmi
                  (28 m=0 obs. now marked as incomplete)
                  
                  . set seed 29390
                  
                  . mi impute mvn age bmi = attack smokes hsgrad female, add(10)
                  
                  Performing EM optimization:
                  note: 12 observations omitted from EM estimation because of all imputation variables missing
                    observed log likelihood = -651.75868 at iteration 7
                  
                  Performing MCMC data augmentation ...
                  
                  Multivariate imputation                     Imputations =       10
                  Multivariate normal regression                    added =       10
                  Imputed: m=1 through m=10                       updated =        0
                  
                  Prior: uniform                               Iterations =     1000
                                                                  burn-in =      100
                                                                  between =      100
                  
                  ------------------------------------------------------------------
                                     |               Observations per m            
                                     |----------------------------------------------
                            Variable |   Complete   Incomplete   Imputed |     Total
                  -------------------+-----------------------------------+----------
                                 age |        142           12        12 |       154
                                 bmi |        126           28        28 |       154
                  ------------------------------------------------------------------
                  (complete + incomplete = total; imputed is the minimum across m
                   of the number of filled-in observations.)
                  
                  . mi estimate: logistic attack smokes age bmi hsgrad female
                  
                  Multiple-imputation estimates                   Imputations       =         10
                  Logistic regression                             Number of obs     =        154
                                                                  Average RVI       =     0.0835
                                                                  Largest FMI       =     0.2642
                  DF adjustment:   Large sample                   DF:     min       =     139.75
                                                                          avg       =  19,591.87
                                                                          max       =  67,578.07
                  Model F test:       Equal FMI                   F(   5, 4836.6)   =       3.32
                  Within VCE type:          OIM                   Prob > F          =     0.0054
                  
                  ------------------------------------------------------------------------------
                        attack |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                  -------------+----------------------------------------------------------------
                        smokes |   1.187152   .3623514     3.28   0.001     .4768502    1.897453
                           age |   .0315179   .0163884     1.92   0.055    -.0006696    .0637055
                           bmi |   .1090419   .0516554     2.11   0.037     .0069434    .2111404
                        hsgrad |   .1712372   .4054594     0.42   0.673     -.623472    .9659464
                        female |   -.065744   .4156809    -0.16   0.874    -.8804781    .7489901
                         _cons |  -5.369962   1.863821    -2.88   0.005    -9.054895   -1.685029
                  ------------------------------------------------------------------------------
                  
                  . twoway (scatter bmi age), by(_mi_m)
                  
                  
                  .
                  Attached Files
                  Kind regards,
                  Carlo
                  (StataNow 18.5)

                  Comment


                  • #10
                    Hi Carlo,

                    Thank you so much for the kind response! Unfortunately, I'm unable open the graph attached, Stata says that the "graph is in a new format and this version of stata does not know how to read it".

                    I've another question please. I'm trying to plot the example graph which I had sent earlier in this thread. Please see my code below. Could you please guide me how to plot the above graph after running the mixed command. In the example graph, Indpendent var: exercise, dependent var: mood and lines would represent 4 timepoints whereas in the example graph the lines representing states. I'm working on longitudinal dataset where patients are followed up from 0 months through 90 months, we have recorded exercise and mood at 4 timepoints. we need to see the slopes for each time point. I've carried out multiple imputation for some of the variables by MICE. I appreciate your insights and advice on this please. Thank you so much!!

                    [ mi estimate: mixed mood exercise i.Timepoint || ptid: Timepoint]

                    Kind regards,
                    Anjana

                    Comment


                    • #11
                      Hi Carlo,

                      Another question please, when I tried to plot residuals and fitted values with the below code, I got an error message saying that "file miest.ster not found". My question here is what filename do we need to specify after the keyword "using"

                      [mi predictnl predicted_probability = normal(xb()) using miest]

                      Thank you so much!!

                      Kind regards,
                      Anjana
                      [Stata 15.1]

                      Comment


                      • #12
                        Anjana:
                        I cannot be of any help for the graph.
                        As far as your code is concerned, you should have saved -miest- as a .dta file before invoking it.
                        Please take a look at -help mi_predict-.
                        Kind regards,
                        Carlo
                        (StataNow 18.5)

                        Comment

                        Working...
                        X