How to set up a joint model correctly (repeated measures - outcome (1) and a later distal outcome (2))

Welcome to the forum for runmlwin users. Feel free to post your question about runmlwin here. The Centre for Multilevel Modelling take no responsibility for the accuracy of these posts, we are unable to monitor them closely. Do go ahead and post your question and thank you in advance if you find the time to post any answers!

Go to runmlwin: Running MLwiN from within Stata >> http://www.bristol.ac.uk/cmm/software/runmlwin/
Post Reply
GemmaWolves
Posts: 1
Joined: Fri Jan 13, 2023 3:11 pm

How to set up a joint model correctly (repeated measures - outcome (1) and a later distal outcome (2))

Post by GemmaWolves »

Hi, I'm trying to fit a joint/multivariate model with one outcome measured repeatedly and the second outcome measured later on in order to try to answer does weight in childhood predict (or relate to) SBP in early adulthood?

There are 6 clinics with weight (outcome 1 - repeatedly measured) being measured in the first 5 and SBP (outcome 2 – measured once as a ‘distal’ outcome) measured at the 6th clinic. The model written out with some simulated data is attached.

The code I thought would work is this but it gives me a log likelihood error :

Code: Select all

runmlwin ///
(weight cons clinic, eq(1)) ///
(sbp cons, eq(2)), ///
level2(id: (clinic cons, eq(1)) (cons, eq(2))) ///
level1(clinic: (cons, eq(1))) nopause
I can fit this model via an sem framework (model code attached) but struggling to fit the same model in a multilevel model framework. Do you know where I’m going wrong? Is my data in the wrong format?

Thanks in advance
Attachments
example_weight_sbp.csv
Example (simulated) data
(78.7 KiB) Downloaded 114 times
Model.docx
(14.88 KiB) Downloaded 115 times
Equivalent SEM model.docx
(14.06 KiB) Downloaded 116 times
ChrisCharlton
Posts: 1348
Joined: Mon Oct 19, 2009 10:34 am

Re: How to set up a joint model correctly (repeated measures - outcome (1) and a later distal outcome (2))

Post by ChrisCharlton »

I asked George about this and he recommended the following method of replicating the model in MLwiN:

Code: Select all

// create variable to represent the intercept
generate cons = 1

// combine weight and sbp responses into a single column
capture drop y
replace weight = 0 if weight == .
replace sbp = 0 if sbp ==.
generate y = weight + sbp
drop weight sbp

// move variables of interest to the start of the data
order id clinic y cons

// generate indicator for which row corresponds to each response
// value == 1 for "weight" response, value == 2 for "sbp" response
generate resp = 1 + (clinic == 10)

// generate r1, value == 1 for "weight" response, zero otherwise
// generate r2, value == 1 for "sbp" response, zero otherwise
tabulate resp, generate(r)

// predictors filtered for "weight" response
generate r1Xcons = r1*cons
generate r1Xclinic = r1*clinic

// predictors filtered for "ebp" response
generate r2Xcons = r2*cons

// combined response model
runmlwin y r1Xcons r1Xclinic r2Xcons, level2(id: r1Xcons r1Xclinic r2Xcons) level1(clinic: r1Xcons) nopause

Code: Select all

MLwiN 3.06 multilevel model                     Number of obs      =      4650
Normal response model (hierarchical)
Estimation algorithm: IGLS

-----------------------------------------------------------
                |   No. of       Observations per Group
 Level Variable |   Groups    Minimum    Average    Maximum
----------------+------------------------------------------
             id |      775          6        6.0          6
-----------------------------------------------------------

Run time (seconds)   =       0.97
Number of iterations =          2
Log likelihood       = -14545.649
Deviance             =  29091.298
------------------------------------------------------------------------------
           y |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
     r1Xcons |   26.38501   .2011492  131.17    0.000     25.99076    26.77925
   r1Xclinic |   4.083665   .0421116   96.97    0.000     4.001127    4.166202
     r2Xcons |    128.072   .2120958  603.84    0.000     127.6563    128.4877
------------------------------------------------------------------------------

------------------------------------------------------------------------------
   Random-effects Parameters |   Estimate   Std. Err.     [95% Conf. Interval]
-----------------------------+------------------------------------------------
Level 2: id                  |
                var(r1Xcons) |   21.83627   1.617242      18.66653      25.006
      cov(r1Xcons,r1Xclinic) |   3.305099   .2481617      2.818711    3.791487
              var(r1Xclinic) |    .977666   .0707812      .8389374    1.116395
        cov(r1Xcons,r2Xcons) |   16.27911   1.323837      13.68444    18.87378
      cov(r1Xclinic,r2Xcons) |   2.146946   .2603331      1.636703     2.65719
                var(r2Xcons) |   34.86309   1.771047      31.39191    38.33428
-----------------------------+------------------------------------------------
Level 1: clinic              |
                var(r1Xcons) |   15.86836   .4654099      14.95617    16.78055
------------------------------------------------------------------------------
This is a slightly different parameterisation to your SEM model example. The equivalent SEM model would be:

