Featured post

Textbook: Writing for Statistics and Data Science

If you are looking for my textbook Writing for Statistics and Data Science here it is for free in the Open Educational Resource Commons. Wri...

Sunday, 1 February 2015

R Package Spotlight - nhlscrapr

NOTE: AN UPDATED INTRODUCTION TO NHLSCRAPR HAS BEEN POSTED HERE.

nhlscrapr is a package to acquire and use play-by-play information of National Hockey League games. It's similar in function to pitchRx for Major League Baseball. Unlike pitchRx, it doesn't allow for SQL Queries to be sent to an open database, but is instead a system to collect raw data from www.nhl.com and format it into an R dataframe.

The focus of this package spotlight will be on acquiring the game data rather than using it. 

Thursday, 29 January 2015

Abstract Thoughts About Concrete

The production of cement is a major source of anthropogenic (i.e. human-made) carbon dioxide. In fact, its impact is comparable to that of using fossil fuels to transport goods and heat buildings.

It uses limestone, which contains carbon dioxide that has been locked away for a geologic time, and a portion of this is released in the process of cooking it into a material called clinker. Eventually, the cement will re-absorb some, but not all of the CO2 released this way. Cooking the limestone to 1500 C takes a lot of energy too, and in an intensity that makes it difficult to produce cleanly. There's also the costs and impact of the limestone quarrying and transportation to consider.


Another problem is disposal: Construction waste makes up a large part of what goes into landfills, and cement products like concrete and mortar potentially make up a large part of that. This is from buildings being demolished or renovated, from road construction, and from the occasional truckload of concrete that is mixed but can't be poured at the right time.

So I wonder, in my limited understanding, if it's possible to take cement products and reclaim some of the cement. Currently, concrete is recycled to reduce its landfill impact and the need to mine gravel and other fill. However, that seems to be all it's used for - simple rocks rather than the magic gluestone stuff that holds skyscrapers up.

Curing is a one-way chemical process (I think), and that there's a lot of fill that's added to cement to make concrete, so maybe it's just too hard to be profitable. Fresh cement powder is so fine that it would be a stretch to call it dust, so a tremendous amount of mechanical grinding would be necessary to get concrete down to a point where the fill could be removed from what was cement powder before curing.

Has anyone given serious thought to a chemical or biological means of doing this however? If lichen can break down solid rock, could concrete gravel be broken down or separated into something finer with a plant, enzyme, or type of bacterium? Can the curing process be undone by similar means that leaves behind clinker as a waste product?

Similarly, could wet concrete mix be saved for another time in the cases where it spoils from water contamination or when it can't be poured when intended? Could aging or damaged infrastructure be reinforced or renewed by drilling into it and injecting something to force it to re-cure?

Just some thoughts from someone ignorant on the limitations of infrastructure.  Comments, corrections and discussion about this would be very welcome.

Here's a general statement to close -- climate change won't simply be fixed by driving hybrids and using recycle bins. It's a complex problem and solving it will be the great work of this and the next generation.

http://en.wikipedia.org/wiki/Environmental_impact_of_concrete

http://en.wikipedia.org/wiki/Concrete_recycling

Thursday, 22 January 2015

R Package Spotlight - stringr

One of my ongoing projects is to maintain a database of international cricket games, which I do by scraping the text from ESPN Cricinfo. For this kind of work, the R package 'stringr' is essential.

Saturday, 17 January 2015

R Package Spotlight - xtable

xtable is an R package on CRAN that converts output into LaTeX code for a table of that output.

For writing papers, it has cut the time it takes to produce and manage a table by a factor of 3 or 4.

Sunday, 4 January 2015

SPSS Guide for Basic Practice of Statistics

I've made some major updates to this introductory guide to SPSS. (Google docs link, but you can download from there)

It's a guide to using SPSS to answer homework problems from Basic Practice of Statistics (BPS), by Moore, Notz, and Flinger. Although it was originally made for a specific stats for social sciences course, I hope it's applicable beyond that.

The biggest change from the 2012 and 2013 versions is that the guide is no longer tooled around Elementary Statistics for Social Sciences by Levin, Fox, and Forde. Those versions will not be posted here because this 'elementary' textbook is better at teaching fear than statistics. Consequently the GLM procedure and logistic regression chapters have been removed from the SPSS guide.

The updates also includes more information about data manipulation specific to 'Basic Practise' such as random selection, sorting, and weighting data.

There is already a larger, official SPSS companion for this textbook, but my guide is intended to provide just what a novice student needs to get through their course, rather than be a comprehensive reference.

This work is freely available to share and was originally commissioned with a research grant from Simon Fraser University in 2012.

Wednesday, 31 December 2014

GDA-PK, a cleaner powerplay skill measure for NHL hockey

In the Vancouver Canucks' latest game, a 3-1 win against at the Anaheim Ducks on December 29, a paradox happened in the first period:

At the 13:31 mark, Vancouver got a 2-minute minor penalty
At the 14:26 mark, Anaheim got a 2-minute minor penalty
At the 15:18 mark, Vancouver got another 2-minute minor penalty.
All penalties ran their full course without being converted into goals.

