BookmarkSubscribeRSS Feed

Mixed Models: Is It Random or Repeated? (2026 Remix)

Started ‎08-27-2026 by
Modified ‎08-27-2026 by
Views 148

Years ago, I wrote a post on another platform about whether it makes more sense to treat patients in a crossover study as a random effect, or as a repeated measures effect, in a mixed model. At the time, I was primarily talking about models with a normal distribution and an identity link. I still get the question regularly, so I figured this is a good time to resurrect the content plus update the whole thing with remarks about more recent research and some additional procedures. I'm reproducing most of the original post here along with additions and newer references in the statistical literature. I'm using PROC GLIMMIX code this time instead of PROC MIXED, and will explain why later. I hope you enjoy!

 

The Question: Should This Be RANDOM or REPEATED (a.k.a. RESIDUAL)

 

I frequently get questions similar to this one when I teach Mixed Models Analysis Using SAS or Statistical Analysis with the GLIMMIX Procedure. This comes up in particular when we are talking about crossover designs (sometimes known as AB-BA designs, where Factors vary within Subjects. Not ABBA designs where you’re like a Super Trouper).

 

Does it make sense to look at repeated measures (multiple treatments on the same patients) in the same way as repeated measures (multiple measurements over time)? Is the model essentially the same?

 

This is a common point of confusion for people learning mixed models, particularly if they have experience with other types of repeated measures analysis. With a linear mixed model, a crossover trial with repeated office visits can be modeled two structurally different ways in PROC MIXED that produce identical variance-covariance matrices (V) : through repeated measures (R-side) or through random effects (G-side).

 

A Side Note on Crossover Designs

 

AB-BA designs have advantages over parallel designs such as reduced variance and efficient use of sample size (in clinical trials, you can learn more with fewer patients). But there's no free lunch, and AB-BA designs can risk the purity of measuring the effects of A and B. A 2024 review of crossover methodology (Koner, 2024) makes important points about the magnitude of carryover effects when washout periods are too short, and that patient dropout (that is not MAR, or missing-at-random) is an unresolved problem for longer crossover studies. Another review of published crossover trials (Li, Yu, Hawkins, and Dickersin, 2015) found fewer than half reported using a washout period at all, which is a slightly alarming thing to see, if you are consuming, for example, medications that are likely tested in this way. When a washout period isn't clinically feasible, such as with behavioral rather than biological carryover, there's further discussion of the power tradeoff between crossover and parallel-group designs in Shi and Ye (2024). None of this changes the covariance modeling that follows, but it's worth a sentence in your methods section before you get to the analysis. Maybe I will dive deeper into these issues in a future post (interested? let me know).

Here is an example of a crossover study structured for a mixed models analysis that has 3 measurements (treatments) per patient: 

CatTruxillo_5-1787852180276.png

The Study Design

In the crossover design the student asks about, where we have a sufficiently long washout period, each patient came in for three different office visits. There are three repeated measurements for each patient. Each visit corresponded to a different drug, and the sequence of drugs within patients was randomized. The response was the change in heart rate from a baseline measurement. There are other effects in the model, which we will not elaborate upon here. Instead, let’s focus on how the variance and covariance part of the model could be handled.

 

PROC GLIMMIX DATA = crossover;
   CLASS patient drug visit;
   MODEL hr_change = drug visit /* and other effects not of interest here*/ / ddfm=kr2;
  RANDOM or RANDOM _RESIDUAL_ /*this way goes controversy*/;
RUN;

The Residual Approach: Mixed Models Repeated Measures Analysis

The mixed models repeated measures analysis that many people think of enables correlation among observations and possible nonconstant variances through the specification of the R matrix, the covariance matrix of the residuals. In PROC GLIMMIX, the syntax uses a _RESIDUAL_ keyword or a RESIDUAL option on the RANDOM statement to indicate that these are effects to model through the R matrix. For a linear mixed model, R-side random effects are exactly the same as REPEATED effects.

For example,

RANDOM visit / SUBJECT = patient TYPE = CS /*or other structures*/ RESIDUAL;

What does it mean for the covariances?

This produces a V matrix where the variance of observations is constant, and the covariance between two visits within an observation is an estimate of σp2. The covariance among observations from different patients is 0.

The V matrix is the R matrix and looks like this:

CatTruxillo_2-1787851753418.png

where the CS parameter estimate is 2 and the Residual variance is 3, therefore the Total variance of an observation is 5. 

 Mixed Model with a Random Patient Effect

This can also be conceptualized as a mixed model with multiple observations nested within a larger observation. For example,

RANDOM patient;

or, equivalently (but more computationally efficient)

RANDOM INTERCEPT / SUBJECT = patient;

Here are the G and R matrices:

