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...

Monday, 17 November 2014

First look at the statistical thesaurus


Part of my work at the Institute for the Study of Teaching and Learning in the Disciplines, or ISLTD for short, is to develop a handbook for statistical design and analysis.

The clients of the ISTLD are Simon Fraser University faculty across all disciplines that are looking to incorporate new teaching ideas and methods into their courses. This handbook is intended for faculty and grad student research assistants with little statistical background. As such, the emphasis is on simplicity rather than accuracy.

One wall I've run into in making this document as accessible as possible is terminology. Different fields use different terms for the same statistical ideas and methods. There's also a lot of shorthand that's used, like "correlation" for "Pearson correlation coefficient".

Why is spatial autocorrelation referred to as 'kriging'? Why is spatial covariance described in terms of the 'sill' and the 'nugget'? Because those are the terms that the miners and geologists came up with when they developed it to predict mineral abundance in areas.

Why are explanatory variables still called 'independent variables' in the social sciences even though it causes other mathematical ambiguities? Because they're trying not to imply a causal relationship by using terms like 'explain' and 'response'.

For the sake of general audience readability field specific language will be kept to a minimum, and shortenings will be used whenever a default option is established, as it is with correlation. However, the alternate terms and shortenings will be included and explained in a statistical thesaurus to be included with the handbook.

Here are three pages from the rough draft of that thesaurus. Since such a thesaurus, to my knowledge, has not been published before, I would very much appreciate your input on its readability, or what terms should be included.


https://docs.google.com/document/d/15IWtH9a_bpfhu2cvvtBOCL6FCCaH7zyPwDDsLEXz7d4/edit?usp=sharing

Thanks for reading!
- Jack

Tuesday, 4 November 2014

Sabremetrics, A.K.A. applied metagaming.

In baseball, sabremetrics started a push for batters to hold off for more and better pitches. By 2011 or 2012, strikeout rates were higher than they were in a century, probably in part of the reduced hitting but also due to pitchers throwing more pitches, knowing they would be swung at less often. How long until batters adapt and capitalize on the higher quality pitches they are receiving to increase hit rates and home runs instead of waiting for many pitches?

This is an example of perfect imbalance, as explained in this video by Extra Credits.  Players of strategic games that involve a lot of pre game decisions often refer to these decisions and the information leading to them as "the meta game". In MOBA games like League of Legends or fighting games like Smash Bros. or Soul Caliber this amounts to selecting one's avatar character and the bonuses they will bring into the start of a match. In collectible and living card games like Magic: The Gathering and Android: Netrunner the meta game is one's deck building process and the popular types of decks among one's opponents.

The pre game decisions, the meta game, in sports include who to hire and how to train. In sports where game-to-game fatigue is a factor, such as hockey with goalies or baseball with pitchers, the meta also involves choosing who will start the game, and how well that matches against the opposing goalie or pitcher.

The general idea of metagaming is to make choices that counter the likely choices of opponents. Against a learning opponent, this requires constant adaptation.

Consider fashion, where to win is to receive  attention, admiration as a consumer and sales as a designer. Fashion is played by wearing/creating an outfit that stands out from that of the existing crowd.

Consider the red queen hypothesis, a biological principle whereby a species succeeds by apadting to its prey predators and competitors. Specifically, the red queen hypothesis is that since all species are doing this, the best a species can hope for is to keep up in evolution, never get ahead.

Sabremetrics got so big as a statistical toolset not simply because it was interesting or novel, but because it was actionable. It provided information that could be converted in decisions, instead of just being elegant or produce a pretty graph.

If hitting in baseball is due for a comeback, might it make sense to load up your farm team with sluggers and curveball pitchers now? Do you reduce your emphasis on stolen bases in anticipation of fewer pitches per at bat?

Would a change from walks and strikeouts to hitting favour franchises that traditionally rely on high scores like Texas, or ones that rely on many small hits like Kansas City?

As always, comments welcome, including those stating I'm wrong about everything.

Monday, 3 November 2014

Teach the Controversy

