secret
Created

benford-prices.r

  • Download Gist
gistfile1.r
R
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
library(ggplot2)
orig <- read.csv("prices.tsv.gz", sep = "\t")
orig <- mutate(orig,
cents = (100 * Price) %% 100,
fd = cents %/% 10)
 
df <- count(orig, "fd")
df <- mutate(df,
prob = prop.table(freq),
benford = log10(fd + 1) - log10(fd + 0))
 
ggplot(df, aes(x = fd, y = prob)) +
geom_bar(stat = "identity", fill = "blue") +
geom_line(aes(x = Numeral, y = benford, size = 0.1)) +
geom_point(aes(x = Numeral, y = benford, color = "red", size = 1)) +
theme_bw()
scale_x_continuous(breaks = seq(1:9))
ggsave("benford.png")

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.