| detect_roles | R Documentation |
Inspects an already-loaded data frame and assigns each column (or group of
columns) to statistical roles – group variable, continuous/binary outcome,
survival time and event, paired and agreement measurement pairs, repeated
measures, scale items, subject id, and covariates – using only the data
information-theoretic signature (Shannon entropy, distributional shape,
inter-column structure) and never the column names. Renaming columns to
col_1, col_2, ... does not change the result (the name-blindness, or
"turnusol", invariant).
detect_roles(data, name_bonus = NULL, verbose = FALSE)
## S3 method for class 'role_detection'
print(x, ...)
## S3 method for class 'role_detection'
summary(object, ...)
data |
A |
name_bonus |
Optional named list mapping role keys to character vectors
of case-insensitive keyword regex fragments, e.g.
|
verbose |
Logical; if |
x |
A |
... |
Ignored. |
object |
A |
Detection is purely mathematical by default (name_bonus = NULL). When
a keyword dictionary is supplied via name_bonus, column names act only
as a small, capped tie-breaker (at most a +10 point nudge, i.e. <= 10 percent,
applied to candidate selection for the group, outcome, subject-id and
survival roles) – the reported confidence stays the mathematical signature.
See rolescry_default_name_bonus() for a ready-made dictionary.
A column can hold more than one role (e.g. a measurement in both
paired_pairs and agreement_pairs). The covariate role is
residual: it lists the continuous, categorical and binary columns that no other
role claimed. A role whose evidence does not single out a column is reported as
not found rather than guessed.
The coupled_pair role (0.3.0) reports a dependent pair of one binary and
one positive continuous column whose reading is ambiguous: it may be a survival
(time, event) pair or a (cause, binary outcome) pair, and the data alone cannot
say which. The survival roles are assigned instead only when censoring geometry
singles the survival reading out. The entry carries continuous_col,
binary_col and the two interpretations; the choice is the user's.
The time_index role (0.3.0) reports calendar columns: Date/POSIXct
classes, or character columns whose every value parses as a date. The class
and format are properties of the values, so name-blindness is preserved. On a
balanced long panel whose entity/time axes are value-symmetric, the axes are
reported as ambiguous (repeated_measures$panel_axes) unless serial
dependence of the measures singles one reading out.
An S3 object of class "role_detection": a list with
data.frame(column, type) – value-based column typing.
named list; each entry has found, columns,
score, max_score, pct, detected_by and a
components score breakdown. Meaning of score/pct per role:
group_var: score = pct = 100 * B (normalized-entropy ranking;
max_score = 100; there is no description-length test).
Paired/agreement pairs, ordinal scale items and the outcomes: score
is in bits, max_score is NA, and pct is the display map
100 * (1 - 2^(-bits/8)). Survival, wide repeated measures and binary
scale items (ported point scorers): score and max_score are
points and pct is the points ratio.
named character vector of per-column value-type labels.
list of candidate continuous column pairs with
MDL pair bits and shift bits. The paired/agreement split is the sign of the
shift bits, a BIC-type test of a mean difference between the two columns:
agreement_pairs means "no detectable systematic shift", so a
method-comparison pair with a real calibration bias is labeled
paired_pairs, and the label depends on n. Exactly one pair is
reported across the two roles.
dataset dimensions.
read_data(), compute_nmi(), rolescry_default_name_bonus()
set.seed(1)
d <- data.frame(
arm = rep(c(0, 1), each = 50),
pre = rnorm(100, 10, 2),
post = rnorm(100, 11, 2),
resp = rbinom(100, 1, 0.4)
)
res <- detect_roles(d)
res
res$roles$group_var$columns
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.