Case Study: HMM with Basketball Player Tracking Data


I’d like to contribute a case study to the Stan case studies page that discusses how to use Hidden Markov Models (HMMs) with basketball player tracking data. Specifically, I show how to tag drive events and identify defensive assignment (i.e. Stan implementations of previous research). From my experience, a majority of the basketball analytics community is unfamiliar with HMMs so the first section of the write up outlines the “data story” behind a simple HMM and how to implement it in rstan.

The write up and code are available here. A direct link to the write up is available here.

I’d appreciate any comments/feedback to improve the work to make it contribution-worthy.


Very cool. Note that the inline math rendering seems to not be working at the html version.

This is cool, thanks for sharing! I love the animations showing the schematic view of the basketball play along with time-series of observations and parameter estimates.

Note that in the beginning where you explain the HMM, you have the following piece of code:

 generated quantities {
real best_total_logp;

(which is also in the Stan User Guide page on HMMs) - but this variable best_total_logp is never actually used.

@mike-lawrence it seems to be rendering fine for me (on Chrome and Safari). Do you think it might be a browser issue? The only issue seems to be the lack of syntax highlighting, which is fine in the html file in the repo but not when GitHub renders it.

@MauritsM thanks for the catch. I’ll update the Stan files accordingly.

Ah, I’m viewing from firefox. When I pop over to chromium, it renders fine. Checked to see if I had any script blockers active in firefox, and I don’t, so I have no idea why it’s not rendering there.

@imadmali ou should have push permission to add case studies. You are a developer. I can take a look at the case study next week if you’d like some feedback first. Please ping me by email if you’d like me to—I might miss a reply on Discourse.