# 1. Wide-format input: 4 timepoints x 10 subjects.
set.seed(113)
n <- 10; k <- 4
Y <- matrix(rnorm(n * k, 0, 1), n, k) +
matrix(rep(seq(0, 0.9, length.out = k), n), n, k, byrow = TRUE) +
rnorm(n, 0, 1.5)
colnames(Y) <- paste0("T", 1:k)
pairwise_within(Y)
# 2. Long-format input:
long <- data.frame(
subject = factor(rep(1:n, times = k)),
time = factor(rep(paste0("T", 1:k), each = n)),
y = as.vector(Y)
)
pairwise_within(long, subject = "subject", condition = "time", outcome = "y")
Run the code above in your browser using DataLab