Ask Your Question
0

integers following Normal distribution

asked 2012-12-21 00:55:36 -0600

anonymous user

Anonymous

Hello,

how can I produce positive integers, say in (1,n), which follow the normal distribution with parameters (m,sigma).

Thanks.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2012-12-22 00:50:59 -0600

ppurka gravatar image

You could use the binomial distribution to approximate a normal distribution with only integer entries (because of the Central Limit Theorem). You will have to relate the mean of the binomial to the mean of the normal distribution. However, you can not get both the mean to be m and variance to be sigma exactly for any m and sigma, since for the binomial distribution they are closely related.

edit flag offensive delete link more
0

answered 2012-12-21 01:26:39 -0600

Jesustc gravatar image

updated 2012-12-21 04:44:37 -0600

I think it is pretty self explanatory:

# Sample size (not counting negatives!)
sample_size = 10000

# Parameters of the distribution
mean = 10
sigma = 10
dist = RealDistribution('gaussian', sigma)

# Getting the elements (notice the 'mean' in 'event'!)
sample = []
while len(sample) < sample_size :
    event = round(mean + dist.get_random_element())
    if event >= 0 :
        sample.append(event)

# Getting the frequencies and plotting
sample_range = range(min(sample),1+max(sample))
frequencies = [sample.count(i) for i in sample_range]
list_plot(zip(sample_range,frequencies),gridlines=[[mean,mean-sigma,mean+sigma],[]])
edit flag offensive delete link more

Comments

Thank you for your answer. If mean is integer then it is ok, you get integers following the normal distribution. If mean is not integer then the sampling set is not an integer vector.

Helen gravatar imageHelen ( 2012-12-21 04:15:09 -0600 )edit

That's true, sorry! I edited and now it should be fine: "event = round(mean + ...)". Cheers!

Jesustc gravatar imageJesustc ( 2012-12-21 04:45:26 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-12-21 00:55:36 -0600

Seen: 594 times

Last updated: Dec 22 '12