Skip to main content

7  Modeling Longitudinal Responses using Generalized Least Squares and Semiparametric Models

Some good general references on longitudinal data analysis are Davis (2002), Pinheiro & Bates (2000), Diggle et al. (2002), Venables & Ripley (2003), Hand & Crowder (1996), Verbeke & Molenberghs (2000), Lindsey (1997)

7.1 Notation

  • \(N\) subjects
  • Subject \(i\) (\(i=1,2,\ldots,N\)) has \(n_{i}\) responses measured at times \(t_{i1}, t_{i2}, \ldots, t_{in_{i}}\)
  • Response at time \(t\) for subject \(i\): \(Y_{it}\)
  • Subject \(i\) has baseline covariates \(X_{i}\)
  • Generally the response measured at time \(t_{i1}=0\) is a covariate in \(X_{i}\) instead of being the first measured response \(Y_{i0}\)
  • Time trend in response is modeled with \(k\) parameters so that the time “main effect” has \(k\) d.f.
  • Let the basis functions modeling the time effect be \(g_{1}(t), g_{2}(t), \ldots, g_{k}(t)\)
A

7.2 Model Specification for Effects on \(E(Y)\)

7.2.1 Common Basis Functions

  • \(k\) dummy variables for \(k+1\) unique times (assumes no functional form for time but may spend many d.f.)
  • \(k=1\) for linear time trend, \(g_{1}(t)=t\)
  • \(k\)–order polynomial in \(t\)
  • \(k+1\)–knot restricted cubic spline (one linear term, \(k-1\) nonlinear terms)
B

7.2.2 Model for Mean Profile

  • A model for mean time-response profile without interactions between time and any \(X\):
    \(E[Y_{it} | X_{i}] = X_{i}\beta + \gamma_{1}g_{1}(t) + \gamma_{2}g_{2}(t) + \ldots + \gamma_{k}g_{k}(t)\)
  • Model with interactions between time and some \(X\)’s: add product terms for desired interaction effects
  • Example: To allow the mean time trend for subjects in group 1 (reference group) to be arbitrarily different from time trend for subjects in group 2, have a dummy variable for group 2, a time “main effect” curve with \(k\) d.f. and all \(k\) products of these time components with the dummy variable for group 2
  • Time should be modeled using indicator variables only when time is really discrete, e.g., when time is in weeks and subjects were followed at exactly the intended weeks. In general time should be modeled continuously (and nonlinearly if there are more than 2 followup times) using actual visit dates instead of intended dates (Donohue et al., n.d.).
C

7.2.3 Model Specification for Treatment Comparisons

  • In studies comparing two or more treatments, a response is often measured at baseline (pre-randomization)
  • Analyst has the option to use this measurement as \(Y_{i0}\) or as part of \(X_{i}\)
D

For RCTs, I draw a sharp line at the point when the intervention begins. The LHS [left hand side of the model equation] is reserved for something that is a response to treatment. Anything before this point can potentially be included as a covariate in the regression model. This includes the “baseline” value of the outcome variable. Indeed, the best predictor of the outcome at the end of the study is typically where the patient began at the beginning. It drinks up a lot of variability in the outcome; and, the effect of other covariates is typically mediated through this variable.

I treat anything after the intervention begins as an outcome. In the western scientific method, an “effect” must follow the “cause” even if by a split second.

Note that an RCT is different than a cohort study. In a cohort study, “Time 0” is not terribly meaningful. If we want to model, say, the trend over time, it would be legitimate, in my view, to include the “baseline” value on the LHS of that regression model.

Now, even if the intervention, e.g., surgery, has an immediate effect, I would include still reserve the LHS for anything that might legitimately be considered as the response to the intervention. So, if we cleared a blocked artery and then measured the MABP, then that would still be included on the LHS.

Now, it could well be that most of the therapeutic effect occurred by the time that the first repeated measure was taken, and then levels off. Then, a plot of the means would essentially be two parallel lines and the treatment effect is the distance between the lines, i.e., the difference in the intercepts.

If the linear trend from baseline to Time 1 continues beyond Time 1, then the lines will have a common intercept but the slopes will diverge. Then, the treatment effect will the difference in slopes.

One point to remember is that the estimated intercept is the value at time 0 that we predict from the set of repeated measures post randomization. In the first case above, the model will predict different intercepts even though randomization would suggest that they would start from the same place. This is because we were asleep at the switch and didn’t record the “action” from baseline to time 1. In the second case, the model will predict the same intercept values because the linear trend from baseline to time 1 was continued thereafter.

More importantly, there are considerable benefits to including it as a covariate on the RHS. The baseline value tends to be the best predictor of the outcome post-randomization, and this maneuver increases the precision of the estimated treatment effect. Additionally, any other prognostic factors correlated with the outcome variable will also be correlated with the baseline value of that outcome, and this has two important consequences. First, this greatly reduces the need to enter a large number of prognostic factors as covariates in the linear models. Their effect is already mediated through the baseline value of the outcome variable. Secondly, any imbalances across the treatment arms in important prognostic factors will induce an imbalance across the treatment arms in the baseline value of the outcome. Including the baseline value thereby reduces the need to enter these variables as covariates in the linear models.

Senn (2006) states that temporally and logically, a “baseline cannot be a response to treatment”, so baseline and response cannot be modeled in an integrated framework.

… one should focus clearly on ‘outcomes’ as being the only values that can be influenced by treatment and examine critically any schemes that assume that these are linked in some rigid and deterministic view to ‘baseline’ values. An alternative tradition sees a baseline as being merely one of a number of measurements capable of improving predictions of outcomes and models it in this way.

The final reason that baseline cannot be modeled as the response at time zero is that many studies have inclusion/exclusion criteria that include cutoffs on the baseline variable. In other words, the baseline measurement comes from a truncated distribution. In general it is not appropriate to model the baseline with the same distributional shape as the follow-up measurements. Thus the approaches recommended by Liang & Zeger (2000) and Liu et al. (2009) are problematic1.

E

1 In addition to this, one of the paper’s conclusions that analysis of covariance is not appropriate if the population means of the baseline variable are not identical in the treatment groups is not correct (Senn, 2006). See Kenward et al. (2010) for a rebuke of Liu et al. (2009).

7.3 Modeling Within-Subject Dependence

  • Random effects and mixed effects models have become very popular
  • Disadvantages:
    • Induced correlation structure for \(Y\) may be unrealistic
    • Numerically demanding
    • Require complex approximations for distributions of test statistics
  • Conditional random effects vs. (subject-) marginal models:
    • Random effects are subject-conditional
    • Random effects models are needed to estimate responses for individual subjects
    • Models without random effects are marginalized with respect to subject-specific effects
    • They are natural when the interest is on group-level (i.e., covariate-specific but not patient-specific) parameters (e.g., overall treatment effect)
    • Random effects are natural when there is clustering at more than the subject level (multi-level models)
  • Extended linear model (marginal; with no random effects) is a logical extension of the univariate model (e.g., few statisticians use subject random effects for univariate \(Y\))
  • This was known as growth curve models and generalized least squares (Goldstein, 1989; Potthoff & Roy, 1964) and was developed long before mixed effect models became popular
  • Pinheiro and Bates (Section~5.1.2) state that “in some applications, one may wish to avoid incorporating random effects in the model to account for dependence among observations, choosing to use the within-group component \(\Lambda_{i}\) to directly model variance-covariance structure of the response.”
  • We will assume that \(Y_{it} | X_{i}\) has a multivariate normal distribution with mean given above and with variance-covariance matrix \(V_{i}\), an \(n_{i}\times n_{i}\) matrix that is a function of \(t_{i1}, \ldots, t_{in_{i}}\)
  • We further assume that the diagonals of \(V_{i}\) are all equal
  • Procedure can be generalized to allow for heteroscedasticity over time or with respect to \(X\) (e.g., males may be allowed to have a different variance than females)
  • This extended linear model has the following assumptions:
    • all the assumptions of OLS at a single time point including correct modeling of predictor effects and univariate normality of responses conditional on \(X\)
    • the distribution of two responses at two different times for the same subject, conditional on \(X\), is bivariate normal with a specified correlation coefficient
    • the joint distribution of all \(n_{i}\) responses for the \(i^{th}\) subject is multivariate normal with the given correlation pattern (which implies the previous two distributional assumptions)
    • responses from any times for any two different subjects are uncorrelated
FGH
What Methods To Use for Repeated Measurements / Serial Data? 2 3
Repeated Measures ANOVA GEE Mixed Effects Models GLS Markov LOCF Summary Statistic4
Assumes normality × × ×
Assumes independence of measurements within subject ×5 ×6
Assumes a correlation structure7 × ×8 × × ×
Requires same measurement times for all subjects × ?
Does not allow smooth modeling of time to save d.f. ×
Does not allow adjustment for baseline covariates ×
Does not easily extend to non-continuous \(Y\) × ×
Loses information by not using intermediate measurements ×9 ×
Does not allow widely varying # observations per subject × ×10 × ×11
Does not allow for subjects to have distinct trajectories12 × × × × ×
Assumes subject-specific effects are Gaussian ×
Badly biased if non-random dropouts ? × ×
Biased in general ×
Harder to get tests & CLs ×13 ×14
Requires large # subjects/clusters ×
SEs are wrong ×15 ×
Assumptions are not verifiable in small samples × N/A × × ×
Does not extend to complex settings such as time-dependent covariates and dynamic 16 models × × × × ?

2 Thanks to Charles Berry, Brian Cade, Peter Flom, Bert Gunter, and Leena Choi for valuable input.

3 GEE: generalized estimating equations; GLS: generalized least squares; LOCF: last observation carried forward.

4 E.g., compute within-subject slope, mean, or area under the curve over time. Assumes that the summary measure is an adequate summary of the time profile and assesses the relevant treatment effect.

5 Unless one uses the Huynh-Feldt or Greenhouse-Geisser correction

6 For full efficiency, if using the working independence model

7 Or requires the user to specify one

8 For full efficiency of regression coefficient estimates

9 Unless the last observation is missing

10 The cluster sandwich variance estimator used to estimate SEs in GEE does not perform well in this situation, and neither does the working independence model because it does not weight subjects properly.

11 Unless one knows how to properly do a weighted analysis

12 Or users population averages

13 Unlike GLS, does not use standard maximum likelihood methods yielding simple likelihood ratio \(\chi^2\) statistics. Requires high-dimensional integration to marginalize random effects, using complex approximations, and if using SAS, unintuitive d.f. for the various tests.

14 Because there is no correct formula for SE of effects; ordinary SEs are not penalized for imputation and are too small

15 If correction not applied

16 E.g., a model with a predictor that is a lagged value of the response variable

  • Markov models use ordinary univariate software and are very flexible
  • They apply the same way to binary, ordinal, nominal, and continuous Y
  • They require post-fitting calculations to get probabilities, means, and quantiles that are not conditional on the previous Y value
I

Gardiner et al. (2009) compared several longitudinal data models, especially with regard to assumptions and how regression coefficients are estimated. Peters et al. (2012) have an empirical study confirming that the “use all available data” approach of likelihood–based longitudinal models makes imputation of follow-up measurements unnecessary.

J

