:<math> f''(x) = f(x+2) - 2 f(x+1) + f(x)</math>
I required that a city-year had more than two layers, as it takes at least 3 layers to form an elbow. I then used <math>f'(x) </math> to determine the layer index from which the variance explained was monotonic (i.e., there was no change in sign in <math>f'(x) </math> in higher layer indices), and used <math>f''(x) </math> to find the layer index <math>i</math> at which <math>varexp_i = min(varexp)</math> for some city-year. I then marked <math>i+1</math> as the elbow layer for that city-year, as we are using forward differences, not central differences.
====Fixing the layer index====