sim_panel: Simulate a panel of one or two categorical variables and a...

Description Usage Arguments Value Author(s) Examples

View source: R/sim_panel.R

Description

Simulate a panel of one or two categorical variables and a response variable corresponding to a specified distribution or design

Usage

1
sim_panel(nx = 2, nfacet = 3, ntimes = 500, sim_dist = sim_varall)

Arguments

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

Value

the simulated data for the data structure considered

Author(s)

Sayani07

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
library(tidyverse)
library(distributional)
sim_varx_normal <- function(nx, nfacet, mean, sd, w) {
  rep(dist_normal((mean + seq(0, nx - 1, by = 1) * w), sd), nfacet)
}

sim_panel_data <- sim_panel(
  nx = 1, nfacet = 3,
  ntimes = 5,
  sim_dist = sim_varx_normal(1, 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_panel_data <- sim_panel(
  nx = 2, nfacet = 3,
  ntimes = 5,
  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_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
)

Sayani07/hakear documentation built on Sept. 14, 2021, 10:59 a.m.