The statistical approach to random numbers is very particular. In gambling and games of chance, random numbers have the main role. So, in a sequence of posts in Armancomputer magazine, I will discuss probability distribution and introduce some commands in R language, to generate random numbers from the main statistical distributions such as Normal, Uniform, t-student, and chi-square.
Random Number Generation and Statistical Distribution
In probability Theory, we compute probability based on the sample space and event set. As a rule, the probability of an event is its size (as a set) divided by the sample set size. However, this definition has some limitations.
- If sample space is not countable, how is probability computed.
- If the event is not countable, how is probability computed.
- …
And some many questions about real-world probability and random phenomena.
- is there any rule for computing probability in the real world?
- is there any pattern to see an event for the random phenomenon.
- …
These problems, lead the scientists to a new approach to probability and its rules.
Statistical distributions and Random numbers
Many real random phenomena have a pattern of occurrence. This rule is named the Probability distribution. However using some translations, we convert a set function of probability (measure theory) to a real function to recognize these patterns or distributions. So, the set theory is converted to real function problems in probability and statistical theory.
Normal Distribution
If you come across a random phenomenon its outcome is real numbers, it may fit by Normal Distribution. The normal distribution is identified by the below plot.
The plots show that there are two parameters for normal distribution. Mean as shown by $\mu$ and variance $\sigma^2$. The rnorm command in R may generate random numbers from a normal distribution. As it is clear, rnorm has three parameters.
1 2 |
rnorm(n,mean,sd) rnorm(100,0,1) |
The first parameter (n) shows how many random numbers may be generated. The second and third parameters are normal distribution characteristics. Mean and Standard deviation (square root of variance). The R language code below shows how to generate normal random numbers and visualize their distribution.
1 2 3 4 |
n = 10000 mean = 0 sd = 1 x=rnorm(n,mean,sd) |
The probability distribution graph is plotted as follows:
PS: If using the ggplot2 library, your command may be as follows:
1 2 3 4 5 6 7 8 |
n = 10000 mean = 0 sd = 1 x=rnorm(n,mean,sd) plot(density(x)) library(ggplot2) x = as.data.frame(x) ggplot(x,aes(x = x)) + geom_density(alpha = 0.5) |
In the next post, I will describe how to compare two normal distributions through their plots.
excellent submit, very informative. I’m wondering wwhy the opposite speccialists off
this sectorr doo nnot notice this. You musst prroceed youjr writing.
I’m sure, you’ve a great readers’ base already!