Monday, January 25, 2021

3D plotting: how hard can it be?

Why aren't 2D plots good enough?

Most data visualization problems involve some form of two-dimensional plotting, for example plotting sales by month. Over the last two hundred years, analysts have developed several different types of 2D plots, including scatter charts, line charts, and bar charts, so we have all the chart types we need for 2D data. But what happens if we have a 3D dataset? 

The dataset I'm looking at is English Premier League (EPL) results. I want to know how the full-time scores are distributed, for example, are there more 1-1 results than 2-1 results? I have three numbers, the full-time home goals (FTHG), the full-time away goals (FTAG). and the number of games that had that score. How can I present this 3D data in a meaningful way? 

(You can't rely on 3D glasses to visualize 3D data. Image source: Wikimedia Commons, License: Creative Commons, Author: Oliver Olschewski)

Just the text

The easiest way to view the data is to create a table, so here it is. The columns are the away goals, the rows are the home goals, and the cell values are the number of matches with that result, so 778 is the number of matches with a score of 0-1.

This presentation is easy to do, and relatively easy to interpret. I can see 1-1 is the most popular score, followed by 1-0. You can also see that some scores just don't occur (9-9) and results with more than a handful of goals are very uncommon.

This is OK for a smallish dataset like this, but if there are hundreds of rows and/or columns, it's not really viable. So what can we do?


A heatmap is a 2D map where the 3rd dimension is represented as color. The more intense (or lighter) the color, the higher the value. For this kind of plot to work, you do have to be careful about your color map. Usually, it's best to choose the intensity of just one color (e.g. shades of blue). In a few cases, multiple colors can work (colors for political parties), but those are the exceptions. 

Here's the same data plotted as a heatmap using the Brewer color palette "RdPu" (red-purple).

The plot does clearly show the structure. It's obvious there's a diagonal line beyond which no results occur. It's also obvious which scores are the most common. On the other hand, it's hard to get a sense of how quickly the frequency falls off because the human eye just isn't that sensitive to variations in color, but we could probably play around with the color scale to make the most important color variation occur over the range we're interested in. 

This is an easy plot to make because it's part of R's ggplot package. Here's my code:

plt_goal_heatmap <- goal_distribution %>% 
  ggplot(aes(FTHG, FTAG, fill=Matches)) + 
  geom_tile() +   
  scale_fill_distiller(palette = "RdPu") +
  ggtitle("Home/Away goal heatmap")

Perspective scatter plot

Another alternative is the perspective plot, which in R, you can create using the 'persp' function. This is a surface plot as you can see below.

You can change your perspective on the plot and view it from other angles, but even from this perspective, it's easy to see the very rapid falloff in frequency as the scores increase. 

However, I found this plot harder to use than the simple heatmap, and I found changing my viewing angle was awkward and time-consuming.

Here's my code in case it's useful to you:

persp(x = seq(0, max(goal_distribution$FTHG)), 
      y = seq(0, max(goal_distribution$FTAG)), 
      z = as.matrix(
            goal_distribution, FTAG, Matches, fill=0)[,-1])), 
      xlab = "FTHG", ylab = "FTAG", zlab = "Matches", 
      main = "Distribution of matches by score",
      theta = 60, phi = 20, 
      expand = 1, 
      col = "lightblue")

3D scatter plot

We can go one stage further and create a 3D scatter chart. On this chart, I've plotted the x, y, and z values and color-coded them so you get a sense of the magnitude of the z values. I've also connected the points to the axis (the zero plane if you like) to emphasize the data structure a bit more.

As with the persp function,  you can change your perspective on the plot and view it from another angle.

The downside with this approach is it requires the 'plot3D' library in R and it requires you to install a new graphics server (XQuartz). It's a chunk of work to get to a visualization. The function to draw the plot is 'scatter3D'. Here's my code:

          xlab = "FTHG", ylab = "FTAG", zlab = "Matches",
          phi = 5, 
          theta = 40,
          bty = "g",  
          type = "h", 
          pch = 19,
          main="Distribution of matches by score",
          cex = 0.5)

What's my choice?

My goal was to understand the distribution of goals in the EPL, so what presentations of the data were most useful to me?

The simple table worked well and was the most informative, followed by the heatmap. I found both persp and scatter3D to be awkward to use and both consumed way more time than they were worth. The nice thing about the heatmap is that it's available as part of the wonderful ggplot library.

Bottom line: keep it simple.

Monday, January 18, 2021

Dinosaurs and time-travel: the wrong kind of air

Dinosaurs and time-travel don't mix

Time-traveling to see dinosaurs has been a science-fiction trope for a long time and of course stories of dinosaurs in modern times have been around since at least the Professor Challenger books of the 1910s. Like everyone else, I enjoyed the Jurassic Park movies, but sadly, something nagged at the back of my mind: could these animals breathe?

(Do you think he saw us? Author: Lothar Dieterich, Source: Pixabay, License: Pixabay.)

From what I've read, some re-animated dinosaurs would have serious trouble breathing today's atmosphere, and time travelers may have convulsions breathing ancient atmospheres. How we know this is an interesting story of itself.

Ice and amber and simulation

In the Jurassic Park movies, InGen scientists extracted dinosaur DNA from mosquitos trapped in amber. After sucking on dinosaur blood, mosquitos landed on trees, where they were trapped by sap that turned into amber. But mosquitos weren't the only thing trapped in amber. Amber also contains air bubbles, in other words, air samples from dinosaur times. By analyzing the gas composition of amber air bubbles, we can estimate the atmospheric composition at the time the bubble was formed [Cerling]. Obviously, these samples are rare.