G matrix with sigma squared P on the diagonalG matrix with sigma squared P on the diagonal

R matrix with sigma squared on the diagonalR matrix with sigma squared on the diagonal

Where the patient variance is 2 and the residual variance is 3, like before. 

What does it mean for the covariances?

This produces a G matrix with a constant variance σp2 and covariance between patients = 0. The R matrix (by default) assumes constant variance and no covariance among residuals. In the final covariance matrix of the observations (V), the within-patient covariance is the estimate of σp2.

V Matrix with CS block diagonal structureV Matrix with CS block diagonal structure

 

Did You See That?

Both of the previous models (random patient and repeated patient with type=cs) lead to the same V matrix- they are equivalent in a linear mixed model.

 

I have heard people refer to this as a “split-plot analysis, ” a convention that is useful because in essence you are treating visits as sub-plots within the whole-plot unit (the patient). The error term for tests of sub-plot treatments (here, it is the Drug) is the residual variance and the error term for tests of whole-plot treatments is the patient variance.

 

Multiple Random Effects

Now consider the example of patients nested within clinics. This is a more complex design than the crossover above, because there are measurements within patients as well as patients within clinics. If you think of the time points as being nested within a larger "subject", the patient, and the patient is nested within a larger “subject,” the clinic, you get:

RANDOM INTERCEPT / SUBJECT = patient;

In split-plot terminology, the clinic is the whole plot, and σc2 is the error term for testing whole-plot effects. Patient is the sub-plot, and σp2 is the error term for testing sub-plot effects. Visit is the sub-sub plot and σ2 is the error term for testing sub-sub plot effects.

 

What does it mean for the covariances?

Under this specification, in the final V matrix, 2 measurements from different patients from the same clinic have an estimated covariance of σc2.

Furthermore, two measurements from the same patient-by-clinic combination have an estimated covariance of (σc2 + σp2).

 

Random Effects and Repeated Measures

Now comes the part where your subject matter knowledge is critical. Is the correlation between pairs of visits constant? In other words, for a patient, is the correlation between visit 1 and visit 2 the same as the correlation between visit 1 and visit 3? Are the variances of the visits roughly equal? In other words, is the heart rate variance between patients the same at visit 1 , at visit 2, and at visit 3?

 

If the answer to any of these questions is no, then a more general approach is necessary to handle this changing correlation over time. In a split-plot approach, one assumption was that the visits had the same correlation within a subject regardless of distance in time. That's the reason for a random effect for patient(clinic). If that assumption were not warranted, then you could use a repeated measures analysis with R-side covariance parameters (other than the default estimate of the residual variance, σ2) which enable the within-subject correlation to change with distance in time. For example,

RANDOM INTERCEPT / SUBJECT=clinic;
REPEATED visit / SUBJECT=patient(clinic) TYPE = AR(1) RESIDUAL;

What does it mean for the covariances?

In the V matrix, the covariance between patients from different clinics is 0. The covariance between different patients from the same clinic is σc2. The covariance between two visits from the same patient is σc2+ σ2ρj where j is 1 for observations 1 visit apart, 2 for observations 2 visits apart, and so on and ρ is the correlation between adjacent visits (the first-order autocorrelation). The variance of an observation is σc2+ σ2.

 

What Else?

A few things worth knowing about if you primarily use PROC MIXED for your crossover analysis.

  • If you are modeling a non-normal response, then the impact of G-side vs R-side effects is a big deal. With G-side effects processed by-subjects, you can generally use maximum-likelihood estimation through LaPlace or Adaptive Quadrature to estimate effects. This gives you a whole slew of useful fit statistics for comparing models across fixed and/or random effects. It also gives you subject-specific interpretation of the effects.
  • Using R-side random effects with non-normal data requires using pseudo-likelihood estimation, which lets you test hypotheses about your fixed effects, and it gives you a population average interpretation of the effects (similar to a GEE). But comparing models on the basis of fit statistics isn't an option with this approach. There can also be issues with biased covariance parameter estimates, especially with small group size and/or binary responses. So, in general, with non-normal data, the G-side approach has statistical advantages over the R-side approach.
  • The GLIMMIX procedure can do almost everything that the MIXED procedure can do and then some. GLIMMIX also accommodates non-normal response distributions from the exponential family, supports nonpositional syntax for least squares means estimates, and enables you to use programming statements within the procedure.
  • One key advantage of MIXED over GLIMMIX is the PRIORS statement, which introduces Bayesian priors to mixed model analysis. But, if Bayesian is your jam, look at PROC BGLIMM....
  • PROC BGLIMM, introduced in SAS/STAT 15.1, applies a Bayesian framework to mixed models. It uses the same CLASS/MODEL/RANDOM/REPEATED syntax as PROC MIXED, handles nested and non-nested multilevel structures and repeated-measures data, and offers a variety of covariance structures on both the G side and the R side. Models can be compared using DIC instead of AIC/BIC. If your crossover example needs informative priors, such as external evidence on typical between-patient heart-rate variability, this is a good PROC to get to know.

