Tutorials › Generalized Linear Mixed Models (GLMM) › Random-Walk Temporal Effects and Intrinsic Precision

Spatial and Temporal Correlation · Tutorial 592 of 698

Random-Walk Temporal Effects and Intrinsic Precision

Derive the intrinsic precision for first-order random-walk effects and see why a level constraint is needed to identify the temporal effects.

Advanced 11 min read

What You'll Learn

  • Derive the first-order random-walk precision matrix from independent increments.
  • Identify its rank, null space, and quadratic penalty.
  • Explain why an intrinsic random-walk prior does not identify a constant temporal level.
  • Compare sum-to-zero and reference-time constraints.
  • Adapt the precision matrix when increments have variances proportional to unequal time gaps.
  • Recognize common problems when fitting or interpreting random-walk effects.

Why a Random Walk Has Intrinsic Precision

A temporal random effect can represent changes in a latent predictor across ordered time points. A first-order random walk (RW1) says that successive changes, rather than the levels themselves, are independent and have a common variance. This expresses local smoothness: adjacent effects are encouraged to be similar, but there is no preferred overall level.

In a generalized linear mixed model, an RW1 effect \(u_t\) can enter a conditional linear predictor such as \(\eta_{it}=x_{it}^{\mathsf T}\beta+u_t\). The response distribution and link are specified as usual for the chosen GLMM; the RW1 specifies the dependence structure of the latent temporal effects. The key issue here is that the increment model determines a singular precision matrix. A constraint is needed when the latent level must be separated from a fixed intercept.

Definition: For \(T\) equally spaced time points, a first-order random walk has increments \(u_t-u_{t-1}\), for \(t=2,\ldots,T\), that are independent with distribution \(N(0,\tau^{-1})\), where \(\tau>0\) is the increment precision. Its intrinsic Gaussian prior has density proportional to \(\exp\{-\frac{\tau}{2}\sum_{t=2}^T(u_t-u_{t-1})^2\}\). This expression penalizes changes but does not define a proper density over all \(T\) levels until a level constraint is imposed.

The precision parameter \(\tau\) is the reciprocal of the increment variance. Large \(\tau\) implies smaller typical changes and hence a smoother latent sequence; small \(\tau\) allows larger changes. It is not the precision of each \(u_t\) considered separately.

Deriving the Precision Matrix

Let \(u=(u_1,\ldots,u_T)^{\mathsf T}\). Define the \((T-1)\)-by-\(T\) first-difference matrix \(D\) so that its \(t\)th row takes the difference \(u_{t+1}-u_t\). For example, with \(T=4\),

$$ D= \begin{pmatrix} -1&1&0&0\\ 0&-1&1&0\\ 0&0&-1&1 \end{pmatrix}, \qquad Du= \begin{pmatrix} u_2-u_1\\ u_3-u_2\\ u_4-u_3 \end{pmatrix}. $$

The increment model gives \(Du\sim N(0,\tau^{-1}I_{T-1})\) as a distribution on the increments. Its quadratic contribution to the negative log density is \(\frac{\tau}{2}(Du)^{\mathsf T}(Du)\). Since \((Du)^{\mathsf T}(Du)=u^{\mathsf T}D^{\mathsf T}Du\), the intrinsic precision matrix is \(Q=\tau D^{\mathsf T}D\).

$$ Q=\tau \begin{pmatrix} 1&-1&0&\cdots&0\\ -1&2&-1&\ddots&\vdots\\ 0&-1&2&\ddots&0\\ \vdots&\ddots&\ddots&2&-1\\ 0&\cdots&0&-1&1 \end{pmatrix}, \qquad u^{\mathsf T}Qu=\tau\sum_{t=2}^{T}(u_t-u_{t-1})^2. $$

The first and last diagonal entries are 1, while interior diagonal entries are 2, because each endpoint occurs in one difference and each interior time point occurs in two. When \(T=2\), there are no interior entries: \(Q=\tau\begin{pmatrix}1&-1\\-1&1\end{pmatrix}\).

Key result: The RW1 precision is positive semidefinite, has rank \(T-1\), and has null space \(\operatorname{span}\{\mathbf{1}\}\), where \(\mathbf{1}\) is the length-\(T\) vector of ones. Thus \(Q\mathbf{1}=0\), and adding the same constant to every \(u_t\) leaves the increment penalty unchanged.

These properties follow directly from the quadratic form. For any vector \(a\),

$$ a^{\mathsf T}Qa=\tau\sum_{t=2}^{T}(a_t-a_{t-1})^2\geq 0. $$

Equality holds exactly when every adjacent difference is zero, which means \(a_1=\cdots=a_T\). Therefore the null space consists precisely of constant vectors. There are \(T-1\) independent differences, so the rank is \(T-1\) for \(T\geq2\). The matrix is singular and has no ordinary inverse: it is an intrinsic precision, not the precision matrix of a nonsingular Gaussian distribution on all of \(\mathbb{R}^T\).

