Pages

Sunday, May 9, 2010

Random Basketball Shooting (Explains High Nerd Score)

Today, after enjoying watching the Lakers go up 3-0 on the Jazz, I decided to go to the gym.  At UC Irvine, we have a nice track that borders a few basketball courts.  While running around the track, I watched the players miss some pretty lousy shots.

Anyways, I began wondering how often you would make a basket if you literally shot randomly.  I decided I had to know the answer so I went home and wrote a Monte Carlo code (in Python of course).  (Now I know why I got such a high nerd score.)

Here is the code:


As you can see from the code I put a player on a random spot on the floor from which he/she shoots a random shot.   I used this to get the details of the court size.  The units are in feet except the angle of the shot which is in radians.

I assume that the average random shot a person would make would have the distance of a typical "free throw" shot as it passes the the "10 foot plane" the rim sits at with a standard deviation of half that distance.    Furthermore, I don't take into account the advantage of the backboard or the infrequent shot off the wall into the rim.  However, this is deficiency (hopefully) is compensated by the rim being square instead of round (and therefore having more surface area) plus not allowing ball to "bounce out".

I then ran this code 100 times to get an error estimate.

And here is the results:  If you were to randomly shoot a ball in a basketball court a million times you should expect to make 681 +/- 26 (0.068%) out of the million in either basket and 342 +/- 19 (0.034%) in your own basket.

Therefore, if you are playing basketball and are not making ~ one out of every 1468 (unblocked) shots, (in either basket) there is something really wrong with you.  

6 comments:

  1. You're also not factoring in the height difference between the shooter and the basket. A more accurate simulation would be to randomize the force, angle, and heading of the throw, and calculate the parabolic trajectory.

    Oh, and BTW: you don't need to import "random" from numpy. It's its own standalone module. "from random import uniform gauss" works just fine; replace the "normal" function calls with "gauss".

    ReplyDelete
  2. Thanks Soren. Yes things can be better approximated and in the future I will only import pylab. :)

    After your comment I noticed importing pylab imports numpy's version of random. Buy I could have always used the basic random package as well.

    ReplyDelete
  3. Joseph,

    Cool. One of my professors complained that a couple of students did worse than guessing on a multiple choice exam. I don't recall how he calculated it. He may have used the binomial expansion a'la (NCr)(p^r)(q^N-r).

    I like your use of monte carlo resampling. A few years ago some people wondered if resampling and randomization tests would overtake classical-frequentist statistical approaches. It hasn't happened yet, at least not where I work. Now some are wondering is Bayesian analyses will overtake classical approaches. I'll guess no.

    ReplyDelete
  4. Dave C.,

    Thanks for the comment. I think random sampling methods are great, especially because many real world processes have a lot of randomness to them. They can be pretty darn accurate too. (In comparing theory with experiment.)

    ReplyDelete
  5. Resampling techniques like the Permutation test are good when data do not satisfy parametric normalcy assumptions and when nonparametric alternatives are underpowered. It's just that so few people have heard about them.

    ReplyDelete

To add a link to text:
<a href="URL">Text</a>