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?
            Asked
            
        
        
            Active
            
        
            Viewed 90 times
        
    1 Answers
1
            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)))
        M.Viking
        
- 5,067
 - 4
 - 17
 - 33
 
- 
                    That worked great! The only thing I’m trying to work out now is how to label the plots by vendor. We have a lot of vendors and the blank plots on their own are impossible to sort out – coult Jun 28 '22 at 00:22
 - 
                    Check out the modified version in this Q&A - https://stackoverflow.com/q/56936984/10276092 . (ps. The latest "GitHub" version doesn't make a legend for me) – M.Viking Jun 28 '22 at 16:06