# Load packages JM
library("JM")


#################
# Section 2.2.2 #
#################

# random-intercepts model for the AIDS dataset
lmeFit.int <- lme(CD4 ~ obstime, random = ~ 1 | patient,
    data = aids)

summary(lmeFit.int)

# marginal covariance matrix for Patient 12
margCov.int <- getVarCov(lmeFit.int, individuals = 12,
    type = "marginal")

margCov.int
cov2cor(margCov.int[[1]])

# random-intercepts and random-slopes model for the AIDS dataset
lmeFit.slp <- lme(CD4 ~ obstime, random = ~ obstime | patient, data = aids)

summary(lmeFit.slp)

# marginal covariance matrix for Patient 12
margCov.slp <- getVarCov(lmeFit.slp, individuals = 12,
    type = "marginal")

margCov.slp
cov2cor(margCov.slp[[1]])