Worked Example: Constructing the RW1 Precision for Four Times

Suppose there are four equally spaced times and the increment precision is \(\tau=3\). Construct \(Q\), verify its null space, and state its rank.

For four times, the first-difference matrix has three rows. Multiplying \(D^{\mathsf T}D\) by \(\tau=3\) gives

$$ Q=3 \begin{pmatrix} 1&-1&0&0\\ -1&2&-1&0\\ 0&-1&2&-1\\ 0&0&-1&1 \end{pmatrix} = \begin{pmatrix} 3&-3&0&0\\ -3&6&-3&0\\ 0&-3&6&-3\\ 0&0&-3&3 \end{pmatrix}. $$

Multiplying by \(\mathbf{1}=(1,1,1,1)^{\mathsf T}\) gives \(Q\mathbf{1}=(0,0,0,0)^{\mathsf T}\). More generally, \(a^{\mathsf T}Qa=3\sum_{t=2}^4(a_t-a_{t-1})^2\), which is zero only for a constant vector. Thus the null space is one-dimensional and the rank is \(4-1=3\). The matrix penalizes changes, not the common level.

Constraints and the Latent Temporal Level

In a GLMM with a fixed intercept, the linear predictor can be unchanged when a constant is shifted between the intercept and the temporal effects. For example, if \(\eta_t=\beta_0+u_t\), then replacing \(u_t\) by \(u_t-c\) and \(\beta_0\) by \(\beta_0+c\) leaves every \(\eta_t\) unchanged. The RW1 penalty is also unchanged by a constant shift. The data and intrinsic penalty therefore do not, by themselves, select a unique decomposition into intercept and temporal level.

A common identifying choice is the sum-to-zero constraint \(\sum_{t=1}^T u_t=0\). This makes the fixed intercept represent the overall level and the temporal effects represent deviations around it. Another choice is to anchor the sequence at a reference time, such as \(u_1=0\); the remaining effects then describe changes relative to that time. The choice affects interpretation, so it should be reported and used consistently.

With a sum-to-zero constraint, the intrinsic Gaussian distribution is defined on the \((T-1)\)-dimensional subspace perpendicular to \(\mathbf{1}\). On that subspace the quadratic form is positive definite, so it can be normalized as a proper Gaussian distribution there. The resulting covariance is an inverse only on the constrained subspace; it is not \(Q^{-1}\) on the full space. Anchoring one level also removes the constant direction and yields a proper distribution for the remaining levels under the increment model.

Worked Example: Applying a Sum-to-Zero Constraint

Suppose four estimated temporal effects before imposing a constraint are \(u=(1,2,0,1)^{\mathsf T}\), and the fixed intercept is \(\beta_0=0.4\). Re-express these effects so they sum to zero, and check that the linear predictors and RW1 penalty are unchanged. Treat the listed effects as values on the model's linear-predictor scale.

The mean of the four effects is \((1+2+0+1)/4=1\). Subtracting this mean gives \(u^*=(0,1,-1,0)^{\mathsf T}\), whose entries sum to zero. To preserve \(\eta_t=\beta_0+u_t\), add 1 to the intercept: \(\beta_0^*=1.4\). For instance, at the third time, \(\beta_0+u_3=0.4+0=0.4\), and \(\beta_0^*+u_3^*=1.4-1=0.4\). The same equality holds at each time because the same constant was shifted.

The original successive differences are \(1,-2,1\); the constrained differences are also \(1,-2,1\). Their squared sum is \(1^2+(-2)^2+1^2=6\). If \(\tau=2\), then

$$ u^{\mathsf T}Qu=2(6)=12, \qquad \frac{1}{2}u^{\mathsf T}Qu=6. $$

The quadratic penalty, and therefore the increment contribution to the log density, is unchanged by centering. The constraint identifies a representation; it does not alter the estimated temporal contrasts.

Unequal Time Gaps

The standard RW1 assumes equally spaced time points and a common increment variance. If time gaps differ, applying that same variance to every adjacent pair treats a one-day change and a one-year change as equally variable. A different, explicit assumption is needed when variability is intended to grow with elapsed time. For a Brownian-increment specification, an increment over a gap \(\Delta_t>0\) has variance \(\sigma^2\Delta_t\), independently across disjoint intervals. Writing \(\tau=1/\sigma^2\), its precision contribution is \(\tau/\Delta_t\).

$$ Q=\tau D^{\mathsf T}WD,\qquad W=\operatorname{diag}\left(\frac{1}{\Delta_2},\ldots,\frac{1}{\Delta_T}\right), \qquad u^{\mathsf T}Qu=\tau\sum_{t=2}^{T}\frac{(u_t-u_{t-1})^2}{\Delta_t}. $$