7.4 Parameter Estimation Procedure

  • Generalized least squares
  • Like weighted least squares but uses a covariance matrix that is not diagonal
  • Each subject can have her own shape of \(V_{i}\) due to each subject being measured at a different set of times
  • Maximum likelihood
  • Newton-Raphson or other trial-and-error methods used for estimating parameters
  • For small number of subjects, advantages in using REML (restricted maximum likelihood) instead of ordinary MLE (Diggle et al., 2002, p. Section~5.3), (Pinheiro & Bates, 2000, p. Chapter~5), Goldstein (1989) (esp. to get more unbiased estimate of the covariance matrix)
  • When imbalances are not severe, OLS fitted ignoring subject identifiers may be efficient
    • But OLS standard errors will be too small as they don’t take intra-cluster correlation into account
    • May be rectified by substituting covariance matrix estimated from Huber-White cluster sandwich estimator or from cluster bootstrap
  • When imbalances are severe and intra-subject correlations are strong, OLS is not expected to be efficient because it gives equal weight to each observation
    • a subject contributing two distant observations receives \(\frac{1}{5}\) the weight of a subject having 10 tightly-spaced observations
KLM

7.5 Common Correlation Structures

  • Usually restrict ourselves to isotropic correlation structures — correlation between responses within subject at two times depends only on a measure of distance between the two times, not the individual times (this will be relaxed in the last structure covered below)
  • We simplify further and assume depends on \(|t_{1} - t_{2}|\)
  • Can speak interchangeably of correlations of residuals within subjects or correlations between responses measured at different times on the same subject, conditional on covariates \(X\)
  • Assume that the correlation coefficient for \(Y_{it_{1}}\) vs. \(Y_{it_{2}}\) conditional on baseline covariates \(X_{i}\) for subject \(i\) is \(h(|t_{1} - t_{2}|, \rho)\), where \(\rho\) is a vector (usually a scalar) set of fundamental correlation parameters
  • Some commonly used structures when times are continuous and are not equally spaced (Pinheiro & Bates, 2000, Section 5.3.3) (nlme correlation function names are at the right if the structure is implemented in nlme):
NO
Table 7.1: Some longitudinal data correlation structures
Structure nlme Function
Compound symmetry: \(h = \rho\) if \(t_{1} \neq t_{2}\), 1 if \(t_{1}=t_{2}\) 17 corCompSymm
Autoregressive-moving average lag 1: \(h = \rho^{|t_{1} - t_{2}|} = \rho^s\) where \(s = |t_{1}-t_{2}|\) corCAR1
Exponential: \(h = \exp(-s/\rho)\) corExp
Gaussian: \(h = \exp[-(s/\rho)^2]\) corGaus
Linear: \(h = (1 - s/\rho)[s < \rho]\) corLin
Rational quadratic: \(h = 1 - (s/\rho)^{2}/[1+(s/\rho)^{2}]\) corRatio
Spherical: \(h = [1-1.5(s/\rho)+0.5(s/\rho)^{3}][s < \rho]\) corSpher
Linear exponent AR(1): \(h = \rho^{d_{min} + \delta\frac{s - d_{min}}{d_{max} - d_{min}}}\), 1 if \(t_{1}=t_{2}\) Simpson et al. (2010)
Exponential decline with floor and non-isotropy: \(h = k + (1-k) \exp(-\exp(a+b\frac{t_{1}+t_{2}}{2})|t_{1}-t_{2}|)\) corFloorExp

17 Essentially what two-way ANOVA assumes

The structures 3-7 use \(\rho\) as a scaling parameter, not as something restricted to be in \([0,1]\)

The last structure is implemented in the rms package. The \(k\) parameter is restricted to be in \([0,1]\) by modeling it as \(\text{expit}(k^{*})\) where \(k^{*}\) has an unrestricted range and \(\text{expit}(x) = \frac{1}{1 + \exp(-x)}\). This structure allows for non-isotropy and for a nonzero limiting correlation as the time lag \(\rightarrow \infty\). It is a shared random effect plus serial decay mixture (a continuous-time analog of a random intercept superimposed on an Ornstein-Uhlenbeck exponential-decay process). \(k\) is the correlation contributed by a persistent, subject-level component that never fades; \(1 - k\) is the share of correlation carried by a component that decays with lag at rate \(\exp(a + b\frac{t_{1}+t_{2}}{2})\). \(b\) is the non-isotropy term, letting the rate grow or shrink with the time pair’s midpoint.

7.6 Checking Model Fit

  • Constant variance assumption: usual residual plots
  • Normality assumption: usual qq residual plots
  • Correlation pattern: Variogram
    • Estimate correlations of all possible pairs of residuals at different time points
    • Pool all estimates at same absolute difference in time \(s\)
    • Variogram is a plot with \(y = 1 - \hat{h}(s, \rho)\) vs. \(s\) on the \(x\)-axis
    • Superimpose the theoretical variogram assumed by the model
    • This does not allow for non-isotropy
P

7.7 R Software

  • Nonlinear mixed effects model package of Pinheiro & Bates
  • For linear models, fitting functions are
    • lme for mixed effects models
    • gls for generalized least squares without random effects
  • For this version the rms package has Gls so that many features of rms can be used:
    • anova: all partial Wald tests, test of linearity, pooled tests
    • summary: effect estimates (differences in \(\hat{Y}\)) and confidence limits, can be plotted
    • plot, ggplot, plotp: continuous effect plots
    • nomogram: nomogram
    • Function: generate R function code for fitted model
    • latex:  representation of fitted model
Q

In addition, Gls has a bootstrap option (hence you do not use rms’s bootcov for Gls fits).
To get regular gls functions named anova (for likelihood ratio tests, AIC, etc.) or summary use anova.gls or summary.gls * nlme package has many graphics and fit-checking functions * Several functions will be demonstrated in the case study

7.8 Case Study

Consider the dataset in Table~6.9 of Davis[davis-repmeas, pp. 161-163] from a multi-center, randomized controlled trial of botulinum toxin type B (BotB) in patients with cervical dystonia from nine U.S. sites.

  • Randomized to placebo (\(N=36\)), 5000 units of BotB (\(N=36\)), 10,000 units of BotB (\(N=37\))
  • Response variable: total score on Toronto Western Spasmodic Torticollis Rating Scale (TWSTRS), measuring severity, pain, and disability of cervical dystonia (high scores mean more impairment)
  • TWSTRS measured at baseline (week 0) and weeks 2, 4, 8, 12, 16 after treatment began
  • Dataset cdystonia from web site
R

7.8.1 Graphical Exploration of Data

Code
require(rms)
require(data.table)
options(prType='html')    # for model print, summary, anova, validate
getHdata(cdystonia)
setDT(cdystonia)          # convert to data.table
cdystonia[, uid := paste(site, id)]   # unique subject ID

# Tabulate patterns of subjects' time points
g <- function(w) paste(sort(unique(w)), collapse=' ')
cdystonia[, table(tapply(week, uid, g))]

            0         0 2 4   0 2 4 12 16       0 2 4 8    0 2 4 8 12 
            1             1             3             1             1 
0 2 4 8 12 16    0 2 4 8 16   0 2 8 12 16   0 4 8 12 16      0 4 8 16 
           94             1             2             4             1 
Code
# Plot raw data, superposing subjects
xl <- xlab('Week'); yl <- ylab('TWSTRS-total score')
ggplot(cdystonia, aes(x=week, y=twstrs, color=factor(id))) +
       geom_line() + xl + yl + facet_grid(treat ~ site) +
       guides(color=FALSE)
Figure 7.1: Time profiles for individual subjects, stratified by study site and dose
Code
# Show quartiles
g <- function(x) {
  k <- as.list(quantile(x, (1 : 3) / 4, na.rm=TRUE))
  names(k) <- .q(Q1, Q2, Q3)
  k
}
cdys <- cdystonia[, g(twstrs), by=.(treat, week)]
ggplot(cdys, aes(x=week, y=Q2)) + xl + yl + ylim(0, 70) +
  geom_line() + facet_wrap(~ treat, nrow=2) +
  geom_ribbon(aes(ymin=Q1, ymax=Q3), alpha=0.2)
Figure 7.2: Quartiles of TWSTRS stratified by dose
Code
# Show means with bootstrap nonparametric CLs
cdys <-  cdystonia[, as.list(smean.cl.boot(twstrs)),
                   by = list(treat, week)]
ggplot(cdys, aes(x=week, y=Mean)) + xl + yl + ylim(0, 70) +
  geom_line() + facet_wrap(~ treat, nrow=2) +
  geom_ribbon(aes(x=week, ymin=Lower, ymax=Upper), alpha=0.2)
Figure 7.3: Mean responses and nonparametric bootstrap 0.95 confidence limits for population means, stratified by dose

Model with \(Y_{i0}\) as Baseline Covariate

Code
baseline <- cdystonia[week == 0]
baseline[, week := NULL]
setnames(baseline, 'twstrs', 'twstrs0')
followup <- cdystonia[week > 0, .(uid, week, twstrs)]
setkey(baseline, uid)
setkey(followup, uid, week)
both     <- Merge(baseline, followup, id = ~ uid)
         Vars Obs Unique IDs IDs in #1 IDs not in #1
baseline    7 109        109        NA            NA
followup    3 522        108       108             0
Merged      9 523        109       109             0

Number of unique IDs in any data frame : 109 
Number of unique IDs in all data frames: 108 
Code
# Remove person with no follow-up record
both     <- both[! is.na(week)]
dd       <- datadist(both)
options(datadist='dd')

7.8.2 Using Generalized Least Squares

We stay with baseline adjustment and use a variety of correlation structures, with constant variance. Time is modeled as a restricted cubic spline with 3 knots, because there are only 3 unique interior values of week.

S
Code
require(nlme)
cp <- list(corCAR1,corExp,corCompSymm,corLin,corGaus,corSpher,corFloorExp)
z  <- vector('list', length(cp))
for (k in 1:length(cp)) {
  z[[k]] <- gls(
    twstrs ~ treat * rcs(week, 3) +
      rcs(twstrs0, 3) + rcs(age, 4) * sex,
    data = both,
    correlation = cp[[k]](form = ~ week | uid)
  )
}
anova(z[[1]],z[[2]],z[[3]],z[[4]],z[[5]],z[[6]],z[[7]], test=FALSE)
       Model df      AIC      BIC    logLik
z[[1]]     1 20 3553.906 3638.357 -1756.953
z[[2]]     2 20 3553.906 3638.357 -1756.953
z[[3]]     3 20 3587.974 3672.426 -1773.987
z[[4]]     4 20 3575.079 3659.531 -1767.540
z[[5]]     5 20 3621.081 3705.532 -1790.540
z[[6]]     6 20 3570.958 3655.409 -1765.479
z[[7]]     7 22 3540.028 3632.925 -1748.014

AIC computed above is set up so that smaller values are better. From this the 3-parameter correlation structure is the best fitting. For the remainder of the analysis use corFloorExp, using Gls.

Keselman et al. (1998) did a simulation study to study the reliability of AIC for selecting the correct covariance structure in repeated measurement models. In choosing from among 11 structures, AIC selected the correct structure 47% of the time. Gurka et al. (2011) demonstrated that fixed effects in a mixed effects model can be biased, independent of sample size, when the specified covariate matrix is more restricted than the true one.
Code
a <- Gls(twstrs ~ treat * rcs(week, 3) + rcs(twstrs0, 3) +
         rcs(age, 4) * sex, data=both,
         correlation=corFloorExp(form=~week | uid))
a

Generalized Least Squares Fit by REML

