### Univariate linear mixed model
# response variable for 10 objects
y <- c(5.42, -1.91, 2.82, -0.14, -1.83, 3.44, 6.18, -1.20, 2.68, 1.12)
# corresponding measurement error standard deviations
se <- c(1.05, 1.15, 1.22, 1.45, 1.30, 1.29, 1.31, 1.10, 1.23, 1.11)
# one covariate information for 10 objects
x <- c(2, 3, 0, 2, 3, 0, 1, 1, 0, 0)
## Fitting without covariate information
# (DTA) maximum likelihood estimates of A and beta via an EM algorithm
res <- lmm(y = y, v = se^2, method = "em", dta = TRUE)
# (DTA) posterior samples of A and beta via an MCMC method
res <- lmm(y = y, v = se^2, n.burn = 1e1, n.sample = 1e1,
method = "mcmc", dta = TRUE)
# (DA) maximum likelihood estimates of A and beta via an EM algorithm
res <- lmm(y = y, v = se^2, method = "em", dta = FALSE)
# (DA) posterior samples of A and beta via an MCMC method
res <- lmm(y = y, v = se^2, n.burn = 1e1, n.sample = 1e1,
method = "mcmc", dta = FALSE)
## Fitting with the covariate information
# (DTA) maximum likelihood estimates of A and beta via an EM algorithm
res <- lmm(y = y, v = se^2, x = x, method = "em", dta = TRUE)
# (DTA) posterior samples of A and beta via an MCMC method
res <- lmm(y = y, v = se^2, x = x, n.burn = 1e1, n.sample = 1e1,
method = "mcmc", dta = TRUE)
# (DA) maximum likelihood estimates of A and beta via an EM algorithm
res <- lmm(y = y, v = se^2, x = x, method = "em", dta = FALSE)
# (DA) posterior samples of A and beta via an MCMC method
res <- lmm(y = y, v = se^2, x = x, n.burn = 1e1, n.sample = 1e1,
method = "mcmc", dta = FALSE)
### Multivariate linear mixed model
# (arbitrary) 10 hospital profiling data (two response variables)
y1 <- c(10.19, 11.53, 16.28, 12.32, 12.84, 11.85, 14.81, 13.24, 14.43, 9.35)
y2 <- c(12.06, 14.97, 11.50, 17.88, 19.21, 14.69, 13.96, 11.07, 12.71, 9.63)
y <- cbind(y1, y2)
# making measurement error covariance matrices for 10 hospitals
n <- c(24, 34, 38, 42, 49, 50, 79, 84, 96, 102) # number of patients
v0 <- matrix(c(186.87, 120.43, 120.43, 250.60), nrow = 2) # common cov matrix
temp <- sapply(1 : length(n), function(j) { v0 / n[j] })
v <- array(temp, dim = c(2, 2, length(n)))
# covariate information (severity measure)
severity <- c(0.45, 0.67, 0.46, 0.56, 0.86, 0.24, 0.34, 0.58, 0.35, 0.17)
## Fitting without covariate information
# (DTA) maximum likelihood estimates of A and beta via an EM algorithm
# \donttest{
res <- lmm(y = y, v = v, method = "em", dta = TRUE)
# }
# (DTA) posterior samples of A and beta via an MCMC method
# \donttest{
res <- lmm(y = y, v = v, n.burn = 1e1, n.sample = 1e1,
method = "mcmc", dta = TRUE)
# }
# (DA) maximum likelihood estimates of A and beta via an EM algorithm
# \donttest{
res <- lmm(y = y, v = v, method = "em", dta = FALSE)
# }
# (DA) posterior samples of A and beta via an MCMC method
# \donttest{
res <- lmm(y = y, v = v, n.burn = 1e1, n.sample = 1e1,
method = "mcmc", dta = FALSE)
# }
## Fitting with the covariate information
# (DTA) maximum likelihood estimates of A and beta via an EM algorithm
# \donttest{
res <- lmm(y = y, v = v, x = severity, method = "em", dta = TRUE)
# }
# (DTA) posterior samples of A and beta via an MCMC method
# \donttest{
res <- lmm(y = y, v = v, x = severity, n.burn = 1e1, n.sample = 1e1,
method = "mcmc", dta = TRUE)
# }
# (DA) maximum likelihood estimates of A and beta via an EM algorithm
# \donttest{
res <- lmm(y = y, v = v, x = severity, method = "em", dta = FALSE)
# }
# (DA) posterior samples of A and beta via an MCMC method
# \donttest{
res <- lmm(y = y, v = v, x = severity, n.burn = 1e1, n.sample = 1e1,
method = "mcmc", dta = FALSE)
# }
Run the code above in your browser using DataLab