Post · 10 min read· pp. 535–544

How Does a Compound Symmetric Correlation Structure Translate to a Markov Model?

How to cite this article

Harrell FE (2023). How Does a Compound Symmetric Correlation Structure Translate to a Markov Model?. Statistical Thinking. https://doi.org/10.59350/v56y8-jbb06

Random intercepts in a model induce a compound symmetric correlation structure in which the correlation between two responses on the same subject have the same correlation no matter the time gap between the responses. How does one capture such an unnatural structure using a Markov semiparametric model?

Let’s generate some data with repeatedly measured outcome per subject where the outcome is a coursened continuous response from a linear model, treated as ordinal, and the random effects have a N(0,0.252)N(0, 0.25^2) distribution. Generate 5000 subjects having 10 measurements each.

Code

text
n <- 5000   # subjects
set.seed(2)
re <- rnorm(n) * 0.25
X  <- runif(n)   # baseline covariate, will be duplicated over time within subject
m  <- 10         # measurements per subject

id <- rep(1 : n, each = m)
x  <- X[id]
y  <- x + re[id] + rnorm(n * m) * 0.5
y  <- pmin(2, pmax(-1, y))   # curtail y
y  <- round(4 * y)           # coursen it
d  <- data.table(id, x, y)
d[, t := 1 : .N, by=id]
# Make short and wide dataset
w <- dcast(d[, .(id, t, y)],
           id ~ t, value.var='y')
r <- cor(as.matrix(w[, -1]), use='pairwise.complete.obs',
         method='pearson')
p <- plotCorrM(r)
p[[1]]

Code

text
p[[2]] + ylim(0,1)

The flat correlation pattern vs. time gap is as expected.

Fit a first-order Markov PO model to times 2, 3, …, 10. Allow previous y to interact with a flexible function of time.

Code

text
d[, yprev := shift(y), by=id]
f <- orm(y ~ pol(x, 2) + pol(yprev, 2) * pol(t, 3), data=d)
anova(f)
Wald Statistics for y
χ2d.f.P
x5565.782<0.0001
Nonlinear6.2810.0122
yprev (Factor+Higher Order Factors)1696.298<0.0001
All Interactions3.7760.7082
Nonlinear (Factor+Higher Order Factors)0.6840.9544
t (Factor+Higher Order Factors)5.9490.7458
All Interactions3.7760.7082
Nonlinear (Factor+Higher Order Factors)2.0160.9188
yprev × t (Factor+Higher Order Factors)3.7760.7082
Nonlinear1.5050.9126
Nonlinear Interaction : f(A,B) vs. AB1.5050.9126
f(A,B) vs. Af(B) + Bg(A)0.3120.8560
Nonlinear Interaction in yprev vs. Af(B)0.4330.9346
Nonlinear Interaction in t vs. Bg(A)1.3840.8472
TOTAL NONLINEAR8.4190.4938
TOTAL NONLINEAR + INTERACTION10.65100.3853
TOTAL11187.9213<0.0001

Code

text
g <- orm(y ~ pol(x,2) + yprev + t, data=d)
g

Logistic (Proportional Odds) Ordinal Regression Model

text
orm(formula = y ~ pol(x, 2) + yprev + t, data = d)

Frequencies of Responses

text
  -4   -3   -2   -1    0    1    2    3    4    5    6    7    8 
 634 1012 2109 3494 5106 6413 6908 6529 5315 3620 2106 1090  664 

Frequencies of Missing Values Due to Each Variable

text
    y     x yprev     t 
    0     0  5000     0 
Model Likelihood Ratio TestDiscrimination IndexesRank Discrim. Indexes
Obs 45000LR χ2 12078.42R2 0.238ρ 0.488
Distinct Y 13d.f. 4R24,45000 0.235
Y0.5 2Pr(>χ2) <0.0001R24,44374.5 0.238
max∂log L/∂β1×10-6Score χ2 12153.40
Pr(>χ2) <0.0001

| | β | S.E. | Wald Z | Pr(>|Z|) | | --- | --- | --- | --- | --- | | x | 2.7847 | 0.1160 | 24.01 | <0.0001 | | x2 | -0.2728 | 0.1113 | -2.45 | 0.0142 | | yprev | 0.1551 | 0.0038 | 41.14 | <0.0001 | | t | 0.0040 | 0.0032 | 1.24 | 0.2136 |

There was no evidence for a nonlinear effect of previous y, or an interaction between previous value and time.

Fifth-Order Markov Model with Linear Effects

Code

