# Offensive Value of A Player – Part I: NBA shot log analysis

**Jun Ma - Data Blog**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

**tl;dr: here is my final web app for this project. You can right click the plot and download it to create your own case study. Enjoy! **

## Data used in the analysis

## Analysis using R

One for loop for different defender distance nested inside another for loop for shot distance. The following function takes a single data.frame argument in the shot log format and returns the FG%, total FGA, total FGM Pts and 2pt/total for each shot distance and defender distance. So depending on the input data.frame, we can get either the league average or the data for an individual player. I used chaining to simplify the code and it worked really well. I tried to use ddply(), it worked in the main script, however not inside a function due to some scoping bug.

## League average

**We’ve got a large enough sample size that we actually statistically proved it**(except shot distance > 30 ft, where the sample size is limited)!

As for shot selection, about quarter of the total shots are inside 5 ft or between 20-25 ft (this is a choice of compromise. NBA has a varying 3pts distance from 22 to 24 ft, so it is difficult to use shot distance for 2pt/3pt indication. However, about 75% of the shots between 20-25 ft are 3 pointers. So this range is a fairly good indicator for close 3 pointers). These two types shots are easy shots, or easy shots-with-good-return. 8.5% are long 3 pointers and less than 1% total for desperation shots (30-35 ft and 35+ ft).

On the other hand, 46% of the shots are open (and 18% are wide open). Another 18% are closely contested while 37% are within normal defender distance 2-4 ft. By displaying an individual player’s shot selection, we can see whether this player likes 3 pointers, prefers open shots and etc.

## Player value added to team offense

1, obtain the league average FG% (as in previous section)

2, for each player, calculate the expected Pts (equals FGA * average FG%) and actual Pts scored at each location each defender distance

3, take the difference between these two, the more positive the difference is, the more value that player added to team offense from a scoring point of view.

For those who have negative impact to their team, we see Mudiay and Rose leading the way. If you take a look their FG% break down, it is mostly because they couldn’t finish contested shots in the paint and open 3 pointers. Notably, Kobe is also in the bottom 5.

All right, there you have it. I will put another article on how to construct the shiny app during this holiday season. Until then, have fun comparing your favourite player with the rest!

**leave a comment**for the author, please follow the link and comment on their blog:

**Jun Ma - Data Blog**.

R-bloggers.com offers

**daily e-mail updates**about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.