This weighted precision still has the constant vector as its null direction, since differences of a constant are zero. It is not simply the equally spaced RW1 with a relabelled time index: the gap weights encode a substantive variance assumption.

Worked Example: Precision With Unequal Gaps

Consider three observation times with gaps \(\Delta_2=2\) and \(\Delta_3=3\) time units. Assume independent increments with variance \(\sigma^2\Delta_t\), and let \(\tau=1/\sigma^2=0.25\). Construct the precision and compute the quadratic penalty for \(u=(2,5,1)^{\mathsf T}\).

The gap-weight matrix is \(W=\operatorname{diag}(1/2,1/3)\). Thus

$$ Q=0.25 \begin{pmatrix} 1/2&-1/2&0\\ -1/2&1/2+1/3&-1/3\\ 0&-1/3&1/3 \end{pmatrix}. $$

The increments are \(5-2=3\) and \(1-5=-4\). The unscaled weighted sum of squares is \(3^2/2+(-4)^2/3=9/2+16/3=59/6\). Therefore

$$ u^{\mathsf T}Qu=0.25\left(\frac{59}{6}\right)=\frac{59}{24}\approx2.458, \qquad \frac{1}{2}u^{\mathsf T}Qu\approx1.229. $$

The null space remains the constants, and the rank is \(3-1=2\). The weights reduce the contribution of the same-sized increment over the longer gap, as specified by the variance-proportional-to-time assumption.

Diagnostics, Alternatives, and Limitations

An RW1 is useful when neighboring latent levels should be related through their increments and the overall level is handled separately. It is not automatically suitable for every time series. A stationary AR(1) random effect, for example, has a proper stationary distribution when its parameters satisfy the model's stationarity conditions; unlike the intrinsic RW1, it does not have a constant null direction. A deterministic time trend instead specifies a systematic mean pattern rather than a random sequence of local increments. These structures answer different modeling questions and should not be selected solely because one produces a smoother fitted curve.

After fitting, inspect the estimated temporal sequence, its uncertainty, and its successive increments on the scale of the latent predictor. Look for abrupt changes that the chosen precision suppresses, long stretches of drift that the model represents only through accumulated increments, and sensitivity to the time grid or constraint. Compare fitted behavior and predictive performance with scientifically plausible alternatives. A very large estimated \(\tau\) may correspond to nearly constant temporal effects; a very small \(\tau\) may permit highly variable changes. Neither value alone proves that the model is adequate.

Common warning signs include a nearly unidentified intercept and temporal level, strong dependence of results on the constraint or reference time, and use of equal increment variances despite materially unequal gaps. Also check that the temporal index corresponds to the ordering and spacing assumed by the model. An RW1 penalizes adjacent differences; it does not explicitly encode cycles, a stationary long-run level, or a separate long-term trend. Those require other structures and should not be inferred merely from a visually smooth RW1 fit.

Common mistake: Because the RW1 matrix is called a precision matrix, it is tempting to compute \(Q^{-1}\) and interpret the result as the covariance of all temporal effects. This is not valid: \(Q\mathbf{1}=0\), so \(Q\) is singular and has no ordinary inverse. Impose and state an identifying constraint, then interpret the distribution on the resulting constrained space (or use an explicitly defined generalized inverse for the relevant contrasts).

Check Your Understanding

Answer each question, then compare with the brief solutions below.

  1. For an equally spaced RW1 with five time points, what are the rank and null space of \(Q\)?
  2. If \(\tau\) is multiplied by four, what happens to the variance of each increment under the common-variance RW1 model?
  3. For \(u=(0,2,1)\), calculate the unweighted sum of squared successive differences and the quadratic penalty when \(\tau=2\).
  4. With a fixed intercept in \(\eta_t=\beta_0+u_t\), explain how the sum-to-zero constraint clarifies the interpretation of the intercept.
  5. For unequal gaps, what increment variance assumption produces weights \(1/\Delta_t\) in the precision matrix?

Solutions. (1) The rank is \(5-1=4\), and the null space is the span of \((1,1,1,1,1)^{\mathsf T}\). (2) The increment variance is \(\tau^{-1}\), so multiplying \(\tau\) by four divides that variance by four. (3) The differences are \(2\) and \(-1\), so the sum of squares is \(2^2+(-1)^2=5\), and \(u^{\mathsf T}Qu=2(5)=10\); the negative-log-density quadratic contribution is half of this, or 5. (4) The constraint forces the temporal deviations to average zero, so the intercept represents the overall level rather than an arbitrary trade-off between intercept and temporal effects. (5) Independent increments with variance \(\sigma^2\Delta_t\) give increment precision \(1/(\sigma^2\Delta_t)=\tau/\Delta_t\).

Clinical Biostats