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

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

7.2.2 Model for Mean Profile

  • A model for mean time-response profile without interactions between time C 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.).

7.2.3 Model Specification for Treatment Comparisons

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

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 E 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.

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 F
  • 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 G 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: H
    • 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
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 I
  • 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

Gardiner et al. (2009) compared several longitudinal data J 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.

7.4 Parameter Estimation Procedure

  • Generalized least squares K
  • 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 L 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 M 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

7.5 Common Correlation Structures

  • Usually restrict ourselves to isotropic correlation structures N — 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 O not equally spaced (Pinheiro & Bates, 2000, sec. 5.3.3) (nlme correlation function names are at the right if the structure is implemented in nlme):
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 P
  • 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

7.7 R Software

  • Nonlinear mixed effects model package of Pinheiro & Bates Q
  • 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

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\)), R 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

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 S 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.

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 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.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 V 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.

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 W
  • 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
Code
require(rmsb)
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')
# 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 treedepth.
Treedepth satisfactory for all transitions.

Checking sampler transitions for divergences.
No divergent transitions found.

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

Effective sample size satisfactory.

Split R-hat values satisfactory all parameters.

Processing complete, no problems detected.

EBFMI: 0.779 0.865 0.79 0.696 

   Parameter  Rhat ESS bulk ESS tail