Is That All There Is to Repeated Measures Analysis in PROC GLIMMIX?

Oh gosh no! If you’ve modeled the covariance structure of your population reasonably well, then you are ready to interpret your fixed effects and estimate quantities of interest to answer your research question. Alternatively, you could take a different approach altogether. Hierarchical linear models with random coefficients are exceptionally handy in situations where the number of observations per subject and the spacing between measurements vary across subjects. (We discuss the random coefficients approach in the Multilevel Models class, and that’s a topic for another day.) If your distribution is non-normal, then you want to think about the relevance of a subject-specific versus population-average interpretation of your fixed effects. (If you’re still reading, then welcome to my underground nerd lair! I salute you with the secret handshake!)

I hope this explanation is useful, and that not too many of you got an ABBA song stuck in your head today. See you in class!

 

References

Disclosure: Because I'm not great with graphic design, I asked Claude to help me create pictures of the matrices for this blog. They were not accurate and I got irritated waiting for it to think. So I drew them by hand, like I do on the board when I'm teaching. The data structure is pictured here, but the hand-drawn matrices were too messy. So I went to PROC IML which is a matrix programming language in SAS. It's been a minute since I taught that class, and my PROC IML syntax was really rusty. So I used the SAS Viya Copilot for Code Assistance to help me out, and ended up with the G, R, and V matrices you saw. Here is my code, if you are interested: 

/* Random Patient */
proc iml;
   /* Define the diagonal values for G and R */
   SigSq_p = 2; /* Example value for SigSq(c) */
   SigSq_r = 3; /* Example value for SigSq(r) */
   /* Create vectors of the diagonal values */
   vecG = j(3, 1, SigSq_p); /* 3x1 vector of SigSq(p) */
   vecR = j(9, 1, SigSq_r); /* 9x1 vector of SigSq(r) */
   /* Create the diagonal matrices */
   G = diag(vecG); /* 3x3 diagonal matrix */
   R = diag(vecR); /* 9x9 diagonal matrix */
   print G;
   print R;
   /* Create the 9x3 matrix Z as specified */
   Z = {
      1 0 0,
      1 0 0,
      1 0 0,
      0 1 0,
      0 1 0,
      0 1 0,
      0 0 1,
      0 0 1,
      0 0 1
   };
   print Z;
   /* Calculate matrix V: V = Z*G*t(Z) + R */
   /* Z*G*t(Z) computes the covariance structure, then add R */
   V = Z * G * t(Z) + R;
   print V;
quit;

/* Repeated Patient with TYPE=CS and no Random */
proc iml;
   /* Define variance components */
   SigSq_p = 2; /* Block off-diagonal (compound symmetry) */
   SigSq_r = 3; /* Block diagonal (additional variance) */
   /* Set G to a 3x3 zero matrix */
   G = j(3, 3, 0);
   print G;
   /* Create 9x9 block diagonal R matrix with 3 compound symmetric blocks */
   R = j(9, 9, 0); /* Initialize all zeros */
   do b = 0 to 2;
      startIdx = 3*b + 1;
      endIdx = 3*b + 3;
      do i = startIdx to endIdx;
         do j = startIdx to endIdx;
            if i = j then
               R[i, j] = SigSq_p + SigSq_r; /* Diagonal element */
            else
               R[i, j] = SigSq_p; /* Off-diagonal within block */
         end;
      end;
   end;
   print R;
   /* Create the 9x3 matrix Z as specified */
   Z = {
      1 0 0,
      1 0 0,
      1 0 0,
      0 1 0,
      0 1 0,
      0 1 0,
      0 0 1,
      0 0 1,
      0 0 1
   };
   print Z;
   /* Calculate matrix V: V = Z*G*t(Z) + R */
   V = Z * G * t(Z) + R;
   print V;
quit;

I stopped short of doing this for every single example in the blog, but you get the idea. Definitely try it out on your own if you want to see other examples. 

 

Find more articles from SAS Global Enablement and Learning here.

Contributors
Version history
Last update:
‎08-27-2026 02:10 PM
Updated by:

Viya Copilot Motion Graphic.gifViya Copilot Motion Graphic

Ready to see what SAS Viya Copilot can do?

Visit the Tips & Tricks page for setup guidance, demos, and practical examples that show how Copilot supports your workflows.

Get Started →

SAS AI and Machine Learning Courses

The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.

Get started

Article Tags