Example:
library(tidyverse)
library(mmrm)
set.seed(42)
example <- tibble(eye=rep(c("left", "right"), 30),
visit=rep(rep(c("Week0", "Week4", "Week8"), each=2), 10),
id=rep(1L:10L, each=6),
random_subject_effect = rnorm(n=10, mean=0, sd=10)[id],
age = sample(18:85, size=10, replace=T)[id],
IOP = rnorm(n=60,
mean=random_subject_effect+10-(eye=="left")*3+as.integer(str_extract(visit, "[0-8]+")),
sd=5)) %>%
dplyr::select(-random_subject_effect) %>%
mutate(eye_visit = factor(paste0(eye, "_", visit)),
id=factor(id))
mmrmfit1 <- mmrm::mmrm(
formula = IOP ~ 0 + eye_visit + age + us(eye_visit | id),
data = example,
method = "Kenward-Roger")
mmrmfit1 %>%
summary()