Code: Select all

sem ///
	(weight0 <- _cons@0 Intercept@1 Slope@0) ///
	(weight2 <- _cons@0 Intercept@1 Slope@2) ///
	(weight4 <- _cons@0 Intercept@1 Slope@4) ///
	(weight6 <- _cons@0 Intercept@1 Slope@6) ///
	(weight8 <- _cons@0 Intercept@1 Slope@8) ///
	(sbp <- Intercept_r2), ///
	latent(Intercept Slope Intercept_r2) ///
	means(Intercept Slope) ///
	var(Intercept Slope) ///
	cov(Intercept*Slope) ///
	var(e.sbp@0 e.weight0@fix e.weight2@fix e.weight4@fix e.weight6@fix e.weight8@fix)

Code: Select all

Structural equation model                                  Number of obs = 775
Estimation method: ml

Log likelihood = -14545.649

 ( 1)  [weight0]Intercept = 1
 ( 2)  [weight2]Intercept = 1
 ( 3)  [weight2]Slope = 2
 ( 4)  [weight4]Intercept = 1
 ( 5)  [weight4]Slope = 4
 ( 6)  [weight6]Intercept = 1
 ( 7)  [weight6]Slope = 6
 ( 8)  [weight8]Intercept = 1
 ( 9)  [weight8]Slope = 8
 (10)  [sbp]Intercept_r2 = 1
 (11)  [/]var(e.weight0) - [/]var(e.weight8) = 0
 (12)  [/]var(e.weight2) - [/]var(e.weight8) = 0
 (13)  [/]var(e.weight4) - [/]var(e.weight8) = 0
 (14)  [/]var(e.weight6) - [/]var(e.weight8) = 0
 (15)  [/]var(e.sbp) = 0
 (16)  [weight0]_cons = 0
 (17)  [weight2]_cons = 0
 (18)  [weight4]_cons = 0
 (19)  [weight6]_cons = 0
 (20)  [weight8]_cons = 0
--------------------------------------------------------------------------------------------
                           |                 OIM
                           | Coefficient  std. err.      z    P>|z|     [95% conf. interval]
---------------------------+----------------------------------------------------------------
Measurement                |
  weight0                  |
                 Intercept |          1  (constrained)
                     _cons |          0  (constrained)
  -------------------------+----------------------------------------------------------------
  weight2                  |
                 Intercept |          1  (constrained)
                     Slope |          2  (constrained)
                     _cons |          0  (constrained)
  -------------------------+----------------------------------------------------------------
  weight4                  |
                 Intercept |          1  (constrained)
                     Slope |          4  (constrained)
                     _cons |          0  (constrained)
  -------------------------+----------------------------------------------------------------
  weight6                  |
                 Intercept |          1  (constrained)
                     Slope |          6  (constrained)
                     _cons |          0  (constrained)
  -------------------------+----------------------------------------------------------------
  weight8                  |
                 Intercept |          1  (constrained)
                     Slope |          8  (constrained)
                     _cons |          0  (constrained)
  -------------------------+----------------------------------------------------------------
  sbp                      |
              Intercept_r2 |          1  (constrained)
                     _cons |    128.072   .2120958   603.84   0.000     127.6563    128.4877
---------------------------+----------------------------------------------------------------
            mean(Intercept)|   26.38501   .2011492   131.17   0.000     25.99076    26.77925
                mean(Slope)|   4.083665   .0421116    96.97   0.000     4.001127    4.166202
---------------------------+----------------------------------------------------------------
             var(e.weight0)|   15.86836   .4654099                       14.9819    16.80727
             var(e.weight2)|   15.86836   .4654099                       14.9819    16.80727
             var(e.weight4)|   15.86836   .4654099                       14.9819    16.80727
             var(e.weight6)|   15.86836   .4654099                       14.9819    16.80727
             var(e.weight8)|   15.86836   .4654099                       14.9819    16.80727
                 var(e.sbp)|          0  (constrained)
             var(Intercept)|   21.83627   1.617242                      18.88585    25.24761
                 var(Slope)|    .977666   .0707812                      .8483306     1.12672
          var(Intercept_r2)|   34.86309   1.771047                      31.55912    38.51297
---------------------------+----------------------------------------------------------------
       cov(Intercept,Slope)|   3.305099   .2481617    13.32   0.000     2.818711    3.791487
cov(Intercept,Intercept_r2)|   16.27911   1.323837    12.30   0.000     13.68444    18.87378
    cov(Slope,Intercept_r2)|   2.146946   .2603331     8.25   0.000     1.636703     2.65719
--------------------------------------------------------------------------------------------
LR test of model vs. saturated: chi2(17) = 1464.49                      Prob > chi2 = 0.0000
tonyadams
Posts: 6
Joined: Fri Jun 16, 2023 9:24 am

Re: How to set up a joint model correctly (repeated measures - outcome (1) and a later distal outcome (2))

Post by tonyadams »

From my point of view, missing data can cause log likelihood errors. poeltl unlimited
Post Reply