Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

My statistics are rusty, but here's what I'm trying to do. Creating an application around football and have this distribution around rushing yards per attempt.

http://farm3.static.flickr.com/2580/3813734078_7801aab534_o.png

I'm just looking at the NFL average in the chart. Basically, I want to create a random number generator that gives me a number along that distribution. I'll want to do the same for passing too. Since this is football, I'd like to generate from roughly -10 to 100.

I reverse engineered the plot in Excel, but my memory is absolutely failing on how I can create or fit a known distribution to this plot. I left my math skills behind in college and have just been doing general programming since.

share|improve this question
2  
If $f(x)$ is the probability distribution, let $F(x) := \int_0^x f(t) dt$ and use $F^{-1}(r)$ for random number $r$ uniformly generated in $[0,1]$. –  Scaramouche Sep 4 '13 at 2:23
    
I advise you not to do this. Use the Mersenne Twister or other vetted PRNG. "Anyone who considers arithmetical methods of producing random digits is, of course, in a state of sin." Robert Coveyou - it's incredibly difficult to make a good random number generator. –  Eric Tressler Sep 4 '13 at 2:37
    
Any insight on pulling f(x) from the distribution plot or insight on how to tweak an existing distribution to get reasonably close to the chart. –  Nick Sep 4 '13 at 3:42
    
Also, I don't want to create a new way of generating random numbers, I just want them on a distribution that fits the plot I shared. –  Nick Sep 4 '13 at 14:17
add comment

2 Answers

up vote 1 down vote accepted

You don't need a known distribution, just a computable function that approximates the curve closely enough. You can get fancier but if you generate pairs of uniform random variables using an acceptable PRNG, scaled so one is on your -10,100 scale and the other is 0 to the max value of your approximation function. Call the first one x and the second y, if f(x) > y then accept x as the next value. Otherwise discard both x and y and generate a new pair. The distribution of accepted x values will follow the curve.

Efficiency can be poor if f has long thin tails. Than you need to generate x from a non-uniform distribution g that approximates f but dominates it and y on [0,1), accept when y < g(x)/f(x). But that's just for efficiency, it will work as described above.

share|improve this answer
    
I think I understand this one conceptually the best so I'll give it a shot. Thinking visually, you're trying to generate a point under the curve of your distribution and keep trying until you succeed? –  Nick Sep 5 '13 at 18:31
add comment

This answer assumes that you have a collection of samples representing the gains in yards.

Use Kernel density estimation with a Gaussian kernel, to approximate the actual probability density function for the gains.

For the range of values that you want to generate $(-10, 100)$, go through and evaluate each value against the estimate to calculate the probability and store that result in an array location corresponding to the generated value. You can make this process as coarse or as fine grained as needed.

Create a new zero valued array and starting at the lowest value aggregate the values from the previous array ($cdf[i] = cdf[i-1] + pdf[i]$) at each index in order to produce an estimate of the cumulative density function.

(If on the final value the cdf does not equal one, you'll need to normalize the cdf array by going back through and dividing each entry by the last so that the sum adds up to one.)

As Scaramouche pointed out in the comments to your question, you can sample a value from the unit interval uniformly using a pseudo-random number generator in the programming language of your choosing.

From that value, you can then search over the cumulative distribution array to find the nearest match and use the corresponding array index to then calculate the value you want to report back between $(-10, 100)$.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.