library(extraDistr) # for rmixnorm
library(ggplot2)
dists <- list(
rmixnorm = list(mean = c(70, 150), sd = c(15, 5), alpha = c(0.3, 0.7)),
rnorm = list(mean = 90, sd = 3)
)
x <- mvSim(dists = dists, wide = FALSE)
dim(x)
x2 <- mvSim(dists = dists)
dim(x2)
ggplot(x, aes(
x = as.numeric(sub("sim_", "", variable)),
y = value, group = interaction(group, id), fill = group
)) +
geom_col(position = "identity", alpha = 0.25) +
pcv_theme() +
labs(x = "bin")
dists = list(rnorm = list(mean = 30, sd = 15), rnorm = list(mean = 25, sd = 10))
x3 <- mvSim(
dists = dists, wide = FALSE, # here we make longitudinal data
t = 10, model = "linear", params = list("A" = c(10, 5))
)
ggplot(x3, aes(
x = as.numeric(sub("sim_", "", variable)),
y = value, group = interaction(group, id), fill = group
)) +
facet_wrap(~times) +
geom_col(position = "identity", alpha = 0.25) +
pcv_theme() +
labs(x = "bin")
Run the code above in your browser using DataLab