Hello,
I have a linear mixed model to test the within-subject difference in activity behaviours (eg sleep, sedentary time etc) between 2 different timepoints (school vs. holidays). The trouble is, there is heteroskedasticity in the activity behaviours coming from the timepoint variable.
I'm wondering how I should deal with this? Can I use residuals(, by(timepoint)) to model the heteroskedasticity? Or should I use vce(robust)? Or something else?
I've tried both but I get the same coefficient for the activity behaviour regardless of which of those syntax I run, and this doesn't change from the model without any adjustment for heteroskedasticity.
What am I doing wrong?
Here's what I mean:
. mixed MARCAphysicalactivity i.time_new || wave: || schoolid: || id:, residuals(,by(time_new))
Obtaining starting values by EM ...
Performing gradient-based optimization:
Iteration 0: log likelihood = -1546.7942
Iteration 1: log likelihood = -1531.5529
Iteration 2: log likelihood = -1530.5315
Iteration 3: log likelihood = -1530.4198
Iteration 4: log likelihood = -1530.4172
Iteration 5: log likelihood = -1530.4172
Computing standard errors ...
Mixed-effects ML regression Number of obs = 266
Grouping information
-------------------------------------------------------------
| No. of Observations per group
Group variable | groups Minimum Average Maximum
----------------+--------------------------------------------
wave | 2 124 133.0 142
schoolid | 23 2 11.6 62
id | 133 2 2.0 2
-------------------------------------------------------------
Wald chi2(1) = 3.45
Log likelihood = -1530.4172 Prob > chi2 = 0.0632
---------------------------------------------------------------------------------------
MARCAphysicalactivity | Coefficient Std. err. z P>|z| [95% conf. interval]
----------------------+----------------------------------------------------------------
time_new |
holiday | -16.9201 9.106392 -1.86 0.063 -34.7683 .9281045
_cons | 148.2458 5.242488 28.28 0.000 137.9707 158.5209
---------------------------------------------------------------------------------------
------------------------------------------------------------------------------
Random-effects parameters | Estimate Std. err. [95% conf. interval]
-----------------------------+------------------------------------------------
wave: Identity |
var(_cons) | 3.69e-12 1.11e-10 8.84e-38 1.54e+14
-----------------------------+------------------------------------------------
schoolid: Identity |
var(_cons) | 6.069217 128.3406 6.07e-18 6.06e+18
-----------------------------+------------------------------------------------
id: Identity |
var(_cons) | 1196.898 566.381 473.4367 3025.882
-----------------------------+------------------------------------------------
Residual: Independent, |
by time_new |
school: var(e) | 2382.838 602.2506 1451.969 3910.493
holiday: var(e) | 8646.371 1183.862 6611.306 11307.86
------------------------------------------------------------------------------
LR test vs. linear model: chi2(4) = 38.32 Prob > chi2 = 0.0000
Note: LR test is conservative and provided only for reference.
. mixed MARCAphysicalactivity i.time_new || wave: || schoolid: || id:, vce(robust)
Performing EM optimization ...
Performing gradient-based optimization:
Iteration 0: log pseudolikelihood = -1546.7942
Iteration 1: log pseudolikelihood = -1546.4791
Iteration 2: log pseudolikelihood = -1546.4684
Iteration 3: log pseudolikelihood = -1546.4684
Computing standard errors ...
Mixed-effects regression Number of obs = 266
Grouping information
-------------------------------------------------------------
| No. of Observations per group
Group variable | groups Minimum Average Maximum
----------------+--------------------------------------------
wave | 2 124 133.0 142
schoolid | 23 2 11.6 62
id | 133 2 2.0 2
-------------------------------------------------------------
Wald chi2(1) = 20.08
Log pseudolikelihood = -1546.4684 Prob > chi2 = 0.0000
(Std. err. adjusted for 2 clusters in wave)
---------------------------------------------------------------------------------------
| Robust
MARCAphysicalactivity | Coefficient std. err. z P>|z| [95% conf. interval]
----------------------+----------------------------------------------------------------
time_new |
holiday | -16.9201 3.776363 -4.48 0.000 -24.32163 -9.51856
_cons | 145.6965 .4892915 297.77 0.000 144.7375 146.6555
---------------------------------------------------------------------------------------
------------------------------------------------------------------------------
| Robust
Random-effects parameters | Estimate std. err. [95% conf. interval]
-----------------------------+------------------------------------------------
wave: Identity |
var(_cons) | 1.13e-11 7.10e-09 0 .
-----------------------------+------------------------------------------------
schoolid: Identity |
var(_cons) | 241.3284 215.7017 41.8597 1391.3
-----------------------------+------------------------------------------------
id: Identity |
var(_cons) | 962.7075 272.0551 553.2865 1675.092
-----------------------------+------------------------------------------------
var(Residual) | 5514.618 1806.245 2902.116 10478.91
------------------------------------------------------------------------------
. mixed MARCAphysicalactivity i.time_new || wave: || schoolid: || id:
Performing EM optimization ...
Performing gradient-based optimization:
Iteration 0: log likelihood = -1546.7942
Iteration 1: log likelihood = -1546.4791
Iteration 2: log likelihood = -1546.4684
Iteration 3: log likelihood = -1546.4684
Computing standard errors ...
Mixed-effects ML regression Number of obs = 266
Grouping information
-------------------------------------------------------------
| No. of Observations per group
Group variable | groups Minimum Average Maximum
----------------+--------------------------------------------
wave | 2 124 133.0 142
schoolid | 23 2 11.6 62
id | 133 2 2.0 2
-------------------------------------------------------------
Wald chi2(1) = 3.45
Log likelihood = -1546.4684 Prob > chi2 = 0.0632
---------------------------------------------------------------------------------------
MARCAphysicalactivity | Coefficient Std. err. z P>|z| [95% conf. interval]
----------------------+----------------------------------------------------------------
time_new |
holiday | -16.9201 9.106403 -1.86 0.063 -34.76832 .9281262
_cons | 145.6965 8.127796 17.93 0.000 129.7663 161.6267
---------------------------------------------------------------------------------------
------------------------------------------------------------------------------
Random-effects parameters | Estimate Std. err. [95% conf. interval]
-----------------------------+------------------------------------------------
wave: Identity |
var(_cons) | 1.13e-11 4.08e-10 1.94e-42 6.56e+19
-----------------------------+------------------------------------------------
schoolid: Identity |
var(_cons) | 241.3284 248.5558 32.05642 1816.778
-----------------------------+------------------------------------------------
id: Identity |
var(_cons) | 962.7075 589.5634 289.8794 3197.212
-----------------------------+------------------------------------------------
var(Residual) | 5514.618 676.2449 4336.452 7012.878
------------------------------------------------------------------------------
LR test vs. linear model: chi2(3) = 6.22 Prob > chi2 = 0.1014
Note: LR test is conservative and provided only for reference.
Thanks for your help.
I have a linear mixed model to test the within-subject difference in activity behaviours (eg sleep, sedentary time etc) between 2 different timepoints (school vs. holidays). The trouble is, there is heteroskedasticity in the activity behaviours coming from the timepoint variable.
I'm wondering how I should deal with this? Can I use residuals(, by(timepoint)) to model the heteroskedasticity? Or should I use vce(robust)? Or something else?
I've tried both but I get the same coefficient for the activity behaviour regardless of which of those syntax I run, and this doesn't change from the model without any adjustment for heteroskedasticity.
What am I doing wrong?
Here's what I mean:
. mixed MARCAphysicalactivity i.time_new || wave: || schoolid: || id:, residuals(,by(time_new))
Obtaining starting values by EM ...
Performing gradient-based optimization:
Iteration 0: log likelihood = -1546.7942
Iteration 1: log likelihood = -1531.5529
Iteration 2: log likelihood = -1530.5315
Iteration 3: log likelihood = -1530.4198
Iteration 4: log likelihood = -1530.4172
Iteration 5: log likelihood = -1530.4172
Computing standard errors ...
Mixed-effects ML regression Number of obs = 266
Grouping information
-------------------------------------------------------------
| No. of Observations per group
Group variable | groups Minimum Average Maximum
----------------+--------------------------------------------
wave | 2 124 133.0 142
schoolid | 23 2 11.6 62
id | 133 2 2.0 2
-------------------------------------------------------------
Wald chi2(1) = 3.45
Log likelihood = -1530.4172 Prob > chi2 = 0.0632
---------------------------------------------------------------------------------------
MARCAphysicalactivity | Coefficient Std. err. z P>|z| [95% conf. interval]
----------------------+----------------------------------------------------------------
time_new |
holiday | -16.9201 9.106392 -1.86 0.063 -34.7683 .9281045
_cons | 148.2458 5.242488 28.28 0.000 137.9707 158.5209
---------------------------------------------------------------------------------------
------------------------------------------------------------------------------
Random-effects parameters | Estimate Std. err. [95% conf. interval]
-----------------------------+------------------------------------------------
wave: Identity |
var(_cons) | 3.69e-12 1.11e-10 8.84e-38 1.54e+14
-----------------------------+------------------------------------------------
schoolid: Identity |
var(_cons) | 6.069217 128.3406 6.07e-18 6.06e+18
-----------------------------+------------------------------------------------
id: Identity |
var(_cons) | 1196.898 566.381 473.4367 3025.882
-----------------------------+------------------------------------------------
Residual: Independent, |
by time_new |
school: var(e) | 2382.838 602.2506 1451.969 3910.493
holiday: var(e) | 8646.371 1183.862 6611.306 11307.86
------------------------------------------------------------------------------
LR test vs. linear model: chi2(4) = 38.32 Prob > chi2 = 0.0000
Note: LR test is conservative and provided only for reference.
. mixed MARCAphysicalactivity i.time_new || wave: || schoolid: || id:, vce(robust)
Performing EM optimization ...
Performing gradient-based optimization:
Iteration 0: log pseudolikelihood = -1546.7942
Iteration 1: log pseudolikelihood = -1546.4791
Iteration 2: log pseudolikelihood = -1546.4684
Iteration 3: log pseudolikelihood = -1546.4684
Computing standard errors ...
Mixed-effects regression Number of obs = 266
Grouping information
-------------------------------------------------------------
| No. of Observations per group
Group variable | groups Minimum Average Maximum
----------------+--------------------------------------------
wave | 2 124 133.0 142
schoolid | 23 2 11.6 62
id | 133 2 2.0 2
-------------------------------------------------------------
Wald chi2(1) = 20.08
Log pseudolikelihood = -1546.4684 Prob > chi2 = 0.0000
(Std. err. adjusted for 2 clusters in wave)
---------------------------------------------------------------------------------------
| Robust
MARCAphysicalactivity | Coefficient std. err. z P>|z| [95% conf. interval]
----------------------+----------------------------------------------------------------
time_new |
holiday | -16.9201 3.776363 -4.48 0.000 -24.32163 -9.51856
_cons | 145.6965 .4892915 297.77 0.000 144.7375 146.6555
---------------------------------------------------------------------------------------
------------------------------------------------------------------------------
| Robust
Random-effects parameters | Estimate std. err. [95% conf. interval]
-----------------------------+------------------------------------------------
wave: Identity |
var(_cons) | 1.13e-11 7.10e-09 0 .
-----------------------------+------------------------------------------------
schoolid: Identity |
var(_cons) | 241.3284 215.7017 41.8597 1391.3
-----------------------------+------------------------------------------------
id: Identity |
var(_cons) | 962.7075 272.0551 553.2865 1675.092
-----------------------------+------------------------------------------------
var(Residual) | 5514.618 1806.245 2902.116 10478.91
------------------------------------------------------------------------------
. mixed MARCAphysicalactivity i.time_new || wave: || schoolid: || id:
Performing EM optimization ...
Performing gradient-based optimization:
Iteration 0: log likelihood = -1546.7942
Iteration 1: log likelihood = -1546.4791
Iteration 2: log likelihood = -1546.4684
Iteration 3: log likelihood = -1546.4684
Computing standard errors ...
Mixed-effects ML regression Number of obs = 266
Grouping information
-------------------------------------------------------------
| No. of Observations per group
Group variable | groups Minimum Average Maximum
----------------+--------------------------------------------
wave | 2 124 133.0 142
schoolid | 23 2 11.6 62
id | 133 2 2.0 2
-------------------------------------------------------------
Wald chi2(1) = 3.45
Log likelihood = -1546.4684 Prob > chi2 = 0.0632
---------------------------------------------------------------------------------------
MARCAphysicalactivity | Coefficient Std. err. z P>|z| [95% conf. interval]
----------------------+----------------------------------------------------------------
time_new |
holiday | -16.9201 9.106403 -1.86 0.063 -34.76832 .9281262
_cons | 145.6965 8.127796 17.93 0.000 129.7663 161.6267
---------------------------------------------------------------------------------------
------------------------------------------------------------------------------
Random-effects parameters | Estimate Std. err. [95% conf. interval]
-----------------------------+------------------------------------------------
wave: Identity |
var(_cons) | 1.13e-11 4.08e-10 1.94e-42 6.56e+19
-----------------------------+------------------------------------------------
schoolid: Identity |
var(_cons) | 241.3284 248.5558 32.05642 1816.778
-----------------------------+------------------------------------------------
id: Identity |
var(_cons) | 962.7075 589.5634 289.8794 3197.212
-----------------------------+------------------------------------------------
var(Residual) | 5514.618 676.2449 4336.452 7012.878
------------------------------------------------------------------------------
LR test vs. linear model: chi2(3) = 6.22 Prob > chi2 = 0.1014
Note: LR test is conservative and provided only for reference.
Thanks for your help.
Comment