Belfast Lectures
Belfast Lectures
Peter Diggle
• three treatments:
– haloperidol (standard)
– placebo
– risperidone (novel)
150
PANSS
100
50
0
0 2 4 6 8
• autocorrelation
• prediction
Analysis of Bailrigg temperature data
data<-read.table("../data_and_figures/maxtemp.data",header=F)
temperature<-data[,4]
n<-length(temperature)
day<-1:n
plot(day,temperature,type="l",cex.lab=1.5,cex.axis=1.5)
#
# plot shows strong seasonal variation,
# try simple harmonic regression
#
c1<-cos(2*pi*day/n)
s1<-sin(2*pi*day/n)
fit1<-lm(temperature~c1+s1)
lines(day,fit1$fitted.values,col="red")
#
# add first harmonic of annual frequency to check for
# non-sinusoidal pattern
#
c2<-cos(4*pi*day/n)
s2<-sin(4*pi*day/n)
fit2<-lm(temperature~c1+s1+c2+s2)
lines(day,fit2$fitted.values,col="blue")
#
# two fits look similar, but conventional F test says otherwise
#
summary(fit2)
RSS1<-sum(fit1$resid^2); RSS2<-sum(fit2$resid^2)
F<-((RSS1-RSS2)/2)/(RSS2/361)
1-pf(F,2,361)
#
# conventional residual plots
#
# residuals vs fitted values
#
plot(fit2$fitted.values,fit2$resid)
#
# residuals in time-order as scatterplot
#
plot(1:365,fit2$resid)
#
# and as line-graph
#
plot(1:365,fit2$resid,type="l")
#
# examine autocorrelation properties of residuals
#
residuals<-fit2$resid
par(mfrow=c(2,2),pty="s")
for (k in 1:4) {
plot(residuals[1:(n-k)],residuals[(k+1):n],
pch=19,cex=0.5,xlab=" ",ylab=" ",main=k)
}
par(mfrow=c(1,1))
acf(residuals)
#
# exponentially decaying correlation looks reasonable
#
cor(residuals[1:(n-1)],residuals[2:n])
Xmat<-cbind(rep(1,n),c1,s1,c2,s2)
rho<-0.01*(60:80)
profile<-AR1.profile(temperature,Xmat,rho)
#
# examine results
#
plot(rho,profile$logl,type="l",ylab="L(rho)")
Lmax<-max(profile$logl)
crit.val<-0.5*qchisq(0.95,1)
lines(c(rho[1],rho[length(rho)]),rep(Lmax-crit.val,2),lty=2)
profile
#
# Exercise: how would you now re-assess the significance of
# the second harmonic term?
#
# profile log-likelihood function follows
#
AR1.profile<-function(y,X,rho) {
m<-length(rho)
logl<-rep(0,m)
n<- length(y)
hold<-outer(1:n,1:n,"-")
for (i in 1:m) {
Rmat<-rho[i]^abs(hold)
ev<-eigen(Rmat)
logdet<-sum(log(ev$values))
Rinv<-ev$vectors%*%diag(1/ev$values)%*%t(ev$vectors)
betahat<-solve(t(X)%*%Rinv%*%X)%*%t(X)%*%Rinv%*%y
residual<- y-X%*%betahat
logl[i]<- - logdet - n*log(c(residual)%*%Rinv%*%c(residual))
}
max.index<-order(logl)[m]
Rmat<-rho[max.index]^abs(hold)
ev<-eigen(Rmat)
logdet<-sum(log(ev$values))
Rinv<-ev$vectors%*%diag(1/ev$values)%*%t(ev$vectors)
betahat<-solve(t(X)%*%Rinv%*%X)%*%t(X)%*%Rinv%*%y
residual<- y-X%*%betahat
sigmahat<-sqrt(c(residual)%*%Rinv%*%c(residual)/n)
list(logl=logl,rhohat=rho[max.index],sigmahat=sigmahat,betahat=betahat)
}
Longitudinal data
• exploratory analysis
p
Classical result: Ȳ ± 2 σ 2 /n
• E[Ȳ ] = µ
2 −1
P
• Var{Ȳ } = (σ /n) × {1 + n u6=t Corr(Yt , Yu )}
−4 −2 0 2 4
time
Correlation may or may not hurt you
−4 −2 0 2 4
time
Correlation may or may not hurt you
−4 −2 0 2 4
time
Correlation may or may not hurt you
150
150
100
100
100
PANSS
PANSS
PANSS
50
50
50
0
0
0 2 4 6 8 0 2 4 6 8 0 2 4 6 8
time (weeks) time (weeks) time (weeks since randomisation)
Exploring covariance structure: balanced data
(Yij , tj ) : j = 1, ..., n; i = 1, ..., m
PANSS data:
SD Y.t0 Y.t1 Y.t2 Y.t4 Y.t6 Y.t8
Y.t0 20.019 1.000 0.533 0.366 0.448 0.285 0.229
Y.t1 20.184 0.533 1.000 0.693 0.589 0.658 0.535
Y.t2 22.120 0.366 0.693 1.000 0.670 0.567 0.678
Y.t4 20.996 0.448 0.589 0.670 1.000 0.718 0.648
Y.t6 24.746 0.285 0.658 0.567 0.718 1.000 0.792
Y.t8 23.666 0.229 0.535 0.678 0.648 0.792 1.000
V (u) = σ 2 {1 − ρ(u)}
• Define
1
vijkℓ = (rij − rkℓ )2
2
• Estimate
400
300
Variogram
200
100
0
0 2 4 6 8
Lag
Where does the correlation come from?
• measurement error
General linear model, correlated residuals
• Random effects
• Random effects
• Serial correlation
• Measurement error
• Compound symmetry
Ui ∼ N(0, ν 2 )
Zij ∼ N(0, τ 2 )
(Ui , Wi ) ∼ BVN(0, Σ)
Zij ∼ N(0, τ 2 )
0
−1
−2
−3
t
Time-varying random effects: continued
stationary process
3
2
1
R(t)
0
−1
−2
−3
t
• A general model
Ui ∼ MVN(0, Σ)
(random effects)
dij = vector of explanatory variables for random effects
Wi (t) = continuous-time Gaussian process
(serial correlation)
Zij ∼ N(0, τ 2 )
(measurement errors)
0 1 2 3 4 5 6
u
Fitting the model: non-technical summary
1
• Dimensionality of optimisation is 2
n(n + 1) − 1
Rubin (1976)
Dropout
Once a subject goes missing, they never return
Example : Longitudinal clinical trial
Little (1995)
Modelling the missing value process
• Selection factorisation
[Y, M ] = [Y ][M |Y ]
[Y, M ] = [M ][Y |M ]
• Random effects
Z
[Y, M ] = [Y |U ][M |U ][U ]dU
Comparing the three approaches
L = p(m|yo )f (yo )
5
4
3
2
y
1
0
−1
2 4 6 8 10
time
• F = dropout time
week −1 0 1 2 4 6 8
missing 0 3 9 70 122 205 251
proportion 0.00 0.01 0.02 0.14 0.24 0.40 0.49
160
140
120
PANSS
100
80
60
40
0 2 4 6 8
time (weeks)
empirical cumulative distribution empirical cumulative distribution
0.0 0.2 0.4 0.6 0.8 1.0 0.0 0.2 0.4 0.6 0.8 1.0
40
60
60
80
80
100
Y
Y
t=4
t=0
100
120
120
140
140
160
40
60
60
80
80
Y
Y
100
t=6
t=1
100
120
120
140
140
160
100
160
Schizophrenia trial data
Mean response (random effects model)
95
90
85
Mean response
80
75
placebo
halperidol
risperidone
70
0 2 4 6 8
Time (weeks)
Schizophrenia trial data
Empirical and fitted variograms
400
300
Variogram
200
100
0
0 2 4 6 8
Lag
Schizophrenia trial data: summary
Measurement model
General linear model for Yi = {Yit : t = 1, ..., n}
(balanced data)
Dropout model
Logistic regression:
Hybrid time-scales
Linkage
d
!
X
P(Di = d|Di > d − 1, U ) = 1 − Φ µ̃id + γk Uik
k=1
• transition models
• marginal models
• Var(Yj |U ) = φv(µj )
• E(Yj |history) = µj
Pj−1
• h(µj ) = x′j β + k=1
′
Yj−k αk
• E(y) = µ : h(µ) = Xβ
• Var(yi ) = φv(µi )
• Corr(y) = R(α).
−10 −5 0 5 10
x
Example: Effect of mother’s smoking on probability of
intra-uterine growth retardation (IUGR).
• Marginal models
Function gee within package of same name
• Transition models
Standard glm function, after computing values of required
functions of lagged responses to be used as explanatory
variables.
Illustration of marginal modelling
set.seed(2346)
x=rep(1:10,50)
logit=0.1*(x-mean(x))
subject=rep(1:50,each=10)
re=2*rnorm(50)
re=rep(re,each=10)
prob=exp(re+logit)/(1+exp(re+logit))
y=(runif(500)<prob)
fit1=glm(y~x,family=binomial)
summary(fit1)
library(gee)
fit2<-gee(y~x,id=subject,family=binomial)
summary(fit2)
5. Joint modelling: repeated measurements
and time-to-event outcomes
• what is it?
• why do it?
• Subjects i = 1, ..., m.
• Baseline covariates xi .
• Parameters θ.
[Y, F |x, θ]
Joint modelling: what is it?
60
F=6.4
55
outcome
50
5<F<6
45
F>7
40
0 2 4 6 8 10
time
Joint modelling: why do it?
R1 F α
R2 Y β
Example: Wulfsohn and Tsiatis, 1997
Measurement model
• Zij ∼ N(0, τ 2 )
• Zij ∼ N(0, τ 2 )
Hazard model
• Informative follow-up
fit<-joint(mental.joint,long.formula=Y~-1+treat+time,
surv.formula=Surv(surv.time,cens.ind)~treat,
model="intslope")
summary(fit)
set.seed(389712)
fit.se <- jointSE(fit, n.boot = 5)
# use much larger number of bootstrap samples in practice
set.seed(54912)
fit.se100 <- jointSE(fit, n.boot = 100,max.it=2000,tol=0.01,
print.detail=TRUE)
fit.se100
Take-home messages
• Correlation matters