Skip to content

Data Science Tutorials

  • Home
  • R
  • Statistics
  • Course
  • Machine Learning
  • Guest Blog
  • Contact
  • About Us
  • Toggle search form
  • droplevels in R with examples
    droplevels in R with examples R
  • Get the first value in each group in R
    Get the first value in each group in R? R
  • Check whether any values of a logical vector are TRUE
    Check whether any values of a logical vector are TRUE R
  • How to Add a title to ggplot2 Plots in R
    How to Add a caption to ggplot2 Plots in R? R
  • How to Join Data Frames for different column names in R
    How to Join Data Frames for different column names in R R
  • Remove Rows from the data frame in R
    Remove Rows from the data frame in R R
  • R Percentage by Group Calculation
    R Percentage by Group Calculation R
  • test for normal distribution in r
    Test for Normal Distribution in R-Quick Guide R
The Uniform Distribution in R

The Uniform Distribution in R

Posted on September 18September 18 By Jim 2 Comments on The Uniform Distribution in R
Tweet
Share
Share
Pin

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)
[1] 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)
[1] 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)

[1] 0

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

Check your inbox or spam folder to confirm your subscription.

Tweet
Share
Share
Pin
R

Post navigation

Previous Post: Error in rbind(deparse.level …) numbers of columns of arguments do not match
Next Post: How do augmented analytics work?

Related Posts

  • How to Replace String in Column in R
    How to Replace String in Column using R R
  • Bind together two data frames by their rows or columns in R
    Bind together two data frames by their rows or columns in R R
  • Remove Columns from a data frame
    How to Remove Columns from a data frame in R R
  • Making games in R- Nara and eventloop Game Changers
    Making games in R- Nara and eventloop Game Changers Machine Learning
  • Detecting and Dealing with Outliers
    Detecting and Dealing with Outliers: First Step R
  • How to do Conditional Mutate in R
    How to do Conditional Mutate in R? R

Comments (2) on “The Uniform Distribution in R”

  1. Marc says:
    December 19 at 6:09 pm

    The function returns percentages in decimal form, so 0.625 is 62.5%. You can check this by running punif(.5) which returns 0.5 or 50%.

    Reply
    1. Jim says:
      December 19 at 9:00 pm

      Sure

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • About Us
  • Contact
  • Disclaimer
  • Guest Blog
  • Privacy Policy
  • YouTube
  • Twitter
  • Facebook
  • Top 7 Skills Required to Become a Data Scientist
  • Learn Hadoop for Data Science
  • How Do Online Criminals Acquire Sensitive Data
  • Top Reasons To Learn R in 2023
  • Linear Interpolation in R-approx

Check your inbox or spam folder to confirm your subscription.

 https://www.r-bloggers.com
  • display the last value of each line in ggplot
    How to add labels at the end of each line in ggplot2? R
  • Crosstab calculation in R
    Crosstab calculation in R R
  • How to move from Junior Data Scientist
    How to move from Junior Data Scientist Machine Learning
  • Add new calculated variables to a data frame and drop all existing variables
    Add new calculated variables to a data frame and drop all existing variables R
  • How to Create a Frequency Table by Group in R
    How to Create a Frequency Table by Group in R? R
  • Methods for Integrating R and Hadoop
    Methods for Integrating R and Hadoop complete Guide R
  • How to Turn Off Scientific Notation in R
    How to Turn Off Scientific Notation in R? R
  • How to perform TBATS Model in R
    How to perform TBATS Model in R R

Copyright © 2023 Data Science Tutorials.

Powered by PressBook News WordPress theme