# 1. Randomized design, two groups, equal n.
set.seed(113)
simple <- simulate_ancova_data(
mu_y = c(3, 5),
mu_x = 10,
sigma_y = 1,
sigma_x = 2,
rho = 0.8,
a = 2,
n = 20
)
head(simple)
# 2. Four preexisting groups with different correlations and unequal n.
# The first two groups share rho = 0.30; the second two share a larger
# rho = 0.60. The four groups are not used in the data-generation
# machinery beyond their per-group means and correlations -- they are
# just four distinct populations being sampled. In a downstream
# analysis these four groups could be cross-classified as a 2 x 2
# factorial design (e.g., the first factor distinguishing groups 1-2
# from groups 3-4, and the second factor distinguishing groups 1, 3
# from groups 2, 4) and analyzed via factorial ANCOVA.
set.seed(113)
preexisting <- simulate_ancova_data(
mu_y = c(50, 55, 60, 65),
mu_x = c(10, 12, 11, 13),
sigma_y = 8,
sigma_x = 3,
rho = c(0.30, 0.30, 0.60, 0.60),
a = 4,
n = c(40, 35, 45, 30),
randomized = FALSE
)
aggregate(cbind(y, x) ~ group, data = preexisting,
FUN = function(z) round(c(mean = mean(z), sd = sd(z)), 2))
Run the code above in your browser using DataLab