Understanding uniform distributions
If we roll a fair dice, the likelihood of drawing any side is equal. By plotting the samples in a bar plot, we can see bars with equal heights. This type of distribution is known as uniform distribution. In this recipe, we will introduce how to generate samples from a uniform distribution.
Getting ready
In this recipe, you need to prepare your environment with R installed.
How to do it…
Please perform the following steps to generate a sample from uniform distribution:
First, we can create samples from uniform distribution by using the
runif
function:> set.seed(123) > uniform <- runif(n = 1000, min = 0, max = 1)
We can then make a histogram plot out of the samples from the uniform distribution:
> hist(uniform, main = "1,000 random variates from a uniform distribution")
For uniform distribution, we also can find the density at each point equals
1
, and the density function...