set.seed(1234)
n <- 20000
change_points <- c(
952, 1905, 2858, 3810, 4763, 5715, 6668, 7620, 8573, 9525,
10478, 11430, 12383, 13335, 14288, 15240, 16193, 17145, 18098,
19050
)
segment_starts <- c(1, change_points + 1)
segment_ends <- c(change_points, n)
families <- c(
"normal", "exponential", "poisson", "t", "gamma", "uniform", "lognormal",
"weibull", "chisq", "beta", "normal", "poisson", "exponential", "uniform",
"gamma", "t", "lognormal", "beta", "weibull", "chisq", "normal"
)
scale_factors <- c(
0.7, 1.4, 0.6, 1.8, 0.75, 2.5, 0.65, 3.0, 0.7, 2.6, 0.6,
1.7, 0.65, 2.9, 0.7, 2.8, 0.6, 2.6, 0.65, 3.0, 0.7
)
simulate_base <- function(m, family) {
z <- switch(
family,
normal = rnorm(m, mean = 0, sd = 1),
exponential = rexp(m, rate = 1),
poisson = rpois(m, lambda = 2),
gamma = rgamma(m, shape = 2, rate = 1),
uniform = runif(m, min = -sqrt(3), max = sqrt(3)),
t = rt(m, df = 3),
lognormal = rlnorm(m, meanlog = 0, sdlog = 0.7),
beta = rbeta(m, shape1 = 2, shape2 = 5),
weibull = rweibull(m, shape = 1.5, scale = 1),
chisq = rchisq(m, df = 5)
)
as.numeric((z - mean(z)) / sd(z))
}
x_dist <- numeric(n)
for (j in seq_along(families)) {
segment_index <- segment_starts[j]:segment_ends[j]
x_dist[segment_index] <- scale_factors[j] * simulate_base(length(segment_index), families[j])
}
change_points