#Generate data: X, Y, and Z.
set.seed(2024)
n <- 1e3
m <- 10
Y <- matrix(rnorm(m*n), m, n)
rownames(Y) <- paste0("Gene", 1:nrow(Y))
trt <- sample(c("A", "B"), n, replace = TRUE)
X <- model.matrix(~ 0 + trt)
q <- 20
sam <- rep(NA, n)
sam[trt == "A"] <- paste0("A", sample.int(q/2, sum(trt == "A"), replace = TRUE))
sam[trt == "B"] <- paste0("B", sample.int(q/2, sum(trt == "B"), replace = TRUE))
Z <- model.matrix(~ 0 + sam)
d <- ncol(Z)
#Fit LMM by the cell-level data
fit <- lmmfit(Y, X, Z, d = d)
str(fit)
#Hypothesis testing
lmmtest(fit)
lmmtest(fit, index = 2)
lmmtest(fit, contrast = cbind("B-A" = c(-1, 1)))
Run the code above in your browser using DataLab