John Cook shares a story of five different mathematical expressions that look different but are all actually the same thing.
It’s a cool example, and it reminds me of something that comes up a lot in statistics, that there can be more than one way to write the same model.
For a very simple example, you can write y = a + b*x + error, or y = X*b + error. This second expression is more general, so there’s the temptation to write the first model as y = b_1 + b_2*x + error. Which would seem fine, but then when you move to multilevel modeling where the coefficients vary by group j, it’s awkward to write y = b_1j + b_2j*x + error. It’s clearer to write y = a_j + b_j*x + error. The point is that you can use the a+bx notation when you only have one predictor and then move to Xb when you need it. Actually, even with two predictors it often makes sense to use separate letters for the coefficients. My go-to regression example is y = a + b*x + theta*z + error, where y is the outcome measurement, x is a pre-treatment predictor, and z is a treatment indicator or exposure variable. This can be displayed as a graph of y vs. x, using blue dots for the z=0 cases and red dots for the z=1 cases, and then plotting the lines y = a + bx in blue and y = (a + theta) + bx in red.
A more complicated set of examples arises in models of correlations in multilevel data structures. Section 12.5 of my book with Jennifer is called, Five ways to write the same model.” You can put the intercept in different places, you can express the structure using correlation or latent variables, all sorts of things. When writing the book, we spent lots of time trying to figure out the best notation to use, and then we had the realization that we didn’t need to choose, that indeed it’s better both for teaching and for practice to be more flexible. No need to try to pick one formulation to use for all problems.
“Five ways to write the same model” was an immensely clarifying section of Gelman and Hill for me.
DUH. Have you ever done circular proofs before? Ugh these physics/stats backgrounds. If you can show A->B and B->C and C-> A then all statements are equivalent. This is the first thing they show you. Abstract Algebra, Convex Analysis, whatever. How old are we, Andrew?
61
Hmm, this makes me wonder about something. Is there a similar value in having multiple equivalent representations of more general code?
For example, for ease of maintenance you might group all constants at the top of your code in a block, in alphabetical order, and then refer to them as needed. But when you’re debugging a function, it would be more convenient to see only the constants used by that one function, in the order they are used, and maybe even right next to where they are used. Same result, different presentation.