{"id":37,"date":"2017-04-02T15:22:11","date_gmt":"2017-04-02T15:22:11","guid":{"rendered":"https:\/\/www.datahasbyte.com\/blog\/?p=37"},"modified":"2017-04-02T15:22:11","modified_gmt":"2017-04-02T15:22:11","slug":"workout-wednesday-benfords-law","status":"publish","type":"post","link":"https:\/\/www.a-j-c.com\/welcome\/2017\/04\/02\/workout-wednesday-benfords-law\/","title":{"rendered":"Workout Wednesday Week 13: Benford&#8217;s law"},"content":{"rendered":"<p>My third #<a href=\"https:\/\/twitter.com\/search?q=WorkoutWednesday\">WorkoutWednesday<\/a>\u00a0ever, yet the 13th of 2017, gave me such excitement at first glance &#8211; I was sure I could nail this one in an hour&#8217;s time. The author&#8217;s comment\u00a0&#8220;[t]his shouldn&#8217;t be too terribly challenging&#8221; boosted the confidence. It still knocked me around a bit.<\/p>\n<p>The full details of the challenge are at <a href=\"http:\/\/www.vizwiz.com\/2017\/03\/benfords-law.html\">vizwiz.com<\/a>, the short of\u00a0Benford&#8217;s law is that the distribution of the first digits of real-world numbers are not evenly distributed. Meaning, the numbers 1-9 are not represented equally as the leading digit in a number. Reading it, processing it, it was a quick &#8220;well, of course!&#8221; Identification numbers, account numbers, etc &#8211; you start with 1 and count up!<\/p>\n<p id=\"gXMOyqL\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-160 size-medium\" src=\"https:\/\/www.a-j-c.com\/wp-content\/uploads\/2017\/04\/img_58eeec9145e19-273x300.png\" alt=\"\" width=\"273\" height=\"300\" srcset=\"https:\/\/www.a-j-c.com\/wp-content\/uploads\/2017\/04\/img_58eeec9145e19-273x300.png 273w, https:\/\/www.a-j-c.com\/wp-content\/uploads\/2017\/04\/img_58eeec9145e19.png 600w\" sizes=\"auto, (max-width: 273px) 100vw, 273px\" \/><!--more--><\/p>\n<p>The requirements, and my initial thoughts on the challenge:<\/p>\n<ul>\n<li>Data should reflect 2010 only\u00a0<span style=\"color: #339966;\"><em>easy &#8211; filter<\/em><\/span><\/li>\n<li>User should be able to pick between the eight metrics you see listed\u00a0<em>\u00a0<span style=\"color: #339966;\">easy parameters and calculated fields<\/span><\/em><\/li>\n<li>Zeros and nulls should be excluded\u00a0<em>check!<\/em><\/li>\n<li>Match my title and subtitle exactly\u00a0<em>no problem<\/em><\/li>\n<li>Match my colors throughout\u00a0<span style=\"color: #339966;\"><em>hmmm &#8230; these don&#8217;t appear standard, what&#8217;s going on in the probabity coloring&#8230;<\/em><\/span><\/li>\n<li>Each bar represents the % of countries that end with that number for the metric selected\u00a0<span style=\"color: #339966;\"><em>ok<\/em><\/span><\/li>\n<li>No tooltips\u00a0<span style=\"color: #339966;\"><em>sure<\/em><\/span><\/li>\n<li>Labels for the bars should be on the inside-top of each bar<span style=\"color: #339966;\">\u00a0<em>yea, I&#8217;ve seen this before, time to turn on the memory bank<\/em><\/span><\/li>\n<li>The lighter blue bars behind the red bars indicate the &#8220;expected&#8221; outcome of Benford&#8217;s law. Notice those don&#8217;t change even when the user changes the metric.\u00a0<span style=\"color: #339966;\"><em>still hmmm, obvioulsy dual-axis<\/em><\/span><\/li>\n<li>Dashboard layout is 800&#215;600<\/li>\n<li>You cannot use LOD expressions\u00a0<span style=\"color: #339966;\"><em>wasn&#8217;t planning to&#8230; is this where most would start?\u00a0<\/em><\/span><\/li>\n<\/ul>\n<p>My first go at it resulted in this chart:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-40\" src=\"https:\/\/www.datahasbyte.com\/blog\/wp-content\/uploads\/2017\/04\/Capture-1-300x197.png\" alt=\"\" width=\"300\" height=\"197\" srcset=\"https:\/\/www.a-j-c.com\/wp-content\/uploads\/2017\/04\/Capture-1-300x197.png 300w, https:\/\/www.a-j-c.com\/wp-content\/uploads\/2017\/04\/Capture-1-1024x672.png 1024w, https:\/\/www.a-j-c.com\/wp-content\/uploads\/2017\/04\/Capture-1-768x504.png 768w, https:\/\/www.a-j-c.com\/wp-content\/uploads\/2017\/04\/Capture-1-1080x709.png 1080w, https:\/\/www.a-j-c.com\/wp-content\/uploads\/2017\/04\/Capture-1.png 1230w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>This involved:<\/p>\n<ul>\n<li>CASE statement to get the Parameter to read between the selections<\/li>\n<li>taking the LEFT most character (after converting to STR)<\/li>\n<li>multiplying Birth Rate * 100 (as it&#8217;s a percent)<\/li>\n<li>looking up how exactly Benford&#8217;s law is calculated &#8211; hello <a href=\"https:\/\/en.wikipedia.org\/wiki\/Benford%27s_law\">Wikipedia<\/a><\/li>\n<li>calculating the probability for numbers 1-9, plotting on a second chart with reference bands, combining both as a dual-axis, and synchronizing the axis<\/li>\n<\/ul>\n<p>Where I&#8217;m left:<\/p>\n<ul>\n<li>why did I\u00a0have a mark that has to show for the reference bands and Andy doesn&#8217;t?<\/li>\n<li>how did he color the reference bands?<\/li>\n<\/ul>\n<p>Another 30-40 minutes, and I didn&#8217;t care to create a custom color palette, not one utilizing Facebook&#8217;s guidelines at least. More importantly, I figured out the way to handle the reference bands without a second chart.<\/p>\n<p>Here it is (tablet version to fit embed &#8211; <a href=\"https:\/\/public.tableau.com\/views\/WorkoutWednesday2017Week13\/Dashboard1?:embed=y&amp;:display_count=yes\">full version<\/a>):<\/p>\n<p><iframe loading=\"lazy\" src=\"https:\/\/public.tableau.com\/views\/WorkoutWednesday2017Week13\/Dashboard1?:showVizHome=no&amp;:device=tablet&amp;:embed=true&amp;:toolbar=no&amp;:tabs=no&amp;:tooltip=no\" width=\"600\" height=\"960\"><\/iframe><\/p>\n<p>Other changes I made:<\/p>\n<ul>\n<li>tablet layout<\/li>\n<li>controlled the tooltips via parameters rather than in the workbook\/dashboard<\/li>\n<li>changed the layout and parameter control for the tablet layout<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>My third #WorkoutWednesday\u00a0ever, yet the 13th of 2017, gave me such excitement at first glance&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[4],"tags":[15,19],"class_list":["post-37","post","type-post","status-publish","format-standard","hentry","category-viz","tag-tableau","tag-workout-wednesday"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.a-j-c.com\/welcome\/wp-json\/wp\/v2\/posts\/37","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.a-j-c.com\/welcome\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.a-j-c.com\/welcome\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.a-j-c.com\/welcome\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.a-j-c.com\/welcome\/wp-json\/wp\/v2\/comments?post=37"}],"version-history":[{"count":0,"href":"https:\/\/www.a-j-c.com\/welcome\/wp-json\/wp\/v2\/posts\/37\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.a-j-c.com\/welcome\/wp-json\/wp\/v2\/media?parent=37"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.a-j-c.com\/welcome\/wp-json\/wp\/v2\/categories?post=37"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.a-j-c.com\/welcome\/wp-json\/wp\/v2\/tags?post=37"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}