Nothing
## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
## ----setup--------------------------------------------------------------------
library(wavecov)
## -----------------------------------------------------------------------------
set.seed(123)
n_id <- 100
waves <- 0:2
ids <- sprintf("ee%03d", 1:n_id)
base_panel <- expand.grid(
eeid = ids,
wave = waves,
KEEP.OUT.ATTRS = FALSE,
stringsAsFactors = FALSE
)
# Simple group assignment (one group per id-wave, then reused)
base_panel$group <- sample(c("Group A", "Group B"),
nrow(base_panel), replace = TRUE)
# Engagement metric block
eng_panel <- base_panel
eng_panel$metric_id <- "engagement_score"
eng_panel$metric <-
3.5 +
0.2 * eng_panel$wave +
ifelse(eng_panel$group == "Group A", 0.1, -0.1) +
rnorm(nrow(eng_panel), sd = 0.4)
# Pay index metric block
pay_panel <- base_panel
pay_panel$metric_id <- "pay_index"
pay_panel$metric <-
1.0 +
0.05 * pay_panel$wave +
ifelse(pay_panel$group == "Group A", 0.05, -0.05) +
rnorm(nrow(pay_panel), sd = 0.1)
# Stack into one long panel
panel <- rbind(eng_panel, pay_panel)
head(panel)
nrow(panel) # should be 100 ids * 3 waves * 2 metrics = 600
## -----------------------------------------------------------------------------
wave_pairs <- data.frame(
wave_0 = c(0, 1),
wave_1 = c(1, 2)
)
wave_pairs
## -----------------------------------------------------------------------------
batch_res <- compare_waves_batch(
data = panel,
wave_pairs = wave_pairs,
id_col = "eeid",
wave_col = "wave",
metric_col = "metric",
metric_id_col = "metric_id",
group_cols = "group",
method = "auto",
reliability = 0.8
)
head(batch_res)
## -----------------------------------------------------------------------------
batch_res_min <- batch_res[, c(
"wave_0", "wave_1",
"metric_id", "group",
"estimate", "se",
"ci_lower", "ci_upper",
"method"
)]
head(batch_res_min)
## -----------------------------------------------------------------------------
eng_changes <- subset(batch_res_min, metric_id == "engagement_score")
eng_changes
## -----------------------------------------------------------------------------
subset(batch_res_min, metric_id == "engagement_score" & wave_0 == 0 & wave_1 == 1)
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.