What if we started including short (500 words, 2 pages double spaced) essay assignments into the stats curriculum?  Students could choose from various controversial topics in stats. They could be referred to a small amount of literature, such as a paper or a couple of book chapters on their chosen issue.
 
Essay questions could include:
- Take a side, or compare Bayesian vs Frequentist methods.
- Take a side, or compare parametric vs non parametric methods.
- ... or simulations vs real data.
- How important is parsimony vs accuracy?
- How valuable is null hypothesis testing, what does it mask?
- Should pvalues be the gold standard?
- How feasible are causality studies?
- Is multiple testing a valid remedy?
- Is imputation a valid remedy?
- Are the flexibility of ultra-complex methods like neural networks worth the fact that they can't be explained or described reasonably?
- Why do we use the mean as the basis for everything instead of the median?
 
In service courses, the essays could be more about social issues that statistics illuminate rather than the methodology itself.
 
- Discuss what multiple regression reveals about the wage gap between sexes. 
- Discuss publication bias and how asymmetric tests like funnel plots can expose it.
- Discuss the pros and cons of bar graphs and pie graphs.
- Consider [attached infographic]. Describe the author is trying to convey. Describe, as best you can from this graphic, what is really going on? How could the graphic more clearly convey this?
 
There are a lot of articles in chance magazine that a social studies ugrad could add their own perspective to while learning to incorporate statistical arguments into their own essays. Math background students benefit from the writing practice and wider perspective, and writing students will have an opportunity to use their strengths in an otherwise intimidating class.
 
The essay prompts above can be answered at multiple levels of depth, allowing them to be slotted into different courses. Finally, this gives the instructor license to remove other written questions from the remaining assignments, which can offset the change in marking load. The necessary material for writing would come at the cost of either some methods or some mathematical depth, but given the challenges in modern statistics, being able to consider questions like those above is worth that cost.

Wednesday, 29 October 2014

Fractional data types

There's likely a good solution to this already, but it eludes me:  Why are there no fraction data types at the same basic level at int, char, and float?

A lot of statistical operations, like matrix inversions, are computationally very expensive. Part of the reason they take so long to perform for large matrices is because of all the division of numbers that's going on. Compared to addition and multiplication, division of floating point numbers is very hard for computers. It has to be done in a form of binary long division, which involves a subtraction and multiplication for each bit.

However, division of fractions is simply cross-multiplication, which is cheap.
Consider a double length float in a 32-bit system. It has 64 bits, 52 which store the actual number ( the mantissa), 11 which store how large the number is, and 1 for the plus or minus sign.

Modelled on this, a 64-bit fraction data type could have two 28-bit mantissae, 11 bits for the magnitude, and 1 for the sign.

Note that fractions are not unique representations of numbers. 18/12 is 6/4 is 3/2. We can exploit that to use only a single sign and magnitude for the fraction as a whole.

Conversion from fraction to double is a simple division, so we can't avoid division entirely, but we could do intermediate steps as fractions.

Conversion from double to fraction is harder. It can be done in a arbitrary manner, of setting the denominator to 1, but in the above system, 28 bits of precision are lost, and the whole denominator is wasted storing '1'.

Is there a way to convert a double to fraction to minimize loss? Can it be determined in a way that's cheap enough to make conversion worthwhile? My uninformed hunch is converting x to x^1.5 / x^0.5 would work, but square roots are still a bit costly, and I have no idea if it's particularly good at preserving precision.

Any ideas?

Sunday, 26 October 2014

SQL - An Introduction in 25 Minutes

Twice a year, the stats grad students from UBC and from SFU meet at the Harbour Centre downtown and have a one day seminar of student talks. Rather than present research, I gave a 25 minute introduction to SQL.

Specifically, it's a few slides on what SQL is, and some example queries using data from Major League Baseball's PITCHf/x data with the pitchRx package in R, and a package called sqldf. sqldf  interprets queries on R data frames that are stored in local memory or in .csv files. This package is very handy for writing practice queries when you don't have access to an external database, and faster than setting up one on localhost through Wamp server.

The example queries in the talk were a showcase of common clauses in a select query, and a simple join. Below are the PDF slides and the TeX code for the presentation if you wish to use it as a template. You won't be able to compile it without the images, so be sure to comment them out first.