Gls(model = twstrs ~ treat * rcs(week, 3) + rcs(twstrs0, 3) + 
    rcs(age, 4) * sex, data = both, correlation = corFloorExp(form = ~week | 
    uid))
Obs522 Log-restricted-likelihood-1748.01
Clusters108 Model d.f.17
g11.481 σ8.5635
d.f.504
β S.E. t P(>|t|)
Intercept  -2.1683  12.4446 -0.17 0.8617
treat=5000U   0.5425   2.6007 0.21 0.8348
treat=Placebo   7.2832   2.6176 2.78 0.0056
week   0.3533   0.3012 1.17 0.2414
week'   0.6672   0.2957 2.26 0.0245
twstrs0   0.8181   0.1518 5.39 <0.0001
twstrs0'   0.2180   0.1881 1.16 0.2470
age  -0.0941   0.2461 -0.38 0.7022
age'   0.6436   0.6794 0.95 0.3440
age''  -3.2761   2.6813 -1.22 0.2223
sex=M  23.6319  19.5183 1.21 0.2266
treat=5000U × week   0.0589   0.4273 0.14 0.8905
treat=Placebo × week  -0.1469   0.4297 -0.34 0.7326
treat=5000U × week'  -0.4238   0.4188 -1.01 0.3121
treat=Placebo × week'  -0.6140   0.4207 -1.46 0.1450
age × sex=M  -0.5641   0.4661 -1.21 0.2267
age' × sex=M   1.3575   1.2976 1.05 0.2960
age'' × sex=M  -3.5408   5.0401 -0.70 0.4827
Correlation Structure: corFloorExp
 Formula: ~week | uid 
 Parameter estimate(s):
          k           a           b 
 0.17571863 -1.08095556 -0.08066475 
Code
cs <- a$modelStruct$corStruct
cs
Correlation structure of class corFloorExp representing
  corr(t1,t2) = k + (1-k)*exp(-exp(a+b*(t1+t2)/2)*|t1-t2|)
          k           a           b 
 0.17571863 -1.08095556 -0.08066475 

Plot the estimated correlation function for all observed pairs of times.

Code
co <- coef(cs)
g <- function(t1, t2) {
  k <- plogis(co["k"])
  a <- co["a"]
  b <- co["b"]
  k + (1 - k) * exp(-exp(a + b * (t1 + t2) / 2) * abs(t1 - t2))
}
times <- sort(unique(both$week))
w <- setDT(expand.grid(t1 = times, t2 = times))
w <- w[t2 > t1]
w[, lag := t2 - t1]
w[, mid := (t1 + t2) / 2]
w[, rho := g(t1, t2)]
ggplot(w, aes(x = lag, y = rho, label=mid)) +
  geom_text(size=2.5) +
  xlab(expression(t[2] - t[1])) + ylab(expression(hat(rho)))
Figure 7.4: Fitted 3-parameter correlation \(\hat{\rho}\) as a function of time lag (\(x\)) and time midpoint (numbers)

The numbers drawn for each point are the values of \(\frac{t_{1} + t_{2}}{2}\). The degree to which points for the same time lag have different vertical values is the degree to which time midpoints figure into the correlation structure in addition to time lags, i.e., the degree of non-isotropy. We see a moderate degree of non-isotropy. We also see the possibility of greater-than-zero long-term correlation, i.e., a need for a compound symmetric correlation term and slight inadequacy of AR(1).

\(\hat{\rho} = 0.8672\) from an AR(1) fit, the estimate of the correlation between two T measurements taken one week apart on the same subject. The estimated correlation for measurements 10 weeks apart is \(0.8672^{10} = 0.24\).
Code
v <- Variogram(a, form=~ week | uid)
plot(v)
Figure 7.5: Variogram, with assumed correlation pattern superimposed

Check constant variance and normality assumptions:

U
Code
both$resid <- r <- resid(a); both$fitted <- fitted(a)
yl <- ylab('Residuals')
p1 <- ggplot(both, aes(x=fitted, y=resid)) + geom_point() +
      facet_grid(~ treat) + yl
p2 <- ggplot(both, aes(x=twstrs0, y=resid)) + geom_point()+yl
p3 <- ggplot(both, aes(x=week, y=resid)) + yl + ylim(-20,20) +
      stat_summary(fun.data="mean_sdl", geom='smooth')
p4 <- ggplot(both, aes(sample=resid)) + stat_qq() +
      geom_abline(intercept=mean(r), slope=sd(r)) + yl
gridExtra::grid.arrange(p1, p2, p3, p4, ncol=2)
Figure 7.6: Three residual plots to check for absence of trends in central tendency and in variability. Upper right panel shows the baseline score on the \(x\)-axis. Bottom left panel shows the mean \(\pm 2\times\) SD. Bottom right panel is the QQ plot for checking normality of residuals from the GLS fit.

Now get hypothesis tests, estimates, and graphically interpret the model.

Code
anova(a)

Wald Statistics for twstrs

χ2 d.f. P
treat (Factor+Higher Order Factors) 27.50 6 0.0001
 All Interactions 19.39 4 0.0007
week (Factor+Higher Order Factors) 102.07 6 <0.0001
 All Interactions 19.39 4 0.0007
 Nonlinear (Factor+Higher Order Factors) 5.80 3 0.1219
twstrs0 219.82 2 <0.0001
 Nonlinear 1.34 1 0.2465
age (Factor+Higher Order Factors) 8.21 6 0.2231
 All Interactions 4.41 3 0.2205
 Nonlinear (Factor+Higher Order Factors) 6.56 4 0.1608
sex (Factor+Higher Order Factors) 5.21 4 0.2668
 All Interactions 4.41 3 0.2205
treat × week (Factor+Higher Order Factors) 19.39 4 0.0007
 Nonlinear 2.24 2 0.3263
 Nonlinear Interaction : f(A,B) vs. AB 2.24 2 0.3263
age × sex (Factor+Higher Order Factors) 4.41 3 0.2205
 Nonlinear 3.48 2 0.1753
 Nonlinear Interaction : f(A,B) vs. AB 3.48 2 0.1753
TOTAL NONLINEAR 13.24 8 0.1040
TOTAL INTERACTION 23.77 7 0.0013
TOTAL NONLINEAR + INTERACTION 31.06 11 0.0011
TOTAL 332.95 17 <0.0001
Code
plot(anova(a))
Figure 7.7: Results of anova.rms from generalized least squares fit with continuous time AR1 correlation structure
Code
ylm <- ylim(25, 60)
p1 <- ggplot(Predict(a, week, treat, conf.int=FALSE),
             adj.subtitle=FALSE, legend.position='top') + ylm
p2 <- ggplot(Predict(a, twstrs0), adj.subtitle=FALSE) + ylm
p3 <- ggplot(Predict(a, age, sex), adj.subtitle=FALSE,
             legend.position='top') + ylm
gridExtra::grid.arrange(p1, p2, p3, ncol=2)
Figure 7.8: Estimated effects of time, baseline TWSTRS, age, and sex
Code
summary(a)  # Shows for week 8
Low High Δ Effect S.E. Lower 0.95 Upper 0.95
week 4 12 8 6.8290 1.061 4.750 8.909
twstrs0 39 53 14 13.7600 0.928 11.940 15.580
age 46 65 19 2.3580 2.147 -1.851 6.567
treat --- 5000U:10000U 1 2 0.5895 1.980 -3.291 4.470
treat --- Placebo:10000U 1 3 5.4940 1.986 1.602 9.386
sex --- M:F 1 2 -1.1110 1.864 -4.763 2.542
Code
# To get results for week 8 for a different reference group
# for treatment, use e.g. summary(a, week=4, treat='Placebo')

# Compare low dose with placebo, separately at each time
k1 <- contrast(a, list(week=c(2,4,8,12,16), treat='5000U'),
                  list(week=c(2,4,8,12,16), treat='Placebo'))
options(width=80)
print(k1, digits=3)
    week twstrs0 age sex Contrast S.E.  Lower  Upper     Z P(>|z|)
1      2      46  56   F    -6.33 2.08 -10.41 -2.248 -3.04  0.0024
2      4      46  56   F    -5.92 1.77  -9.38 -2.451 -3.35  0.0008
3      8      46  56   F    -4.90 2.00  -8.82 -0.992 -2.46  0.0140
4*    12      46  56   F    -3.13 1.84  -6.74  0.484 -1.70  0.0896
5*    16      46  56   F    -1.17 2.10  -5.29  2.956 -0.55  0.5794

Redundant contrasts are denoted by *

Confidence intervals are 0.95 individual intervals
Code
# Compare high dose with placebo
k2 <- contrast(a, list(week=c(2,4,8,12,16), treat='10000U'),
                  list(week=c(2,4,8,12,16), treat='Placebo'))
print(k2, digits=3)
    week twstrs0 age sex Contrast S.E.  Lower Upper     Z P(>|z|)
1      2      46  56   F    -6.99 2.05 -11.01 -2.97 -3.41  0.0007
2      4      46  56   F    -6.70 1.74 -10.11 -3.28 -3.84  0.0001
3      8      46  56   F    -5.49 1.99  -9.39 -1.60 -2.77  0.0057
4*    12      46  56   F    -1.84 1.83  -5.43  1.75 -1.00  0.3163
5*    16      46  56   F     2.44 2.09  -1.66  6.53  1.17  0.2435

Redundant contrasts are denoted by *

Confidence intervals are 0.95 individual intervals
Code
k1 <- as.data.frame(k1[c('week', 'Contrast', 'Lower', 'Upper')])
p1 <- ggplot(k1, aes(x=week, y=Contrast)) + geom_point() +
      geom_line() + ylab('Low Dose - Placebo') +
      geom_errorbar(aes(ymin=Lower, ymax=Upper), width=0)
k2 <- as.data.frame(k2[c('week', 'Contrast', 'Lower', 'Upper')])
p2 <- ggplot(k2, aes(x=week, y=Contrast)) + geom_point() +
      geom_line() + ylab('High Dose - Placebo') +
      geom_errorbar(aes(ymin=Lower, ymax=Upper), width=0)
gridExtra::grid.arrange(p1, p2, ncol=2)
Figure 7.9: Contrasts and 0.95 confidence limits from GLS fit

Although multiple d.f. tests such as total treatment effects or treatment \(\times\) time interaction tests are comprehensive, their increased degrees of freedom can dilute power. In a treatment comparison, treatment contrasts at the last time point (single d.f. tests) are often of major interest. Such contrasts are informed by all the measurements made by all subjects (up until dropout times) when a smooth time trend is assumed.

V
Code
n <- nomogram(a, age=c(seq(20, 80, by=10), 85))
plot(n, cex.axis=.55, cex.var=.8, lmgp=.25)  # Figure (*\ref{fig:longit-nomogram}*)
Figure 7.10: Nomogram from GLS fit. Second axis is the baseline score.

7.8.3 Semiparametric Random Effects Models

  • Ordinal semiparametric model does away with distributional assumptions
  • Within-subject dependence can be accounted for with a Markov structure, (see later), GEE, or random effects
  • Semiparametric models’ coefficient estimates don’t change if \(Y\) is monotonically transformed
  • Start with a proportional odds (PO) model
  • Add random subject-specific intercepts to the model
  • Would have been a good fit to the correlation pattern had it been compound symmetric
  • Compare deviance of PO model to deviances of all available link functions to see which link fits best
Code
f <- orm(twstrs ~ treat * rcs(week, 3) + rcs(twstrs0, 3) +
         rcs(age, 4) * sex + cluster(uid), data=both,
         x=TRUE, y=TRUE, maxit.outer=300)