(Beetle in amber - and maybe some ancient air. Image source: Wikimedia Commons, Author: Anders L. Damgaard, License: Creative Commons)

Less directly, ice cores also give us a way of looking into atmospheric change. Voids in ice cores capture ancient air, and of course, some atmospheric gases dissolve in water and are trapped when the water freezes.

(Ice, ice, baby - preparing an ice core. Author: NASA Ice, Image source: Wikimedia Commons. License: Creative Commons)

Amber and ice only take us back so far in time. To go all the way back, we have to rely on simulation and understanding the processes that drive the composition of the atmosphere. 

For dinosaurs and human time travelers, the most important gas to understand is oxygen. Bear in mind, oxygen is a very reactive gas. It reacts with iron and water to form rust, and when things burn, oxygen turns into carbon dioxide, carbon monoxide, and other combustion products. It's also partially soluble in water; fish rely on dissolved oxygen and there's dissolved oxygen even at great depths

The fraction of oxygen in the atmosphere is the result of two processes: non-organic processes that absorb oxygen, and organic processes that generate oxygen. To say it another way, free oxygen in a planet's atmosphere is a sign of life.

Oxygen by time - the l-o-n-g view and the long view

I went into the literature and pulled all the sources I could find that talked about the fraction of the atmosphere that contained oxygen [Kump, Holland]. Here are the chart and the story. This is a long story over deep time, so I'm going to give you the l-o-n-g view and then focus on more 'recent' times (the long view) that includes the dinosaurs and us.

4 to 2.45 billion years ago

In the beginning, the earth's atmosphere would have contained trace amounts of oxygen. Bear in mind, there was no plant life and the only source of oxygen was geological processes which would have produced minute amounts of the gas at best. The oceans would have had no oxygen, with the possible exception of 'oxygen oasis' in shallow oceans.

Single-celled life began at about -4 billion years, with photosynthesis appearing around -3.5 billion years. 

2.5 to 1.85 billion years ago

As life got going, simple organisms produced more oxygen and the oxygen content of the atmosphere rose. The earth's oceans absorbed some of this oxygen (but the deep oceans remained oxygen-free), limiting the build-up in the atmosphere. The period 2.4 to 2.0 billion years ago is known as the "Great Oxidation Event", and the chemistry of the "earth system" changed, though geologists are unsure of some of the mechanisms [Holland, Kump].

1.85 to 0.85 billion years ago

Life keeps pumping out the gas. Eventually, there was enough to form the ozone layer, and of course, exposed iron deposits would have rusted, consuming more oxygen. The surface oceans became mildly oxygenated.

Multicellular organisms evolved, with fungi appearing about 1.5 billion years and the earliest plants around 0.85 billion years.

0.85 to 0.54 billion years ago 

More of the same. The oxygen content rose in the atmosphere and the shallow oceans, but not in the deep oceans. This was a period of great change, there were three ice ages followed by unusually hot climates. Animals appeared on the scene.

0.54 billion years ago to the present time

Things start to get interesting around 360 million years ago, so that's where I'll focus.

Geologists separate the deep past into named periods. In some cases, there are clear boundaries between them, in others not so much. Here are the periods, the major plants and animals, and the oxygen content of the atmosphere for the last 360 million years.

Period (million years) Name Animals and plants Oxygen content
360-299 Carboniferous Large plants using lignin. Arthropods and amphibians. 20-34%
299-252 Permian Seed-bearing plants. Cicadas and beetles. Synapsids (very early line that lead to mammals) and Sauropsids (very early line that lead to reptiles). 34-14%
252-201 Triassic Turtles, flies, ichthyosaurs, early dinosaurs. Ferns, conifer trees. 14-20%
201-145 Jurassic Allosaurus, Stegosaurus, Diplodocus, Pterosaurus. Pine trees. 20-27%
145-66 Cretaceous Bees, ants, velociraptors, Tyrannosaurus rex. Palm trees. 28-30%
66-23 Paleogene Primates, bats, camels, cats, penguins, elephants. 24-28%
23-2.6 Neogene Hyenas, mammoths, kangaroos, hippopotamus. 21-24%
2.6-now Quaternary Bears, humans, sabre-toothed cats 21%

I've re-drawn my plot of oxygen content so you can orient yourself to the changes and periods.

During the Carboniferous period, plants evolved to use lignin which enabled them to grow much, much larger than before. Lycopods (relatives of the club moss), for example, grew to the size of trees. Lignin is resistant to bacterial decomposition and when it first appeared, bacteria couldn't digest it at all, meaning the world was littered with dead plants. Because they weren't digested and recycled, the dead plants went on to form coal (giving this period its name). Bacteria's inability to munch lignin is important for the atmosphere too; as bacteria breakdown carbon-rich material, they consume oxygen. In the Carboniferous period plants were busy pumping out oxygen, but bacteria weren't consuming it, so the oxygen content rose [Black]. As you might expect, the oxygen-rich atmosphere was a huge boon to animal life. Arthropods, early relatives of the insects, grew to enormous sizes. Arthropleura, a giant millipede, ranged in size from 0.3 meters to 2.5 meters, and famously, Meganeura, an early relative of the dragonfly, had a wingspan of about 70 cm.

The Permian period saw a huge drop off in oxygen content. My researches suggest this was triggered by volcanic activity pumping vast amounts of carbon dioxide (a greenhouse gas) into the atmosphere, leading to global warming, which caused reduced ocean circulation and a sharp drop in oxygen content in the deep oceans [Benton]. An oxygen content of about 14% put an end to a large number of species, it also isolated animal populations from one another as mountains became impossible to pass because of low oxygen [Huey]. This really was the great die off.