text
d[, yprev2 := shift(yprev),  by=id]
d[, yprev3 := shift(yprev2), by=id]
d[, yprev4 := shift(yprev3), by=id]
d[, yprev5 := shift(yprev4), by=id]
f <- orm(y ~ pol(x, 2) + yprev + yprev2 + yprev3 + yprev4 + yprev5 + t, data=d)
f

Logistic (Proportional Odds) Ordinal Regression Model

text
orm(formula = y ~ pol(x, 2) + yprev + yprev2 + yprev3 + yprev4 + 
    yprev5 + t, data = d)

Frequencies of Responses

text
  -4   -3   -2   -1    0    1    2    3    4    5    6    7    8 
 337  540 1183 1958 2754 3601 3855 3647 2964 2015 1167  622  357 

image

Model Likelihood Ratio TestDiscrimination IndexesRank Discrim. Indexes
Obs 25000LR χ2 8641.08R2 0.295ρ 0.538
Distinct Y 13d.f. 8R28,25000 0.292
Y0.5 2Pr(>χ2) <0.0001R28,24649.9 0.295
max∂log L/∂β2×10-6Score χ2 8831.52
Pr(>χ2) <0.0001

| | β | S.E. | Wald Z | Pr(>|Z|) | | --- | --- | --- | --- | --- | | x | 1.6573 | 0.1579 | 10.49 | <0.0001 | | x2 | -0.2336 | 0.1494 | -1.56 | 0.1180 | | yprev | 0.0949 | 0.0053 | 17.91 | <0.0001 | | yprev2 | 0.0956 | 0.0053 | 18.12 | <0.0001 | | yprev3 | 0.1062 | 0.0053 | 20.07 | <0.0001 | | yprev4 | 0.0882 | 0.0052 | 16.80 | <0.0001 | | yprev5 | 0.0771 | 0.0052 | 14.70 | <0.0001 | | t | 0.0060 | 0.0079 | 0.76 | 0.4488 |

Code

text
anova(f, yprev2, yprev3, yprev4, yprev5)
Wald Statistics for y
χ2d.f.P
yprev2328.181<0.0001
yprev3402.611<0.0001
yprev4282.371<0.0001
yprev5216.131<0.0001
TOTAL1833.154<0.0001

For the compound symmetric correlation structure the effect of all previous values of y is the same, and all lags are important.

See if the mean of all previous values can replace all the individual lagged variables.

Code

text
d[, ypmean := (yprev + yprev2 + yprev3 + yprev4 + yprev5) / 5]
fm <- orm(y ~ pol(x, 2) + ypmean + t, data=d)
fm

Logistic (Proportional Odds) Ordinal Regression Model

text
orm(formula = y ~ pol(x, 2) + ypmean + t, data = d)

Frequencies of Responses

text
  -4   -3   -2   -1    0    1    2    3    4    5    6    7    8 
 337  540 1183 1958 2754 3601 3855 3647 2964 2015 1167  622  357 

Frequencies of Missing Values Due to Each Variable

text
     y      x ypmean      t 
     0      0  25000      0 
Model Likelihood Ratio TestDiscrimination IndexesRank Discrim. Indexes
Obs 25000LR χ2 8626.32R2 0.295ρ 0.538
Distinct Y 13d.f. 4R24,25000 0.292
Y0.5 2Pr(>χ2) <0.0001R24,24649.9 0.295
max∂log L/∂β2×10-6Score χ2 8815.53
Pr(>χ2) <0.0001

| | β | S.E. | Wald Z | Pr(>|Z|) | | --- | --- | --- | --- | --- | | x | 1.6530 | 0.1579 | 10.47 | <0.0001 | | x2 | -0.2297 | 0.1494 | -1.54 | 0.1243 | | ypmean | 0.4618 | 0.0087 | 52.90 | <0.0001 | | t | 0.0061 | 0.0079 | 0.78 | 0.4355 |

Code

text
AIC(fm); AIC(f)

[1] 107771.7 [1] 107765

The previous model is better but by an inconsequential amount. The compound symmetric correlation pattern is reproduced by conditioning on the mean of all previous response values.

Combined Markov and Random Effects Model

Add random intercepts and see if lags are still important in a Bayesian PO model.

Code

text
require(rmsb)
options(mc.cores=4, rmsb.backend='cmdstan')  # took 7m on 4 cores (4 chains)
b <- blrm(y ~ pol(x, 2) + yprev + yprev2 + yprev3 + yprev4 + yprev5 + t +
          cluster(id), data=d, file='corstruct-b.rds')