f

Logistic (Proportional Odds) Ordinal Regression Model

orm(formula = twstrs ~ treat * rcs(week, 3) + rcs(twstrs0, 3) + 
    rcs(age, 4) * sex + cluster(uid), data = both, x = TRUE, 
    y = TRUE, maxit.outer = 300)
Model Likelihood
Ratio Test
Discrimination
Indexes
Rank Discrim.
Indexes
Obs522 LR χ2298.48 R20.436 ρ0.781
ESS521.7 d.f.17 R217,5220.417 Dxy0.600
Distinct Y62 P(>χ2)<0.0001 R217,521.70.417
Cluster onuid |P(Y ≥ Y0.5)-½|0.350
Clusters108
σγ1.7359 [1.4321, 2.104]
Y0.542
max |∂log L/∂β|0.0001
β S.E. Wald Z P(>|Z|)
treat=5000U   0.1063  0.6978 0.15 0.8789
treat=Placebo   2.3443  0.7106 3.30 0.0010
week   0.1210  0.0795 1.52 0.1277
week'   0.1891  0.0872 2.17 0.0301
twstrs0   0.2253  0.0472 4.77 <0.0001
twstrs0'   0.1280  0.0581 2.20 0.0276
age  -0.0156  0.0741 -0.21 0.8336
age'   0.1927  0.2041 0.94 0.3452
age''  -1.0597  0.8037 -1.32 0.1873
sex=M   4.8434  5.8230 0.83 0.4055
treat=5000U × week   0.0499  0.1099 0.45 0.6502
treat=Placebo × week  -0.0554  0.1122 -0.49 0.6217
treat=5000U × week'  -0.1610  0.1203 -1.34 0.1807
treat=Placebo × week'  -0.1365  0.1226 -1.11 0.2656
age × sex=M  -0.1065  0.1392 -0.77 0.4441
age' × sex=M   0.1479  0.3872 0.38 0.7025
age'' × sex=M   0.0330  1.5021 0.02 0.9825
Code
Olinks(f)
      link null.deviance deviance      AIC      LR    R2
1 logistic      3713.175 3414.694 3570.694 298.481 0.417
2   probit      3732.011 3443.773 3599.773 288.239 0.405
3   loglog      3748.263 3463.493 3619.493 284.770 0.401
4  cloglog      3712.715 3438.655 3594.655 274.061 0.389
  • Stay with the PO model
  • SD of random effects \(\sigma_\gamma\) is fairly large on the logit scale, indicating within-person correlation
  • orm function also fits a random effects structure with two \(\sigma\) parameters
  • \(u\) is a \(N(0,1)\) random effect
  • Within-subject time weighting function \(w(t)\)
  • Random effect contribution is \((1 - w(t))\sigma_{1}\times u + w(t)\sigma_{2}\times u\)
  • Take \(w(t)\) to be the fraction of elapsed time between the first and last follow-up visits
Code
both[, mix := (week - 2) / 14]
f <- orm(twstrs ~ treat * rcs(week, 3) + rcs(twstrs0, 3) +
         rcs(age, 4) * sex + cluster(uid) + mix_re(mix), data=both,
         maxit.outer=300)
f

Logistic (Proportional Odds) Ordinal Regression Model

orm(formula = twstrs ~ treat * rcs(week, 3) + rcs(twstrs0, 3) + 
    rcs(age, 4) * sex + cluster(uid) + mix_re(mix), data = both, 
    maxit.outer = 300)
Model Likelihood
Ratio Test
Discrimination
Indexes
Rank Discrim.
Indexes
Obs522 LR χ2284.25 R20.420 ρ0.781
ESS521.7 d.f.17 R217,5220.401 Dxy0.600
Distinct Y62 P(>χ2)<0.0001 R217,521.70.401
Cluster onuid |P(Y ≥ Y0.5)-½|0.351
Clusters108
σ11.6439 [1.2765, 2.1171]
σ21.8507 [1.3712, 2.3302]
Y0.542
max |∂log L/∂β|0.0002
β S.E. Wald Z P(>|Z|)
treat=5000U   0.1024  0.6816 0.15 0.8805
treat=Placebo   2.3625  0.6952 3.40 0.0007
week   0.1196  0.0796 1.50 0.1330
week'   0.1913  0.0873 2.19 0.0285
twstrs0   0.2234  0.0472 4.73 <0.0001
twstrs0'   0.1343  0.0587 2.29 0.0222
age  -0.0094  0.0751 -0.12 0.9006
age'   0.1648  0.2085 0.79 0.4292
age''  -0.9589  0.8169 -1.17 0.2405
sex=M   5.1700  5.8538 0.88 0.3771
treat=5000U × week   0.0504  0.1101 0.46 0.6472
treat=Placebo × week  -0.0571  0.1124 -0.51 0.6111
treat=5000U × week'  -0.1611  0.1203 -1.34 0.1807
treat=Placebo × week'  -0.1353  0.1227 -1.10 0.2704
age × sex=M  -0.1154  0.1400 -0.82 0.4096
age' × sex=M   0.1782  0.3896 0.46 0.6474
age'' × sex=M  -0.0785  1.5098 -0.05 0.9586
Code
deviance(f)
                 intercepts                intercepts+x 
                   4078.936                    3571.416 
  intercepts+random effects intercepts+x+random effects 
                   3698.472                    3414.225 
  • Deviance did not improve since \(\sigma_1\) and \(\sigma_2\) are close
  • If random effects are used, they can be the single-\(\sigma\) variety.

7.8.4 Bayesian Proportional Odds Random Effects Model

  • Develop a \(y\)-transformation invariant longitudinal model
  • Proportional odds model with no grouping of TWSTRS scores
  • Bayesian random effects model
  • Random effects Gaussian with exponential prior distribution for its SD, with mean 1.0
  • Compound symmetry correlation structure
  • Demonstrates a large amount of patient-to-patient intercept variability
W
Code
require(rmsb)
cmdstanr::set_cmdstan_path(cmdstan.loc)
# cmdstan.loc is defined in ~/.Rprofile
options(mc.cores=4, rmsb.backend='cmdstan')
bpo <- borm(twstrs ~ treat * rcs(week, 3) + rcs(twstrs0, 3) +
            rcs(age, 4) * sex + cluster(uid), data=both, file='bpo.rds')
Running MCMC with 4 parallel chains...

Chain 4 finished in 7.0 seconds.
Chain 3 finished in 7.1 seconds.
Chain 2 finished in 7.4 seconds.
Chain 1 finished in 7.6 seconds.

All 4 chains finished successfully.
Mean chain execution time: 7.3 seconds.
Total execution time: 7.7 seconds.
Code
# file= means that after the first time the model is run, it will not
# be re-run unless the data, fitting options, or underlying Stan code change
stanDx(bpo)
Iterations: 2000 on each of 4 chains, with 4000 posterior distribution samples saved

For each parameter, n_eff is a crude measure of effective sample size
and Rhat is the potential scale reduction factor on split chains
(at convergence, Rhat=1)


Checking sampler transitions for divergences.
No divergent transitions found.

Checking E-BFMI - sampler transitions HMC potential energy.
E-BFMI satisfactory.

Rank-normalized split effective sample size satisfactory for all parameters.

The following parameters had rank-normalized split R-hat greater than 1.01:
  alpha[23], alpha[24], alpha[25], alpha[26], alpha[27], alpha[28], alpha[29], alpha[30], alpha[31], alpha[32], alpha[33], alpha[34], alpha[35], alpha[36], alpha[37], alpha[38], alpha[39], alpha[40], alpha[41], alpha[42], alpha[43], alpha[44], alpha[45], alpha[46]
Such high values indicate incomplete mixing and biased estimation.
You should consider regularizing your model with additional prior information or a more effective parameterization.

Processing complete.

EBFMI: 0.744 0.734 0.668 0.79 

   Parameter  Rhat ESS bulk ESS tail
1   alpha[1] 1.006      571     1557
2   alpha[2] 1.008      408      907
3   alpha[3] 1.009      377      889
4   alpha[4] 1.010      346      789
5   alpha[5] 1.011      317      683
6   alpha[6] 1.011      307      670
7   alpha[7] 1.012      293      707
8   alpha[8] 1.012      292      746
9   alpha[9] 1.012      314      988
10 alpha[10] 1.011      312      774
11 alpha[11] 1.012      317      798
12 alpha[12] 1.013      303      739
13 alpha[13] 1.013      298      757
14 alpha[14] 1.013      308      679
15 alpha[15] 1.014      310      699
16 alpha[16] 1.012      318      681
17 alpha[17] 1.012      325      708
18 alpha[18] 1.014      326      688
19 alpha[19] 1.014      330      668
20 alpha[20] 1.014      336      599
21 alpha[21] 1.014      337      618
22 alpha[22] 1.015      334      622
23 alpha[23] 1.016      330      628
24 alpha[24] 1.017      321      561
25 alpha[25] 1.020      324      644
26 alpha[26] 1.020      332      743
27 alpha[27] 1.020      339      722
28 alpha[28] 1.021      344      722
29 alpha[29] 1.022      348      741
30 alpha[30] 1.023      343      805
31 alpha[31] 1.023      340      810
32 alpha[32] 1.024      345      818
33 alpha[33] 1.023      353      847
34 alpha[34] 1.023      363      945
35 alpha[35] 1.023      358      821
36 alpha[36] 1.023      366      899
37 alpha[37] 1.022      380      756
38 alpha[38] 1.022      391      847
39 alpha[39] 1.021      391      782
40 alpha[40] 1.021      403      743
41 alpha[41] 1.020      428      768
42 alpha[42] 1.020      434      806
43 alpha[43] 1.019      446      831
44 alpha[44] 1.018      466      846
45 alpha[45] 1.017      494      873
46 alpha[46] 1.016      553      910
47 alpha[47] 1.014      567     1104
48 alpha[48] 1.014      595     1109
49 alpha[49] 1.012      627     1376
50 alpha[50] 1.009      664     1188
51 alpha[51] 1.008      714     1528
52 alpha[52] 1.007      742     1353
53 alpha[53] 1.005      738     1174
54 alpha[54] 1.005      754     1242
55 alpha[55] 1.005      760     1470
56 alpha[56] 1.005      763     1351
57 alpha[57] 1.004      812     1413
58 alpha[58] 1.004      862     1505
59 alpha[59] 1.004      892     1599
60 alpha[60] 1.003     1038     1727
61 alpha[61] 1.002     1233     2107
62   beta[1] 1.003      720     1467
63   beta[2] 1.005      581     1104
64   beta[3] 1.001     1237     2020
65   beta[4] 1.003     3668     2956
66   beta[5] 1.002      552     1242
67   beta[6] 1.006      873     1533
68   beta[7] 1.007      778     1615
69   beta[8] 1.003      856     1349
70   beta[9] 1.001      803     1538
71  beta[10] 1.004      788     1705
72  beta[11] 1.001     3579     2959
73  beta[12] 1.001     3351     3140
74  beta[13] 1.000     4054     2975
75  beta[14] 1.001     3297     2751
76  beta[15] 1.006      851     1568
77  beta[16] 1.000      949     1642
78  beta[17] 1.003      840     1274
79 sigmag[1] 1.002      633     1277
Code
print(bpo, intercepts=TRUE)

Bayesian Logistic (Proportional Odds) Ordinal Regression Model

Dirichlet Priors With Concentration Parameter 0.044 for Intercepts

borm(formula = twstrs ~ treat * rcs(week, 3) + rcs(twstrs0, 3) + 
    rcs(age, 4) * sex + cluster(uid), data = both, file = "bpo.rds")
Mixed Calibration/
Discrimination Indexes
Discrimination
Indexes
Rank Discrim.
Indexes
Obs522 LOO log L-1746.72±23.75 |P(Y ≥ Y0.5)-½|0.355 [0.336, 0.372] ρ0.767 [0.753, 0.781]
Distinct Y62 LOO IC3493.44±47.5 C0.793 [0.786, 0.799]
Y0.542 Effective p179.47±7.77 Dxy0.586 [0.571, 0.599]
p17 B0.149 [0.139, 0.16]
Draws4000
Chains4
Time9.1s
Cluster onuid
Clusters108
σγ1.8833 [1.5382, 2.2963]
Mean β Median β S.E. Lower Upper P(β>0) Symmetry
y≥7   -1.5720   -1.6078  4.1951   -9.2483   6.8519  0.3428  1.02
y≥9   -2.5850   -2.6220  4.1112  -10.6225   5.3861  0.2618  1.04
y≥10   -3.7632   -3.8547  4.0451  -11.4695   4.1585  0.1812  1.02
y≥11   -4.2145   -4.3435  4.0281  -11.5259   4.0076  0.1535  1.01
y≥13   -4.4115   -4.5606  4.0259  -11.8623   3.6348  0.1437  1.01
y≥14   -4.7675   -4.9356  4.0320  -12.1260   3.2934  0.1248  1.01
y≥15   -5.0697   -5.1894  4.0305  -12.4109   3.1150  0.1070  1.00
y≥16   -5.4555   -5.5912  4.0206  -12.7103   2.8077  0.0900  1.02
y≥17   -6.2618   -6.4382  4.0110  -13.8012   1.8442  0.0622  1.01
y≥18   -6.5185   -6.6735  4.0090  -14.0047   1.5322  0.0550  1.01
y≥19   -6.8063   -6.9443  4.0070  -14.1248   1.4106  0.0485  1.01
y≥20   -6.9987   -7.1278  4.0067  -14.3242   1.2295  0.0432  1.02
y≥21   -7.1798   -7.3212  4.0060  -14.5152   1.0184  0.0388  1.01
y≥22   -7.5938   -7.7205  4.0044  -15.0140   0.5561  0.0305  1.02
y≥23   -7.8595   -8.0222  4.0048  -15.1770   0.3741  0.0260  1.02
y≥24   -8.1450   -8.2985  4.0069  -15.3825   0.1792  0.0222  1.02
y≥25   -8.4053   -8.5557  4.0088  -15.7605   -0.2412  0.0182  1.02
y≥26   -8.8022   -8.9409  4.0091  -16.1711   -0.5898  0.0147  1.03
y≥27   -9.0937   -9.2287  4.0088  -16.2448   -0.6612  0.0125  1.03
y≥28   -9.3386   -9.4712  4.0099  -16.6962   -1.1163  0.0110  1.02
y≥29   -9.5729   -9.7063  4.0100  -17.0265   -1.4746  0.0098  1.02
y≥30   -9.8780  -10.0085  4.0114  -17.1352   -1.5563  0.0082  1.02
y≥31  -10.1710  -10.3326  4.0130  -17.5543   -1.9788  0.0070  1.02
y≥32  -10.2876  -10.4470  4.0139  -17.7106   -2.0778  0.0065  1.03
y≥33  -10.6536  -10.7746  4.0170  -18.0320   -2.4571  0.0050  1.03
y≥34  -10.9639  -11.0901  4.0221  -18.3800   -2.6982  0.0032  1.02
y≥35  -11.1888  -11.3161  4.0252  -18.5938   -2.9897  0.0020  1.03
y≥36  -11.4347  -11.5682  4.0255  -18.7282   -3.1264  0.0018  1.03
y≥37  -11.7117  -11.8391  4.0274  -19.1059   -3.4773  0.0018  1.03
y≥38  -11.9396  -12.0704  4.0287  -19.2576   -3.6035  0.0015  1.02
y≥39  -12.1867  -12.3012  4.0302  -19.5240   -3.8310  0.0015  1.02
y≥40  -12.3721  -12.4948  4.0309  -19.6878   -3.9822  0.0015  1.02
y≥41  -12.5543  -12.6639  4.0323  -20.2463   -4.5504  0.0010  1.02
y≥42  -12.8818  -13.0162  4.0356  -20.5621   -4.8384  0.0005  1.03
y≥43  -13.1119  -13.2388  4.0368  -20.7682   -5.0248  0.0005  1.03
y≥44  -13.4545  -13.6069  4.0418  -21.1503   -5.3743  0.0005  1.03
y≥45  -13.7724  -13.9205  4.0445  -21.4567   -5.6923  0.0005  1.03
y≥46  -14.0736  -14.2213  4.0477  -21.7131   -5.9281  0.0000  1.02
y≥47  -14.4948  -14.6288  4.0495  -21.9025   -6.0711  0.0000  1.02
y≥48  -14.7840  -14.9421  4.0502  -22.5809   -6.7314  0.0000  1.02
y≥49  -15.1568  -15.2941  4.0515  -22.8694   -7.0132  0.0000  1.01
y≥50  -15.4750  -15.6061  4.0510  -23.1979   -7.3766  0.0000  1.02
y≥51  -16.0042  -16.1391  4.0544  -23.8252   -7.9420  0.0000  1.03
y≥52  -16.3703  -16.4831  4.0594  -24.1669   -8.2794  0.0000  1.03
y≥53  -16.8169  -16.9572  4.0616  -24.4996   -8.6445  0.0000  1.02
y≥54  -17.3165  -17.4572  4.0661  -24.6481   -8.7551  0.0000  1.03
y≥55  -17.7293  -17.8605  4.0683  -25.4748   -9.5689  0.0000  1.03
y≥56  -17.9814  -18.1178  4.0713  -25.4868   -9.5427  0.0000  1.04
y≥57  -18.4515  -18.5701  4.0726  -25.7663   -9.8365  0.0000  1.03
y≥58  -19.0120  -19.1306  4.0744  -26.8362  -10.8687  0.0000  1.05
y≥59  -19.3633  -19.4676  4.0781  -26.5873  -10.6038  0.0000  1.04
y≥60  -19.6946  -19.7988  4.0841  -28.2127  -12.2506  0.0000  1.03
y≥61  -20.3902  -20.4763  4.0950  -27.7580  -11.6917  0.0000  1.03
y≥62  -20.7700  -20.8896  4.1037  -28.4717  -12.3341  0.0000  1.03
y≥63  -21.1801  -21.3107  4.1042  -29.4881  -13.3960  0.0000  1.02
y≥64  -21.3235  -21.4345  4.1080  -29.5084  -13.3992  0.0000  1.03
y≥65  -22.0536  -22.1566  4.1163  -30.0504  -14.0163  0.0000  1.03
y≥66  -22.4282  -22.5385  4.1247  -30.0969  -14.0200  0.0000  1.03
y≥67  -22.8431  -22.9603  4.1257  -31.0119  -14.7935  0.0000  1.02
y≥68  -23.6149  -23.7126  4.1418  -31.7650  -15.6396  0.0000  1.01
y≥71  -24.4790  -24.6035  4.1672  -32.5058  -16.2690  0.0000  1.03
treat=5000U   0.0939   0.1045  0.7480   -1.3092   1.5525  0.5528  0.98
treat=Placebo   2.3676   2.3705  0.7369   0.8232   3.6918  0.9995  0.99
week   0.1212   0.1225  0.0812   -0.0385   0.2753  0.9342  0.99
week'   0.1939   0.1922  0.0894   0.0358   0.3776  0.9868  1.02
twstrs0   0.2274   0.2270  0.0506   0.1301   0.3283  1.0000  0.99
twstrs0'   0.1297   0.1306  0.0630   0.0151   0.2557  0.9825  1.06
age   -0.0198   -0.0182  0.0794   -0.1699   0.1392  0.4095  0.96
age'   0.2119   0.2087  0.2178   -0.2075   0.6425  0.8378  1.07
age''   -1.1520   -1.1481  0.8507   -2.8682   0.4801  0.0843  0.95
sex=M   4.4218   4.5276  6.3928   -8.0185   16.9292  0.7532  0.99
treat=5000U × week   0.0521   0.0510  0.1117   -0.1588   0.2671  0.6750  0.99
treat=Placebo × week   -0.0525   -0.0528  0.1133   -0.2643   0.1809  0.3135  1.03
treat=5000U × week'   -0.1643   -0.1639  0.1219   -0.4170   0.0561  0.0907  0.99
treat=Placebo × week'   -0.1411   -0.1408  0.1252   -0.3992   0.0910  0.1278  0.94
age × sex=M   -0.0964   -0.0989  0.1527   -0.3839   0.2034  0.2668  1.01
age' × sex=M   0.1226   0.1228  0.4259   -0.6908   0.9389  0.6220  0.96
age'' × sex=M   0.1218   0.1056  1.6530   -2.9489   3.4179  0.5235  1.05
Code
a <- anova(bpo)
a

Relative Explained Variation for twstrs. Approximate total model Wald χ2 used in denominators of REV:245.1 [204.6, 323.2].

REV Lower Upper d.f.
treat (Factor+Higher Order Factors) 0.131 0.063 0.222 6
 All Interactions 0.093 0.035 0.164 4
week (Factor+Higher Order Factors) 0.588 0.451 0.679 6
 All Interactions 0.093 0.035 0.164 4
 Nonlinear (Factor+Higher Order Factors) 0.021 0.002 0.069 3
twstrs0 0.650 0.504 0.726 2
 Nonlinear 0.017 0.000 0.058 1
age (Factor+Higher Order Factors) 0.025 0.005 0.093 6
 All Interactions 0.014 0.001 0.060 3
 Nonlinear (Factor+Higher Order Factors) 0.022 0.004 0.078 4
sex (Factor+Higher Order Factors) 0.018 0.002 0.073 4
 All Interactions 0.014 0.001 0.060 3
treat × week (Factor+Higher Order Factors) 0.093 0.035 0.164 4
 Nonlinear 0.008 0.000 0.043 2
 Nonlinear Interaction : f(A,B) vs. AB 0.008 0.000 0.043 2
age × sex (Factor+Higher Order Factors) 0.014 0.001 0.060 3
 Nonlinear 0.013 0.000 0.051 2
 Nonlinear Interaction : f(A,B) vs. AB 0.013 0.000 0.051 2
TOTAL NONLINEAR 0.057 0.024 0.145 8
TOTAL INTERACTION 0.106 0.048 0.193 7
TOTAL NONLINEAR + INTERACTION 0.140 0.092 0.260 11
TOTAL 1.000 1.000 1.000 17
Code
plot(a)

  • Show the final graphic (high dose:placebo contrast as function of time
  • Intervals are 0.95 highest posterior density intervals
  • \(y\)-axis: log-odds ratio
X
Code
wks <- c(2,4,8,12,16)
k <- contrast(bpo, list(week=wks, treat='10000U'),
                   list(week=wks, treat='Placebo'),
              cnames=paste('Week', wks))
k
           week   Contrast      S.E.     Lower      Upper P(Contrast>0)
1  Week 2     2 -2.2626083 0.6120556 -3.433556 -1.0799524         0.000
2  Week 4     4 -2.1575922 0.5557379 -3.305747 -1.1264934         0.000
3  Week 8     8 -1.8064637 0.6220963 -2.926396 -0.4885583         0.001
4* Week 12   12 -0.8909499 0.5579443 -1.928477  0.2905370         0.049
5* Week 16   16  0.1656603 0.6272139 -1.094613  1.3450243         0.607

Redundant contrasts are denoted by *

Intervals are 0.95 highest posterior density intervals
Contrast is the posterior mean 
Code
plot(k)

Code
k <- as.data.frame(k[c('week', 'Contrast', 'Lower', 'Upper')])
ggplot(k, aes(x=week, y=Contrast)) + geom_point() +
  geom_line() + ylab('High Dose - Placebo') +
  geom_errorbar(aes(ymin=Lower, ymax=Upper), width=0)

For each posterior draw compute the difference in means and get an exact (to within simulation error) 0.95 highest posterior density intervals for these differences.

Code
M <- Mean(bpo)   # create R function that computes mean Y from X*beta
k <- contrast(bpo, list(week=wks, treat='10000U'),
                   list(week=wks, treat='Placebo'),
              fun=M, cnames=paste('Week', wks))
plot(k, which='diff') + theme(legend.position='bottom')

Code
f <- function(x) {
  hpd <- HPDint(x, prob=0.95)   # is in rmsb
  r <- c(mean(x), median(x), hpd)
  names(r) <- c('Mean', 'Median', 'Lower', 'Upper')
  r
}
w    <- as.data.frame(t(apply(k$esta - k$estb, 2, f)))
week <- as.numeric(sub('Week ', '', rownames(w)))
ggplot(w, aes(x=week, y=Mean)) + geom_point() +
  geom_line() + ylab('High Dose - Placebo') +
  geom_errorbar(aes(ymin=Lower, ymax=Upper), width=0) +
  scale_y_continuous(breaks=c(-8, -4, 0, 4))

7.8.5 Bayesian Markov Semiparametric Model

  • First-order Markov model
  • Serial correlation induced by Markov model is similar to AR(1) which we already know fits these data
  • Markov model is more likely to fit the data than the random effects model, which induces a compound symmetry correlation structure
  • Models state transitions
  • PO model at each visit, with Y from previous visit conditioned upon just like any covariate
  • Need to uncondition (marginalize) on previous Y to get the time-response profile we usually need
  • Semiparametric model is especially attractive because one can easily “uncondition” a discrete Y model, and the distribution of Y for control subjects can be any shape
  • Let measurement times be \(t_{1}, t_{2}, \dots, t_{m}\), and the measurement for a subject at time \(t\) be denoted \(Y(t)\)
  • First-order Markov model:
Y
\[\begin{array}{ccc} \Pr(Y(t_{i}) \geq y | X, Y(t_{i-1})) &=& \mathrm{expit}(\alpha_{y} + X\beta\\ &+& g(Y(t_{i-1}), t_{i}, t_{i} - t_{i-1})) \end{array}\]
  • \(g\) involves any number of regression coefficients for a main effect of \(t\), the main effect of time gap \(t_{i} - t_{i-1}\) if this is not collinear with absolute time, a main effect of the previous state, and interactions between these
  • Examples of how the previous state may be modeled in \(g\):
    • linear in numeric codes for \(Y\)
    • spline function in same
    • discontinuous bi-linear relationship where there is a slope for in-hospital outcome severity, a separate slope for outpatient outcome severity, and an intercept jump at the transition from inpatient to outpatient (or vice versa)
  • Markov model is quite flexible in handling time trends and serial correlation patterns
  • Can allow for irregular measurement times:
    hbiostat.org/stat/irreg.html

Fit the model and run standard Stan diagnostics.

Code
# Create a new variable to hold previous value of Y for the subject
# For week 2, previous value is the baseline value
setDT(both, key=c('uid', 'week'))
both[, ptwstrs := shift(twstrs), by=uid]
both[week == 2, ptwstrs := twstrs0]
dd <- datadist(both)
bmark <- borm(twstrs ~  treat * rcs(week, 3) + rcs(ptwstrs, 4) +
                        rcs(age, 4) * sex,
              data=both, file='bmark.rds')
Running MCMC with 4 parallel chains...

Chain 1 finished in 4.0 seconds.
Chain 2 finished in 4.3 seconds.
Chain 3 finished in 4.3 seconds.
Chain 4 finished in 4.2 seconds.

All 4 chains finished successfully.
Mean chain execution time: 4.2 seconds.
Total execution time: 4.4 seconds.
Code
# When adding partial PO terms for week and ptwstrs, z=-1.8, 5.04
stanDx(bmark)
Iterations: 2000 on each of 4 chains, with 4000 posterior distribution samples saved

For each parameter, n_eff is a crude measure of effective sample size
and Rhat is the potential scale reduction factor on split chains
(at convergence, Rhat=1)


Checking sampler transitions for divergences.
No divergent transitions found.

Checking E-BFMI - sampler transitions HMC potential energy.
E-BFMI satisfactory.

Rank-normalized split effective sample size satisfactory for all parameters.

Rank-normalized split R-hat values satisfactory for all parameters.

Processing complete, no problems detected.

EBFMI: 1.001 1.014 0.987 0.954 

   Parameter  Rhat ESS bulk ESS tail
1   alpha[1] 1.001     2896     2155
2   alpha[2] 1.001     2137     2437
3   alpha[3] 1.001     1954     2465
4   alpha[4] 1.001     1567     2295
5   alpha[5] 1.002     1398     2395
6   alpha[6] 1.001     1471     2234
7   alpha[7] 1.001     1466     2278
8   alpha[8] 1.001     1483     2213
9   alpha[9] 1.002     1807     2388
10 alpha[10] 1.002     1844     2202
11 alpha[11] 1.002     1853     2122
12 alpha[12] 1.002     1860     2118
13 alpha[13] 1.002     1932     2309
14 alpha[14] 1.001     2197     2409
15 alpha[15] 1.001     2436     2524
16 alpha[16] 1.002     2483     2673
17 alpha[17] 1.002     2618     2698
18 alpha[18] 1.002     2751     2488
19 alpha[19] 1.002     3119     3142
20 alpha[20] 1.001     3318     3214
21 alpha[21] 1.001     3245     3341
22 alpha[22] 1.002     3523     3226
23 alpha[23] 1.002     3771     3170
24 alpha[24] 1.001     3844     3080
25 alpha[25] 1.000     4225     3583
26 alpha[26] 1.000     4926     3585
27 alpha[27] 1.001     5476     3548
28 alpha[28] 1.001     6171     3336
29 alpha[29] 1.000     6420     3398
30 alpha[30] 1.001     6804     3321
31 alpha[31] 1.000     6994     3530
32 alpha[32] 1.000     6833     3174
33 alpha[33] 1.001     6497     3003
34 alpha[34] 1.001     7093     3306
35 alpha[35] 1.000     6720     3325
36 alpha[36] 1.000     7210     3593
37 alpha[37] 1.000     6485     3032
38 alpha[38] 1.001     6464     3243
39 alpha[39] 1.000     5667     3139
40 alpha[40] 1.000     5843     3306
41 alpha[41] 1.000     5815     2974
42 alpha[42] 1.001     5693     3772
43 alpha[43] 1.000     5478     3285
44 alpha[44] 1.000     5327     3565
45 alpha[45] 1.000     4851     2972
46 alpha[46] 1.000     4530     3146
47 alpha[47] 1.000     4468     3068
48 alpha[48] 1.000     4603     3354
49 alpha[49] 1.000     4501     2873
50 alpha[50] 1.000     4199     2879
51 alpha[51] 1.001     4172     3114
52 alpha[52] 1.001     4205     2727
53 alpha[53] 1.000     3932     3061
54 alpha[54] 1.000     3979     3334
55 alpha[55] 1.000     3621     2910
56 alpha[56] 1.000     3822     3374
57 alpha[57] 1.000     3684     3472
58 alpha[58] 1.000     3843     3223
59 alpha[59] 1.001     3637     3303
60 alpha[60] 1.002     4029     3423
61 alpha[61] 1.003     4399     3468
62   beta[1] 1.001     8475     3130
63   beta[2] 1.000     8243     2837
64   beta[3] 1.000     5007     3179
65   beta[4] 1.002     8356     2864
66   beta[5] 1.002     2403     2699
67   beta[6] 1.002     4399     3124
68   beta[7] 1.000     5287     3263
69   beta[8] 1.001     7681     2449
70   beta[9] 1.002     8651     2795
71  beta[10] 1.000     9107     3182
72  beta[11] 1.003     7732     2531
73  beta[12] 1.001     8336     2643
74  beta[13] 1.002     7647     2605
75  beta[14] 1.002     8702     3161
76  beta[15] 1.001     7366     3000
77  beta[16] 1.002     9289     2967
78  beta[17] 1.001     8280     3042
79  beta[18] 1.000     8363     2777
Code
stanDxplot(bmark)

Note that posterior sampling is much more efficient without random effects.

Code
bmark

Bayesian Logistic (Proportional Odds) Ordinal Regression Model

Dirichlet Priors With Concentration Parameter 0.044 for Intercepts

borm(formula = twstrs ~ treat * rcs(week, 3) + rcs(ptwstrs, 4) + 
    rcs(age, 4) * sex, data = both, file = "bmark.rds")
Frequencies of Missing Values Due to Each Variable
 twstrs   treat    week ptwstrs     age     sex 
      0       0       0       5       0       0 
Mixed Calibration/
Discrimination Indexes
Discrimination
Indexes
Rank Discrim.
Indexes
Obs517 LOO log L-1786.07±22.28 |P(Y ≥ Y0.5)-½|0.332 [0.315, 0.349] ρ0.83 [0.825, 0.834]
Distinct Y62 LOO IC3572.13±44.57 C0.828 [0.825, 0.831]
Y0.542 Effective p89.88±4.81 Dxy0.656 [0.651, 0.661]
p18 B0.117 [0.113, 0.121]
Draws4000
Chains4
Time5.5s
Mode β Mean β Median β S.E. Lower Upper P(β>0) Symmetry
treat=5000U   0.2216   0.2166   0.2165  0.5519  -0.8748   1.2943  0.6577  1.02
treat=Placebo   1.8317   1.8312   1.8252  0.5699   0.7867   2.9789  0.9998  1.03
week   0.4865   0.4877   0.4882  0.0812   0.3151   0.6356  1.0000  0.98
week'  -0.2878  -0.2884  -0.2890  0.0860  -0.4537  -0.1177  0.0005  1.00
ptwstrs   0.1997   0.2006   0.2013  0.0267   0.1449   0.2489  1.0000  1.01
ptwstrs'  -0.0620  -0.0648  -0.0643  0.0623  -0.1831   0.0577  0.1465  1.03
ptwstrs''   0.5323   0.5466   0.5462  0.2487   0.0178   1.0087  0.9848  0.98
age  -0.0295  -0.0283  -0.0283  0.0310  -0.0948   0.0272  0.1765  1.01
age'   0.1236   0.1208   0.1210  0.0865  -0.0482   0.2924  0.9172  0.99
age''  -0.5069  -0.4978  -0.5009  0.3436  -1.1453   0.1868  0.0752  1.00
sex=M  -0.4631  -0.4167  -0.3922  2.3057  -4.6703   4.1711  0.4305  1.03
treat=5000U × week  -0.0341  -0.0333  -0.0336  0.1070  -0.2591   0.1646  0.3735  1.03
treat=Placebo × week  -0.2719  -0.2718  -0.2716  0.1114  -0.4823  -0.0495  0.0068  0.98
treat=5000U × week'  -0.0340  -0.0352  -0.0344  0.1148  -0.2616   0.1846  0.3845  0.98
treat=Placebo × week'   0.1198   0.1192   0.1179  0.1199  -0.1202   0.3386  0.8388  0.98
age × sex=M   0.0112   0.0102   0.0100  0.0554  -0.0943   0.1180  0.5690  0.97
age' × sex=M  -0.0510  -0.0484  -0.0486  0.1572  -0.3455   0.2504  0.3835  1.01
age'' × sex=M   0.2616   0.2541   0.2542  0.6168  -0.9134   1.4466  0.6587  0.99
Code
a <- anova(bmark)
a

Relative Explained Variation for twstrs. Approximate total model Wald χ2 used in denominators of REV:452 [397.6, 554.4].

REV Lower Upper d.f.
treat (Factor+Higher Order Factors) 0.050 0.027 0.104 6
 All Interactions 0.048 0.021 0.094 4
week (Factor+Higher Order Factors) 0.297 0.222 0.381 6
 All Interactions 0.048 0.021 0.094 4
 Nonlinear (Factor+Higher Order Factors) 0.061 0.025 0.109 3
ptwstrs 0.930 0.857 0.954 3
 Nonlinear 0.040 0.010 0.079 2
age (Factor+Higher Order Factors) 0.008 0.003 0.039 6
 All Interactions 0.001 0.000 0.018 3
 Nonlinear (Factor+Higher Order Factors) 0.005 0.001 0.032 4
sex (Factor+Higher Order Factors) 0.001 0.000 0.022 4
 All Interactions 0.001 0.000 0.018 3
treat × week (Factor+Higher Order Factors) 0.048 0.021 0.094 4
 Nonlinear 0.004 0.000 0.024 2
 Nonlinear Interaction : f(A,B) vs. AB 0.004 0.000 0.024 2
age × sex (Factor+Higher Order Factors) 0.001 0.000 0.018 3
 Nonlinear 0.001 0.000 0.013 2
 Nonlinear Interaction : f(A,B) vs. AB 0.001 0.000 0.013 2
TOTAL NONLINEAR 0.105 0.068 0.180 9
TOTAL INTERACTION 0.048 0.024 0.098 7
TOTAL NONLINEAR + INTERACTION 0.141 0.101 0.220 12
TOTAL 1.000 1.000 1.000 18
Code
plot(a)

Let’s add subject-level random effects to the model. Smallness of the standard deviation of the random effects provides support for the assumption of conditional independence that we like to make for Markov models and allows us to simplify the model by omitting random effects.

Code
bmarkre <- borm(twstrs ~  treat * rcs(week, 3) + rcs(ptwstrs, 4) +
                          rcs(age, 4) * sex + cluster(uid),
                data=both, file='bmarkre.rds')
Running MCMC with 4 parallel chains...

Chain 1 finished in 4.4 seconds.
Chain 2 finished in 4.6 seconds.
Chain 3 finished in 4.6 seconds.
Chain 4 finished in 4.6 seconds.

All 4 chains finished successfully.
Mean chain execution time: 4.6 seconds.
Total execution time: 4.7 seconds.
Code
stanDx(bmarkre)
Iterations: 2000 on each of 4 chains, with 4000 posterior distribution samples saved

For each parameter, n_eff is a crude measure of effective sample size
and Rhat is the potential scale reduction factor on split chains
(at convergence, Rhat=1)


Checking sampler transitions for divergences.
3 of 4000 (0.07%) transitions ended with a divergence.
These divergent transitions indicate that HMC is not fully able to explore the posterior distribution.
Try increasing adapt delta closer to 1.
If this doesn't remove all divergences, try to reparameterize the model.

Checking E-BFMI - sampler transitions HMC potential energy.
E-BFMI satisfactory.

Rank-normalized split effective sample size satisfactory for all parameters.

Rank-normalized split R-hat values satisfactory for all parameters.

Processing complete.
Divergent samples: 0 0 0 3 

EBFMI: 0.969 0.896 1.01 0.898 

   Parameter  Rhat ESS bulk ESS tail
1   alpha[1] 1.001     1669     1832
2   alpha[2] 1.002     1207     1623
3   alpha[3] 1.002     1284     2049
4   alpha[4] 1.001     1115     1871
5   alpha[5] 1.002      969     1556
6   alpha[6] 1.002      900     1454
7   alpha[7] 1.002      860     1360
8   alpha[8] 1.003      920     1544
9   alpha[9] 1.002     1044     1685
10 alpha[10] 1.003     1023     1551
11 alpha[11] 1.002     1079     1917
12 alpha[12] 1.003     1039     1673
13 alpha[13] 1.003      983     1595
14 alpha[14] 1.004     1121     1846
15 alpha[15] 1.003     1190     1510
16 alpha[16] 1.003     1251     1769
17 alpha[17] 1.003     1305     1794
18 alpha[18] 1.004     1340     1440
19 alpha[19] 1.003     1456     1723
20 alpha[20] 1.003     1601     1590
21 alpha[21] 1.003     1643     1660
22 alpha[22] 1.002     1939     1877
23 alpha[23] 1.003     2183     1971
24 alpha[24] 1.004     2312     1578
25 alpha[25] 1.003     2685     2319
26 alpha[26] 1.001     2930     2690
27 alpha[27] 1.001     3094     2618
28 alpha[28] 1.001     2778     1906
29 alpha[29] 1.001     3277     2260
30 alpha[30] 1.002     3432     2652
31 alpha[31] 1.004     3534     1759
32 alpha[32] 1.002     3618     2303
33 alpha[33] 1.001     3877     2480
34 alpha[34] 1.001     3764     2667
35 alpha[35] 1.001     3837     2109
36 alpha[36] 1.001     3725     2283
37 alpha[37] 1.000     3272     2161
38 alpha[38] 1.001     2873     2499
39 alpha[39] 1.002     2993     2339
40 alpha[40] 1.001     3371     2285
41 alpha[41] 1.002     2992     2050
42 alpha[42] 1.000     2679     1978
43 alpha[43] 1.000     2875     1940
44 alpha[44] 1.000     2966     2887
45 alpha[45] 1.000     2753     2983
46 alpha[46] 1.001     2501     3115
47 alpha[47] 1.001     2400     2632
48 alpha[48] 1.002     2403     2916
49 alpha[49] 1.002     2429     3055
50 alpha[50] 1.002     2300     2987
51 alpha[51] 1.003     2367     2789
52 alpha[52] 1.003     2341     2577
53 alpha[53] 1.002     2170     2629
54 alpha[54] 1.002     2315     2861
55 alpha[55] 1.002     2255     2566
56 alpha[56] 1.003     2265     2761
57 alpha[57] 1.002     2387     2879
58 alpha[58] 1.002     2316     2933
59 alpha[59] 1.002     2324     2497
60 alpha[60] 1.002     2550     2588
61 alpha[61] 1.001     3170     2548
62   beta[1] 1.003     4489     2694
63   beta[2] 1.000     4474     2085
64   beta[3] 1.001     3446     2794
65   beta[4] 1.001     5456     2669
66   beta[5] 1.003     1283     1886
67   beta[6] 1.001     2896     2779
68   beta[7] 1.004     3270     3294
69   beta[8] 1.000     5729     2947
70   beta[9] 1.001     4661     2237
71  beta[10] 1.001     3472     2236
72  beta[11] 1.001     4695     2599
73  beta[12] 1.000     5621     2609
74  beta[13] 1.001     5241     3128
75  beta[14] 1.001     5950     2813
76  beta[15] 1.001     6406     3138
77  beta[16] 1.002     5400     2854
78  beta[17] 1.002     5076     2480
79  beta[18] 1.001     4888     2972
80 sigmag[1] 1.005     1016     1298
Code
bmarkre

Bayesian Logistic (Proportional Odds) Ordinal Regression Model

Dirichlet Priors With Concentration Parameter 0.044 for Intercepts

borm(formula = twstrs ~ treat * rcs(week, 3) + rcs(ptwstrs, 4) + 
    rcs(age, 4) * sex + cluster(uid), data = both, file = "bmarkre.rds")
Frequencies of Missing Values Due to Each Variable
      twstrs        treat         week      ptwstrs          age          sex 
           0            0            0            5            0            0 
cluster(uid) 
           0 
Mixed Calibration/
Discrimination Indexes
Discrimination
Indexes
Rank Discrim.
Indexes
Obs517 LOO log L-1786.61±22.26 |P(Y ≥ Y0.5)-½|0.332 [0.316, 0.35] ρ0.83 [0.825, 0.835]
Distinct Y62 LOO IC3573.22±44.52 C0.828 [0.825, 0.83]
Y0.542 Effective p93.21±5 Dxy0.656 [0.65, 0.661]
p18 B0.117 [0.113, 0.121]
Draws4000
Chains4
Time6.2s
Cluster onuid
Clusters108
σγ0.1068 [0, 0.3294]
Mean β Median β S.E. Lower Upper P(β>0) Symmetry
treat=5000U   0.2118   0.2083  0.5694  -0.8899   1.3368  0.6458  0.96
treat=Placebo   1.8406   1.8428  0.5891   0.6731   2.9428  0.9988  1.00
week   0.4867   0.4860  0.0825   0.3239   0.6532  1.0000  0.98
week'  -0.2862  -0.2857  0.0865  -0.4480  -0.1023  0.0013  1.03
ptwstrs   0.2000   0.2002  0.0271   0.1457   0.2506  1.0000  1.03
ptwstrs'  -0.0646  -0.0637  0.0642  -0.1856   0.0624  0.1565  0.96
ptwstrs''   0.5446   0.5445  0.2550   0.0761   1.0653  0.9855  1.04
age  -0.0291  -0.0294  0.0311  -0.0891   0.0330  0.1730  0.98
age'   0.1226   0.1235  0.0862  -0.0345   0.2991  0.9248  1.01
age''  -0.5043  -0.5057  0.3405  -1.1822   0.1261  0.0727  0.96
sex=M  -0.3886  -0.4373  2.3925  -5.0841   4.3425  0.4310  1.00
treat=5000U × week  -0.0324  -0.0338  0.1101  -0.2497   0.1795  0.3780  1.01
treat=Placebo × week  -0.2735  -0.2757  0.1140  -0.4926  -0.0454  0.0073  0.98
treat=5000U × week'  -0.0362  -0.0343  0.1180  -0.2696   0.1916  0.3898  0.95
treat=Placebo × week'   0.1209   0.1213  0.1210  -0.1094   0.3600  0.8378  0.98
age × sex=M   0.0093   0.0106  0.0577  -0.1016   0.1230  0.5652  1.02
age' × sex=M  -0.0454  -0.0432  0.1641  -0.3513   0.2882  0.3915  1.00
age'' × sex=M   0.2424   0.2371  0.6379  -1.0460   1.4026  0.6460  1.01

The random effects SD is only 0.11 on the logit scale. Also, the standard deviations of all the regression parameter posterior distributions are virtually unchanged with the addition of random effects:

Code
plot(sqrt(diag(vcov(bmark))), sqrt(diag(vcov(bmarkre))),
     xlab='Posterior SDs in Conditional Independence Markov Model',
     ylab='Posterior SDs in Random Effects Markov Model')
abline(a=0, b=1, col=gray(0.85))

So we will use the model omitting random effects.

Show the partial effects of all the predictors, including the effect of the previous measurement of TWSTRS. Also compute high dose:placebo treatment contrasts on these conditional estimates.

Code
ggplot(Predict(bmark))

Code
ggplot(Predict(bmark, week, treat))

Code
k <- contrast(bmark, list(week=wks, treat='10000U'),
                     list(week=wks, treat='Placebo'),
              cnames=paste('Week', wks))
k
           week   Contrast      S.E.      Lower      Upper P(Contrast>0)
1  Week 2     2 -1.2875447 0.3837578 -2.0350142 -0.5591566        0.0003
2  Week 4     4 -0.7438717 0.2628552 -1.2649127 -0.2340552        0.0027
3  Week 8     8  0.2243063 0.3547112 -0.4399538  0.9234413        0.7310
4* Week 12   12  0.7158124 0.2630005  0.2066607  1.2182303        0.9970
5* Week 16   16  1.0881505 0.3930081  0.3062447  1.8339968        0.9980

Redundant contrasts are denoted by *

Intervals are 0.95 highest posterior density intervals
Contrast is the posterior mean 
Code
plot(k)

Code
k <- as.data.frame(k[c('week', 'Contrast', 'Lower', 'Upper')])
ggplot(k, aes(x=week, y=Contrast)) + geom_point() +
  geom_line() + ylab('High Dose - Placebo') +
  geom_errorbar(aes(ymin=Lower, ymax=Upper), width=0)

Using posterior means for parameter values, compute the probability that at a given week twstrs will be \(\geq 40\) when at the previous visit it was 40. Also show the conditional mean twstrs when it was 40 at the previous visit.

Code
ex <- ExProb(bmark)
ex40 <- function(lp, ...) ex(lp, y=40, ...)
ggplot(Predict(bmark, week, treat, ptwstrs=40, fun=ex40))

Code
ggplot(Predict(bmark, week, treat, ptwstrs=40, fun=Mean(bmark)))

  • Semiparametric models provide not only estimates of tendencies of Y but also estimate the whole distribution of Y
  • Estimate the entire conditional distribution of Y at week 12 for high-dose patients having TWSTRS=42 at week 8
  • Other covariates set to median/mode
  • Use posterior mean of all the cell probabilities
  • Also show pointwise 0.95 highest posterior density intervals
  • To roughly approximate simultaneous confidence bands make the pointwise limits sum to 1 like the posterior means do
Z
Code
# Get median/mode for covariates including ptwstrs (TWSTRS in previous visit)
d <- gendata(bmark)
d
   treat week ptwstrs age sex
1 10000U    8      42  56   F
Code
d$week <- 12
p <- predict(bmark, d, type='fitted.ind')   # defaults to posterior means
yvals <- as.numeric(sub('twstrs=', '', p$y))
lo <- p$Lower / sum(p$Lower)
hi <- p$Upper / sum(p$Upper)
plot(yvals, p$Mean, type='l', xlab='TWSTRS', ylab='',
     ylim=range(c(lo, hi)))
lines(yvals, lo, col=gray(0.8))
lines(yvals, hi, col=gray(0.8))

  • Repeat this showing the variation over 5 posterior draws
A
Code
p <- predict(bmark, d, type='fitted.ind', posterior.summary='all')
cols <- adjustcolor(1 : 10, 0.7)
for(i in 1 : 5) {
  if(i == 1) plot(yvals, p[i, 1, ], type='l', col=cols[1], xlab='TWSTRS', ylab='')
  else lines(yvals, p[i, 1, ], col=cols[i])
}

  • Turn to marginalized (unconditional on previous twstrs) quantities
  • Capitalize on PO model being a multinomial model, just with PO restrictions
  • Manipulations of conditional probabilities to get the unconditional probability that twstrs=y doesn’t need to know about PO
  • Compute all cell probabilities and use the law of total probability recursively \[\Pr(Y_{t} = y | X) = \sum_{j=1}^{k} \Pr(Y_{t} = y | X, Y_{t-1} = j) \Pr(Y_{t-1} = j | X)\]
  • predict.borm method with type='fitted.ind' computes the needed conditional cell probabilities, optionally for all posterior draws at once
  • Easy to get highest posterior density intervals for derived parameters such as unconditional probabilities or unconditional means
  • Hmisc package soprobMarkovOrdm function (in version 4.6) computes an array of all the state occupancy probabilities for all the posterior draws
B
Code
# Baseline twstrs to 42 in d
# For each dose, get all the posterior draws for all state occupancy
# probabilities for all visit
ylev <- sort(unique(both$twstrs))
tlev <- c('Placebo', '10000U')
R <- list()
for(trt in tlev) {   # separately by treatment
  d$treat <- trt
  u <- soprobMarkovOrdm(bmark, d, wks, ylev,
                        tvarname='week', pvarname='ptwstrs')
  R[[trt]] <- u
}
dim(R[[1]])    # posterior draws x times x distinct twstrs values
[1] 4000    5   62
Code
# For each posterior draw, treatment, and week compute the mean TWSTRS
# Then compute posterior mean of means, and HPD interval
Rmean <- Rmeans <- list()
for(trt in tlev) {
  r <- R[[trt]]
  # Mean Y at each week and posterior draw (mean from a discrete distribution)
  m <- apply(r, 1:2, function(x) sum(ylev * x))
  Rmeans[[trt]] <- m
  # Posterior mean and median and HPD interval over draws
  u <- apply(m, 2, f)   # f defined above
  u <- rbind(week=as.numeric(colnames(u)), u)
  Rmean[[trt]] <- u
}
r <- lapply(Rmean, function(x) as.data.frame(t(x)))
for(trt in tlev) r[[trt]]$treat <- trt
r <- do.call(rbind, r)
ggplot(r, aes(x=week, y=Mean, color=treat)) + geom_line() +
  geom_ribbon(aes(ymin=Lower, ymax=Upper), alpha=0.2, linetype=0)

  • Use the same posterior draws of unconditional probabilities of all values of TWSTRS to get the posterior distribution of differences in mean TWSTRS between high and low dose
C
Code
Dif <- Rmeans$`10000U` - Rmeans$Placebo
dif <- as.data.frame(t(apply(Dif, 2, f)))
dif$week <- as.numeric(rownames(dif))
ggplot(dif, aes(x=week, y=Mean)) + geom_line() +
  geom_ribbon(aes(ymin=Lower, ymax=Upper), alpha=0.2, linetype=0) +
  ylab('High Dose - Placebo TWSTRS')

  • Get posterior mean of all cell probabilities estimates at week 12
  • Distribution of TWSTRS conditional high dose, median age, mode sex
  • Not conditional on week 8 value
D
Code
p <- R$`10000U`[, '12', ]   # 4000 x 62
pmean <- apply(p, 2, mean)
yvals <- as.numeric(names(pmean))
plot(yvals, pmean, type='l', xlab='TWSTRS', ylab='')

7.8.6 Frequentist Markov Semiparametric Model

Fitting a frequentist MOST model will allow us to take advantage of the orm functions 2-parameter random effects contribution, which was designed to improve fit to correlation structure for Markov-1 models. The improvement comes from canceling out a buildup of variances of \(Y\) due to using lagged raw \(Y\) instead of lag residuals as used in linear models. For this purpose, a good choice of weighting functions \(w(t)\) is an indicator function for being at the first follow-up time.

Code
both[, mix2 := ifelse(week == 2, 0, 1)]
f <- orm(twstrs ~  treat * rcs(week, 3) + rcs(ptwstrs, 4) +
                    rcs(age, 4) * sex + cluster(uid) + mix_re(mix2),
         data=both, x=TRUE)
f

Logistic (Proportional Odds) Ordinal Regression Model

orm(formula = twstrs ~ treat * rcs(week, 3) + rcs(ptwstrs, 4) + 
    rcs(age, 4) * sex + cluster(uid) + mix_re(mix2), data = both, 
    x = TRUE)
Frequencies of Missing Values Due to Each Variable
      twstrs        treat         week      ptwstrs          age          sex 
           0            0            0            5            0            0 
cluster(uid) mix_re(mix2) 
           0            0 
Model Likelihood
Ratio Test
Discrimination
Indexes
Rank Discrim.
Indexes
Obs517 LR χ2291.74 R20.432 ρ0.834
ESS516.7 d.f.18 R218,5170.411 Dxy0.661
Distinct Y62 P(>χ2)<0.0001 R218,516.70.411
Cluster onuid |P(Y ≥ Y0.5)-½|0.341
Clusters108
σ11.4341 [0.9403, 2.1872]
σ2-0.20520 [-0.44540, 0.03504]
Y0.542
max |∂log L/∂β|2×10-5
β S.E. Wald Z P(>|Z|)
treat=5000U   0.3063  0.6466 0.47 0.6358
treat=Placebo   1.6058  0.6526 2.46 0.0139
week   0.4910  0.0901 5.45 <0.0001
week'  -0.2870  0.0924 -3.11 0.0019
ptwstrs   0.2226  0.0288 7.74 <0.0001
ptwstrs'  -0.0728  0.0658 -1.11 0.2680
ptwstrs''   0.5705  0.2631 2.17 0.0302
age  -0.0319  0.0310 -1.03 0.3025
age'   0.1309  0.0864 1.51 0.1299
age''  -0.5317  0.3417 -1.56 0.1197
sex=M  -0.5530  2.3744 -0.23 0.8158
treat=5000U × week  -0.0485  0.1226 -0.40 0.6926
treat=Placebo × week  -0.2315  0.1250 -1.85 0.0641
treat=5000U × week'  -0.0248  0.1268 -0.20 0.8452
treat=Placebo × week'   0.0818  0.1294 0.63 0.5275
age × sex=M   0.0135  0.0572 0.24 0.8134
age' × sex=M  -0.0542  0.1621 -0.33 0.7382
age'' × sex=M   0.2631  0.6288 0.42 0.6756
Code
deviance(f)
                 intercepts                intercepts+x 
                   4041.567                    3392.026 
  intercepts+random effects intercepts+x+random effects 
                   3674.128                    3382.387 

\(\sigma_{1}\) is large; there is substantial subject-level correlation at baseline (before ptwstrs is contributing anything), consistent with a real, non-trivial random effect there.

\(\sigma_{2} ≈ -0.2\) is small and negative, but not collapsed to the boundary the way the single-\(\sigma\) model did. That’s exactly the pattern the additive design was meant to reveal — once the lag term is active, a plain constant-weight random effect would be adding back in some of the same correlation the lag term already explains, and a small negative \(\sigma_2\) is the model’s way of trimming that slight over-induction rather than needing to zero the whole random effect out just to compensate.

7.9 Study Questions

Section 7.2

  1. When should one model the time-response profile using discrete time?

Section 7.3

  1. What makes generalized least squares and mixed effect models relatively robust to non-completely-random dropouts?
  2. What does the last observation carried forward method always violate?

Section 7.4

  1. Which correlation structure do you expect to fit the data when there are rapid repetitions over a short time span? When the follow-up time span is very long?

Section 7.8

  1. What can go wrong if many correlation structures are tested in one dataset?
  2. In a longitudinal intervention study, what is the most typical comparison of interest? Is it best to borrow information in estimating this contrast?