Things recovered slowly in the Triassic period. The oxygen content rose gradually as plants pumped it out. Early dinosaurs appeared on the scene and rapidly diversified. The oxygen content at the end of the Triassic period was about today's levels, so those dinosaurs could survive in modern times. Some of them were already getting big, Lessemsaurus for example was around 9m long. The Triassic came to an end with another mass-extinction event that occurred about 201.3 million years ago, and again it may have been caused by vulcanism. Volcanoes in what's now the Atlantic ocean (in an area called Central Atlantic Magmatic Province (CAMP)) released vast amounts of carbon dioxide and sulfur dioxide, which sparked huge climatic change, killing off many, many species.

Once again, life recovered and the oxygen content continued to rise. We're now in the Jurassic period. The dinosaurs really got going, but the oxygen levels weren't that much higher than today, so Stegosaurus probably could survive in today's atmosphere. The era ended with another extinction event, but this one is poorly understood.

During the Cretaceous period, the oxygen content rose to about 32%. By this time there were trees and a great deal of plant life, so an upper limiting factor on the oxygen content is forest fires; at 30% oxygen, forest fires would have raged out of control. Everyone's favorite dinosaur, Tyrannosaurs rex, was around at the end of Cretaceous period, as were Velociraptors and Brachiosaurus. The high oxygen content would have favored big animals, but these monsters wouldn't be able to breathe today's atmosphere.

meteor impact put an end to the party about 66 million years ago.

The oxygen content has fluctuated over the last 66 million years, but not as much as in the prior billions of years.

It's in the bag

Some dinosaurs could be revived and live among us, but not others. The modern oxygen content of 21% spells bad news for reanimating Tyrannosaurus Rex and velociraptor and friends, on the other hand, Stegosaurus probably would be OK. But what about our time travelers?

(The one thing a time traveler must have: a paper bag. Image source: Wikimedia Commons, Author: Donald Trung, License: Creative Commons.)

It depends on when our time travelers travel back to. They might arrive at a time when oxygen was roughly at current levels, or maybe at a time with too much or too little. For too little oxygen, a small oxygen tank would do the trick. For too much oxygen, a gas mask that reduced oxygen would be enough to survive, but there could be an even simpler solution. 

For people having panic attacks and hyperventilating, medical advice is often to breathe into a paper bag. This reduces the oxygen content in the blood because we re-inhale our exhaled carbon dioxide. Perhaps all our intrepid time travelers need to survive with the dinosaurs is a paper bag - maybe even the one their lunch came in.

Posts like this

If you liked this post, here are some others you might like.


[Benton] Michael J. Benton, Richard J. Twitchett, How to kill (almost) all life: the end-Permian extinction event, TRENDS in Ecology and Evolution Vol.18 No.7 July 2003

[Black] Riley Black, The history of air, Smithsonian Magazine, April 2010,

[Cerling] Cerling, T. Does the gas content of amber reveal the composition of palaeoatmospheres?. Nature 339, 695–696 (1989)

[Holland] Heinrich D Holland, The oxygenation of the atmosphere and oceans, Philos Trans R Soc Lond B Biol Sci. 2006 Jun 29; 361(1470): 903–915.

[Huey] Raymond B. Huey, Peter D. Ward, Hypoxia, Global Warming, and Terrestrial Late Permian Extinctions, Science  15 Apr 2005, Vol. 308, Issue 5720, pp. 398-401

[Kump] Kump, L. The rise of atmospheric oxygen. Nature 451, 277–278 (2008)

Monday, January 11, 2021

How to grow a market segment

Growing a new business

I'm going to tell you how I grew a market segment from almost nothing to multi-millions. It's kind of an instruction manual if you're trying to grow a new segment within a larger business and I hope you find something useful in it. I'm going to be deliberately vague about the segment and the company and I've obscured some of the details.

(Every new business segment starts from small seeds. Image source: Wikimedia Commons, License: Creative Commons, Author: Laitche)

Some background

A few years ago, I was working for a large company that produced products that could be used in many different industries. Part of my role was to find new business segments to sell into, but I had no budget to research or grow segments. On the upside, I had access to a large team of very good salespeople and sales engineers.

First, catch your hare

The first job was to find the market segment to sell into. I was friendly with one of the company's very experienced sales engineers. He knew what I was trying to do and suggested a market he was very familiar with. We'd had this conversation before and I was skeptical. This time, I decided to take a closer look.

I didn't fully understand the market segment, but my friend was correct. The company's products had sold into this segment. They'd sold because my friend had customized the products for that market and developed a sales pitch that worked. He'd largely been ignored and was the only person who sold into the market. Bottom line: there was maybe something there.

How does this market work?

To sell into a segment, you need to:

  • understand it 
  • know what your value proposition really is
  • know where you sit in the value chain. 

I needed a crash course in understanding the segment and I needed prospective customers to tell me their pain points. 

Fortunately, there was a major trade show/conference coming up and I went to it. I got the speaker list and identified over ten people who I thought could help. By guessing emails, I reached out to them and asked for an informational interview at the conference. Of course, not everyone responded or talked to me, but I got enough feedback to understand how my company's products could fit and I understood the pain points.

Market sizing 

This is the piece that gets all the attention, but it shouldn't. Lots of people are spilling lots of ink talking about market sizing and offering paid-for sizing products. I found no one who could give me a good market size for my new segment; they could offer me details on some aspects of the market, but not the ones useful to me. In the end, I found the best market sizing data came from free resources on the web. I coupled this data with my own analysis, viewing the segment in different ways and calculating different sizing estimates. I got slightly different estimates of market size, but the difference was immaterial, the segment was big enough to be profitable.

