Chi-square FAIL when many cells have small expected values

William Perkins, Mark Tygert, and Rachel Ward write:

If a discrete probability distribution in a model being tested for goodness-of-fit is not close to uniform, then forming the Pearson χ2 statistic can involve division by nearly zero. This often leads to serious trouble in practice — even in the absence of round-off errors . . .

The problem is not merely that the chi-squared statistic doesn’t have the advertised chi-squared distribution—a reference distribution can always be computed via simulation, either using the posterior predictive distribution or by conditioning on a point estimate of the cell expectations and then making a degrees-of-freedom sort of adjustment.

Rather, the problem is that, when there are lots of cells with near-zero expectation, the chi-squared test is mostly noise.

And this is not merely a theoretical problem. It comes up in real examples.

Here’s one, taken from the classic 1992 genetics paper of Guo and Thomspson:

And here are the expected frequencies from the Guo and Thompson model:

The p-value of the chi-squared test is 0.693. That is, nothing going on.

But it turns out that that if you do an equally-weighted mean square test (rather than chi-square, which weights each cell proportional to expected counts), you get a p-value of 0.039. (Perkins, Tygert, and Ward compute the p-value via simulation.) Rejection!

This is no trick. All those zeroes and near-zeroes in the data give you a chi-squared test that is so noisy as to be useless. If people really are going around saying their models fit in such situations, it could be causing real problems.

Here’s what’s going on. The following graph shows the discrepancies ((Observed – Expected)/sqrt(Expected)) which are squared and summed to form the chi-squared statistic:

Only one of the cells is really bad—that point on the lower-right—but it has a high expected value (it’s one of the largest cells in the table), and when you take the equally-weighted mean square (which is equivalent to weighting the contributions to the chi-square in proportion to the expected count), you get a big total value. In the chi-squared statistic, all that noise in the empty cells is diluting the signal.

Statistical models and actual models

A statistician friend reports the following conversation at a dinner party:

My friend: “So what do you do?”
A good looking fellow: “I do modeling. What about you?”
My friend: “Actually, I do modeling too…”

Which reminds me . . . on Halloween I went out trick-or-treating straight from work. I decided to tell people I was dressed as a “dork.” Everyone was amused. But next year I want to do a real costume.

Josh Tenenbaum presents . . . a model of folk physics!

Josh Tenenbaum describes some new work modeling people’s physical reasoning as probabilistic inferences over intuitive theories of mechanics.

A general-purpose capacity for “physical intelligence”—inferring physical properties of objects and predicting future states in complex dynamical scenes—is central to how humans interpret their environment and plan safe and effective actions. The computations and representations underlying physical intelligence remain unclear, however. Cognitive studies have focused on mapping out judgment biases and errors, or on testing simple heuristic models suitable only for highly specific cases; they have not attempted to give general-purpose unifying models. In computer science, artificial intelligence and robotics researchers have long sought to formalize common-sense physical reasoning but without success in approaching human-level competence. Here we show that a wide range of human physical judgments can be explained by positing an “intuitive mechanics”, an implicit theory in the brain that embodies abstract laws of motion surprisingly faithful to the laws of classical (Newtonian) mechanics. Intuitive mechanics differs from scientific mechanics in that it is instantiated in runnable simulations, akin to the outputs of a video game physics engine, rather than a physicist’s equations that can be solved analytically; it is resource-bounded, supporting only judgments that can be made based on a few low-precision, short-lived simulation runs; and it is probabilistic rather than deterministic, allowing Bayesian inferences and predictions but prone to biases due to noise. A formal model of intuitive mechanics closely fits human judgments in a number of behavioral experiments, explaining both how people make such rich and accurate physical inferences in general and also why they show several systematic biases.

Cool. I love models of folk science.

P.S. Here’s a short conference paper by Hamrick, Battaglia, and Tenenbaum that contains a preliminary report on some of the above work. A journal paper is in progress.

Deadwood in the math curriculum

Mark Palko asks: What are the worst examples of curriculum dead wood?

