The goal of lmmpar is to …
You can install lmmpar from github with:
# install.packages("devtools")
::install_github("fulyagokalp/lmmpar") devtools
This is a basic example which shows you how to solve a common problem:
# Set up fake data
<- 10000 # number of subjects
n <- 4 # number of repeats
m <- n * m # true size of data
N <- 50 # number of betas
p <- 2 # width of random effects
q
# Initial parameters
# beta has a 1 for the first value. all other values are ~N(10, 1)
<- rbind(1, matrix(rnorm(p, 10), p, 1))
beta <- diag(m)
R <- matrix(c(16, 0, 0, 0.025), nrow = q)
D <- 1
sigma
# Set up data
<- rep(1:n, each = m)
subject <- rep(1:m, n)
repeats
<- lapply(1:n, function(i) cbind(1, matrix(rnorm(m * p), nrow = m)))
subj_x <- do.call(rbind, subj_x)
X <- X[, 1:q]
Z <- lapply(1:n, function(i) mnormt::rmnorm(1, rep(0, q), D))
subj_beta <- lapply(1:n, function(i) mnormt::rmnorm(1, rep(0, m), sigma * R))
subj_err
# create a known response
<- lapply(
subj_y seq_len(n),
function(i) {
%*% beta) +
(subj_x[[i]] 1:q] %*% subj_beta[[i]]) +
(subj_x[[i]][,
subj_err[[i]]
}
)<- do.call(rbind, subj_y)
Y
# run the algorithm in parallel to recover the known betas
<- lmmpar(
ans
Y,
X,
Z,
subject,beta = beta,
R = R,
D = D,
cores = 4,
sigma = sigma,
verbose = TRUE
)