I'm thinking retirement is pretty much set several months in advance. Maybe years--as soon as a set is produced, TLG has a sense of its lifespan. Knowing how LEGO operates (i.e., the quality of their business model), I'm pretty sure they do have projected production lifespans upon launch. They study the sales data and trends. A set is effectively "retired" long before we purchase the last box. Seal codes give us some clue, but we have little ideas about the size of production runs, etc. Even the EU stock tracker has proven somewhat mysterious and oddly inconsistent.
Just a guess like everyone else's, but I agree it becomes complicated when a set's sales jumps like Red 5 did early this year. All of a sudden, a set has altered its sales path and doesn't provide a clear trend. I think Red 5 was likely on track for retirement this spring, but resellers smelled blood and really messed with the data. Just a hunch based on the looooong backorder time (close to three months for one of my orders).
Either way, its fun to speculate.