Here’s the background:

One of the first things that hit me [Palko] when I started teaching high school math was how much material there was to cover. . . . The most annoying part, though, was the number of topics that could easily have been cut, thus giving the students the time to master the important skills and concepts.

The example that really stuck with me was synthetic division, a more concise but less intuitive way of performing polynomial long division. Both of these topics are pretty much useless in daily life but polynomial long division does, at least, give the student some insight into the relationship between polynomials and familiar base-ten numbers. Synthetic division has no such value; it’s just a faster but less interesting way of doing something you’ll never have to do.

I started asking hardcore math people — mathematicians, statisticians, physicists, rocket scientists — if they.’d ever used synthetic division. By an overwhelming margin, the answer I got was “what’s synthetic division?” Not only did they not need it; it made so little impression that they forgot ever learning it. . . .

Since we need to pare down the curriculum, what you choose to cut? Specifically, what mathematical topics that you learned in school can future generations do without?

I’m too distant from the high school curriculum to have much to offer. I think the math in the local elementary school goes a bit too slow, but of course I’d think that. There has been some progress over the decades, though. The teachers used to get angry at my sisters when they’d read ahead in the workbook, but by the time I came around, they’d let me curl up with a math book and leave me alone. As long as I kept my mouth shut they had no problem with me.

More recently, we spent a year on sabbatical in France (as regular blog readers will recall), and one thing I liked about the public schools there was the uniform national curriculum. It was completely clear what was being covered each year, you could go to a bookstore and get a book such as “L’Année de CP” which had exercises covering the whole year (“CP” is first grade), you could see what was coming next, etc. I liked this transparency. Maybe it wouldn’t work so well in the higher grades but I liked it for elementary school.

Does anyone have thoughts on Mark’s original question about the high school curriculum?

The sort of thing that gives technocratic reasoning a bad name

1. Freakonomics characterizes drunk driving as an example of “the human tendency to worry about rare problems that are unlikely to happen.”

2. The CDC reports, “Alcohol-impaired drivers are involved in about 1 in 3 crash deaths, resulting in nearly 11,000 deaths in 2009.”

No offense to the tenured faculty at the University of Chicago, but I’m going with the CDC on this one.
Continue reading →

Insecure researchers aren’t sharing their data

Jelte Wicherts writes:

I thought you might be interested in reading this paper that is to appear this week in PLoS ONE.

In it we [Wicherts, Marjan Bakker, and Dylan Molenaar] show that the willingness to share data from published psychological research is associated both with “the strength of the evidence” (against H0) and the prevalence of errors in the reporting of p-values.

The issue of data archiving will likely be put on the agenda of granting bodies and the APA/APS because of what Diederik Stapel did.

I hate hate hate hate hate when people don’t share their data. In fact, that’s the subject of my very first column on ethics for Chance magazine. I have a story from 22 years ago, when I contacted some scientists and showed them how I could reanalyze their data more efficiently (based on a preliminary analysis of their published summary statistics). They seemed to feel threatened by the suggestion and refused to send me their raw data. (It was an animal experiment, so no issues with confidentiality etc., and it was a government lab, so it had nothing to do with trade secrets or proprietary data.)

P.S. Regular readers will not be surprised to find that I hate the pie charts, dislike the bar chart, and absolutely detest the tables in the above-linked article. It’s great work but I think the paper would’ve been improved through a more careful graphical presentation in which the authors thought a bit about their goals in presenting the numbers and their comparisons of interest.

This post does not mention Wegman

A correspondent writes:

Since you have commented on scientific fraud a lot. I wanted to give you an update on the Diederik Stapel case. I’d rather not see my name on the blog if you would elaborate on this any further. It is long but worth the read I guess.

I’ll first give you the horrible details which will fill you with a mixture of horror and stupefied amazement at Stapel’s behavior. Then I’ll share Stapel’s abject apology, which might make you feel sorry for the guy.

First the amazing story of how he perpetrated the fraud:
Continue reading →