SQL - An Introduction in 25 Minutes, PDF Slides, TeX Code

Saturday, 25 October 2014

Some fan-made Dominion cards.

Playwright (3+)
Action
You may overpay for this card. Gain one coin token for each 1 you overpay.
+1 Card, +1 Coin Token

This is a foil to the Guilds card Masterpiece, which is a poor card on its own, but allows to you overpay to put a Silver into your deck for each amount overpaid. 

It's called Playwright because coin token cards traditionally are people, and it seems plausible for a playwright to produce one amazing work and then be only marginally valuable after. What I like about Masterpiece is that it's a viable buy for 7 coins, the 'deadzone', without being board-defining.

Playwright fixes the deadzone problem doubly - it gives you something worth buying for 7, gives you enough coin tokens to prevent issues in the future, or set up for a megaturn.



Dig Site
Victory/Treasure (0*)
This card cannot be bought normally.
You may gain this card when you trash a victory card.
1 VP, +1 Money.


Museum
Victory/Action (0*)
You may gain this card when you trash a card worth 6 or more.
3 VP, +1 Action, +1 VP chip.


Dig Site is intended to give some purchasing power when you trash an Estate, or Overgrown Estate, or beef up Silk Road without much drawback. Museum is a late game vehicle to convert Golds into Victory Points, and it's not a dead card if it ends up in your hand.

Farmland combos brilliantly with either of these cards.

These cards push the bounds of the original game a bit because there's usually at least ten non-basic cards that can be bought in a game. If there's a card with a special gain condition, like Prize, or Madman, it's placed in the game as an attachment to an existing card (Tournament and Hermit, respectively). These could be attached to an... Archeologist card?

The creator of Dominion has said he's not interested in making more cards because the game is complex enough with 220+ cards across all the sets. However, I feel like there's still room for expansion in the single-player mode that's playable online, much like how there are special cards and conditions that are only in Hearthstone's Naxxrammas fights.

The Value of Choice in Game Design

Choice has value, but it’s not always possible to quantify. This allows a game mechanics to be recycled. Consider the following three cards in Magic: The Gathering.

1. Lightning Bolt - A spell to deal 3 damage to a creature or player once, and at any time.
2. Kird Ape - A creature with 2 attack and 3 defence, as long as a certain easily attainable condition is met, and worse otherwise.

3. Vexing Devil - A creature with 4 attack and 3 defence, but the opposing player may choose to take 4 damage immediately instead of having this creature enter play.


 

All of the cards have the same requirements to be played (one red mana). There are differences in the years between when each card was tournament legal, but all three cards are considered better than the typical card. In short, all three of these cards are highly interchangeable in a deck. So which one is the best?

Case I:

If the opposing player allows Vexing Devil to come into play, it has more attack than a Kird Ape would, so it's better than using a Kird Ape in that situation.

Case II:

If the opposing player does NOT allow Vexing Devil to enter play, then the opposing player takes 4 damage. This is more than the 3 damage than a Lightning Bolt would deal.

In either case, it seems like Vexing Devil performs better than either card. What makes these three cards fairly comparable? The opponent's choice does.

From the player of Vexing Devil's perspective, they will always end up with the least favourable of the two cases. If either one of those cases were as good as the two alternative cards mentioned, the alternative card should be used instead. So, to make Vexing Devil viable, both cases must be better than those on alternative cards.

From the opponent's perspective, they can choose to let the creature come into play only when they can deal with it in a way that is less costly than taking 4 damage.

In short, the value of choice must be priced into the relative strength of game elements. This is what makes the Queen in chess strictly better than either the Rook or the Bishop. The Queen can only make moves that either the Rook or the Bishop can do, but having the choice to do either is what gives her her power.

 

Consider one more card:

Forked Bolt – Deals 2 damage to target creature or player, OR 1 damage to each of 2 such targets.

This card is also considered above-par, and has the same mana requirements as the other three. It's arguably weaker than Lightning Bolt, but not by much. Why? The player of this card has the additional choice of splitting the damage.