I am attempting to implement Benford’s Law using the benford.analysis package in R across all vendors’ invoices. Over the entire dataset the data confirms. I’m trying to find a way to group by vendor to determine if any individual vendor is displaying fraud indicators by not conforming. Is there a way to break out non-conforming by group?
CodePudding user response:
Here is a way to use group_by
and group_map
to create benford.analysis
plots for each group. In this example, grouping Iris data by Species and performing analysis on Sepal Length variable.
In group_map()
, .x
means the grouped subset data, and .y
means the name of the group.
library(dplyr)
library(benford.analysis)
iris %>%
group_by(Species) %>%
group_map(.f = ~ plot(benford(.x$Sepal.Length)))