How Khan Academy is using Machine Learning to Assess Student Mastery

This is sooooo cool. The actual statistical methods they are using are pretty crude, but that’s fine. What’s important is their focus on the important goal. It’s sort of like Bill James or Nate Silver: if you’re using good information, and you’re focused on good questions, then the fancy statistics can come later (or from others).

In most educational efforts I know of (including my own), very little is done to target assessments to improvements for individual students. I really like what they’re doing here and it reminds me how I want to figure out how to do something similar in my own teaching and course materials.

MacKay update: where 12 comes from

In reply to my question, David MacKay writes:

You said that can imagine rounding up 9 to 10 – which would be elegant if we worked in base 10.

But in the UK we haven’t switched to base 10 yet, we still work in dozens and grosses. (One gross = 12^2 = 144.) So I was taught (by John Skilling, probably) “a dozen samples are plenty”.

Probably in an earlier draft of the book in 2001 I said “a dozen”, rather than “12”. Then some feedbacker may have written and said “I don’t know what a dozen is”; so then I sacrificed elegant language and replaced “dozen” by “12”, which leads to your mystification.

PS – please send the winner of your competition a free copy of my other book (sewtha) too, from me.

PPS I see that Mikkel Schmidt [in your comments] has diligently found the correct answer, which I guessed above. I suggest you award the prizes to him.

OK, we’re just giving away books here!

P.S. See here for my review of MacKay’s book on sustainable energy.

David MacKay sez . . . 12??

I’ve recently been reading David MacKay’s 2003 book, Information Theory, Inference, and Learning Algorithms. It’s great background for my Bayesian computation class because he has lots of pictures and detailed discussions of the algorithms. (Regular readers of this blog will not be surprised to hear that I hate all the Occam-factor stuff that MacKay talks about, but overall it’s a great book.)

Anyway, I happened to notice the following bit, under the heading, “How many samples are needed?”:

In many problems, we really only need about twelve independent samples from P(x). Imagine that x is an unknown vector such as the amount of corrosion present in each of 10 000 underground pipelines around Cambridge, and φ(x) is the total cost of repairing those pipelines. The distribution P(x) describes the probability of a state x given the tests that have been carried out on some pipelines and the assumptions about the physics of corrosion. The quantity Φ is the expected cost of the repairs. The quantity σ^2 is the variance of the cost — σ measures by how much we should expect the actual cost to differ from the expectation Φ.

Now, how accurately would a manager like to know Φ? I would suggest there is little point in knowing Φ to a precision finer than about σ/3. After all, the true cost is likely to differ by ±σ from Φ. If we obtain R = 12 independent samples from P(x), we can estimate Φ to a precision of σ/√12 – which is smaller than σ/3. So twelve samples suffice.

By “P(x)”, I think he means p(theta|y), by “10 000”, I think he means 10,000, and by “R” I think he means n_{sims} or something like that.

Setting aside the “two cultures separated by a common language” thing, and taking MacKay at his word regarding the priorities of pipeline repair managers, I’m in complete agreement with this reasoning. I’m always telling people they don’t need as many independent draws as they think they need, and I squirm in frustration when I read a paper where the authors proudly announce that they ran 100,000 simulation draws.

My only question is . . . where did the “12” come from in MacKay’s passage? When I first saw the number there, I assumed it would have something to do with the variance of the uniform distribution. But that doesn’t seem to come up at all.

Accepting MacKay’s stipulation that σ/3 would be enough precision in this sort of example, shouldn’t he have said that 9 random draws would suffice? I could see him rounding that up to 10. Or even 16, if he wanted to get all base-2 on us. But why 12? I don’t get this at all.

Free pdf copy of MacKay’s book to whoever gives the best explanation.

[Update: here’s the answer.]

P.S. The close reader will have noticed that, unlike you-know-who, I actually read before copying and pasting. That’s why I inserted the ^ in σ^2 above—the superscript got lost in the copying from pdf.
Continue reading →