Making marketing content

I wanted the sales team to sell, but they were skeptical. Their belief was, the experienced sales engineer could sell the story to the segment, but no one else could. I needed to change this perception. I also needed to gather customer proof that the product worked in the segment.

One of the salespeople told me of a well-known company that had bought the product for use in our new market segment. There were some things that weren't ideal about their use of the product, but it was a start.

Fortunately, about this time I had a new SLR camera and was experimenting with photography. I was also doing a part-time management degree and had chosen a business writing option. Putting both together, I flew out to the customer and interviewed them for a case study, taking photos to illustrate the piece. Normally, this would be done by a writer, but because this was so new, I wanted to take control. I wrote up the case study and my company published it. I had my first piece of marketing content for my segment.

Not long after, I found another segment customer who was using the product. We asked about a case study, but they gave a firm no. We then asked if we could do a ghost-written article that would appear in their name and that they would have editorial control over ('nothing published without your consent'), they said yes, and we found a trade magazine that would publish the story. Once again, I flew out and interviewed the customer. I wrote up the ghost-written article, but I did it carefully and subtly; my company's product wasn't the biggest feature of the piece (it was a quarter or less) and other company's products were mentioned in the article too. The goal was to establish credibility, and the piece succeeded brilliantly. The customer was hugely pleased with the article, to the extent that the person I interviewed took credit for writing it. I submitted the piece for part of my writing class and got an A grade.

I did this a couple of times and ended up with several pieces of content, crucially, they included usable customer quotes (not by accident).

(Like new market segments, saplings need attention and nutrients to grow. Image source: Wikimedia Commons, License: Creative Commons, Author: RobbieRoss123)


By this stage, I had marketing content to help sell the product and I had a known segment user base. The next step was to convince the sales team to sell and for sales engineers to help sell it.

Salespeople have quotas to fulfill so they have to be extremely careful about how they fill their time. This means they can be very suspicious about new market segments; they don't know if it'll be worth investing their time.

I found a sales rep who was willing to try selling into the market. It helped that he was also very friendly with the sales engineer too. We did some pitches together using the new marketing content and the sales rep worked closely with the sales engineer. To cut a long story short, the sales rep brought in a $300,000 order. This got people's attention. Other, smaller orders came in too.

Sales engineering management decided to invest in the segment and started to train some sales engineers in how to sell to it.

Salespeople started to get interested in selling into the market. I created some sales presentations for them, and of course, they had the case studies to use.


The engineering team had other priorities and was unable to customize the product for the segment, but I needed some good demos. Fortunately, my sales engineer came to the rescue again. He had developed a number of demos that worked very well. Another sales engineer had developed some simpler models too. Collectively, we had enough to do something, but the packaging was bad.

Because I have an engineering background, I was able to create a form of product customization that combined the existing demos. In effect, it was a shadow product. We put the product online on the company's website, for free, in exchange for registration. In other words, we had a lead generation tool based on a free product.

Now we had demos and a website, we ran a series of webinars to drive traffic to the shadow product website. The leads went through the standard process and were handed to sales. Bear in mind, by this time, we had a sales deck, demos, and the sales team and sales engineers could sell into the market.

(Eventually, your segment may grow into something big. Image source: Wikimedia Commons, License: Public Domain, Author: AlabamaGuy2007)

Big boys can be bad boys

I did learn a negative lesson in this process. There were a couple of large and prestigious companies in this space. While we were selling into the smaller companies, I faced no political interference, but that changed as soon as we had a big fish on the hook.

I visited a group in a very large and well-known company to talk to them about the market segment. Before visiting the group, I was warned they were doing weird things and had a reputation for giving people the run-around. But what they wanted to do was cool. I came back to the office with a positive message about the big company.

As soon as people found out who the large company was, they wanted to be involved. I went to a meeting where 15 people sat around discussing the sales strategy. Soon, I was cut out of the discussion as more and more strategy meetings were held. The meetings were divorced from reality because no one in them had spoken to the account. However, the meetings were high-profile.

Sadly, the warnings turned out to be right. The group really was doing weird things, and soon they moved on and forgot they'd ever spoken to us. The strategy meetings died off after a month or two as it dawned on the attendees that the opportunity wasn't going anywhere.

After that, I was skeptical of large players. I purposefully downplayed large accounts and kept things technical.

Becoming an expert

I had a very limited background in the segment, but I found I had developed some useful knowledge through this market-building process. I ended up speaking at a segment conference and running an IEEE tutorial. It was bizarre speaking on industry panels next to people who had spent their entire careers in the segment.

Where did this end up?

The market segment went from being less than about $100,000 a year to several million $ per year. Sales reps went from ignoring it, to actively selling into the market, and we went from one sales engineer focused on it to several. We started with zero marketing pieces, and by the end, we had about 15 pieces of focused marketing content, including webinars, articles, and case studies.


Here's my checklist for growing a new segment:

  • Be humble: listen to others and learn from them.
  • Share credit: make sure the people who work with you get credit.
  • Be there for others: this isn't a solo endeavor, you have to support your colleagues.
  • Find out if anyone in your organization has experience in the segment. Learn from them.
  • Talk to and learn from industry experts. Never sell to them at this point.
  • Create marketing content:
    • Create case studies.
    • Create ghost-written articles. 
    • Create great content that adds value.
    • Have a webpage to capture leads.
    • Run webinars.
  • Sell internally.
    • Understand the dynamics of the sales and sales engineering team.
    • Hold their hand until they get the first sales, and even beyond that.
    • Make sure they know you'll stand by them.
  • Avoid politics.
    • Watch out for high-profile accounts, they can mislead and distract and they invite internal politics.

