1. Discrete distributions
Hi and welcome to Preparing for Statistics Interview Questions in R.
My name is Zuzanna Chmielewska, and this course will prepare you to answer R statistical interview questions.
This course is a little bit more challenging than a typical DataCamp course because it aims to get you ready for a job interview.
2. Probability
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.
3. Overview of common distributions
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.
4. Probability functions in R
Let's 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 dnorm function returns the density of a normal distribution.
5. Probability functions in R
The other prefixes are: p for distribution function,
6. Probability functions in R
q for quantile function
7. Probability functions in R
and r for random variates.
8. Discrete uniform distribution
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 fair die.
9. Discrete uniform distribution
The possible outcomes are 1 to 6.
10. Discrete uniform distribution
Each time you throw the dice, the probability of a given score is 1/6.
11. Discrete uniform distribution
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 rdunif function from the purrr package.
12. Bernoulli distribution
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 1 minus p.
13. Bernoulli distribution
If p equals 0.5, the Bernoulli distribution reflects tossing a coin.
The Bernoulli distribution is a particular case of a binomial distribution which we will cover next.
14. Binomial distribution
You can think of the binomial distribution
15. Binomial distribution
as the sum of outcomes of an event
16. Binomial distribution
following a Bernoulli distribution.
17. Binomial distribution
The binomial distribution has three parameters:
18. Binomial distribution
n the number of trials,
19. Binomial distribution
p the probability of a success,
20. Binomial distribution
and k the number of successes.
21. Binomial distribution in R
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.
22. Frequency table
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 frequency.
23. Frequency chart
If you apply the barplot function on a frequency table, you will visualize the discrete distribution.
24. Reproducibility
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.
25. Reproducibility
If you use the set.seed function, you will generate the same set of random numbers.
26. Summary
In this video, we've covered the syntax of probability functions in R, and three examples of discrete distributions: discrete uniform, Bernoulli, and binomial. We've also talked about how to visualize frequencies and the reproducibility of random samples.
27. Let's practice!
Let's practice discrete distributions before your interview!