Monday, May 11, 2015

Reuniting the Alberta Right

After last week's Alberta election, several of Alberta's political pundits expressed frustration that the splitting of the vote on the right may have allowed for the NDP success that we saw on election night. Danielle Smith, for instance, said:


She has a bit of a point - despite all the hype of the NDP surge during the campaign, they did still manage to get a strong majority government with less than half of the popular vote, and the combined popular vote of the two 'right-of-centre' parties could easily have beaten them.

Overall, the Wildrose Party ended up with far more seats than the PCs, even though they got 53,000 fewer votes (all this sounds like a set-up for a discussion on proportional voting systems, but I'll save that for later). Though the PC dynasty is ended for now, they certainly aren't lacking in a core voter base, and I wouldn't say they're definitely out of the game just yet.

But to those who are lamenting the splitting of the right side of the political spectrum, what's the most efficient way to reunite these two parties? If the right is to take control again, would it be easier to have the PC supporters move over to the Wildrose, or vice versa?

Let's check. I looked at the results for each riding from last week's election, and checked what the results would have been for each seat if a certain percentage of PC support moved to the Wildrose, or vice versa. First of all, let's see what happens if we increase the amount of PC voters who move over to the Wildrose: 


What this is telling us is that if 23.1% of PC supporters in each riding had instead voted Wildrose, there would have been enough to completely eliminate the PC presence in the legislature. If 35.8% of PC supporters had moved to the Wildrose, it would have been enough to take seats from the NDP and result in a majority of seats. A full reunification of the right would have resulted in 59 total seats, with 26 remaining for the NDP. In both cases, the seats won by the Liberal and Alberta Party MLAs were higher than the combined PC/Wildrose vote, so they're considered immune to this reunification effort.


On the other hand, it would have taken 30.3% of Wildrose supporters flocking back to the PCs in order to result in no Wildrose MLAs elected, and a 31.4% defection rate in order for the right to take control of a majority government.

Which one of these scenarios is most likely is a more nuanced question. Because of how poorly distributed the PC vote was between ridings, it's much easier for the Wildrose to absorb all of the PC seats (23.1% of PC support is only 95,393 voters across the province, for instance) than it is for the PC to absorb the Wildrose seats. If the goal is to reunite the right and regain control of the legislature, though, it may still be easier for the PCs to try to woo Wildrose voters - 31.4% of the Wildrose support is only 113,072 voters, and would have gotten the right back in power.

Overall, this means that a swing one way or another of about 100,000 right-leaning voters could have made all the difference in stopping the NDP from getting elected. Considering that this represents less than 8% of all voters from the last election, the possibility of a resurgence of the Alberta right is certainly not out of the question. The NDP has four years in power now to make good on their promises from the last election and retain their support, otherwise they may be in a bit of trouble during the next election.

Wednesday, May 6, 2015

Math is Difficult

Math can be difficult, so it's a good thing that Elections Alberta posts its unofficial elections results in a nice, easy-to-copy-into-Excel format!

Now that the Alberta election is done, I figured I'd post a short post just showing visually where the party support bases were located. Nothing too flashy or stats-heavy this time. Hopefully more analysis will follow!

First of all, based on unofficial results, the voter turnout last night was 57.01%. Not great, but how does that look visually?


Northern Alberta seems to have suffered the most to bad turnout, with an interesting grouping of solid turnout in the center. Both Edmonton and Calgary had poor turnout in their northeast halves for some reason. Feel free to zoom and click on the map, it's actually a lot of fun (red is low turnout, and green is high).

How about the Liberal support:




The Liberals didn't even run a full slate of candidates, so it's not terribly surprising that most of the map is blank. They did well in the one riding that they actually won, though, and did respectfully in Edmonton-Centre.

The PCs:




PC vote was surprisingly consistent across most rural areas, however that meant it was mostly consistent and low. Edmonton center and north were particularly low for the PCs, but otherwise the variation across the rest of the ridings was fairly minimal.

Wildrose:




Not terribly surprisingly, Wildrose support was concentrated in the southern rural parts of the province. As official opposition in the new government, they don't have any seats in urban ridings. This is fairly concerning, and hopefully won't create any further urban/rural divides in Alberta.

Finally, the NDP winners:




The NDP did very well in the cities and northwest rural ridings, but urban ridings south of Edmonton were more of a struggle for them. Interestingly enough, there is a substantial hole in NDP support in Calgary-Elbow, suggesting strategic anti-PC voting took precedence down there. I'm sure Greg Clark is appreciative.

There you go! Once the recount is done in Calgary-Glenmore (where it is currently tied between the NDP and PCs), I'll hopefully come back with more election analysis!

Tuesday, April 28, 2015

2012 Alberta Election Results Poll by Poll

There's only one week left until the provincial election!

I figure this as good a time as any to remind everyone of the full results from 2012. I'm going to do it a little differently than most map sources have. 

As an example, Wikipedia has this map of election results for each of the 87 electoral districts in Alberta:


This map suggests to me that two-thirds of rural Alberta voted strongly PC in 2012, rural Alberta south of Red Deer voted Wildrose, and the cities were a mix of mostly PC, Liberal, and NDP voters.

You know what's more interesting than that though? Poll by poll results. Each of the 87 electoral districts represent dozens of polls, and looking at these results can lead to a more detailed view of how people voted almost down to a neighborhood-by-neighborhood level. For instance, here's the full map of Alberta:


And here's Calgary and Edmonton:



If you're a fan of interactive maps, feel free to play with this!



For each poll, the colour represents the party with the most votes, and dark colours mean that the leading party had over 50% of the vote. Blue is for PC, red is Liberal, orange is NDP, and Wildrose is green.

The results generally follow the pattern of the overall district results, though showing significantly more Wildrose rural support up north than the original map would have us believe. As a fun exercise to the reader, I encourage you to try to find the four polls that the Alberta Party won, and the one lonely poll that the communist party won (hint: Calgary-East).

Remember to go vote next Tuesday!

Tuesday, April 21, 2015

Election Tours of Alberta

As of today, we are officially halfway through the 2015 Alberta provincial election! Has it been as much fun for you as it has been for me yet?

At the same time as we pick our Alberta government, over in the United Kingdom voters there are also going through a general election. This has gotten a fair bit more attention than the Alberta election, including a fun post from FiveThirtyEight that determines the best campaign route for the leaders of various parties in that election.

It was such a fun post, in fact, that I figured I'd try to do something similar for Alberta!

As the second half of the provincial election unfolds in Alberta, the various party leaders are going to be scrambling to get to as many events as they can in what they consider to be key constituencies across the province. But what's the best route they can take through the most key constituencies, in order to minimize driving time and get the most bang for their buck?

This is a version of the well-known travelling salesman problem, which I dealt with once before for developing an Edmonton pub crawl. For my last travelling salesman problem, I only looked at a maximum of 10 locations, which allows for a time-consuming but 100% accurate solution. With 10 locations, there are 3,628,800 possible routes between each location to be examined.

I've decided to up the ante this time, and look at 20 constituencies for each of the four parties who elected MLAs in the last election. 20 locations each means a total of 2,432,902,008,176,640,000 distance combinations would need to be checked to ensure the absolute shortest route between them all. That's not a task I'm willing to participate in...

Instead, I've fiddled around with a fun trick called simulated annealing. Essentially, you start with a random travel plan, and each iteration you compare it to a proposed one that's slightly different. If the new one is better, you swap it for the old one, but if the new one is worse then you have a probability of swapping. The probability depends on the annealing 'temperature', which decreases as you iterate the procedure.

The advantage of simulated annealing is that by occasionally allowing worse solutions, you give the system the ability to work itself out of locally optimized solutions it may have found, in order to hopefully end up finding the actual best solution.

But enough math - back to politics. For each of the four parties I looked at, I tried to find the shortest route through the 20 constituencies that each party came closest to winning or losing during the 2012 election campaign. This way, leaders were hopefully going to a mix of constituencies where they barely won and barely lost, where conceivably the appearance of the party's leader over the next two weeks might make the most difference.

Let's start with the NDP:



The closest races for the NDP were, maybe not surprisingly, mostly in Edmonton. Rachel Notley's trip would start up in Edmonton-Manning, run through 13 of Edmonton's closest races, and continue on south to Lethbridge with the occasional stop in Red Deer and Calgary. A pretty easy urban whirlwind tour for her, really.

Total time: 7 hours, 57 minutes.

Next, the Liberals:



David Swann's journey isn't altogether too different than Rachel Notley's, though it's a more even split between Calgary and Edmonton, with less in between. Unlike the NDP, there weren't any races that the Liberals won by enough of a margin that desperate help wasn't needed. The quick trip out to Canmore to deal with Banff-Cochrane ought to make for some great sight-seeing!

Total time: 9 hours, 59 minutes.

The Wildrose:



Brian Jean is in for quite a different ride. Starting up in Dunvegan-Central Peace-Notley, he only barely glances at Edmonton on his way down to the juicy urban Calgary core the Wildrose stands to gain. Then it's off to Medicine Hat before winding his way back north to Fort MacMurray.

Total time: 1 day, 1 hour, 32 minutes.

Lastly, the PCs:


The PC map looks quite similar to the Wildrose, largely because the closest contests in rural Alberta were directly between the two parties. Major differences include the four stops in north Edmonton, and the changed focus on south Calgary.

Total time: 1 day, 1 hour, 57 minutes.

So there you go! If you happen to see the campaign busses on the highway and they're not going the right way, make sure to let them know. Best of luck to all in the last two weeks of the election!

Monday, April 20, 2015

Edmonton's NHL Draft Lottery Luck

This weekend, the hockey world lit up with the news that, for the fourth time in six years, Edmonton got the first overall pick in the NHL draft lottery. This year was extra special, as the projected first-round pick Connor McDavid is supposed to be the chosen one who will lead us from our years of darkness (...or something).

The question I was faced with is just how unlikely is it that Edmonton came first 4 times in the last six years. After all, it is a lottery. The fact that the team who gets the first overall draft pick is randomly determined each year is good because it hopefully reduces the chances of a team tanking on purpose to be the worst team in the league in a given year, and keeps games interesting for fans.

Over the last six years a few different odds distributions were offered for the 14 lottery teams that didn't make the playoffs. Until 2012 only the five worst teams had a chance of getting the first draft pick (the absolute worst team had a 48.2% chance), but since 2013 all 14 of the worst teams have some chance or another.

Edmonton and Carolina were the only two teams to not make it in the playoffs over all six of those years, so it stands to reason that they had the best shots at getting the first draft picks at least once or twice in that period, right? This is what happens if you actually crunch the numbers though:


It turns out Edmonton's chances of getting four first-round picks over the last six years was actually around 1.9%. This is certainly low, but not necessarily anything impossible.

There are two reasons that this may be higher than you'd think. First of all, I was looking at the chances of Edmonton winning any four of the last six drafts, not specifically the first three, losing two, and then winning the sixth. Those odds are astronomically low, but deceptive since nobody is up in arms about the lotteries Edmonton didn't win. Secondly, Edmonton's chances were so much higher than Carolina because the first three years Carolina was in the draft lottery, they weren't in a position where they could have won first pick overall (as before 2013, a team winning the lottery could only move up a maximum of 4 positions).

All told, this gives Edmonton an expected return of 1.456 overall first picks over the last 6 years, where they actually got 4. To put that in perspective, they were expected to get almost twice as many overall first picks as the next worst team over the last six years. Of the 27 teams who made at least one appearance in the draft lottery over the last six years, we have:


Realistically, this means that the luckiest teams in the draft have been Edmonton, Florida, and Colorado, and the unluckiest has probably been Columbus. The four teams at the bottom happened to have their bad seasons in years where they weren't quite bad enough to have a shot at first overall pick (poor guys).

So yes, Edmonton has gotten lucky with draft picks over the last six years, but it's not quite as impossible as it would have otherwise seemed. We were helped out by being the worst team in the league in two years where we had nearly 50% chances of winning the draft, and by generally being terrible in the rest of the years to keep our chances high. We've gotten lucky at the draft, but only by being genuinely terrible over the last six years, and I sincerely hope that trend starts to reverse soon.

Tuesday, April 14, 2015

Edmonton Air Quality

This morning, I read an Edmonton Journal article that claimed that Edmonton's air quality was worse than Toronto's, even though we have five times less population than Toronto. The article's subtitle reads: "Particulate readings 25 per cent higher on some winter days."

I'll admit that my initial reaction to this was skepticism - the language used in the article seemed pretty wishy-washy and I wasn't sure what all the fuss was about. It's not terribly unnatural for some days in some cities to be worse than some days in other cities. Also, if pollution levels are particularly low on certain days, being 25% higher than another city is pretty easy and still reasonably healthy. So I decided to look into the numbers a little bit more.

The article continues, saying "pollution from particulate matter exceeded legal limits of 30 micrograms per cubic metre at two city monitoring stations on several winter days in 2010 through 2012." Ok, that sounds pretty bad, but what do these limits correspond to, and how bad is "several", really?

First of all, let's take a look at what makes air unhealthy. The Air Quality Health Index used by Environment Canada looks at three factors: Ozone at ground level, Particulate Matter (PM2.5/PM10), and Nitrogen Dioxide. Exposure to Ozone is linked to asthma, bronchitis, heart attack, and death (fun), nitrogen dioxide is pretty toxic, and particulate matter less than 2.5 microns is small enough to pass right through your lungs and play with some of your other organs. These aren't things you really want to be breathing a whole lot of. The AQHI for Edmonton today is a 3 out of 10, considered ideal for outdoor activities, but at a 10 out of 10 level people are pretty much encouraged to stay inside and play board games.

The report in the Journal article referenced PM2.5 only, which is particulate matter that's smaller than 2.5 microns. The maximum allowed levels for PM2.5 in Alberta are 80 micrograms per cubic meter (ug/m3) in a single hour, or 30 ug/m3 over a day. According to the Journal article, these levels were exceeded "several" times between 2010 and 2012. How many is several?

Data from the Clean Air Strategic Alliance

I don't know about you, but exceeding government safe levels for air quality on one day out of every eleven in 2010 is not what I'd call "several." There was over a combined month of air quality limits being broken in 2010 in central and east Edmonton.

I strongly disliked the phrase "25 percent higher on some winter days" due to its vagueness, but the idea of comparing Edmonton to Toronto seemed fun. Based on the CASA values for Edmonton, and the Air Quality Ontario values for Toronto, here's a comparison of the two cities from 2006-2012:


That's... not even close. Edmonton was 25% higher than Toronto for pretty much all of 2012, not "some winter days." This is enough to make me feel like perhaps the sources referenced in the Journal were using different data, or perhaps I'm mistaken, but the sources I used are all publicly available and I encourage you to check them out yourself.

But what about the other major air quality indicators? Turns out that, fortunately, exceeding their limits has proven to be much tougher. The maximum one-hour limit for nitrogen dioxide is 0.159 ppm, over 10 times the daily average for both Toronto and Edmonton recently:


Similarly, the one-hour limit for Ozone is 0.082 ppm, about four times the recent daily averages:


Again, these levels are much safer than the particulate levels were, and in general Edmonton is about the same or slightly better than Toronto for these indicators.

So all in all, I started out today thinking the article was being alarmist, if vague, and I've ended up thinking that it's well-meaning but presented oddly. Edmonton definitely does seem to have a problem with one of the major indicators of air quality, and if it takes a city-pride fight with Toronto to get that sorted out, so be it.

Monday, March 9, 2015

The 2015 Brier Playoffs were the Most Exciting in Years

Congratulations to Team Canada on winning back-to-back Brier tournaments! With that, the Canadian national tournaments are over for the season, and two teams are off to represent us at the Worlds!

Now, a lot of people don't find curling to be all that exciting. A lot of that comes from individual taste - some people haven't played curling or aren't from rural Saskatchewan, and without having been there before or having a vested interest in the teams, maybe some of the intricacies aren't all understood.

Either way, for the more ardent curling fans, the game is often very exciting. But some games are undeniably more exciting than others, and apart from the final score is there a numerical way to determine which games are the most riveting?

Sure there is! It's called the Excitement Index.

I first came across the Excitement Index (EI) in the context of the National Football League, where the owners of 'Advanced Football Analytics' have developed a model that predicts each team's chances of winning a football game after each play. They decided to develop an EI based on the absolute sum of chances in winning percentage throughout the game. A game where team storms to an early lead and holds it will have a much lower EI than one that's back and forth all game, and similarly a modestly successful play early in the game will likely have less effect on EI than one that clinches the game in the last minutes.

So I came up with a similar system for curling. Instead of looking at it play-by-play, I came up with a model that predicts winning percentages based on the score after each end. For instance, I now know that over the last 15 years of Brier tournaments, a team that's been up by 1 after 4 ends with the hammer has won 80% of the time.

Going through games end-by-end, using this model, can develop the total EI for that game. For instance, a particularly unexciting game could look like this: (1/2 page playoff game, 2014 Brier):


Last year, British Columbia got 2 with the hammer right off the bat, then stole one, leaving them up 3 without hammer after two - a very strong opening that historically results in a win 91% of the time. Alberta then only got one with the hammer, but in doing so gave the hammer back to BC for only a one-point trade, resulting in no real change in probabilities. BC then got 3 with the hammer, and the game was essentially wrapped up by that point (6-1 after 4 is virtually insurmountable for teams at the Brier). The sum of changes in probability in this game was only 0.27 after the first end - not a terribly exciting game.

On the other hand, here's the most exciting Brier playoff game I've analyzed: (2004 Final)


Nova Scotia started off not too well, only getting one with the hammer. The teams then traded 2-point ends, which resulted in a lot of back-and-forth in terms of probabilities while slowly inching in favour of Alberta. NS only getting one in the 5th was bad, but not quite as bad as AB getting three in the sixth. At this point it was 8-4 after 7, and being down by 4 after 7 with the hammer only has a win rate of 1.6%. The rest of the game was improbable, to say the least, and made for a very exciting finish. The total EI was 1.87, about 6 times 'more' exciting than the previous game.

It's important to note that a mid-game comeback isn't necessary to have a high EI value. The 'most exciting' game I could find while building my model was in Draw 6 of the 2009 Scotties (note: I have a separate model for men's and women's curling):



With all of the high-scoring ends at the beginning, and winning with a steal at the end, the back-and-forth swing throughout this game led it to a massive EI of 2.76.

All this leads to the fun finding that the 2015 Brier playoffs were the most exciting in recent history! Averaging the EI values for all games in the playoffs gives an average EI of 1.41 for 2015, with the final game (1.19) being the third most exciting final analyzed.


Stay tuned for next week, when I use the historical model I have to look at when it's better to take a point as opposed to blank an end, and compare men's curling to women's curling in a little more depth!