Could I do this again? 

I'm going to be honest with you. I got lucky. I benefited from a one-off combination of circumstances that let me succeed:

  • I stumbled on the segment. If it hadn't been for the sales engineer, I would never have looked at it.
  • Benign neglect. Except towards the end, I didn't suffer company politics or people stopping me.
  • Pre-existing content. The sales engineer had developed much of the content I needed.
  • Skills. I had the photography and writing skills I needed, I also had the technical skills to take the sales engineer's work further.

I owe a lot to that sales engineer, as does the company I worked for. Without him, this wouldn't have happened.

Could I do this again? Maybe. I tried again in a different company in different circumstances but had more limited success. Company politics really held things back.

Would I try and do it again? Yes, but. If you want to know what the 'but' is, you'll have to talk to me.

Monday, January 4, 2021

COVID and soccer home team advantage - winning less often

Home advantage

Is it easier for a sports team to win at home? The evidence from sports as diverse as soccer [Pollard], American football [Vergina], rugby [Thomas], and ice hockey [Leard] strongly suggest there is a home advantage and it might be quite large. But what causes it? Is it the crowd cheering the home team, or closeness to home, or playing on familiar turf? One of the weirder side-effects of COVID is the insight it's proving into the origins of home advantage, as we'll see.

(Premier League teams playing in happier times. Image source: Wikimedia Commons, License: Creative Commons, Author: Brian Minkoff)

The EPL - lots of data makes analysis easier

The English Premier League is the world's wealthiest sports' league [Robinson].  There's worldwide interest in the league and there has been for a long time, so there's a lot of data available, which makes it ideal for investigating home advantage. One of the nice features of the league is that each team plays every other team twice, once at home and once away.

Expectation and metric

If there were no home team advantage, we would expect the number of home wins and away wins to be roughly equal for the whole league in a season. To investigate home advantage, the metric I'll use is:
\[home \ win \ proportion = \frac{number\ of\ home\ wins}{total\ number\ of\ wins}\]
If there were no home team advantage, we would expect this number to be close to 0.5.

EPL home team advantage

Let's look at the mean home-win proportion per season for the EPL. In the chart, the error bars are the 95% confidence interval.

For most seasons, the home win proportion is about 0.6 and it's significantly above 0.5 (in the statistical sense). In other words, there's a strong home-field advantage in the EPL.

But look at the point on the right. What's going on in 2020-2021?

COVID and home wins

Like everything else in the world, the EPL has been affected by COVID. Teams are playing behind closed doors for the 2020-2021 season. There are no fans singing and chanting in the terraces, there are no fans 'oohing' over near misses, and there are no fans cheering goals. Teams are still playing matches home and away but in empty and silent stadiums.

So how has this affected home team advantage?

Take a look at the chart above. The 2020-2021 season is the season on the right. Obviously, we're still partway through the season, which is why the error bars are so big, but look at the mean value. If there were no home team advantage, we would expect a mean of 0.5. For 2020-2021, the mean is currently 0.491. 

Let me put this simply. When there are fans in the stadiums, there's a home team advantage. When there are no fans in the stadiums, the home team advantage disappears.

COVID and goals

What about goals? It's possible that a team that might have lost is so encouraged by their fans that they reach a draw instead. Do teams playing at home score more goals?

I worked out the mean goal difference between the home team and the away team and I've plotted it for every season from 2000-2001 onwards.

If there were no home team advantage, you would expect the goal difference to be 0. But it isn't. It mostly hovers around 0.35. Except of course for 2020-2021. For 2020-2021, the goal difference is about zero. The home-field advantage has gone.

What this means

Despite the roll-out of the vaccine, it's almost certain the rest of the 2020-2021 season will be played behind closed doors (assuming the season isn't abandoned). My results are for a partial season, but it's a good bet the final results will be similar. If this is the case, then it will be very strong evidence that fans cheering their team really do make a difference.

If you want your team to win, you need to go to their games and cheer them on. 


[Leard] Leard B, Doyle JM. The Effect of Home Advantage, Momentum, and Fighting on Winning in the National Hockey League. Journal of Sports Economics. 2011;12(5):538-560.

[Pollard] Richard Pollard and Gregory Pollard, Home advantage in soccer: a review of its existence and causes, International Journal of Soccer and Science Journal Vol. 3 No 1 2005, pp28-44

[Robinson] Joshua Robinson, Jonathan Clegg, The Club: How the English Premier League Became the Wildest, Richest, Most Disruptive Force in Sports, Mariner Books, 2019

[Thomas] Thomas S, Reeves C, Bell A. Home Advantage in the Six Nations Rugby Union Tournament. Perceptual and Motor Skills. 2008;106(1):113-116

[Vergina] Roger C.Vergina, John J.Sosika, No place like home: an examination of the home field advantage in gambling strategies in NFL football, Journal of Economics and Business Volume 51, Issue 1, January–February 1999, Pages 21-31

Monday, December 28, 2020

I won an award! How to lose by winning

Company work anniversary awards

Sometimes, companies try and do a good thing but go about it so poorly, they end up doing something bad. 

A few years ago, I worked for a large company. I got to a work anniversary which triggered an award; a plastic slab I was supposed to display on my desk. How it was delivered was eye-opening.

(Winning a trophy like this would be meaningful. Image source: Wikimedia Commons. License: Public Domain.)

I was working at a different office from my manager, so the award was sent directly to me, including the written instructions to my manager on how to give me the award

How to do it wrong

