library(dplyr)
<- 20230906
seed set.seed(seed = seed)
<- c(rep("a1", 8), rep("a2", 5), rep("a3", 7))
A <- c(rep(c("b1", "b2"), 10))
B <- ifelse(A == "a1", 10, ifelse(A == "a2", 13, 15))
m_A <- ifelse(B == "b1", 3, 5)
m_B <- m_A * m_B + rnorm(length(A))
m <- rnorm(n = length(m), mean = m)
y <- data.frame(A, B, y)) (df0
A B y
1 a1 b1 29.91343
2 a1 b2 50.00045
3 a1 b1 29.06207
4 a1 b2 50.84555
5 a1 b1 28.91922
6 a1 b2 50.96287
7 a1 b1 28.27495
8 a1 b2 49.98828
9 a2 b1 39.42510
10 a2 b2 64.91906
11 a2 b1 38.82944
12 a2 b2 65.18426
13 a2 b1 35.91582
14 a3 b2 74.30268
15 a3 b1 48.01233
16 a3 b2 75.39627
17 a3 b1 45.92087
18 a3 b2 76.64767
19 a3 b1 43.91362
20 a3 b2 73.68897