1   alpha[1] 1.003     1825     2282
2   alpha[2] 1.002     1475     1885
3   alpha[3] 1.003     1028     2142
4   alpha[4] 1.002      945     1867
5   alpha[5] 1.002      884     1739
6   alpha[6] 1.002      784     1458
7   alpha[7] 1.003      753     1325
8   alpha[8] 1.005      711     1523
9   alpha[9] 1.003      648     1378
10 alpha[10] 1.002      635     1380
11 alpha[11] 1.003      604     1193
12 alpha[12] 1.002      589     1158
13 alpha[13] 1.002      584     1184
14 alpha[14] 1.002      540     1219
15 alpha[15] 1.002      544      962
16 alpha[16] 1.003      520      951
17 alpha[17] 1.002      504      845
18 alpha[18] 1.003      490      749
19 alpha[19] 1.003      472      779
20 alpha[20] 1.003      468      778
21 alpha[21] 1.003      465      695
22 alpha[22] 1.005      472      691
23 alpha[23] 1.006      479      754
24 alpha[24] 1.004      479      789
25 alpha[25] 1.005      472      622
26 alpha[26] 1.004      493      666
27 alpha[27] 1.004      483      688
28 alpha[28] 1.005      489      682
29 alpha[29] 1.005      497      769
30 alpha[30] 1.005      493      738
31 alpha[31] 1.006      500      894
32 alpha[32] 1.006      513      979
33 alpha[33] 1.005      519      892
34 alpha[34] 1.006      535      893
35 alpha[35] 1.007      530     1011
36 alpha[36] 1.006      565     1090
37 alpha[37] 1.006      583     1190
38 alpha[38] 1.005      621     1173
39 alpha[39] 1.006      671     1128
40 alpha[40] 1.006      693     1301
41 alpha[41] 1.005      720     1309
42 alpha[42] 1.004      729     1451
43 alpha[43] 1.005      764     1683
44 alpha[44] 1.005      809     1762
45 alpha[45] 1.004      867     1883
46 alpha[46] 1.003      967     1955
47 alpha[47] 1.003     1089     2128
48 alpha[48] 1.002     1115     2011
49 alpha[49] 1.003     1182     2603
50 alpha[50] 1.003     1310     2649
51 alpha[51] 1.002     1415     2582
52 alpha[52] 1.002     1453     2413
53 alpha[53] 1.002     1527     2359
54 alpha[54] 1.002     1587     2296
55 alpha[55] 1.001     1619     2459
56 alpha[56] 1.001     1582     2787
57 alpha[57] 1.002     1675     2546
58 alpha[58] 1.002     1689     2384
59 alpha[59] 1.002     1677     2254
60 alpha[60] 1.002     2005     2858
61 alpha[61] 1.001     2534     2730
62   beta[1] 1.004      698     1161
63   beta[2] 1.002      684     1207
64   beta[3] 1.000     1829     2458
65   beta[4] 1.001     2974     2724
66   beta[5] 1.006      611     1447
67   beta[6] 1.015      513     1433
68   beta[7] 1.004      778     1108
69   beta[8] 1.004      909     1645
70   beta[9] 1.006      697     1536
71  beta[10] 1.002      631     1365
72  beta[11] 1.000     3802     2821
73  beta[12] 1.001     3610     3082
74  beta[13] 1.003     3628     2204
75  beta[14] 1.001     3662     2999
76  beta[15] 1.000      925     1463
77  beta[16] 1.005      882     1485
78  beta[17] 1.003      953     1788
79 sigmag[1] 1.006      763     1509
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±23.85 g 3.828 [3.317, 4.391] C 0.793 [0.785, 0.799]
Draws 4000 LOO IC 3494.01±47.71 gp 0.434 [0.418, 0.449] Dxy 0.586 [0.571, 0.599]
Chains 4 Effective p 179.48±7.99 EV 0.592 [0.542, 0.639]
Time 7.1s B 0.148 [0.139, 0.157] v 11.416 [8.516, 14.926]
p 17 vp 0.148 [0.135, 0.159]
Cluster on uid
Clusters 108
σγ 1.8872 [1.5325, 2.2821]
Mean β Median β S.E. Lower Upper Pr(β>0) Symmetry
y≥7   -1.7569   -1.7380  4.2901   -9.7289   7.0611  0.3392  1.03
y≥9   -2.7713   -2.7269  4.1700  -10.6459   5.6849  0.2485  1.02
y≥10   -3.9506   -3.9097  4.1274  -12.5147   3.7143  0.1710  1.04
y≥11   -4.3926   -4.3158  4.1233  -12.7022   3.5052  0.1417  1.03
y≥13   -4.5889   -4.5068  4.1198  -13.0029   3.2093  0.1298  1.01
y≥14   -4.9460   -4.8875  4.1135  -13.1832   2.9475  0.1135  1.03
y≥15   -5.2502   -5.2094  4.1118  -13.7019   2.4404  0.0993  1.02
y≥16   -5.6320   -5.5833  4.1016  -13.7821   2.3398  0.0830  1.03
y≥17   -6.4328   -6.4160  4.0985  -14.3112   1.7188  0.0592  1.03
y≥18   -6.6841   -6.6352  4.0945  -14.6667   1.3972  0.0515  1.04
y≥19   -6.9732   -6.9222  4.0931  -15.6520   0.4186  0.0462  1.04
y≥20   -7.1674   -7.1298  4.0924  -15.1231   0.9383  0.0430  1.05
y≥21   -7.3498   -7.2997  4.0903  -15.3856   0.6301  0.0380  1.04
y≥22   -7.7667   -7.7442  4.0912  -15.7176   0.2615  0.0310  1.04
y≥23   -8.0369   -8.0163  4.0950  -16.0084   -0.0615  0.0257  1.03
y≥24   -8.3179   -8.2836  4.0964  -16.2216   -0.2851  0.0225  1.04
y≥25   -8.5759   -8.5432  4.0971  -16.5792   -0.6285  0.0192  1.04
y≥26   -8.9717   -8.9383  4.0961  -16.8458   -0.9114  0.0155  1.03
y≥27   -9.2597   -9.2359  4.1001  -17.2291   -1.3419  0.0122  1.03
y≥28   -9.5010   -9.4688  4.1017  -17.6453   -1.7234  0.0107  1.03
y≥29   -9.7342   -9.7029  4.1028  -17.9395   -2.0091  0.0082  1.04
y≥30  -10.0373   -9.9970  4.1038  -18.2119   -2.2326  0.0068  1.03
y≥31  -10.3274  -10.3006  4.1037  -18.5543   -2.5710  0.0050  1.03
y≥32  -10.4445  -10.4409  4.1050  -18.5689   -2.6098  0.0048  1.04
y≥33  -10.8093  -10.7880  4.1075  -19.0358   -3.1121  0.0040  1.03
y≥34  -11.1194  -11.0755  4.1093  -19.2418   -3.3924  0.0037  1.03
y≥35  -11.3431  -11.2865  4.1111  -19.5286   -3.5953  0.0032  1.02
y≥36  -11.5886  -11.5629  4.1124  -19.6837   -3.7471  0.0027  1.03
y≥37  -11.8659  -11.8462  4.1143  -19.9268   -4.0338  0.0027  1.03
y≥38  -12.0929  -12.0700  4.1151  -20.1780   -4.2234  0.0025  1.03
y≥39  -12.3401  -12.3255  4.1167  -20.5846   -4.6440  0.0022  1.03
y≥40  -12.5245  -12.5087  4.1186  -20.6775   -4.7154  0.0022  1.03
y≥41  -12.7071  -12.6836  4.1183  -20.7982   -4.8411  0.0020  1.03
y≥42  -13.0326  -13.0001  4.1191  -21.1152   -5.1586  0.0015  1.02
y≥43  -13.2618  -13.2304  4.1221  -21.3328   -5.3508  0.0013  1.03
y≥44  -13.6017  -13.5920  4.1247  -21.7954   -5.8043  0.0010  1.02
y≥45  -13.9191  -13.9053  4.1295  -22.1369   -6.1261  0.0010  1.02
y≥46  -14.2192  -14.2022  4.1308  -22.3636   -6.3389  0.0008  1.02
y≥47  -14.6363  -14.6313  4.1330  -22.7335   -6.6744  0.0008  1.02
y≥48  -14.9267  -14.9166  4.1352  -23.0259   -6.9674  0.0008  1.02
y≥49  -15.3009  -15.2907  4.1369  -23.4229   -7.3108  0.0003  1.02
y≥50  -15.6207  -15.6345  4.1378  -23.7795   -7.6843  0.0003  1.01
y≥51  -16.1511  -16.1505  4.1442  -24.4633   -8.3704  0.0003  1.02
y≥52  -16.5150  -16.4964  4.1461  -24.3301   -8.2661  0.0003  1.01
y≥53  -16.9611  -16.9600  4.1476  -24.7969   -8.7166  0.0003  1.01
y≥54  -17.4648  -17.4617  4.1499  -25.4886   -9.3951  0.0000  1.02
y≥55  -17.8797  -17.8777  4.1509  -26.0702   -9.9923  0.0000  1.02
y≥56  -18.1328  -18.1291  4.1524  -26.1768  -10.1119  0.0000  1.02
y≥57  -18.6057  -18.5755  4.1531  -27.0987  -10.9790  0.0000  1.01
y≥58  -19.1676  -19.1351  4.1565  -27.4457  -11.4053  0.0000  1.02
y≥59  -19.5179  -19.4470  4.1566  -27.7137  -11.6824  0.0000  1.03
y≥60  -19.8497  -19.7864  4.1609  -27.9804  -11.9643  0.0000  1.02
y≥61  -20.5504  -20.4835  4.1669  -28.8839  -12.8039  0.0000  1.01
y≥62  -20.9209  -20.8559  4.1733  -28.9528  -12.9281  0.0000  1.01
y≥63  -21.3361  -21.2812  4.1813  -29.3680  -13.2148  0.0000  1.01
y≥64  -21.4769  -21.4363  4.1803  -29.6579  -13.5218  0.0000  1.01
y≥65  -22.2046  -22.1496  4.1814  -30.6547  -14.5987  0.0000  1.00
y≥66  -22.5832  -22.5207  4.1895  -30.7632  -14.6592  0.0000  0.99
y≥67  -23.0062  -22.9231  4.2046  -31.1310  -14.9526  0.0000  1.01
y≥68  -23.7811  -23.7406  4.2284  -32.4298  -16.0918  0.0000  1.01
y≥71  -24.6437  -24.5713  4.2315  -32.8208  -16.4856  0.0000  0.99
treat=5000U   0.1114   0.1272  0.7065   -1.2138   1.5604  0.5608  0.97
treat=Placebo   2.3361   2.3461  0.7205   0.9193   3.7324  1.0000  1.00
week   0.1212   0.1211  0.0791   -0.0268   0.2802  0.9380  1.00
week'   0.1929   0.1924  0.0879   0.0247   0.3718  0.9855  1.01
twstrs0   0.2284   0.2287  0.0521   0.1290   0.3352  1.0000  1.01
twstrs0'   0.1294   0.1290  0.0636   0.0106   0.2579  0.9822  1.08
age   -0.0165   -0.0174  0.0810   -0.1757   0.1481  0.4185  0.96
age'   0.1950   0.1976  0.2221   -0.2246   0.6413  0.8128  1.01
age''   -1.0766   -1.0882  0.8719   -2.7140   0.6493  0.1060  0.98
sex=M   4.9097   4.9300  6.3225   -7.1868   17.1034  0.7810  1.00
treat=5000U × week   0.0511   0.0509  0.1097   -0.1746   0.2627  0.6788  1.02
treat=Placebo × week   -0.0532   -0.0525  0.1127   -0.2880   0.1552  0.3125  0.99
treat=5000U × week'   -0.1639   -0.1630  0.1205   -0.3909   0.0814  0.0870  0.98
treat=Placebo × week'   -0.1402   -0.1412  0.1241   -0.3668   0.1267  0.1278  1.04
age × sex=M   -0.1084   -0.1072  0.1517   -0.3959   0.1866  0.2350  0.99
age' × sex=M   0.1524   0.1546  0.4213   -0.6506   0.9659  0.6440  1.00
age'' × sex=M   0.0292   0.0117  1.6252   -2.9710   3.2642  0.5038  0.98
Code
a <- anova(bpo)
a
Relative Explained Variation for twstrs. Approximate total model Wald χ2 used in denominators of REV:247.6 [195.3, 325.9].
REV Lower Upper d.f.
treat (Factor+Higher Order Factors) 0.132 0.068 0.220 6
All Interactions 0.094 0.039 0.170 4
week (Factor+Higher Order Factors) 0.572 0.450 0.692 6
All Interactions 0.094 0.039 0.170 4
Nonlinear (Factor+Higher Order Factors) 0.022 0.000 0.070 3
twstrs0 0.660 0.503 0.737 2
Nonlinear 0.017 0.000 0.049 1
age (Factor+Higher Order Factors) 0.027 0.007 0.091 6
All Interactions 0.016 0.001 0.059 3
Nonlinear (Factor+Higher Order Factors) 0.023 0.002 0.076 4
sex (Factor+Higher Order Factors) 0.020 0.003 0.068 4
All Interactions 0.016 0.001 0.059 3
treat × week (Factor+Higher Order Factors) 0.094 0.039 0.170 4
Nonlinear 0.008 0.000 0.045 2
Nonlinear Interaction : f(A,B) vs. AB 0.008 0.000 0.045 2
age × sex (Factor+Higher Order Factors) 0.016 0.001 0.059 3
Nonlinear 0.014 0.000 0.050 2
Nonlinear Interaction : f(A,B) vs. AB 0.014 0.000 0.050 2
TOTAL NONLINEAR 0.059 0.034 0.154 8
TOTAL INTERACTION 0.110 0.060 0.206 7
TOTAL NONLINEAR + INTERACTION 0.144 0.090 0.259 11
TOTAL 1.000 1.000 1.000 17
Code
plot(a)

  • Show the final graphic (high dose:placebo contrast as function of time X
  • Intervals are 0.95 highest posterior density intervals
  • \(y\)-axis: log-odds ratio
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.2296730 0.5938935 -3.4064676 -1.0903588         0.0000
2  Week 4     4 -2.1232910 0.5365308 -3.1693887 -1.0658936         0.0000
3  Week 8     8 -1.7702898 0.6053864 -2.9062809 -0.5287118         0.0027
4* Week 12   12 -0.8563398 0.5422864 -1.9391895  0.1688035         0.0663
5* Week 16   16  0.1978473 0.6112909 -0.9485163  1.3956006         0.6162

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 Y
  • 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:
\[\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')
# 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 treedepth.
Treedepth satisfactory for all transitions.

Checking sampler transitions for divergences.
No divergent transitions found.

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

Effective sample size satisfactory.

Split R-hat values satisfactory all parameters.

Processing complete, no problems detected.

EBFMI: 0.977 0.905 0.969 1.055 

   Parameter  Rhat ESS bulk ESS tail
1   alpha[1] 1.000     4701     2535
2   alpha[2] 0.999     5013     3031
3   alpha[3] 1.001     5398     3383
4   alpha[4] 1.001     5075     3664
5   alpha[5] 1.001     4891     3652
6   alpha[6] 1.001     4726     3698
7   alpha[7] 1.002     4681     3626
8   alpha[8] 1.001     4537     3519
9   alpha[9] 1.001     4051     3223
10 alpha[10] 1.001     3908     3041
11 alpha[11] 1.000     4092     3109
12 alpha[12] 1.002     4116     3192
13 alpha[13] 1.000     3982     3059
14 alpha[14] 1.000     4100     3289
15 alpha[15] 1.001     4086     3548
16 alpha[16] 1.000     4008     3284
17 alpha[17] 1.001     3687     3338
18 alpha[18] 1.001     3595     3415
19 alpha[19] 1.000     3625     3460
20 alpha[20] 1.000     3616     3584
21 alpha[21] 1.001     3629     3450
22 alpha[22] 1.000     3679     3727
23 alpha[23] 1.000     3899     3391
24 alpha[24] 1.000     3958     3632
25 alpha[25] 1.000     4167     3342
26 alpha[26] 1.000     4466     3203
27 alpha[27] 1.001     4610     3344
28 alpha[28] 1.000     4662     3269
29 alpha[29] 1.000     4848     2831
30 alpha[30] 1.001     4960     2832
31 alpha[31] 1.001     5255     2954
32 alpha[32] 1.001     5421     3011
33 alpha[33] 1.001     5689     3190
34 alpha[34] 1.000     5408     2658
35 alpha[35] 1.000     5501     3367
36 alpha[36] 1.001     6623     3279
37 alpha[37] 1.000     6509     3353
38 alpha[38] 1.000     8503     3332
39 alpha[39] 1.000     7672     3348
40 alpha[40] 1.000     7052     3833
41 alpha[41] 1.000     6394     3453
42 alpha[42] 1.002     5831     3496
43 alpha[43] 1.003     5116     3482
44 alpha[44] 1.002     4763     3643
45 alpha[45] 1.001     4691     3342
46 alpha[46] 1.000     4512     3649
47 alpha[47] 1.001     4467     3616
48 alpha[48] 1.002     4585     3508
49 alpha[49] 1.000     4834     3690
50 alpha[50] 1.000     4740     3568
51 alpha[51] 1.000     4809     3841
52 alpha[52] 1.001     4820     3419
53 alpha[53] 1.000     4990     3643
54 alpha[54] 1.000     5163     3513
55 alpha[55] 1.000     5078     3497
56 alpha[56] 1.000     5021     3428
57 alpha[57] 1.000     5265     3399
58 alpha[58] 1.001     5135     3526
59 alpha[59] 1.000     5019     3375
60 alpha[60] 1.001     4991     3236
61 alpha[61] 1.001     5555     3510
62   beta[1] 1.001     8545     2654
63   beta[2] 1.001     8667     3157
64   beta[3] 1.000     5309     3038
65   beta[4] 1.001     7274     2680
66   beta[5] 1.001     3344     3651
67   beta[6] 1.001     6418     3327
68   beta[7] 1.000     8246     3832
69   beta[8] 1.004     9665     2594
70   beta[9] 1.002     9170     2452
71  beta[10] 1.000     9871     2756
72  beta[11] 1.000     8102     2739
73  beta[12] 1.000    10582     2594
74  beta[13] 1.001     8504     2396
75  beta[14] 1.000     8615     2750
76  beta[15] 1.001     8784     2426
77  beta[16] 1.000     8428     2874
78  beta[17] 1.001     8434     2940
79  beta[18] 1.001     8778     2746
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±22.32 g 3.272 [2.938, 3.527] C 0.828 [0.825, 0.83]
Draws 4000 LOO IC 3570.01±44.63 gp 0.416 [0.403, 0.429] Dxy 0.656 [0.651, 0.661]
Chains 4 Effective p 88.87±4.69 EV 0.533 [0.497, 0.572]
Time 3.8s B 0.117 [0.113, 0.121] v 8.433 [6.855, 9.889]
p 18 vp 0.133 [0.124, 0.143]
Mode β Mean β Median β S.E. Lower Upper Pr(β>0) Symmetry
treat=5000U   0.2210   0.2114   0.1986  0.5710  -0.8544   1.3681  0.6428  0.97
treat=Placebo   1.8312   1.8294   1.8324  0.5832   0.7605   3.0076  0.9992  1.03
week   0.4864   0.4866   0.4865  0.0850   0.3234   0.6503  1.0000  1.04
week'  -0.2878  -0.2877  -0.2864  0.0905  -0.4690  -0.1224  0.0003  0.96
ptwstrs   0.1997   0.2013   0.2011  0.0263   0.1475   0.2505  1.0000  1.02
ptwstrs'  -0.0621  -0.0659  -0.0654  0.0620  -0.1855   0.0568  0.1465  0.97
ptwstrs''   0.5325   0.5492   0.5490  0.2468   0.0945   1.0520  0.9862  1.04
age  -0.0295  -0.0282  -0.0279  0.0309  -0.0920   0.0290  0.1792  1.04
age'   0.1236   0.1206   0.1203  0.0863  -0.0543   0.2788  0.9215  0.98
age''  -0.5069  -0.4969  -0.4969  0.3407  -1.1953   0.1406  0.0707  1.02
sex=M  -0.4635  -0.3775  -0.3346  2.2919  -4.8029   3.9812  0.4368  1.01
treat=5000U × week  -0.0341  -0.0323  -0.0306  0.1113  -0.2482   0.1786  0.3955  0.98
treat=Placebo × week  -0.2719  -0.2715  -0.2699  0.1137  -0.4858  -0.0439  0.0088  0.98
treat=5000U × week'  -0.0340  -0.0355  -0.0377  0.1209  -0.2646   0.2043  0.3818  1.00
treat=Placebo × week'   0.1197   0.1193   0.1161  0.1222  -0.1216   0.3474  0.8423  1.04
age × sex=M   0.0112   0.0092   0.0085  0.0553  -0.0965   0.1149  0.5645  1.00
age' × sex=M  -0.0510  -0.0465  -0.0448  0.1577  -0.3571   0.2585  0.3812  1.00
age'' × sex=M   0.2614   0.2475   0.2399  0.6125  -1.0222   1.3862  0.6540  1.02
Code
a <- anova(bpo)
a
Relative Explained Variation for twstrs. Approximate total model Wald χ2 used in denominators of REV:247.6 [205.4, 322.2].
REV Lower Upper d.f.
treat (Factor+Higher Order Factors) 0.132 0.067 0.236 6
All Interactions 0.094 0.035 0.178 4
week (Factor+Higher Order Factors) 0.572 0.429 0.683 6
All Interactions 0.094 0.035 0.178 4
Nonlinear (Factor+Higher Order Factors) 0.022 0.000 0.078 3
twstrs0 0.660 0.504 0.751 2
Nonlinear 0.017 0.000 0.056 1
age (Factor+Higher Order Factors) 0.027 0.010 0.093 6
All Interactions 0.016 0.001 0.063 3
Nonlinear (Factor+Higher Order Factors) 0.023 0.004 0.075 4
sex (Factor+Higher Order Factors) 0.020 0.002 0.073 4
All Interactions 0.016 0.001 0.063 3
treat × week (Factor+Higher Order Factors) 0.094 0.035 0.178 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.016 0.001 0.063 3
Nonlinear 0.014 0.000 0.052 2
Nonlinear Interaction : f(A,B) vs. AB 0.014 0.000 0.052 2
TOTAL NONLINEAR 0.059 0.033 0.157 8
TOTAL INTERACTION 0.110 0.055 0.206 7
TOTAL NONLINEAR + INTERACTION 0.144 0.099 0.274 11
TOTAL 1.000 1.000 1.000 17
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')
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 treedepth.
Treedepth satisfactory for all transitions.

Checking sampler transitions for divergences.
13 of 4000 (0.33%) 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.

Effective sample size satisfactory.

Split R-hat values satisfactory all parameters.

Processing complete.
Divergent samples: 3 2 0 8 

EBFMI: 0.973 1.004 1.035 1.009 

   Parameter  Rhat ESS bulk ESS tail
1   alpha[1] 1.001     3442     1886
2   alpha[2] 1.002     2462     1294
3   alpha[3] 1.002     2150     1086
4   alpha[4] 1.002     1858     1286
5   alpha[5] 1.002     1613     1243
6   alpha[6] 1.003     1563     1043
7   alpha[7] 1.004     1350      977
8   alpha[8] 1.005     1242      774
9   alpha[9] 1.005     1125      642
10 alpha[10] 1.005     1343      912
11 alpha[11] 1.006     1099      759
12 alpha[12] 1.007     1117     1070
13 alpha[13] 1.006     1223     1045
14 alpha[14] 1.005     1413     1906
15 alpha[15] 1.006     1392     1572
16 alpha[16] 1.005     1424     1917
17 alpha[17] 1.004     1566     2462
18 alpha[18] 1.004     1592     2251
19 alpha[19] 1.005     1423     1407
20 alpha[20] 1.005     1484     2012
21 alpha[21] 1.004     1647     2023
22 alpha[22] 1.005     1615     2000
23 alpha[23] 1.005     1677     1997
24 alpha[24] 1.006     1617     1674
25 alpha[25] 1.005     1668     1585
26 alpha[26] 1.005     1691     1834
27 alpha[27] 1.005     1693     1787
28 alpha[28] 1.004     1796     1709
29 alpha[29] 1.005     1544     1152
30 alpha[30] 1.003     2100     2331
31 alpha[31] 1.002     2395     2095
32 alpha[32] 1.002     2577     2199
33 alpha[33] 1.002     2662     2097
34 alpha[34] 1.002     1780      990
35 alpha[35] 1.004     1790     1088
36 alpha[36] 1.003     2026     1158
37 alpha[37] 1.005     2216     1273
38 alpha[38] 1.007     2388     1264
39 alpha[39] 1.005     2130     1119
40 alpha[40] 1.002     1899     1059
41 alpha[41] 1.002     1907     1088
42 alpha[42] 1.002     1943     1206
43 alpha[43] 1.003     1591     1207
44 alpha[44] 1.003     1827     1265
45 alpha[45] 1.003     1738     1220
46 alpha[46] 1.002     1711     1207
47 alpha[47] 1.004     1478     1019
48 alpha[48] 1.003     1667     1039
49 alpha[49] 1.002     2316     1641
50 alpha[50] 1.003     2062     1485
51 alpha[51] 1.003     2179     1418
52 alpha[52] 1.002     2252     1630
53 alpha[53] 1.001     2455     2732
54 alpha[54] 1.002     2469     2738
55 alpha[55] 1.001     2377     2271
56 alpha[56] 1.001     2370     2526
57 alpha[57] 1.001     2524     3124
58 alpha[58] 1.002     2345     3166
59 alpha[59] 1.002     2827     3377
60 alpha[60] 1.001     3158     3090
61 alpha[61] 1.001     3224     3035
62   beta[1] 1.001     4299     2317
63   beta[2] 1.002     5293     2670
64   beta[3] 1.001     2745     2213
65   beta[4] 1.000     4809     2692
66   beta[5] 1.002     1402     2426
67   beta[6] 1.001     2554     2027
68   beta[7] 1.001     4693     3281
69   beta[8] 1.003     1873      757
70   beta[9] 1.002     4509     2208
71  beta[10] 1.003     2658     1524
72  beta[11] 1.001     4092     2347
73  beta[12] 1.005     4228     2167
74  beta[13] 1.002     2740     1389
75  beta[14] 1.001     3763     2422
76  beta[15] 1.001     5221     2710
77  beta[16] 1.001     4324     2427
78  beta[17] 1.000     4957     2662
79  beta[18] 1.005     5053     2451
80 sigmag[1] 1.004      663      311
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.85±22.38 g 3.248 [2.924, 3.526] C 0.828 [0.825, 0.83]
Draws 4000 LOO IC 3573.7±44.77 gp 0.415 [0.402, 0.428] Dxy 0.656 [0.65, 0.661]
Chains 4 Effective p 94.31±5 EV 0.531 [0.492, 0.569]
Time 4.7s B 0.117 [0.114, 0.122] v 8.304 [6.61, 9.697]
p 18 vp 0.133 [0.123, 0.142]
Cluster on uid
Clusters 108
σγ 0.1173 [0, 0.3792]
Mean β Median β S.E. Lower Upper Pr(β>0) Symmetry
treat=5000U   0.2228   0.2169  0.5674  -0.8585   1.3290  0.6558  1.02
treat=Placebo   1.8342   1.8358  0.5554   0.7210   2.9318  0.9998  0.99
week   0.4860   0.4853  0.0821   0.3324   0.6511  1.0000  1.01
week'  -0.2847  -0.2849  0.0870  -0.4602  -0.1260  0.0000  1.01
ptwstrs   0.2003   0.2003  0.0265   0.1445   0.2487  1.0000  0.98
ptwstrs'  -0.0655  -0.0642  0.0614  -0.1853   0.0512  0.1398  0.96
ptwstrs''   0.5453   0.5431  0.2431   0.0664   1.0149  0.9888  1.06
age  -0.0283  -0.0291  0.0320  -0.0904   0.0336  0.1920  1.00
age'   0.1225   0.1232  0.0885  -0.0439   0.2947  0.9120  1.04
age''  -0.5068  -0.5066  0.3506  -1.1973   0.1543  0.0648  0.97
sex=M  -0.4046  -0.3879  2.3564  -5.1096   3.9917  0.4323  0.99
treat=5000U × week  -0.0325  -0.0342  0.1095  -0.2554   0.1770  0.3812  1.00
treat=Placebo × week  -0.2717  -0.2714  0.1064  -0.4792  -0.0567  0.0065  1.01
treat=5000U × week'  -0.0374  -0.0350  0.1179  -0.2735   0.1817  0.3725  0.97
treat=Placebo × week'   0.1176   0.1187  0.1150  -0.1102   0.3456  0.8462  1.02
age × sex=M   0.0097   0.0089  0.0569  -0.0990   0.1204  0.5620  1.01
age' × sex=M  -0.0493  -0.0461  0.1641  -0.3710   0.2604  0.3832  0.97
age'' × sex=M   0.2610   0.2596  0.6432  -0.9998   1.4963  0.6558  1.06

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.2863661 0.3894213 -2.0003197 -0.4892969         0.0005
2  Week 4     4 -0.7433413 0.2582757 -1.2744474 -0.2785185         0.0010
3  Week 8     8  0.2234072 0.3485378 -0.4682498  0.8784669         0.7408
4* Week 12   12  0.7129521 0.2582684  0.2521144  1.2348809         0.9960
5* Week 16   16  1.0831961 0.3989422  0.2746078  1.8176953         0.9965

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 Z 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
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) B 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
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 C values of TWSTRS to get the posterior distribution of differences in mean TWSTRS between high and low dose
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 D
  • Distribution of TWSTRS conditional high dose, median age, mode sex
  • Not conditional on week 8 value
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?