7  Modeling Longitudinal Responses using Generalized Least Squares

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
  • 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)

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]\)

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
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)
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]])
       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

AIC computed above is set up so that smaller values are best. From this the continuous-time AR1 and exponential structures are tied for the best. For the remainder of the analysis use corCAR1, 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=corCAR1(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 = corCAR1(form = ~week | 
    uid))
Obs 522 Log-restricted-likelihood -1756.95
Clusters 108 Model d.f. 17
g 11.334 σ 8.5917
d.f. 504
β S.E. t Pr(>|t|)
Intercept  -0.3093  11.8804 -0.03 0.9792
treat=5000U   0.4344   2.5962 0.17 0.8672
treat=Placebo   7.1433   2.6133 2.73 0.0065
week   0.2879   0.2973 0.97 0.3334
week'   0.7313   0.3078 2.38 0.0179
twstrs0   0.8071   0.1449 5.57 <0.0001
twstrs0'   0.2129   0.1795 1.19 0.2360
age  -0.1178   0.2346 -0.50 0.6158
age'   0.6968   0.6484 1.07 0.2830
age''  -3.4018   2.5599 -1.33 0.1845
sex=M  24.2802  18.6208 1.30 0.1929
treat=5000U × week   0.0745   0.4221 0.18 0.8599
treat=Placebo × week  -0.1256   0.4243 -0.30 0.7674
treat=5000U × week'  -0.4389   0.4363 -1.01 0.3149
treat=Placebo × week'  -0.6459   0.4381 -1.47 0.1411
age × sex=M  -0.5846   0.4447 -1.31 0.1892
age' × sex=M   1.4652   1.2388 1.18 0.2375
age'' × sex=M  -4.0338   4.8123 -0.84 0.4023
Correlation Structure: Continuous AR(1)
 Formula: ~week | uid 
 Parameter estimate(s):
      Phi 
0.8666689 

\(\hat{\rho} = 0.8672\), the estimate of the correlation between two measurements taken one week apart on the same subject. The estimated correlation for measurements 10 weeks apart is \(0.8672^{10} = 0.24\).

T
Code
v <- Variogram(a, form=~ week | uid)
plot(v)
Figure 7.4: 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.5: 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) 22.11 6 0.0012
All Interactions 14.94 4 0.0048
week (Factor+Higher Order Factors) 77.27 6 <0.0001
All Interactions 14.94 4 0.0048
Nonlinear (Factor+Higher Order Factors) 6.61 3 0.0852
twstrs0 233.83 2 <0.0001
Nonlinear 1.41 1 0.2354
age (Factor+Higher Order Factors) 9.68 6 0.1388
All Interactions 4.86 3 0.1826
Nonlinear (Factor+Higher Order Factors) 7.59 4 0.1077
sex (Factor+Higher Order Factors) 5.67 4 0.2252
All Interactions 4.86 3 0.1826
treat × week (Factor+Higher Order Factors) 14.94 4 0.0048
Nonlinear 2.27 2 0.3208
Nonlinear Interaction : f(A,B) vs. AB 2.27 2 0.3208
age × sex (Factor+Higher Order Factors) 4.86 3 0.1826
Nonlinear 3.76 2 0.1526
Nonlinear Interaction : f(A,B) vs. AB 3.76 2 0.1526
TOTAL NONLINEAR 15.03 8 0.0586
TOTAL INTERACTION 19.75 7 0.0061
TOTAL NONLINEAR + INTERACTION 28.54 11 0.0027
TOTAL 322.98 17 <0.0001
Code
plot(anova(a))
Figure 7.6: 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.7: Estimated effects of time, baseline TWSTRS, age, and sex
Code
summary(a)  # Shows for week 8
Effects   Response: twstrs
Low High Δ Effect S.E. Lower 0.95 Upper 0.95
week 4 12 8 6.6910 1.1060 4.524 8.858
twstrs0 39 53 14 13.5500 0.8862 11.810 15.290
age 46 65 19 2.5030 2.0510 -1.518 6.523
treat --- 5000U:10000U 1 2 0.5917 1.9980 -3.325 4.508
treat --- Placebo:10000U 1 3 5.4930 2.0040 1.565 9.421
sex --- M:F 1 2 -1.0850 1.7790 -4.571 2.401
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 Pr(>|z|)
1      2      46  56   F    -6.31 2.10 -10.43 -2.186 -3.00   0.0027
2      4      46  56   F    -5.91 1.82  -9.47 -2.349 -3.25   0.0011
3      8      46  56   F    -4.90 2.01  -8.85 -0.953 -2.43   0.0150
4*    12      46  56   F    -3.07 1.75  -6.49  0.361 -1.75   0.0795
5*    16      46  56   F    -1.02 2.10  -5.14  3.092 -0.49   0.6260

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 Pr(>|z|)
1      2      46  56   F    -6.89 2.07 -10.96 -2.83 -3.32   0.0009
2      4      46  56   F    -6.64 1.79 -10.15 -3.13 -3.70   0.0002
3      8      46  56   F    -5.49 2.00  -9.42 -1.56 -2.74   0.0061
4*    12      46  56   F    -1.76 1.74  -5.17  1.65 -1.01   0.3109
5*    16      46  56   F     2.62 2.09  -1.47  6.71  1.25   0.2099

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.8: 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.9: Nomogram from GLS fit. Second axis is the baseline score.