So, for
13:31 - 14:25, Anaheim had a 5-4 powerplay (55 seconds)
15:18 - 15:30, Anaheim had a 4-3 powerplay (13 seconds)
16:26 - 17:17, Anaheim had a 5-4 powerplay (52 seconds).

Anaheim enjoyed a total of two minutes of powerplay advantage, which makes sense because Vancouver received one more penalty. However, for the sake of measuring Vancouver's ability to kill penalties or Anaheim's ability to use them, this counts as three distinct powerplays.

To me, this seems counter-intuitive for multiple reasons.
- Anaheim somehow managed to have more powerplays than penalties given in their favour.
- Most powerplays are of two minutes in length, but one of these was only 13 seconds long.
- Had it just been Vancouver's two penalties, this period would be recorded as one long powerplay of 13:31 - 17:17. So by getting a penalty, so it looks like Anaheim got two extra powerplays by getting a penalty.
- Had it just been Vancouver's two penalties and the first ended in a goal, it would be recorded as two powerplays, which would look like Anaheim getting an extra powerplay by scoring a goal.



My general objections to the counting of powerplays, and powerplay-based metrics, PK% and PP%*, include:

- Two-player advantages, although rare, are treated the same as one-player advantages.
- Powerplays from 5-minute major penalties are treated the same as 2-minute minors, even though minor (and double-minor) penalties end when the team with the player advantage scores.
- Shorthanded goals are ignored.
- The output of the statistics, like 82% PK and 24% PP, aren't intuitive to the viewer as to what to expect. We can compare the PK% and PP% teams to say that Anaheim is very good on the powerplay, and that Vancouver is very good shorthanded relative to other teams, but it doesn't give the viewer a good idea of the chances of a powerplay goal.


A better solution already exists; GAA*, as in Goals Against Average, which is normalized by time. I propose to adapt GAA into two alternate measures.

GDA-PK: Goal difference average - penalty killing.
GDA-PP: Goal difference average - power play.

where

(GDA-PK) = (Shorthanded goals scored - Shorthanded goals against) / (minutes shorthanded) 

(GDA-PP) = (Powerplay goals scored - Powerplay goals against) / (minutes shorthanded) 

- Going through the Vancouver-Anaheim anomaly again, we would record 0 goals against Vancouver in 2 total minutes. the fact that those 120 seconds are interrupted twice doesn't factor into the computation. 

- If the powerplay had been cut short by a goal, less powerplay time and 1 goal would be recorded.

- If there had only been the two Vancouver penalties, more powerplay time would have been recorded and the two-player advantage time could be used for something else, such as GDA-2PP.

- The longer time of  five-minute major and four-minute double minor penalties are reflected fairly in GDA-PK and GDA-PP.

- Multiple goals during a major penalty do not result in an absurd measure such as a PP% of more than 100%.

- Shorthanded goals are included and simply treated as goals in the opposite direction.

The results that come out these metrics may look like this (THIS HAS NOT YET BEEN CALCULATED, PLEASE DO NOT QUOTE THESE AS ACTUAL FIGURES) :

----------------------
Vancouver Lumbermen**
- 0.103 Goals/min PK ( 2nd in NHL) 

Anaheim Mighty Mallards**
+ 0.138 Goals/min PP ( 4th in NHL)
----------------------

Numbers-keen viewers can get a sense of the average goals any given penalty will cost, and it provides the same comparative sort of ranking as PP% and PK% but with less noise from special cases.  As an added bonus, a fair comparison to even strength play can be made as well by a similar calculation.

Finally, The fact that some Powerplay intervals are cut short by a goal being scored is a non-issue. It has already been addressed (Bartholomew 1957 for the math, Mullet 1977 for the application)***.

Your thoughts? Disagreements welcome in commentary.

========================

* Definitions:
PK% is short for Penalty-Kill Percent. It is a measure of defensive ability in shorthanded situations and calculated by (Goals against when shorthanded / Number of shorthanded situations) X 100%.

PP% is short for Power Play Percent, a measure of offensive ability in player-advantaged situations, is calculated by (Goals scored when player-advantaged / Number of player-advantaged situations) X 100%

GAA, short for Goals Against Average is a metric used to measure goalies and teams' defensive abilities. It is calculated by (Goals against / Hours of play).


** The names of the teams have been changed to emphasize that these numbers are for demonstration only. A lesson to novice statisticians, numbers you throw out, however casually or verbally, have a habit of being quoted as serious analyses. I'm trying my best to avoid that while still giving an example.


*** References: 
Bartholomew, D. J. (1957), “A problem in Life Testing,” Journal of the American Statistical Association,
52, 350-355

Mullet, G. M. (1977), “Simeon Poisson and the National Hockey League,” The American Statistician,
31, 8-12

Thursday, 18 December 2014

New Kudzu Material - The Halls of Lorsem

Here is an update to Scrabble Dungeon, which I'm calling Kudzu for the time being to give it a better search niche, and to avoid future lawsuits.

Google Drive link to 2014-12-17 Version

There are only typo fixes to the material that was in the 2014-12-05, but a lot of new material has been added.

Specifically, a new six-room dungeon called "The Halls of Lorsem" and eight new Relics to draw from a random deck.

To avoid this becoming a single unwieldy document, new material will likely be given as separate modules while rule changes will follow future versions of this document.