## ----setup, include = FALSE--------------------------------------------------- knitr::opts_chunk$set(collapse = TRUE, comment = "#>") library(rolescry) set.seed(1) ## ----example------------------------------------------------------------------ d <- data.frame( arm = rep(c(0, 1), each = 50), # a balanced 2-level grouping pre = rnorm(100, 10, 2), # measured before ... post = rnorm(100, 11, 2), # ... and after (paired) resp = rbinom(100, 1, 0.4) # a binary response ) res <- detect_roles(d) res summary(res) ## ----blind-------------------------------------------------------------------- d_blind <- setNames(d, paste0("col_", seq_along(d))) pos <- function(r, dat) match(r$roles$paired_pairs$columns, names(dat)) identical(pos(detect_roles(d), d), pos(detect_roles(d_blind), d_blind)) ## ----breakdown---------------------------------------------------------------- res$roles$paired_pairs$components[[1]] ## ----nmi---------------------------------------------------------------------- g <- sample(c("A", "B", "C"), 300, replace = TRUE) y <- ifelse(g == "A", "event", sample(c("event", "none"), 300, replace = TRUE)) compute_nmi(g, y) # > 0: g informs y compute_nmi(g, sample(g)) # ~ 0: shuffled -> independent ## ----namebonus---------------------------------------------------------------- clin <- data.frame( male = rbinom(120, 1, 0.5), # a demographic binary (first) death = rbinom(120, 1, 0.3) # the intended outcome ) detect_roles(clin)$roles$outcome_binary$columns # positional default detect_roles(clin, name_bonus = rolescry_default_name_bonus())$roles$outcome_binary$columns # "death"