Continuous Uniform distribution is used to model a flat probability existence with a range (A,B). Its probability density can be depicted as
The follow figure shows probability density curve for a Continuous Uniform distribution defined with range (1,3).
In R programming, we can use following functions in computation of Continuous Uniform distribution.
dunif() – for probability density ,
punif() – for cumulative probability,
qunif() – for quantile value ,
dunif() – for random number generation .
Following code snippet shows how to use these functions in RStudio.
# generating a vector of numbers
x_vec <- seq(0, 10 , by = 0.2)
x_vec
#output
[1] 0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0 2.2 2.4
[14] 2.6 2.8 3.0 3.2 3.4 3.6 3.8 4.0 4.2 4.4 4.6 4.8 5.0
[27] 5.2 5.4 5.6 5.8 6.0 6.2 6.4 6.6 6.8 7.0 7.2 7.4 7.6
[40] 7.8 8.0 8.2 8.4 8.6 8.8 9.0 9.2 9.4 9.6 9.8 10.0# calculating #calculate probability density for these numbers in a Continuous Uniform
#probability distribution, with range defined on (3,8)
dunif(x_vec, min = 3, max = 8)
#output
[1] 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.2
[17] 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2
[33] 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.0 0.0 0.0 0.0 0.0 0.0 0.0
[49] 0.0 0.0 0.0
#plot probability density
plot(dunif(x_vec, min = 3, max = 8))
#calculate cumulative probabilities
punif (x_vec , min =3 , max = 8)
#plot cumulative probabilities
plot(punif (x_vec , min =3 , max = 8))
#create a vector for probalities
q_vec <- seq(0, 1 , by = 0.1)
q_vec
#output
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0plot(qunif(q, min = 3, max = 8))
#quantile of these probability values
#quantile means the associated cumulative probability of values less than
#this quantile value
qunif(q_vec, min = 3, max = 8)
#output
3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0
#random number generation, 10 such random numbers from Continuous Uniform
#distribution
runif(10, min=3, max=8)
#output
[1] 4.892670 3.914989 7.944297 3.637653 4.492242 7.196020 4.513473
[8] 7.857784 6.017247 6.964857
Click here to download Python Course Source Files !
For online Python training registration, click here ! Pandas provides flexible ways of generating data…
For online Python training registration, click here ! Data frame is the tabular data object…
Click her for course registration ! When a data frame in Python is created via…
We provide affordable online training course(via ZOOM meeting) for Python and R programming at fundamental…