[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: specifying random effects in -xtmixed- for pretest/posttest clustered design

From   "Joseph Coveney" <>
To   <>
Subject   st: RE: specifying random effects in -xtmixed- for pretest/posttest clustered design
Date   Sat, 4 Apr 2009 10:31:57 +0900

Michael I. Lichter wrote:

I am having difficulties figuring out how to specify the random effects 
in -xtmixed- for my study design, and I haven't been able to find 
anything helpful in the archives or the manual.

My study is a standard cluster-randomized, two-condition, two-time-point 
trial with balanced allocation of clusters to conditions and only 
moderate variation in cluster size, with no stratification, crossing, 
matching, or anything else. Suppose I have one record per time point per 
person with variables:

c - study condition (control or intervention)
t - time point (pretest or post-test)
m - ID # for individual enrolled in trial
g - group #
y - study result

I am taking my guidance from David Murray's DESIGN AND ANALYSIS OF 
GROUP-RANDOMIZED TRIALS and trying to follow his example for what he 
calls an "unadjusted time x condition analysis" for "nested cohort 
designs" (pp. 296-311). The model, with subscripts omitted, looks like 
this: Y = mu + c + t + tc + G + M + TG + MT + e, where mu is the grand 
mean, tc is the interaction effect t*c (same for TG and MT), and G, M, 
TG, and MT are random effects.

Is any of these correct given the model?

xtmixed y cond t tc || G: || M: || TG: || MT: 
xtmixed y cond t tc || G: TG || M: MT 
xtmixed y cond t tc || G: M TG MT 

None of the above converge successfully with my data, but that doesn't 
mean they're all wrong ... Obviously, I'm unclear on how the 
specification of random effects works.

FWIW, Murray provides the following SAS code (with my variable names; 
and "ddf = 4,4,4" is for a specific example):

proc mixed info order=internal noclprint;
        class C G M T;
        model Y = C T C*T /ddf = 4,4,4 ddfm = res;
        repeated T /type = cs subject = M(G*C) r = 1 to 3 rcorr = 1 to 3;
        random G(C) TG(C);
        lsmeans C*T /slice=C slice=T c1 e;
        estimate `(I3 - I0)-(C3-C0)' C*T 1 -1 -1 1/cl e;

I can run this in SAS, but the value of doing so is diminished by the 
fact that Murray's commands and annotations are about 10 years out of 
date; I'd rather do it in Stata if possible.


As Jeff alluded, you cannot have a person-by-time interaction term (MT) unless
you have multiple observations per person per time point.  

But you *do* have multiple observations per person (one before and one after
treatment), and so person (M) should be included in the model as a random

Try the do-file below.  The -xtmixed- syntax shown should be directly what you

A few notes:

1. Two random effects (person and cluster-by-time interaction) are nested under
cluster (group), but are cross-classified with respect to each other.  I used S.
Rabe-Hesketh & A. Skrondal, Chapter 8. Crossed random effects. _Multilevel and
Longitudinal Modeling Using Stata_ (College Station, Texas: Stata Press, 2005)
pp. 249ff for guidance on the -xtmixed- syntax to set something like this up.

2. You can get an feel for what efficiency to expect from this
cluster-randomized study design by playing with the parameters for cluster
variance, cluster-by-time variance, person variance and treatment effect (which
is the treatment-by-time interaction term in the model that you've chosen).

3. There are alternative models for before-after testing, e.g., analogues of
ANCOVA.  Yet another approach is similar to the one you've chosen except that it
omits the main effect term for treatment, constraining the baseline
(pretreatment) estimates to be equal--this is also shown in the do-file below;
it's somewhat more efficient:  pretreatment conditions don't need to be
estimated separately for control treatment group and experimental treament group
in a pre-post parallel-group study design if you're randomizing to treatment
group.  This latter approach came up on SAS-L ( ) during a discussion of pre-post
testing last October.  See the post by Steve Denham in the thread "Repeated
Measures, or what?" on October 21st of last year.  (Dr. Yeh-Fong Chen was
willing to make the slides referenced in that post available to me, so you might
want to contact him at the U.S. FDA for a copy if you're interested.  The model
is referred to in his slides as the "FLW S2" after the source, which isn't cited
in full there, but is undoubtedly G. M. Fitzmaurice, N. M. Laird, J. H. Ware,
_Applied Longitudinal Analysis_ [Hoboken, NJ: Wiley-Interscience, 2004].  He
favors an ANCOVA-type model, which he refers to as "FLW S5", but that wouldn't
be pertinent in your study with only one posttreatment observation interval.  A
simpler ANCOVA-type model, "FLW S4", is illustrated below instead.)

Joseph Coveney

clear *
set more off

// Creating fictional dataset for illustration
set seed `=date("2009-04-03", "YMD")'

* c = condition (0 = control treatment; 1 = experimental treatment)
set obs 2
generate byte c = _n - 1

* g = group (cluster) within condition: [SAS PROC MIXED's G*C and G(C)]
generate byte g_tally = 10 // 20 clusters, randomly allocated equally
expand g_tally
generate byte g = _n // cluster ID
generate double g_u = sqrt(3) * invnormal(runiform())

* m = person enrolled in trial [SAS PROC MIXED's subject = M(G*C)]
generate byte m_tally = 50 // 50 people per cluster
expand m_tally
generate int m = _n
generate double m_u = sqrt(2) * invnormal(runiform())

* t = time point:  0 = before; 1 = after
* Here is your residual (errors)
forvalues time = 0/1 {
	generate double e`time' = sqrt(0.5) * invnormal(runiform())
reshape long e, i(m) j(t)

egen int gXt = group(g t) // Indicator for TG(C)
bysort gXt: generate double gXt_u = 1 * invnormal(runiform()) if _n == 1
replace gXt_u = gXt_u[_n-1] if missing(gXt_u) & _n > 1

* y = response
* SAS PROC MIXED's model Y = C T C*T; subject = M(G*C); random G(C) TG(C);
* y = c + t + c×t + g_u + m_u + t×g_u + e
* [No MT (person × time interaction) without replication]
local c 0
local t 5
local c×t 10 // Here's your treatment effect in this study design
generate double y = c * `c' + t * `t' + c * t * `c×t' ///
                    + g_u + gXt_u + m_u + e

generate byte cXt = c * t // Indicator for C*T (use -xi- if not 0/1 coded)

// Better estimates of variance components with REML . . .
xtmixed y c t cXt || g: || g: R.gXt || m:, reml variance nolrtest
// "A trick requiring fewer random effects" (Rabe-Hesketh & Skrondal, p. 266)
xtmixed y c t cXt || g: || g: R.t || m:, reml variance nolrtest

// . . . but LR testing with ML
xtmixed y c t cXt || g: || g: R.t || m:, ml variance nolrtest
estimates store Full
xtmixed y c t || g: || g: R.t || m:, ml variance nolrtest nostderr
lrtest Full .

* Constraining pretreatment responses to be equal (FLW S2 model)
xtmixed y t cXt || g: || g: R.t || m:, ml variance nolrtest
estimates store FullModel4
xtmixed y t || g: || g: R.t || m:, ml variance nolrtest
lrtest FullModel4 .

* ANCOVA type (FLW S4 model; here, only one posttreatment observation)
estimates drop _all
drop e gXt cXt gXt_u
reshape wide y, i(m) j(t)
xtmixed y1 y0 c || g: , reml variance nolrtest


*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index