b

Bayesian Proportional Odds Ordinal Logistic Model

Dirichlet Priors With Concentration Parameter 0.187 for Intercepts

text
blrm(formula = y ~ pol(x, 2) + yprev + yprev2 + yprev3 + yprev4 + 
    yprev5 + t + cluster(id), data = d, file = "corstruct-b.rds")

Frequencies of Responses

text
  -4   -3   -2   -1    0    1    2    3    4    5    6    7    8 
 337  540 1183 1958 2754 3601 3855 3647 2964 2015 1167  622  357 

image

Mixed Calibration/ Discrimination IndexesDiscrimination IndexesRank Discrim. Indexes
Obs 25000B 0.194 [0.194, 0.194]g 1.301 [1.273, 1.327]C 0.704 [0.704, 0.704]
Draws 4000gp 0.263 [0.259, 0.267]Dxy 0.408 [0.408, 0.409]
Chains 4EV 0.217 [0.21, 0.223]
Time 369.7sv 1.29 [1.237, 1.342]
p 8vp 0.053 [0.051, 0.054]
Cluster on id
Clusters 5000
σγ 0.0328 [1e-04, 0.0966]
Mean βMedian βS.E.LowerUpperPr(β>0)Symmetry
x1.65921.65870.15671.32811.93781.00000.98
x2-0.2314-0.23340.1482-0.50810.06840.05831.03
yprev0.09460.09460.00520.08470.10521.00000.99
yprev20.09540.09540.00510.08550.10481.00000.95
yprev30.10610.10610.00540.09550.11661.00001.03
yprev40.08830.08820.00490.07840.09771.00000.99
yprev50.07730.07730.00520.06740.08751.00001.01
t0.00610.00610.0083-0.00930.02280.75621.03

With the lagged variables in the model the standard deviation σγ\sigma_\gamma of the random effects is very small, and oddly enough the previous values remain important. I conjecture that if the lagged variables were removed σγ\sigma_\gamma would be much larger and the model would be about as good.

Computing Environment

`

text
 R version 4.3.2 (2023-10-31)
 Platform: aarch64-apple-darwin20 (64-bit)
 Running under: macOS Ventura 13.6.1
 
 Matrix products: default
 BLAS:   /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRblas.0.dylib 
 LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.11.0
 
 attached base packages:
 [1] stats     graphics  grDevices utils     datasets  methods   base     
 
 other attached packages:
 [1] rmsb_1.0-0        ggplot2_3.4.4     data.table_1.14.8 rms_6.8-0        
 [5] Hmisc_5.1-2      
 

To cite R in publications use:

R Core Team (2023). R: A Language and Environment for Statistical Computing. R Foundation for Statistical Computing, Vienna, Austria. https://www.R-project.org/.

To cite the Hmisc package in publications use:

Harrell Jr F (2023). Hmisc: Harrell Miscellaneous. R package version 5.1-2, https://hbiostat.org/R/Hmisc/.

To cite the rms package in publications use:

Harrell Jr FE (2023). rms: Regression Modeling Strategies. R package version 6.8-0, https://github.com/harrelfe/rms, https://hbiostat.org/R/rms/.

To cite the rmsb package in publications use:

Harrell F (2023). rmsb: Bayesian Regression Modeling Strategies. R package version 1.0-0, https://hbiostat.org/R/rmsb/.

To cite the data.table package in publications use:

Dowle M, Srinivasan A (2023). data.table: Extension of ‘data.frame’. R package version 1.14.8, https://CRAN.R-project.org/package=data.table.

To cite the ggplot2 package in publications use:

Wickham H (2016). ggplot2: Elegant Graphics for Data Analysis. Springer-Verlag New York. ISBN 978-3-319-24277-4, https://ggplot2.tidyverse.org.

`{=html}

Reuse

CC BY 4.0

Citation

BibTeX citation:

text
@online{harrell2023,
  author = {Harrell, Frank},
  title = {How {Does} a {Compound} {Symmetric} {Correlation} {Structure}
    {Translate} to a {Markov} {Model?}},
  date = {2023-12-03},
  url = {https://www.fharrell.com/post/corstruct/},
  doi = {10.59350/v56y8-jbb06},
  langid = {en}
}

For attribution, please cite this work as:

Harrell, Frank. 2023. “How Does a Compound Symmetric Correlation Structure Translate to a Markov Model?” Statistical Thinking, December 3. https://doi.org/10.59350/v56y8-jbb06.