Random effects analysis

Random effects analysis#

When a hypothesis concerns a population of subjects, spm1d can conduct random effects analysis using a hierarchical (two-level) model:

  • Level 1 applies one model separately to each subject (e.g., regression or a within-subject mean).

  • Level 2 tests the subject-level estimates with a population-level model (e.g., a one-sample t test).

This hierarchical approach regards each subject’s estimate(s) as drawn randomly from the larger population. In contrast, a model with SUBJECT as a fixed factor (e.g., two-way ANOVA with factors SUBJECT and SPEED) restricts inferences to the tested subjects.

Repeated measurements of each subject improve the precision of that subject’s estimate. They do not add subjects. The random effects degrees of freedom depend only on the number of subjects.

Example#

The dataset from Pataky et al. (2008) contains vertical body weight (BW)-normalized ground reaction forces (GRF) from ten subjects who each walked 60 times at a range of measured speeds. The null hypothesis is that walking speed has no effect on population-level GRF.

speed_grf_rfx.npz

import numpy as np
import spm1d

data = np.load( 'speed_grf_rfx.npz' )
y, x = data['y'], data['x']    # (10,60,101) GRF array (subjects, trials, time) and (10,60) walking speeds
../_images/rfx_means_light.png ../_images/rfx_means_dark.png

Level 1#

Below linear regression of GRF vs. speed is conducted separately for each subject, yielding one slope continuum fit.b[0] per subject. Inference is not conducted at level 1 because the hypothesis does not pertain to individual subjects.

beta = np.array( [spm1d.stats.regress( yy, xx ).fit.b[0]   for yy, xx in zip( y, x )] )   # (10,101) slopes

The figure below depicts the ten slopes and their mean (thick black line). Positive and negative slopes indicate that GRF increases and decreases with speed, respectively.

../_images/rfx_level1_light.png ../_images/rfx_level1_dark.png

Level 2#

If speed had no true population effect, the slopes would vary randomly around zero. The ten slope continua can therefore be tested with a one-sample t test:

ti = spm1d.stats.ttest( beta ).inference( 0.05 )
print( ti )
SPM{t} (1D) inference
    fn_name : ttest
    STAT    : T
    z       : (101,) array
    df      : (1, 9)
Smoothness estimates:
    fwhm    : 9.002
    lkc     : 18.498
    resels  : (1, 11.10903)
Inference results:
    method       : rft
    isparametric : True
    alpha        : 0.05
    dirn         : 0
    zc           : 4.55612
    zmax         : 21.659
    h0reject     : True
    p_zmax       : <0.001
    p_set        : <0.001
    p_cluster    : [<0.001, <0.001, 0.022, 0.002]
    p_point      : None
../_images/rfx_level2_light.png ../_images/rfx_level2_dark.png

These results suggest that speed has a significant effect on population-level GRF, or equivalently that the null hypothesis of no speed effect is a poor one.