Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The post The Uniform Distribution in R appeared first on Data Science Tutorials

What do you have to lose?. Check out Data Science tutorials here Data Science Tutorials.

The Uniform Distribution in R, A uniform distribution is a probability distribution where each value in the range from a to b has an equal chance of being selected.

The following formula can be used to determine the likelihood that a value between x1 and x2 will fall within the range from a to b.

Is Data Science a Dying Profession? – Data Science Tutorials

`P(obtain value between x1 and x2)  =  (x2 – x1) / (b – a)`

Uniform distribution example

The uniform distribution has the following properties:

• The mean of the distribution is μ = (a + b) / 2
• The variance of the distribution is σ2 = (b – a)2 / 12
• The distribution’s standard deviation, or SD, is σ = √σ2

## The syntax for uniform distribution in R

We’ll utilize R’s two built-in functions to provide answers using the uniform distribution.

glm function in r-Generalized Linear Models – Data Science Tutorials

They are:

In the formula dunif(x, min, max), where x is the value of a random variable and min and max are the distribution’s minimum and maximum values, respectively, the probability density function (pdf) for the uniform distribution is calculated.

When x is the value of a random variable and min and max are the minimum and maximum values for the distribution, respectively, punif(x, min, max) generates the cumulative distribution function (cdf) for the uniform distribution.

Here you may access the complete R documentation for the uniform distribution.

How to Create an Interaction Plot in R? – Data Science Tutorials

Using the Uniform Distribution to Solve Problems in R

Example 1:

A bus arrives at a bus stop every 8 minutes. What is the chance that the bus will arrive in 5 minutes or less if you arrive at the bus stop?

Solution:

Since we want to know the cumulative probability that the bus will arrive in 5 minutes or less, given that the minimum time is 0 minutes and the maximum time is 8 minutes, we can easily use the punif() function to calculate the probability that the bus will arrive in 5 minutes or less.

```punif(5, min=0, max=8)
 0.625```

There is a 0.625 percent chance that the bus will arrive within five minutes.

Statistical test assumptions and requirements – Data Science Tutorials

Example 2:

A particular species of frog weighs consistently between 15 and 25 grams. What is the likelihood that a frog you choose at random will weigh between 17 and 19 grams?

Solution:

The cumulative probability of a frog weighing less than 19 pounds will be calculated, and the cumulative likelihood of a frog weighing less than 17 pounds will be subtracted using the syntax shown below.

```punif(19, 15, 25) - punif(17, 15, 25)
 0.2```

Therefore, there is a 0.2 percent chance that the frog weighs between 17 and 19 grams.

Explanation 3:

An X game lasts between 120 and 170 minutes on average. How likely is it that a randomly chosen X game would go longer than 200 minutes?

Solution:

We may use the formula 1 – to find the answer to this (probability that the game lasts less than 200 minutes).

Top 10 online data science programs – Data Science Tutorials

This comes from

`1 - punif(200, 120, 170)`

 0

There is a 0 percent chance that a randomly chosen X game will go over 200 minutes.

The post The Uniform Distribution in R appeared first on Data Science Tutorials

Learn how to expert in the Data Science field with Data Science Tutorials.