# Example 1: Basic grouped analysis
set.seed(123)
data <- c(rnorm(50), rnorm(50, 2), rnorm(50, 4))
groups <- rep(c("A", "B", "C"), each = 50)
resultA <- detect_outlier2(data) # no groups
resultB <- detect_outlier2(data, groups = groups) # with groups
# Example 2: Custom thresholds by group
test_scores <- c(65, 70, 75, 72, 68, 73, 78, 71, 69, 74,
90, 85, 92, 88, 95, 87, 91, 89, 86, 93)
class_groups <- rep(c("Morning", "Afternoon"), each = 10)
result <- detect_outlier2(test_scores,
groups = class_groups,
method = "all",
z_threshold = 2)
result$overall
result$by_group
result$plots$overall$boxplot()
result$plots$overall$density()
result$plots$overall$comparison()
result$plots$by_group$Morning$boxplot()
result$plots$by_group$Morning$density()
result$plots$by_group$Afternoon$boxplot()
result$plots$by_group$Afternoon$density()
Run the code above in your browser using DataLab