The award was a tombstone-shaped piece of transparent plastic with some vaguely encouraging words embossed on it. Other than the company logo, there was no customization of any kind (not even the employee's name), it was completely generic. The instructions gave a formal pattern for how the plastic was to be awarded. They went something like this:

  • Allocate about 20 minutes for the award ceremony.
  • Gather the employee's colleagues together.
  • Thank the employee by name for their service to the company. Mention any noticeable successes. Be warm and encouraging. Use their name. Look them in the eye.
  • Hand over the award, being sure to note that it's a recognition of their service. Use their name.
  • State that you're looking forward to working with them in the future.
  • Start a round of applause.

I told my manager that this had happened and we both laughed. I told him I was going to have an award ceremony for myself and hand myself the award using the instructions in the box. He chuckled and told me to go for it. In other words, the whole thing meant nothing to either of us.

Obviously, the company's intention was to thank employees for not leaving. They'd thought it through sufficiently well enough to have a trophy that would be displayed on desks and that wouldn't cost very much. Of course, the goal of the ceremony was to celebrate the individual and make them feel special.

Unfortunately, the trophy wasn't meaningful to anyone - it didn't even look good. The instructions left a bad taste in my mouth. My guess is, the leadership was trying to reach managers who wouldn't normally celebrate individuals' contributions. By mandating the form of the ceremony, they were trying to introduce consistency and enforce meaning, but by describing the ceremony in detail, they undermined managers - this was a form of micro-managing and hinted at bigger issues with managers' people skills.

How to do it right

By contrast, I worked for another large organization that made a very big deal of work anniversaries. People who reached a significant anniversary were called into a big meeting and personally thanked by the CEO. There were meaningful gifts for reaching multiples of 5 years. Looking back on that experience, I believe the company, and the CEO were sincere - they put a lot of effort into thanking and recognizing people. The fact that the recognition was led by the CEO made a huge difference.

Don't fake it

Employee recognition is a fraught topic and work anniversaries can be tricky. Do you celebrate or not and why? If you do celebrate, then it needs to be meaningful and focused on the person; you can't fake or mandate sincerity. If you're going to do it, do it well.

Monday, December 21, 2020

The $10 screwdriver: a cautionary management tale

Managers gone mild

I've told this story to friends several times. It's a simple story, but the lessons are complex and it touches on many different areas. See what you think.

I was a software developer for a large organization working on network-related software. For various reasons I won't go into, we had to frequently change network cards in our test computers and re-install drivers. My bosses' boss put a rule in place that we had to use IT Support to change cards and re-install drivers - we weren't to change the cards ourselves. No other team had a similar rule and there had been no incidents or injuries. Despite asking many times, he wouldn't explain why he put the rule in place.

At first, IT Support was OK with it. But as time wore on, we wanted to change cards twice a day or more. IT Support had a lot of demands on their time and got irritated with the constant requests. They wanted to know why we couldn't do it ourselves. One of the IT guys burned us a CD with the drivers on it and told us to get our own screwdrivers and change the cards ourselves. They started to de-prioritize our help requests because, quite rightly, they had other things to do and we could swap the cards ourselves. It got to the stage where we had to wait over two hours for someone to come, unscrew two screws, swap the card, and screw the two screws back in.

We were very sympathetic to IT Support, but the situation was becoming intolerable. My software development team complained to our management about the whole thing. My bosses' boss still wouldn't budge and insisted we call IT Support to change cards, he wouldn't explain why and he wouldn't escalate the de-prioritization of tickets. 

Excalibur the screwdriver

I got so fed up with the whole thing, I went out one lunchtime and bought a £7 ($10) screwdriver. It was a very nice screwdriver, it had multiple interchangeable heads, a ratchet action, and it was red. I gave it to the team. We used the screwdriver and stopped calling IT Support - much to their relief.

The blessed screwdriver

(This isn't the actual screwdriver I bought, but it looks a lot like it. Image source: Wikimedia Commons, Author: Klara Krieg, License: Creative Commons.)

The consequences

I then made a big mistake. I put in an expense claim for the screwdriver.

It went to my boss, who didn't have the authority to sign it off. It then went to his boss, who wasn't sure if he could sign it off. It then went to his boss, who did have the authority but wanted to know more. He called a meeting (my boss, my bosses' boss, my bosses' bosses' boss) to discuss my expenses claim. I heard they talked about whether it was necessary or not and whether I had bought a screwdriver that was too expensive when a cheaper one would have done. They decided to allow my expenses claim this one time.

I was called into a meeting with my bosses' bosses' boss and told not to put in a claim like that again. I was called into a meeting with my bosses' boss who told me not to put in an expense claim like that again and that I should have used IT Support every single time and if I were to do it again to buy a cheaper screwdriver. I was then called into a meeting with my boss who told me it was all ridiculous but next time I should just eat the cost. Despite asking, no one ever explained why there had been a 'rule'. Once the screwdriver existed, we were expected to use it and not call IT Support.

Of course, the team all knew what was going on and there was incredulity about the company's behavior. The team lost a lot of respect for our leadership. The screwdriver was considered a holy relic to be treasured and kept safe.

What happened next

Subsequent to these events, I left and got another job. In my new job, I ended up buying thousands of pounds worth of equipment with no one blinking an eye (my new boss told me not to bother him with pre-approval for anything under £1,000). 

All the other technical people in my old group left not long after me. 

A competitor had been making headway in the market while I was there and really started to break through by the time I left. To respond to the competitive challenge, new leadership came in to make the company more dynamic and they replaced my entire management chain.

What I learned

Here's what I learned from all this. I should have eaten the cost of the screwdriver and avoided a conflict with my management chain, at the same time, I should have been looking for another job. The issue was a mismatch of goals: I wanted to build good things quickly but my management team didn't want to rock the boat. Ultimately, you can't bridge a gap this big. Buying the screwdriver was a subversion of the system and not a good thing to do unless there was a payoff, which there wasn't. 

I promised myself I would never behave like the management I experienced, and I never have. With my teams now, I'm careful to explain the why behind rules; it feels more respectful and brings people on side more. I listen to people and I've reversed course if they can make a good case. I've told people to be wise about expenses, to minimize what they spend, but when something needs to be bought, they need to buy it.

What do you think?

If you liked this post, you might also like these ones...

Sunday, December 13, 2020

What's a probability distribution?

Why should you care about probability distributions?

Using the wrong probability distribution can be extremely expensive for businesses:

  • for businesses using machinery (factories, vehicles, aircraft, etc.), it can lead to parts being changed too frequently or too infrequently
  • for businesses relying on returning customers, it can lead to substantial under or over-estimates of revenue and/or targeting the wrong customers with promotions
  • for businesses forecasting future sales by territory and/or product, it can lead to poor territory allocation or poor product resource allocation.

Given that it's so important, what is a probability distribution, and what are some examples?

What's a probability distribution?

At its simplest, a probability distribution tells you how likely an outcome is given some input. For example, how is sales probability distributed by price, or how likely is a component to fail in the next month? 

If something is certain to occur, the probability is 1, if it's certain not to occur, the probability is zero.  Let's imagine a component lasts a maximum of 6 months before failure. Our probability distribution might show the probability of failure on days 1 to 180. The sum of all failure probabilities for all days must sum to 1.

In the real world, data is noisy and we don't expect real data to exactly follow theoretical distributions, but given enough data, the match should be close enough for us to reason about what's going on.

Uniform distribution - gambling and manufacturing

If the probability is the same for all input values, the distribution is uniform.

Let's imagine we're manufacturing candy, and we want to have equal numbers of red, blue, green, black, and white sweets in a packet. In theory, here's what we should observe.

But in reality, there's random noise so we might see something like this below. We can quantify the difference between the expected distribution and the actual distribution, which tells us something about the variability in the manufacturing process. 

The uniform distribution also occurs in gambling, for example, lotteries or dice games.

Reading more

Uniform distribution description by NIST

Binomial distribution - pass/fail and conversion

Each customer who comes into a store or who visits a website will either buy or not buy, which we can turn into a conversion rate. We can model these kinds of pass/fail processes using the binomial distribution. Here's the probability distribution.

The binomial distribution shows us the probability of measuring different results given an underlying 'truth'. Let's imagine the 'true' conversion rate was 0.04, we might not measure 0.04 due to sampling error, instead, we might measure 0.045 or 0.055, depending on how many samples we take. It's important to understand what this means: 

  • There is uncertainty in our measurement. 
  • The smaller the sample, the bigger the uncertainty.

Although many technical people understand this, most non-technical people do not, which can lead to tension.

Reading more

Yale stats

Poisson distribution - waiting in line

Imagine you're a bank serving customers with ATMs at a location. ATMs are expensive, but you don't want to keep people waiting in long lines to do their transactions, it's bad for business. So how do you balance the cost of an ATM against its use? By modeling how many people are using the ATM over a time period.

It turns out, the number of people who visit an ATM over a time period can be modeled using the Poisson distribution, which I've shown below. This gives us a way of assessing how much variation there might be in usage and therefore how many machines we might want to install. 

The Poisson distribution is often used to model counting processes. It's very attractive because it has an unusual feature, the standard deviation for the distribution is \(\sqrt{\gamma}\) where \(\gamma\) is the mean. Unfortunately, this property makes it a little too attractive; it's sometimes used when it shouldn't be.

Reading more

The Poisson Distribution and Poisson Process Explained

Exponential distribution

How long does a car battery last? How long do phone calls last? When will the next earthquake occur? These durations typically follow the exponential distribution (which is strongly related to the Poisson distribution). I've shown this distribution below.

Reading more

The exponential distribution

Power law distribution - finding fraud

How are incomes distributed in a population? How might you find fraud in the pattern of digits in expenses? It turns out, the distribution of the first digits in invoices follows a power-law distribution. The chart below shows a generic power-law distribution - for fraud detection, it's 'flipped'.

Reading more

Power law distribution

Normal distribution - almost everywhere, but not quite

What's the probability distribution for male soldiers' chest measurements? How are the results of A/B tests distributed? What about the distribution of measurement errors? All these, and many, many more follow the normal distribution, which is also called the Gaussian distribution or the bell curve. If you only learn one distribution, this is the one to learn. 

The properties of this distribution are extremely well-known, and every student of statistics and probability theory will know them. It's ubiquitous because of something called the Central Limit Theorem, which, simplifying a great deal, says that the sum of samples from any distribution follows a normal distribution.

Because it's everywhere, for some people, it's the only distribution they know. Like the old saying goes, if you only have a hammer, every problem is a nail. This distribution can be over-used, with bad consequences.

Here's the distribution. It ought to look familiar.

Reading more

The normal distribution

Lognormal distribution

How long do visitors spend on web pages? What about the distribution of internet traffic? Or the distribution of city sizes? These all follow a log-normal distribution that looks like the example below. The lognormal distribution is quite common in business.

Note the 'fat tail' or 'long tail' on the right-hand side. Many businesses have been caught out because they assumed sales or market risk followed a normal distribution when in fact they followed a lognormal distribution.

There's a variation of the Central Limit Theorem that yields log-normal distributions instead of normal distributions.

Reading more

Other distributions

There are lots and lots of different distributions. I saw a list of 90 the other day. Almost all of them are esoteric and apply in a very limited set of cases. You don't have to know all of them but you should be aware that choosing the right distribution is important to make the correct estimates. The distributions I've listed in this blog post are probably the most important, and you should know them and their properties.

As you asked nicely, here is a list of some distributions.

Alpha Distribution
Anglit Distribution
Arcsine Distribution
Beta Distribution
Beta Prime Distribution
Bradford Distribution
Burr Distribution
Burr12 Distribution
Cauchy Distribution
Chi Distribution
Chi-squared Distribution
Cosine Distribution
Double Gamma Distribution
Double Weibull Distribution
Erlang Distribution
Exponential Distribution
Exponentiated Weibull Distribution
Exponential Power Distribution
Fatigue Life (Birnbaum-Saunders) Distribution
Fisk (Log Logistic) Distribution
Folded Cauchy Distribution
Folded Normal Distribution
Fratio (or F) Distribution
Gamma Distribution
Generalized Logistic Distribution
Generalized Pareto Distribution
Generalized Exponential Distribution
Generalized Extreme Value Distribution
Generalized Gamma Distribution
Generalized Half-Logistic Distribution
Generalized Inverse Gaussian Distribution
Generalized Normal Distribution
Gilbrat Distribution
Gompertz (Truncated Gumbel) Distribution
Gumbel (LogWeibull, Fisher-Tippetts, Type I Extreme Value) Distribution
Gumbel Left-skewed (for minimum order statistic) Distribution
HalfCauchy Distribution
HalfNormal Distribution
Half-Logistic Distribution
Hyperbolic Secant Distribution
Gauss Hypergeometric Distribution
Inverted Gamma Distribution
Inverse Normal (Inverse Gaussian) Distribution
Inverted Weibull Distribution
Johnson SB Distribution
Johnson SU Distribution
KSone Distribution
KStwo Distribution
KStwobign Distribution
Laplace (Double Exponential, Bilateral Exponential) Distribution
Left-skewed Lévy Distribution
Lévy Distribution
Logistic (Sech-squared) Distribution
Log Double Exponential (Log-Laplace) Distribution
Log Gamma Distribution
Log Normal (Cobb-Douglass) Distribution
Log-Uniform Distribution
Maxwell Distribution
Mielke’s Beta-Kappa Distribution
Nakagami Distribution
Noncentral chi-squared Distribution
Noncentral F Distribution
Noncentral t Distribution
Normal Distribution
Normal Inverse Gaussian Distribution
Pareto Distribution
Pareto Second Kind (Lomax) Distribution
Power Log Normal Distribution
Power Normal Distribution
Power-function Distribution
R-distribution Distribution
Rayleigh Distribution
Rice Distribution
Reciprocal Inverse Gaussian Distribution
Semicircular Distribution
Student t Distribution
Trapezoidal Distribution
Triangular Distribution
Truncated Exponential Distribution
Truncated Normal Distribution
Tukey-Lambda Distribution
Uniform Distribution
Von Mises Distribution
Wald Distribution
Weibull Maximum Extreme Value Distribution
Weibull Minimum Extreme Value Distribution
Wrapped Cauchy Distribution

Continuous or discrete - shaken or stirred?

Some quantities are discrete and some are continuous. A discrete quantity is something like a sales territory (e.g. Germany, Ireland, Spain) or customer count (you can't have 0.5 of a customer). A continuous quantity can take any value, for example, speed can be 45.2 kph, 120.01 kph, and so on. Some distributions apply to both continuous and discrete, and some apply only to continuous or discrete. To muddy the waters, sometimes continuous distributions are used to approximately model discrete quantities.

Business examples


Imagine you're running a delivery vehicle fleet. You need to keep your vehicles on the road, but you need to keep an eye on maintenance costs. You decide to use math to guide your decisions, so you work out the average lifetime for different components. You have two components A and B with the same lifetimes in miles. If either component fails, you have to tow the vehicle, which is very expensive.

  • Component A. Lifetime is 150,000 miles.
  • Component B. Lifetime is 150,000 miles.

A vehicle comes in for maintenance with 149,000 miles on the odometer. Should you replace components A and B?

As you might expect, there's a gotcha. Without knowing the probability distribution for failures, we can't make these decisions. For example, a windshield might have a uniform failure rate distribution, with the probability of failure for miles 1-100 the same as the probability of failure for miles 100,000-100,100. A clutch may have a failure rate that increases with mileage, the probability of failure at miles 100,000-100,100 being much higher than the probability of failure at miles 0-100. Because we know what a clutch and a windshield are, we might decide to replace the clutch and leave the windshield. But what if A and B were a serpentine belt and a heat shield?

The only way to make rational decisions is to understand what distribution the probability of failure follows, which may well be very different for different components (e.g. car seats vs. tires).


A new analyst is studying the market for luxury goods in Germany. They have partial data for the fraction of the population that have a certain income. Using what they have, they assume their data is normally distributed and they make a forecast for the fraction of the population that will have an income high enough to afford luxury items. Do you think their forecast will be too low, just right, or too high?

Incomes are usually log-normally distributed, so the analyst, in this case, has chosen the wrong distribution. Because the lognormal has a very long right tail, the analyst's estimate is likely to be an underestimate and may be substantially out. A competitor might not make the same mistake.


I've interviewed people who claim data science on their resumes, but only know the normal distribution. If you assume your data is normal, when in reality it's log-normal or Poisson, things are going to go badly wrong for you. Any analyst in business needs to be very comfortable with different distributions and needs to know which may be applicable and when.