R Tutorial: Discrete distributions

Susanne Nahmelewska covers discrete uniform, Bernoulli, and binomial distributions in R. Learn the naming conventions for probability functions (d, p, q, r prefixes), generate random samples with rbinom and sample, and visualize results with barplot and frequency tables.
Chapters
Hi and welcome to Preparing for Statistics Interview Questions in R. My name is Susanne Nahmelewska and this course will prepare you to answer R statistical interview questions. This course is a little bit more challenging than a typical data camp course because it aims to get you ready for a job interview. The first chapter of this course focuses on probability theory. Probability theory is the foundation of statistics, so interviewers like to test your knowledge of this topic. There are plenty of statistical distributions out there, but we will focus on these distributions which are popular among interviewers. This video and the following exercises focus on discrete distributions the next video focuses on continuous distributions. Lets kick off with the structure of probability functions in R for both discrete and continuous distributions. Probability functions consist of a prefix and an abbreviated name of a distribution. For example, D stands for density, and norm is an abbreviated name of a normal distribution. So the d norm function returns the density of a normal distribution. The other prefixes P for distribution function, Q for quantile function, and R for random variates. Awesome. Now let's review some of the discrete distributions, starting with the discrete uniform distribution. Discrete uniform distribution is a probability distribution whereby a finite number of values have equal probability. A simple example of the discrete uniform distribution is throwing a third die. The possible outcomes are 1 to 6. Each time we throw the dice, the probability of a given score is 1/6. There are multiple ways to generate random numbers from a discrete uniform distribution. You can use the sample function, which returns a sample of the specified size from the given elements. But if you prefer to lean on the classical naming convention, you can use the RD uni function from the PER package. The Bernoulli distribution is another discrete distribution important to interviewers. The Bernoulli distribution takes a value of 1 with probability p and a value of 0 with probability 1p. If p equals 0.5, the Bernoulli distribution reflects tossing a coin. The Bernoulli distribution is a particular case of binomial distribution, which we will cover next. You can think of the binomial distribution as the sum of outcomes of an event following a Bernoulli distribution. The binomial distribution has three n the number of trials, p the probability of a success, and k the number of successes. To generate random data from a binomial distribution, use the RBINOM function. The Bernoulli distribution is a special case of a binomial distribution, so you can also use the RBINOM function and set the size parameter to one. If you have some random numbers and want to create a frequency table, you can use the table function. The table function performs the categorical tabulation of data by the variable and its frequenc. If you apply the bar plot function on a frequency table, you will visualize the discrete distribution. Finally, let's recall reproducibility. If you generate random numbers, but you need to reproduce the same sequence every time your program runs, you can use the set seed function. If you use the setseed function, you will generate the same set of random numbers. In this video, we've covered the syntax of probability functions in R and three examples of discrete, discrete, uniform, Bernoulli, and binomial. We've also talked about how to visualize frequencies and the reproducibility of random samples. Let's practice discrete distributions before your interview.
More from Richie

#359 My Best Friend is AI with Valerie Tiberius, Professor of Philosophy at University of Minnesota

How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon

#358 How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon







