Lucky 8?

My state government’s lottery administration, SA Lotteries, makes the results from its various games available online, including tables of how frequently the various lottery numbers were drawn.

For example, you can see here how frequently the numbers 1 through 45 have been drawn in the Saturday X Lotto. At the time of writing this, Number 8 was the most frequently drawn, recorded as occurring a total of 289 times between Draw Number 351 to 3265. Note that the Saturday X Lotto Draws are odd-numbered, so Draw 351 to 3265 actually consists of 1458 (i.e. (3265-351)/2+1) weekly games.

Of course there will be random variation in how frequently balls are drawn over time, just as there’s random variation in heads and tails in the toss of a coin. But is it particularly unusual for the Number 8 Ball being drawn 289 times in 1458 games of Saturday X Lotto?

Is South Australia’s Saturday X Lotto biased towards the number 8?

Now before we can determine if the Number 8 being drawn 289 times in 1458 games of X Lotto is an extraordinary event, it helps if we first work out how many times we expected it to happen. In X Lotto, a total of eight balls (6 balls for the main prize and then 2 supplementary balls) are selected without replacement from a spinning barrel of 45 balls. The probability of any single number of interest being selected in eight attempts without replacement from a pool of 45 can be calculated using a Hypergeometric Calculator as P(X=1)=0.17778 (i.e. just under 18%). Therefore we expect the Number 8 (or any other number for that matter) to be drawn 0.17778 x 1458 = 259 times in 1458 games.

So observing 289 occurrences when we were only expecting 259 certainly seems unusual, but is it extraordinary?

To answer this, I’ll employ the Binomial test to evaluate the null hypothesis, H0:

H0: Observed frequency of the Number 8 being drawn in SA Lotteries’ Saturday X Lotto is within the expected limits attributable to chance (i.e. the lotto is a fair draw)

vs. the alternative hypothesis, H1:

H1: Observed frequency is higher than would be expected from chance alone (i.e. the lotto is not a fair draw)

The statistics package, R, can be used to run the Binomial test:

> binom.test(289,1458,0.17778,alternative=”greater”)

> Exact binomial test
> data: 289 and 1458
> number of successes = 289, number of trials = 1458, p-value = 0.02353
> alternative hypothesis: true probability of success is greater than 0.17778

So we can reject the null hypothesis of a fair draw at the alpha=0.05 level of significance.  The p-value is small enough to conclude that the true probability of Number 8 being drawn is higher than expected based on chance alone.

However, please note that I am definitely not suggesting that anything untoward is going on at SA Lotteries, or that you’ll improve the odds of winning the lottery by including the number 8 in your selection. For a start, rejection of the null hypothesis of a fair system occurs at the standard, but fairly conservative, alpha=0.05 level. What if I had decided to use alpha=0.01 instead? The null hypothesis of a fair system would be retained. Things are all rather arbitrary in the world of statistics.

Still, a curious result that utilised several statistical concepts that I thought would be interesting to blog about.



Queuing Theory and iiNet, Part II

It’s an interesting read, but the author makes a lot of basic errors. Unfortunately, customers refuse to line up and call at regular intervals and spend the average amount of time on the call. The reality is obviously more bursty than that and needs non-linear modelling.

Michael Malone, CEO of iiNet

The feedback from Michael Malone above was in response to my previous blog post on Applying Queuing Theory to iiNet Call Centre Data. I don’t accept that I made “a lot of basic errors”, but I did make a lot of assumptions. Or perhaps the statistician George E. P. Box said it better, “Essentially, all models are wrong, but some are useful.”

But Michael is correct – customers don’t line up and call at regular intervals, and the reality is more “bursty” (i.e. Poisson). My model is inadequate because it doesn’t take into account all the natural variation in the system.

One way of dealing with, or incorporating, this random variation into the model is by applying Monte Carlo methods.

Take the iiNet Support Phone Call Waiting Statistics for 6 February 2012, specifically for the hour 11am to noon. I chose this time block because the values are relatively easy to read off the graph’s scale – (a bit over) 664 calls and an average time in the queue of 24 minutes.

Now if we assume Average Handling Time (AHT), including time on the call itself followed by off-phone wrap-up  time, was 12 minutes, then my model says there were 664*(12/60) / (24/60 +1) = 95 iiNet Customer Service Officers (CSOs) actually taking support calls between 11am and noon on 6 February 2012. That’s an estimate of average number of CSOs actually on the phones and taking calls during that hour, excluding those on a break, performing other tasks, and so on. Just those handling calls.

But there will be a lot of variation in conditions amongst those 664 calls. I constructed a little Monte Carlo simulation and ran 20,000 iterations of the model with random variation in call arrival rates, AHT, and queue wait times.


Little’s Law applies
664 calls were received that hour (at a steady pace)
Average time in the queue of 24 minutes
AHT (time on the actual call itself plus off-call wrap-up) of 12 minutes

then the result of the 20,000 monte carlo runs is a new estimate of 135 iiNet CSOs taking support calls between 11am and noon on 6 February 2012.

I ran a few more simulations, plugging in different values for number of CSOs handling calls (all else remaining equal – i.e. 664 calls an hour; AHT=12 minutes) to see what it did for average time in the queue. The results are summarised in the table below:

Modelling suggests that if iiNet wanted to bring the average time in the phone call support queue down to a sub-5 minute level during that particular hour of interest, an additional 85% in active phone support resourcing would need to be applied.

The table of results is graphically presented below (y-axis is time in queue, x-axis is CSOs)

Looks nice and non-linear to me 🙂 You can see a law of diminishing returns thing start to take place around about the point of the graph corresponding to 160 CSOs / 16.5 minute average queue wait time.


Applying Queuing Theory to iiNet Call Centre Data

In previous posts I’ve talked about queuing theory, and the application of Little’s Law in particular, to Internet Service Provider (ISP) customer support call centre wait times. We can define Little’s Law, as it applies to a call centre, as:

The long-term average number of support staff (N) in a stable system is equal to the total number of customers in the queue (Q) multiplied by the average time support staff spend resolving a customers’ technical problems (T), divided by the total time waited in the queue (W); or expressed algebraically: N=QT/W.

Thinking things through a bit more, the total number of customers in the queue (Q) at a point in time in a stable system should be equal to the rate at which people joined the queue (λ), minus the rate at which the support desk dealt with technical problems (i.e. N/T) over the period of observation. Obviously Q>=0.

So N=QT/W and Q=λ-N/T which all comes out in the wash as:


I thought might be a bit of fun to see if this could be applied to the customer support call centre waiting statistics published by one of Australia’s largest ISPs, iiNet.

iiNet make some support centre data available via their customer toolbox page. Below is a screenshot of call activity and wait times graphed each hour by iiNet on 10 January 2012. The green line (in conjunction with the scale on the left hand side of the graph) represents the average time (in minutes) it took to speak to a customer service representative (CSR), including call-backs. The grey bars (in conjunction with the right hand scale) represents the total number of incoming phone calls to iiNet’s support desk.

It may be possible to use the formula derived above to estimate how many CSRs iiNet had on the support desk handling calls that day. For example, during the observed peak period of 8am to 1pm on Tuesday, 10 January 2012, the iiNet support desk was getting around 732 calls per hour on average. The expected wait time in the queue over the same period was around 11 minutes.

If we assume that the average time taken for a CSR to resolve a technical problem is, let’s say, 12.5 minutes, then we can estimate that the number of CSRs answering calls in a typical peak-hour between 8am to 1pm on 10 January 2012 as:

732*(12.5/60) / (11/60 + 1)

= 129 CSRs actively handling calls.

Sounds sort of a reasonable for a customer service-focussed ISP the size of iiNet. But if iiNet wanted to bring the average time in the queue down even more – to a more reasonable 3 minutes, for example – they’d need 145 CSRs (all else remaining equal) during a typical peak-hour answering calls.


Will the 43rd parliament of Australia survive the next two years?

Good question. I mean, what are the odds?

Australia’s 43rd parliament is a precarious one. Last year’s federal election resulted in a hung parliament in the House of Representatives, with a minority Labor government clinging to power with the help of the Greens and a few Independents. Now I don’t want to sound morbid but, Heaven forbid, should any one of the Honorable Members die, the resulting by-election could conceivably bring down the government. So finely balanced are the numbers.

So, I wonder, what IS the probability that this will happen before the next election, due in 2013?

Statisticians that devote themselves to thinking about exactly this sort of question are called Actuaries, and when calculating risk of mortality they reference a thing called a Life Table. Life tables list the probabilities that a person aged x will survive to x+1 years. For example, looking at the most recent Life Tables for Australia, the probability that a female aged 40 will die before turning 41 is 0.00078 (i.e. 0.078%). Or looking at it in a more positive light, the chance a 40 year old female will live to see her 41st birthday is 1-0.00078, or a healthy 99.922%.

So turning our attention back to the 150-member House of Representatives, what is the probability that one or more of them might shuffle off this mortal coil in the next two years, resulting in a by-election and/or a change of government?

To be rigorous I should aggregate individual probabilities of survival based on each member’s age and gender. But I can’t be arsed, so I’ll talk about it in terms of generalities.

If I recall correctly, the average age of a politician is 51 years. Despite this being a modern society in the year 2011, our parliament is still a massive sausage-fest. Men in government significantly outnumber women. So I’ll just be lazy and use the qx column in the Australian Life Tables linked above for males aged 51 and 52.

From the Life Table, the probability that a male aged 51 years will survive to his 53rd birthday is (1-0.00332)*(1-0.00359)=0.993. Therefore the chance that every member of the 150 seat parliament survives for the next two years can be approximated at 0.993^150=0.349 (i.e. 34.9%). The likelihood that one or more parliamentarian dies within the next two years is the complement all surviving, calculated as 1-0.349=0.651 (65.1%).

65%. That’s a pretty high risk that the parliament won’t see out its full term.


The NBN, CVC and burst capacity

Late last year, NBN Co (the body responsible for rolling out Australia’s National Broadband Network) released more detail on its wholesale products and pricing. You can download their Product and Pricing Overview here. The pricing component that I wanted to analyse in this post is NBN Co’s additional charge for “Connectivity Virtual Circuit” (CVC) capacity.

CVC is bandwidth that ISPs will need to purchase from NBN Co, charged at the rate of $20 (ex-GST) per Mbps per month. Note that this CVC is on top of the backhaul and international transit required to pipe all those interwebs into your home. And just like backhaul and international transit, if an ISP doesn’t buy enough CVC from NBN Co to cover peak utilisation, its customers will experience a congested service.

The problem with the CVC tax, priced as it is by NBN Co, is that it punishes small players. By my calculations, an ISP of (say) 1000 subscribers will need to spend proportionally a lot more on CVC than an ISP of 1,000,000 subscribers if they want to provide a service that delivers the speeds it promises.

Here comes the statistics.

Consider NBN Co’s theoretical 12 megabit service with 10GB of monthly quota example that they use in the document I linked to above. 10GB per month, at 12Mbps gives you 6,827 seconds (a bit under 2 hours) at full speed before you’re throttled off. There’s 2,592,000 seconds in a 30-day month, so if I choose a random moment in time there is a 6827/2592000 = 0.263% chance that I’ll find you downloading at full speed.

That’s on average. The probability would naturally be higher during peak times. But let’s assume in this example that our theoretical ISP has a perfectly balanced network profile (no peak or off-peak periods). It doesn’t affect the point I’ll labour to make.

A mid-sized ISP with (let’s say) 100,000 subscribers can expect, on average, to have 100,000*0.263% = only 263 of those customers downloading at full speed simultaneously at any particular second. However, the Binomial distribution tells us that there’s a relatively small, but still statistically significant (at the alpha=0.05 level) probability that there could be 290 or more customers downloading at the same time.

So a quality ISP of 100,000 subscribers will plan to buy enough CVC bandwidth to service 263 customers at any one time. But a statistician would advise the ISP to buy enough CVC bandwidth to service 290 subscribers, an additional (290-263)/263 = 10% , or find itself with a congested service about one day in every 20.

This additional “burst headroom”, as a percentage, increases as the size of the ISP decreases. From above, an ISP of 10,000 can expect to have 26 customers downloading simultaneously at any random moment in time. But there’s a statistically significant chance this could be 35+. This requires them to buy an additional (35-26)/26=33% in CVC over and above what was expected to cover peak bursts.

The table below summarises, for ISPs of various sizes, how much additional CVC would need to be purchased over and above the expected amount, to provide an uncontended service 95%+ of the time.

Graphically it looks a bit like this…

As you can see, things only really start to settle down for ISPs larger than 100,000 subscribers. Any smaller than that and your relative cost of CVC per subscriber per month is disproportionally large.


Further reading:

Rebalancing NBNCo Pricing Model

NBN Pricing – Background & Examples, Part 1


The Gambler’s Fallacy

Roulette is no match for geeks with a basic knowledge of the fundamentals of statistics

The quote above popped up on my Twitter timeline a few days ago.  It’s not my purpose to embarrass the person who wrote it; their statement simply reflects several very common misconceptions around gambling probability, concepts that I’ve been meaning to write about for a while.  Probability is often unintuitive, and when applied to gambling people can quickly get unstuck.

I think the most fundamental error here, more observational than mathematical, is the idea that casinos could somehow have a poor grasp of probability theory, and therefore roulette can be beaten with a “system”.  Notwithstanding that casinos must have, over centuries, evolved a powerful grip on probability theory else quickly perish, whenever I confront people with this notion I find their strategy boils down to a variation of the debunked Martingale System.  One of the simplest Martingale strategies, as it applies to a roulette player betting on red or black for example, is to wait for a run of a colour (let’s say 5 to 7 reds in a row) and then place a wager on the opposite outcome (i.e. black).   This strategy lends itself to the Gamblers Fallacy, a mistaken belief that a future outcome in a random independent process is somehow “more likely” based on past behaviour.  And while it’s true, given infinite time, that the roulette ball in a fair game must fall as often on black as it does on red, you’ll go broke long before then for reasons I hope to make clear below.

The casino’s strategy, on the other hand, is simple, fullproof and ruthless: keep you playing.  Like a predator stalking its prey to exhaustion, the casino can wear you down to broke using a statistical concept known as Expected Value.  Put simply, the expected value, as it applies to gambling, is the average payoff over time.

Take, for example, the roulette wheels at Adelaide’s “SkyCity” casino.  These tables have 37 numbers consisting of 18 red, 18 black, and one “0” slot.  Even money bets such as black/red pay even money, meaning that if you bet $1 and win (with probability of 18/37) you gain an additional $1.  Conversely, there’s a 19/37 chance you will lose your $1 stake.  So the punters’ average payoff over time is:

Expected Value [$1 even-money bet] = Prob(loss) x Price of losing + Prob(win) x Price of winning

= (19/37 x -$1) + (18/37 x $1)

=  -$0.0270

Therefore you can expect to lose, on average, about 2.7 cents for every $1 even-money bet over the long term.

In other words, the house doesn’t always win, but it will ultimately prevail.


Here’s a clip showing how it can all go horribly, horribly wrong.  Note how the player starts with a wager of just €1 and watch the losses increase exponentially [warning: some language].


Some statistics in the global warming debate

we can’t account for the lack of warming at the moment and it is a travesty that we can’t

US climate change scientist Kevin Trenberth, whose private emails are included in thousands of documents stolen by hackers and posted online

If you’re interested in statistics then I highly recommend that you add the Stats in the Wild blog to your daily must-read list, and if you’re interested in climate change science then I highly recommend you check out the recent post on the topic.  In fact, go and read it now and I’ll wait here until you get back…

Really good stuff, isn’t it?

Now I’m in broad agreement with Stats in the Wild on this one.  While it appears there may be a few rogue elements amongst the climatologist community (which obviously I don’t condone, but every family has its dodgy Uncle), overall the science is still sound. I’ve nailed my colours firmly to the mast of Anthropogenic (i.e. human-caused) Global Warming (AGW).  Personally I think that to deny AGW is to deny the power of academic peer review, a system that has so successfully underpinned the scientific method for many centuries.  Yes, Earth has gone through significant periods of warming and cooling in the past, but the on-average increasing temperatures observed over the last 150 years or so, and particularly the rate of change, is almost certainly a result of increased greenhouse gases (carbon dioxide and methane, particularly) pouring into the atmosphere in ever greater quantities as human populations, industry and agriculture expand.

On the issue of recent lack of warming that has caused Kevin Trenberth such disquiet, Stats in the Wild points out the simple statistical explanation:

You can have a system that is, on the average increasing over the long term, while still observing very flat or even declining trends when we know the overall system is increasing. That doesn’t mean that the system isn’t increasing, it just means we’ve seen one realization of the random system that hasn’t increased entirely by chance.

Stats in the Wild illustrates the point with repeated computer simulations.  If you don’t have access to the “R” statistical analysis package you can produce a simplified version yourself using any spreadsheet.  The parameters in the example below are made up to illustrate a point.

Imagine that the average temperature of the Earth has increased from 15°C to 17°C by a precise, constant amount every year over a 100 year period.  Scientists’ ability to measure this temperature at any point in time is limited by sampling errors, instrument accuracy, and other sources of variability outside of their control.  Despite these shortcomings, assume that the scientists’ estimate is always pretty good – consistently within +/-3% of the true value.  So the sources of measurement variability result in estimates that bounce around randomly, but always within this 3% margin of error around the true value.  Graphically what I’m talking about might look a bit like this:

The grey line in the graph above is the scientists’ estimated temperature randomly distributed around the true value (yellow line) but between the margins of error (red lines).  Now if I emphasise the observed temperature you see that, to the scientists, whose measurement limitations mean they can never know the true value, the situation looks like this:

From the graph above you can see there are (crudely drawn lines in orange) intra-time series periods where random variation makes the trend appear to level off or even decrease.  If you were an observer at roughly year 65, for example, you’d be forgiven for thinking global warming was a right load of old cobblers, because it would appear that temperatures are stagnant, even getting cooler.  As Stats in the Wild concludes, you can have a system that is, on the average increasing over the long term, while still observing very flat or even declining trends when we know the overall system is increasing.

It’s to be expected.


Selected further reading:

Brave New Climate

Climatologists under pressure

Scepticism’s limits