7.8.3 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=parallel::detectCores() - 1, rmsb.backend='cmdstan')
bpo <- blrm(twstrs ~ treat * rcs(week, 3) + rcs(twstrs0, 3) +
            rcs(age, 4) * sex + cluster(uid), data=both, file='bpo.rds')
Running MCMC with 4 chains, at most 11 in parallel...

Chain 4 finished in 5.3 seconds.
Chain 2 finished in 5.5 seconds.
Chain 3 finished in 5.6 seconds.
Chain 1 finished in 5.8 seconds.

All 4 chains finished successfully.
Mean chain execution time: 5.6 seconds.
Total execution time: 6.0 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.

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

Processing complete, no problems detected.

EBFMI: 0.659 0.816 0.69 0.789 

   Parameter  Rhat ESS bulk ESS tail
1   alpha[1] 1.006      827      879
2   alpha[2] 1.011      604     1040
3   alpha[3] 1.008      601     1210
4   alpha[4] 1.008      530     1138
5   alpha[5] 1.010      472      908
6   alpha[6] 1.011      448      799
7   alpha[7] 1.010      442      769
8   alpha[8] 1.011      444      811
9   alpha[9] 1.005      514     1102
10 alpha[10] 1.005      499     1052
11 alpha[11] 1.005      498     1057
12 alpha[12] 1.005      487      977
13 alpha[13] 1.005      490      983
14 alpha[14] 1.005      519     1011
15 alpha[15] 1.005      509      993
16 alpha[16] 1.005      511     1026
17 alpha[17] 1.004      509     1017
18 alpha[18] 1.004      511      916
19 alpha[19] 1.004      505      999
20 alpha[20] 1.005      494     1086
21 alpha[21] 1.005      490     1033
22 alpha[22] 1.005      473      890
23 alpha[23] 1.006      472      915
24 alpha[24] 1.005      466      833
25 alpha[25] 1.005      470     1014
26 alpha[26] 1.005      466      979
27 alpha[27] 1.005      460      886
28 alpha[28] 1.005      456      976
29 alpha[29] 1.005      458      912
30 alpha[30] 1.005      442      918
31 alpha[31] 1.006      437      844
32 alpha[32] 1.005      437      851
33 alpha[33] 1.005      444      775
34 alpha[34] 1.005      449      852
35 alpha[35] 1.006      442      915
36 alpha[36] 1.007      419      831
37 alpha[37] 1.007      421      949
38 alpha[38] 1.007      423     1014
39 alpha[39] 1.007      416      857
40 alpha[40] 1.008      410     1087
41 alpha[41] 1.008      401      960
42 alpha[42] 1.008      409      907
43 alpha[43] 1.008      387      993
44 alpha[44] 1.009      394     1060
45 alpha[45] 1.009      417     1067
46 alpha[46] 1.010      415     1087
47 alpha[47] 1.009      425     1111
48 alpha[48] 1.010      425     1082
49 alpha[49] 1.010      452     1174
50 alpha[50] 1.010      491     1284
51 alpha[51] 1.008      513     1306
52 alpha[52] 1.007      559     1441
53 alpha[53] 1.007      649     1608
54 alpha[54] 1.007      670     1937
55 alpha[55] 1.007      664     1694
56 alpha[56] 1.008      634     1598
57 alpha[57] 1.007      711     1941
58 alpha[58] 1.006      776     2125
59 alpha[59] 1.006      877     1743
60 alpha[60] 1.005     1026     2184
61 alpha[61] 1.003     1271     2253
62   beta[1] 1.003      775     1442
63   beta[2] 1.011      576     1230
64   beta[3] 1.002     1594     2193
65   beta[4] 1.001     4119     3105
66   beta[5] 1.007      752     1474
67   beta[6] 1.004      907     1759
68   beta[7] 1.001      869     1644
69   beta[8] 1.000      998     1723
70   beta[9] 1.001      733     1292
71  beta[10] 1.004      906     1282
72  beta[11] 1.001     4143     2730
73  beta[12] 1.002     4050     2998
74  beta[13] 1.001     4235     2938
75  beta[14] 1.000     4764     3240
76  beta[15] 1.001      908     1533
77  beta[16] 1.005      898     1648
78  beta[17] 1.008      989     1518
79 sigmag[1] 1.002      648     1587
Code
print(bpo, intercepts=TRUE)

Bayesian Proportional Odds Ordinal Logistic Model

Dirichlet Priors With Concentration Parameter 0.044 for Intercepts

blrm(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
Obs 522 LOO log L -1747.51±23.75 g 3.823 [3.319, 4.349] C 0.793 [0.785, 0.799]
Draws 4000 LOO IC 3495.01±47.5 gp 0.434 [0.419, 0.449] Dxy 0.585 [0.571, 0.598]
Chains 4 Effective p 179.59±7.92 EV 0.592 [0.545, 0.639]
Time 7s B 0.148 [0.14, 0.16] v 11.381 [8.466, 14.56]
p 17 vp 0.148 [0.136, 0.16]
Cluster on uid
Clusters 108
σγ 1.8796 [1.5485, 2.275]
Mean β Median β S.E. Lower Upper Pr(β>0) Symmetry
y≥7   -1.9055   -1.9018  4.2891  -10.6479   6.0421  0.3205  1.00
y≥9   -2.9067   -2.8789  4.1829  -11.1067   5.1657  0.2377  0.95
y≥10   -4.0507   -4.0783  4.1369  -12.2219   4.0901  0.1618  0.97
y≥11   -4.4946   -4.4853  4.1341  -12.4471   3.8990  0.1348  0.97
y≥13   -4.6956   -4.6654  4.1320  -12.5159   3.8263  0.1235  0.97
y≥14   -5.0475   -5.0316  4.1254  -13.4201   2.9117  0.1055  0.96
y≥15   -5.3543   -5.3170  4.1222  -13.5435   2.8018  0.0932  0.96
y≥16   -5.7328   -5.6717  4.1178  -13.8308   2.3905  0.0780  0.94
y≥17   -6.5284   -6.4730  4.1083  -14.3015   1.9931  0.0542  0.95
y≥18   -6.7801   -6.7394  4.1065  -14.6657   1.5762  0.0480  0.96
y≥19   -7.0632   -7.0171  4.1067  -14.7320   1.5059  0.0412  0.94
y≥20   -7.2536   -7.2241  4.1083  -14.8425   1.4178  0.0388  0.95
y≥21   -7.4320   -7.3996  4.1075  -15.3442   0.9545  0.0345  0.96
y≥22   -7.8459   -7.7976  4.1067  -15.7897   0.5104  0.0270  0.95
y≥23   -8.1103   -8.0688  4.1047  -16.1079   0.1638  0.0230  0.95
y≥24   -8.3929   -8.3598  4.1028  -16.5510   -0.3258  0.0198  0.95
y≥25   -8.6502   -8.6355  4.1008  -16.7233   -0.5285  0.0160  0.93
y≥26   -9.0444   -9.0297  4.1021  -16.9933   -0.8412  0.0132  0.94
y≥27   -9.3343   -9.3212  4.1041  -17.3582   -1.1676  0.0118  0.94
y≥28   -9.5779   -9.5696  4.1064  -17.7854   -1.5090  0.0102  0.94
y≥29   -9.8103   -9.7885  4.1075  -17.8542   -1.5934  0.0098  0.94
y≥30  -10.1128  -10.1066  4.1106  -18.0570   -1.7822  0.0088  0.94
y≥31  -10.4044  -10.3972  4.1131  -18.3806   -2.1401  0.0080  0.94
y≥32  -10.5222  -10.5182  4.1143  -18.6143   -2.3753  0.0075  0.94
y≥33  -10.8850  -10.8790  4.1164  -18.8678   -2.6311  0.0058  0.94
y≥34  -11.1944  -11.1951  4.1188  -19.1879   -2.9161  0.0055  0.95
y≥35  -11.4171  -11.4044  4.1220  -19.3980   -3.1047  0.0053  0.94
y≥36  -11.6624  -11.6677  4.1245  -19.7076   -3.4283  0.0050  0.94
y≥37  -11.9392  -11.9543  4.1248  -19.8995   -3.6155  0.0043  0.94
y≥38  -12.1677  -12.1712  4.1254  -20.2081   -3.9446  0.0037  0.94
y≥39  -12.4144  -12.4188  4.1285  -20.4142   -4.1149  0.0030  0.94
y≥40  -12.5993  -12.6021  4.1303  -20.6961   -4.4056  0.0027  0.94
y≥41  -12.7835  -12.7807  4.1324  -20.8061   -4.5310  0.0025  0.94
y≥42  -13.1079  -13.0877  4.1352  -21.1900   -4.8836  0.0022  0.94
y≥43  -13.3351  -13.2999  4.1353  -21.4098   -5.1157  0.0018  0.94
y≥44  -13.6754  -13.6816  4.1370  -21.8400   -5.5388  0.0010  0.94
y≥45  -13.9927  -14.0266  4.1400  -22.1703   -5.8691  0.0010  0.94
y≥46  -14.2919  -14.3079  4.1429  -22.4617   -6.1139  0.0010  0.93
y≥47  -14.7110  -14.7016  4.1484  -22.8204   -6.4574  0.0008  0.93
y≥48  -14.9998  -14.9967  4.1496  -23.0967   -6.7286  0.0003  0.94
y≥49  -15.3737  -15.3838  4.1524  -23.5401   -7.1794  0.0000  0.94
y≥50  -15.6931  -15.7242  4.1539  -23.8709   -7.4589  0.0000  0.93
y≥51  -16.2235  -16.2369  4.1568  -24.3176   -7.9410  0.0000  0.94
y≥52  -16.5883  -16.5722  4.1614  -24.8654   -8.3641  0.0000  0.94
y≥53  -17.0342  -17.0482  4.1660  -25.3069   -8.7396  0.0000  0.94
y≥54  -17.5357  -17.5541  4.1685  -25.6453   -9.0978  0.0000  0.94
y≥55  -17.9479  -17.9534  4.1697  -26.1113   -9.5788  0.0000  0.94
y≥56  -18.1993  -18.2100  4.1709  -26.0066   -9.5619  0.0000  0.94
y≥57  -18.6671  -18.6689  4.1715  -26.5921  -10.2384  0.0000  0.93
y≥58  -19.2265  -19.2398  4.1683  -27.1428  -10.8589  0.0000  0.93
y≥59  -19.5780  -19.5898  4.1708  -27.5345  -11.3103  0.0000  0.94
y≥60  -19.9059  -19.9319  4.1726  -27.8183  -11.5063  0.0000  0.93
y≥61  -20.6000  -20.5896  4.1778  -28.3748  -11.9773  0.0000  0.93
y≥62  -20.9672  -20.9637  4.1848  -29.0542  -12.6078  0.0000  0.92
y≥63  -21.3809  -21.3878  4.1879  -29.3775  -12.8415  0.0000  0.92
y≥64  -21.5176  -21.5187  4.1879  -29.7111  -13.1756  0.0000  0.92
y≥65  -22.2439  -22.2491  4.1896  -30.7067  -14.0360  0.0000  0.95
y≥66  -22.6161  -22.6257  4.1991  -30.9358  -14.1827  0.0000  0.95
y≥67  -23.0314  -23.0520  4.2048  -31.3573  -14.6233  0.0000  0.94
y≥68  -23.8098  -23.8168  4.2266  -32.0765  -15.3276  0.0000  0.93
y≥71  -24.6765  -24.6841  4.2552  -32.7270  -15.7873  0.0000  0.95
treat=5000U   0.1165   0.1263  0.7242   -1.2726   1.5488  0.5645  1.05
treat=Placebo   2.3453   2.3397  0.7452   0.8935   3.8198  0.9980  1.04
week   0.1224   0.1217  0.0800   -0.0310   0.2812  0.9352  1.04
week'   0.1907   0.1903  0.0879   0.0153   0.3600  0.9832  0.97
twstrs0   0.2291   0.2276  0.0506   0.1347   0.3352  1.0000  1.05
twstrs0'   0.1267   0.1271  0.0626   -0.0053   0.2448  0.9750  1.01
age   -0.0160   -0.0161  0.0797   -0.1680   0.1438  0.4192  0.99
age'   0.1940   0.1880  0.2205   -0.2341   0.6337  0.8132  1.07
age''   -1.0681   -1.0456  0.8732   -2.8689   0.5764  0.1050  0.94
sex=M   5.2103   5.3236  6.2050   -7.7002   16.3835  0.8032  0.97
treat=5000U × week   0.0510   0.0513  0.1105   -0.1771   0.2471  0.6792  0.98
treat=Placebo × week   -0.0539   -0.0537  0.1128   -0.2877   0.1544  0.3180  0.98
treat=5000U × week'   -0.1618   -0.1618  0.1207   -0.3959   0.0683  0.0932  1.02
treat=Placebo × week'   -0.1388   -0.1392  0.1234   -0.3827   0.1006  0.1305  1.07
age × sex=M   -0.1160   -0.1191  0.1485   -0.4091   0.1696  0.2120  1.03
age' × sex=M   0.1742   0.1795  0.4183   -0.6530   0.9954  0.6660  0.98
age'' × sex=M   -0.0564   -0.0900  1.6381   -3.2290   3.2348  0.4812  0.98
Code
a <- anova(bpo)
a
Relative Explained Variation for twstrs. Approximate total model Wald χ2 used in denominators of REV:252.3 [210.8, 336.8].
REV Lower Upper d.f.
treat (Factor+Higher Order Factors) 0.123 0.060 0.210 6
All Interactions 0.086 0.029 0.154 4
week (Factor+Higher Order Factors) 0.564 0.409 0.648 6
All Interactions 0.086 0.029 0.154 4
Nonlinear (Factor+Higher Order Factors) 0.020 0.000 0.066 3
twstrs0 0.661 0.526 0.751 2
Nonlinear 0.016 0.000 0.042 1
age (Factor+Higher Order Factors) 0.024 0.010 0.090 6
All Interactions 0.015 0.001 0.059 3
Nonlinear (Factor+Higher Order Factors) 0.021 0.004 0.077 4
sex (Factor+Higher Order Factors) 0.019 0.004 0.073 4
All Interactions 0.015 0.001 0.059 3
treat × week (Factor+Higher Order Factors) 0.086 0.029 0.154 4
Nonlinear 0.008 0.000 0.041 2
Nonlinear Interaction : f(A,B) vs. AB 0.008 0.000 0.041 2
age × sex (Factor+Higher Order Factors) 0.015 0.001 0.059 3
Nonlinear 0.014 0.000 0.051 2
Nonlinear Interaction : f(A,B) vs. AB 0.014 0.000 0.051 2
TOTAL NONLINEAR 0.054 0.030 0.146 8
TOTAL INTERACTION 0.100 0.043 0.188 7
TOTAL NONLINEAR + INTERACTION 0.131 0.091 0.246 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 Pr(Contrast>0)
1  Week 2     2 -2.2375496 0.6141540 -3.448798 -1.0513789         0.0000
2  Week 4     4 -2.1297938 0.5485159 -3.208730 -1.0417975         0.0000
3  Week 8     8 -1.7754918 0.6019888 -2.913153 -0.5498133         0.0013
4* Week 12   12 -0.8660284 0.5440641 -1.873756  0.2480518         0.0542
5* Week 16   16  0.1822253 0.6230626 -1.055579  1.3586333         0.6132

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.4 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 <- blrm(twstrs ~  treat * rcs(week, 3) + rcs(ptwstrs, 4) +
                        rcs(age, 4) * sex,
              data=both, file='bmark.rds')
Running MCMC with 4 chains, at most 11 in parallel...

Chain 4 finished in 2.8 seconds.
Chain 3 finished in 3.1 seconds.
Chain 1 finished in 3.2 seconds.
Chain 2 finished in 3.2 seconds.

All 4 chains finished successfully.
Mean chain execution time: 3.1 seconds.
Total execution time: 3.3 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: 0.993 1.08 1.068 1.074 

   Parameter  Rhat ESS bulk ESS tail
1   alpha[1] 1.001     2522     2234
2   alpha[2] 1.001     1888     2504
3   alpha[3] 1.000     1978     2534
4   alpha[4] 1.000     1773     2644
5   alpha[5] 1.000     1555     2369
6   alpha[6] 1.001     1540     2370
7   alpha[7] 1.001     1499     2155
8   alpha[8] 1.000     1572     2339
9   alpha[9] 1.001     1867     2359
10 alpha[10] 1.001     1705     2360
11 alpha[11] 1.000     1761     2703
12 alpha[12] 1.001     1649     2604
13 alpha[13] 1.001     1721     2593
14 alpha[14] 1.000     2015     3062
15 alpha[15] 1.000     2277     2971
16 alpha[16] 1.001     2151     3081
17 alpha[17] 1.000     2460     2890
18 alpha[18] 1.000     2607     2981
19 alpha[19] 1.000     2949     3290
20 alpha[20] 1.000     3251     3019
21 alpha[21] 1.001     3354     3002
22 alpha[22] 1.001     3290     2926
23 alpha[23] 1.002     3218     3416
24 alpha[24] 1.001     3354     3202
25 alpha[25] 1.001     4184     3271
26 alpha[26] 1.000     4743     3141
27 alpha[27] 1.000     4777     3260
28 alpha[28] 1.000     5339     3271
29 alpha[29] 1.001     5605     2475
30 alpha[30] 1.000     5827     3075
31 alpha[31] 1.000     6329     3376
32 alpha[32] 1.000     6928     3536
33 alpha[33] 1.000     6824     3101
34 alpha[34] 1.001     6862     3396
35 alpha[35] 1.000     7034     3396
36 alpha[36] 1.001     6910     3116
37 alpha[37] 1.001     6493     3198
38 alpha[38] 1.001     6778     2892
39 alpha[39] 1.000     6246     3439
40 alpha[40] 1.000     5620     3330
41 alpha[41] 1.001     5127     3238
42 alpha[42] 1.002     5061     3382
43 alpha[43] 1.001     4562     2819
44 alpha[44] 1.000     4324     3136
45 alpha[45] 1.000     4062     3018
46 alpha[46] 1.000     3954     3453
47 alpha[47] 1.001     3936     3270
48 alpha[48] 1.002     3921     3322
49 alpha[49] 1.000     4144     3381
50 alpha[50] 1.000     4083     3217
51 alpha[51] 1.000     4127     3383
52 alpha[52] 1.000     4139     3153
53 alpha[53] 1.000     4058     3264
54 alpha[54] 1.000     4334     3368
55 alpha[55] 1.001     4288     3506
56 alpha[56] 1.000     4240     3348
57 alpha[57] 1.002     4030     3401
58 alpha[58] 1.002     3866     3106
59 alpha[59] 1.002     3764     2908
60 alpha[60] 1.001     4309     2687
61 alpha[61] 1.002     4817     2811
62   beta[1] 1.001     8407     2450
63   beta[2] 1.002     8423     3011
64   beta[3] 1.001     5678     3012
65   beta[4] 1.001     6723     2787
66   beta[5] 1.000     2250     2853
67   beta[6] 1.000     4184     3520
68   beta[7] 1.001     5399     3031
69   beta[8] 1.002     8925     2918
70   beta[9] 1.001     9794     3533
71  beta[10] 1.004     7720     2936
72  beta[11] 1.000     9669     2851
73  beta[12] 1.002     7691     2908
74  beta[13] 1.001     7208     3063
75  beta[14] 1.000     8033     2584
76  beta[15] 1.000     8250     3114
77  beta[16] 1.001     6580     2821
78  beta[17] 1.001     8534     2633
79  beta[18] 1.002     7552     2843
Code
stanDxplot(bmark)

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

Code
bmark

Bayesian Proportional Odds Ordinal Logistic Model

Dirichlet Priors With Concentration Parameter 0.044 for Intercepts

blrm(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
Obs 517 LOO log L -1785.41±22.26 g 3.259 [2.944, 3.564] C 0.828 [0.825, 0.83]
Draws 4000 LOO IC 3570.81±44.52 gp 0.415 [0.403, 0.429] Dxy 0.656 [0.65, 0.661]
Chains 4 Effective p 89.3±4.67 EV 0.531 [0.494, 0.571]
Time 4.2s B 0.117 [0.113, 0.121] v 8.365 [6.696, 9.941]
p 18 vp 0.133 [0.124, 0.143]
Mode β Mean β Median β S.E. Lower Upper Pr(β>0) Symmetry
treat=5000U   0.2213   0.2177   0.2201  0.5910  -0.9514   1.3944  0.6440  1.02
treat=Placebo   1.8320   1.8313   1.8351  0.5732   0.7869   3.0187  0.9995  1.00
week   0.4866   0.4886   0.4884  0.0811   0.3311   0.6470  1.0000  1.02
week'  -0.2879  -0.2898  -0.2893  0.0863  -0.4612  -0.1205  0.0005  1.01
ptwstrs   0.1998   0.2012   0.2009  0.0264   0.1455   0.2489  1.0000  1.02
ptwstrs'  -0.0621  -0.0648  -0.0645  0.0613  -0.1877   0.0526  0.1452  0.97
ptwstrs''   0.5328   0.5431   0.5443  0.2444   0.0785   1.0386  0.9888  1.03
age  -0.0295  -0.0287  -0.0288  0.0313  -0.0900   0.0316  0.1802  1.02
age'   0.1237   0.1215   0.1219  0.0872  -0.0472   0.2916  0.9192  1.03
age''  -0.5073  -0.4988  -0.4955  0.3451  -1.1443   0.1710  0.0725  1.00
sex=M  -0.4614  -0.4251  -0.3895  2.3854  -5.0277   4.2989  0.4278  1.00
treat=5000U × week  -0.0341  -0.0339  -0.0347  0.1139  -0.2555   0.1921  0.3805  0.99
treat=Placebo × week  -0.2720  -0.2729  -0.2728  0.1111  -0.5029  -0.0673  0.0065  1.02
treat=5000U × week'  -0.0340  -0.0343  -0.0344  0.1221  -0.2629   0.2116  0.3875  0.99
treat=Placebo × week'   0.1198   0.1210   0.1219  0.1197  -0.1094   0.3517  0.8375  1.00
age × sex=M   0.0112   0.0105   0.0095  0.0574  -0.1022   0.1223  0.5700  0.99
age' × sex=M  -0.0509  -0.0495  -0.0482  0.1628  -0.3704   0.2608  0.3848  1.00
age'' × sex=M   0.2613   0.2566   0.2516  0.6342  -1.0678   1.4300  0.6617  0.99
Code
a <- anova(bmark)
a
Relative Explained Variation for twstrs. Approximate total model Wald χ2 used in denominators of REV:465.2 [395.8, 565.4].
REV Lower Upper d.f.
treat (Factor+Higher Order Factors) 0.050 0.023 0.103 6
All Interactions 0.047 0.018 0.092 4
week (Factor+Higher Order Factors) 0.296 0.219 0.375 6
All Interactions 0.047 0.018 0.092 4
Nonlinear (Factor+Higher Order Factors) 0.063 0.020 0.107 3
ptwstrs 0.938 0.860 0.948 3
Nonlinear 0.039 0.006 0.077 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.000 0.027 4
sex (Factor+Higher Order Factors) 0.001 0.000 0.020 4
All Interactions 0.001 0.000 0.018 3
treat × week (Factor+Higher Order Factors) 0.047 0.018 0.092 4
Nonlinear 0.004 0.000 0.021 2
Nonlinear Interaction : f(A,B) vs. AB 0.004 0.000 0.021 2
age × sex (Factor+Higher Order Factors) 0.001 0.000 0.018 3
Nonlinear 0.001 0.000 0.015 2
Nonlinear Interaction : f(A,B) vs. AB 0.001 0.000 0.015 2
TOTAL NONLINEAR 0.106 0.063 0.172 9
TOTAL INTERACTION 0.048 0.022 0.103 7
TOTAL NONLINEAR + INTERACTION 0.142 0.103 0.222 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 <- blrm(twstrs ~  treat * rcs(week, 3) + rcs(ptwstrs, 4) +
                          rcs(age, 4) * sex + cluster(uid),
                data=both, file='bmarkre.rds')
Running MCMC with 4 chains, at most 11 in parallel...

Chain 2 finished in 3.8 seconds.
Chain 1 finished in 3.8 seconds.
Chain 4 finished in 3.9 seconds.
Chain 3 finished in 5.2 seconds.

All 4 chains finished successfully.
Mean chain execution time: 4.2 seconds.
Total execution time: 5.3 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.
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: 0.967 1.001 0.946 1.033 

   Parameter  Rhat ESS bulk ESS tail
1   alpha[1] 1.004     1392     1260
2   alpha[2] 1.007      989     1656
3   alpha[3] 1.007      984     1861
4   alpha[4] 1.008      957     1732
5   alpha[5] 1.010      790     1448
6   alpha[6] 1.009      772     1460
7   alpha[7] 1.009      761     1614
8   alpha[8] 1.007      830     1498
9   alpha[9] 1.006      954     1947
10 alpha[10] 1.006     1076     1963
11 alpha[11] 1.006     1078     1780
12 alpha[12] 1.006     1062     1563
13 alpha[13] 1.006     1038     1616
14 alpha[14] 1.005     1094     1787
15 alpha[15] 1.004     1113     1774
16 alpha[16] 1.003     1187     2095
17 alpha[17] 1.003     1265     1734
18 alpha[18] 1.003     1381     1921
19 alpha[19] 1.003     1461     1995
20 alpha[20] 1.003     1540     2400
21 alpha[21] 1.003     1636     2168
22 alpha[22] 1.002     1860     2327
23 alpha[23] 1.002     1971     2451
24 alpha[24] 1.002     1953     2470
25 alpha[25] 1.001     2350     2810
26 alpha[26] 1.001     2701     2839
27 alpha[27] 1.000     3022     2796
28 alpha[28] 1.000     3203     2941
29 alpha[29] 1.000     3559     2868
30 alpha[30] 1.000     3727     3092
31 alpha[31] 1.001     4039     2606
32 alpha[32] 1.000     4037     2774
33 alpha[33] 1.000     3828     3091
34 alpha[34] 1.000     4200     3205
35 alpha[35] 1.000     3961     2857
36 alpha[36] 1.000     4318     2937
37 alpha[37] 1.001     4189     2753
38 alpha[38] 1.001     4113     3013
39 alpha[39] 1.000     3916     3119
40 alpha[40] 1.001     3626     3065
41 alpha[41] 1.001     3064     2859
42 alpha[42] 1.001     2746     2530
43 alpha[43] 1.001     2429     2714
44 alpha[44] 1.001     2386     2515
45 alpha[45] 1.001     2199     2390
46 alpha[46] 1.001     2125     2475
47 alpha[47] 1.001     2157     2728
48 alpha[48] 1.001     2250     2561
49 alpha[49] 1.001     2056     2283
50 alpha[50] 1.002     2088     2513
51 alpha[51] 1.001     2218     2467
52 alpha[52] 1.001     2191     2548
53 alpha[53] 1.000     2146     2574
54 alpha[54] 1.001     1986     2441
55 alpha[55] 1.001     2029     2224
56 alpha[56] 1.001     2024     2026
57 alpha[57] 1.001     2075     2658
58 alpha[58] 1.002     2047     2609
59 alpha[59] 1.001     2192     2478
60 alpha[60] 1.002     2335     2229
61 alpha[61] 1.001     2833     2688
62   beta[1] 1.002     4894     2652
63   beta[2] 1.003     6415     2247
64   beta[3] 1.000     3205     2710
65   beta[4] 1.000     5446     2685
66   beta[5] 1.003     1280     1936
67   beta[6] 1.001     2807     3137
68   beta[7] 1.001     3567     2963
69   beta[8] 1.001     5456     2536
70   beta[9] 1.001     4889     2673
71  beta[10] 1.002     4908     2890
72  beta[11] 1.001     5242     2788
73  beta[12] 0.999     5917     2775
74  beta[13] 1.000     5398     2617
75  beta[14] 1.001     4995     2759
76  beta[15] 1.000     5700     2486
77  beta[16] 1.003     5210     2531
78  beta[17] 1.001     5735     2688
79  beta[18] 1.000     5708     3082
80 sigmag[1] 1.001     1379     1882
Code
bmarkre

Bayesian Proportional Odds Ordinal Logistic Model

Dirichlet Priors With Concentration Parameter 0.044 for Intercepts

blrm(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
Obs 517 LOO log L -1786.41±22.23 g 3.264 [2.989, 3.579] C 0.828 [0.825, 0.83]
Draws 4000 LOO IC 3572.82±44.46 gp 0.416 [0.403, 0.429] Dxy 0.656 [0.65, 0.661]
Chains 4 Effective p 93.33±4.6 EV 0.532 [0.492, 0.57]
Time 6.5s B 0.117 [0.113, 0.122] v 8.389 [6.876, 10.027]
p 18 vp 0.133 [0.123, 0.143]
Cluster on uid
Clusters 108
σγ 0.1172 [0, 0.3396]
Mean β Median β S.E. Lower Upper Pr(β>0) Symmetry
treat=5000U   0.2138   0.2324  0.5764  -0.9497   1.3378  0.6492  0.97
treat=Placebo   1.8327   1.8376  0.5678   0.6720   2.8978  0.9990  1.02
week   0.4857   0.4855  0.0826   0.3219   0.6464  1.0000  1.00
week'  -0.2851  -0.2846  0.0872  -0.4501  -0.1084  0.0003  1.01
ptwstrs   0.2002   0.1999  0.0271   0.1466   0.2532  1.0000  1.01
ptwstrs'  -0.0649  -0.0652  0.0643  -0.1894   0.0598  0.1568  1.02
ptwstrs''   0.5459   0.5451  0.2563   0.0407   1.0393  0.9832  0.98
age  -0.0287  -0.0288  0.0312  -0.0884   0.0326  0.1745  0.99
age'   0.1229   0.1228  0.0873  -0.0595   0.2854  0.9188  0.95
age''  -0.5090  -0.5083  0.3489  -1.1915   0.1743  0.0742  1.04
sex=M  -0.3580  -0.3056  2.4088  -4.8983   4.4480  0.4415  0.98
treat=5000U × week  -0.0321  -0.0345  0.1096  -0.2280   0.1930  0.3850  1.04
treat=Placebo × week  -0.2717  -0.2710  0.1102  -0.4723  -0.0462  0.0060  1.00
treat=5000U × week'  -0.0361  -0.0351  0.1177  -0.2608   0.1929  0.3852  0.96
treat=Placebo × week'   0.1180   0.1189  0.1181  -0.1108   0.3451  0.8398  0.97
age × sex=M   0.0085   0.0080  0.0579  -0.1005   0.1226  0.5565  1.00
age' × sex=M  -0.0441  -0.0419  0.1634  -0.3701   0.2607  0.3928  0.99
age'' × sex=M   0.2402   0.2262  0.6345  -1.0151   1.4535  0.6472  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 Pr(Contrast>0)
1  Week 2     2 -1.2853878 0.3879648 -2.0345044 -0.5277948         0.0003
2  Week 4     4 -0.7395098 0.2668141 -1.2751683 -0.2221261         0.0030
3  Week 8     8  0.2312637 0.3521927 -0.4667871  0.8998026         0.7408
4* Week 12   12  0.7181072 0.2509423  0.2410624  1.2033277         0.9982
5* Week 16   16  1.0839682 0.3779986  0.3378102  1.8093584         0.9975

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.blrm 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.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?