Learn R Programming

DCC (version 1.2.1)

detect_score_anomaly: Detect group-wise score anomalies

Description

Flags respondents whose score is an outlier within their group (IQR fences or z-scores), and groups whose mean deviates strongly from the overall mean.

Usage

detect_score_anomaly(x, score_var, group_vars = NULL,
  method = c("iqr", "zscore"), k = 1.5, group_mean_z = 2,
  id_var = NULL, severity = "warn")

Value

A dcc_findings table (check ids Q_SCORE_OUTLIER

and Q_GROUP_SCORE_SHIFT; group-level findings have record_id = NA and the group label in evidence).

Arguments

x

A dcc_data object or data.frame.

score_var

Name of the numeric score column.

group_vars

Character vector of grouping columns; NULL treats the data as one group.

method

"iqr" (default) or "zscore" for within-group outliers.

k

Fence multiplier: IQR multiplier (default 1.5) or |z| cutoff (use e.g. 3 with method = "zscore").

group_mean_z

Flag groups whose mean is more than this many overall standard deviations from the overall mean (default 2; NULL skips the group-level check).

id_var

Name of the record-id column, or NULL for row numbers.

severity

Severity assigned to findings (default "warn").

Examples

Run this code
df <- data.frame(sid = sprintf("S%d", 1:8),
                 grp = rep(c("A", "B"), each = 4),
                 score = c(80, 82, 15, 81, 60, 62, 61, 59))
detect_score_anomaly(df, "score", group_vars = "grp", id_var = "sid")

Run the code above in your browser using DataLab