| sim_panel | R Documentation | 
Simulate a panel of one or two categorical variables and a response variable corresponding to a specified distribution or design
sim_panel(nx = 2, nfacet = 3, ntimes = 500, sim_dist = sim_varall)
nx | 
 number of x categories  | 
nfacet | 
 number of facet categories  | 
ntimes | 
 number of observations to be simulated for each categories  | 
sim_dist | 
 type of distribution to be simulated  | 
the simulated data for the data structure considered
Sayani07
library(dplyr)
library(distributional)
library(tidyr)
library(ggplot2)
sim_varx_normal <- function(nx, nfacet, mean, sd, w) {
  rep(dist_normal((mean + seq(0, nx - 1, by = 1) * w), sd), nfacet)
}
sim_varx_normal(2, 3, 0, 1, 1)
sim_varx_normal(2, 3, 0, 1, -2)
sim_panel_data <- sim_panel(
  nx = 2, nfacet = 3,
  ntimes = 50,
  sim_dist = sim_varx_normal(2, 3, 0, 1, 10)
) %>% unnest(data)
sim_panel_data %>%
  ggplot() +
  geom_boxplot(aes(x = as.factor(id_x), y = sim_data)) +
  facet_wrap(~id_facet)
compute_quantiles(sim_panel_data) %>%
  unnest(c(sim_data_quantile)) %>%
  ggplot() +
  geom_boxplot(aes(x = as.factor(id_x), y = sim_data_quantile)) +
  facet_wrap(~id_facet)
sim_varf_normal <- function(nx, nfacet, mean, sd, w) {
  rep(dist_normal((mean + seq(0, nfacet - 1, by = 1) * w), sd), each = nx)
}
sim_varf_normal(2, 3, 0, 1, 1)
sim_varf_normal(2, 3, 0, 1, 2)
sim_panel_data <- sim_panel(
  nx = 2, nfacet = 3,
  ntimes = 50,
  sim_dist = sim_varf_normal(2, 3, 0, 1, 10)
) %>% unnest(data)
sim_panel_data %>%
  ggplot() +
  geom_boxplot(aes(x = as.factor(id_x), y = sim_data)) +
  facet_wrap(~id_facet)
compute_quantiles(sim_panel_data) %>%
  unnest(c(sim_data_quantile)) %>%
  ggplot() +
  geom_boxplot(aes(x = as.factor(id_x), y = sim_data_quantile)) +
  facet_wrap(~id_facet)
sim_varall_normal <- function(nx, nfacet, mean, sd, w) {
  dist_normal((mean + seq(0,
    (nx *
      nfacet - 1),
    by = 1
  ) * w), sd)
}
sim_varall_normal(2, 3, 0, 1, 1)
sim_varall_normal(2, 3, 0, 1, 2)
sim_panel_data <- sim_panel(
  nx = 2, nfacet = 3,
  ntimes = 5,
  sim_dist = sim_varall_normal(2, 3, 0, 1, 10)
) %>% unnest(data)
sim_panel_data %>%
  ggplot() +
  geom_boxplot(aes(x = as.factor(id_x), y = sim_data)) +
  facet_wrap(~id_facet)
compute_quantiles(sim_panel_data) %>%
  unnest(c(sim_data_quantile)) %>%
  ggplot() +
  geom_boxplot(aes(x = as.factor(id_x), y = sim_data_quantile)) +
  facet_wrap(~id_facet)
compute_pairwise_max(sim_panel_data, "id_x", "id_facet",
  response = sim_data
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.