Random Variable in Probability

# Random Variable in Probability

Vikram Singh
Assistant Manager - Content
Updated on Aug 8, 2024 12:15 IST

What happens when you toss a coin or roll a dice? In probability, we use a “random variable” to describe these uncertain outcomes. But what does it really mean, and how does it work? Let’s find out.

If you are an aspiring data scientist or statistician, one of the first questions is what random variables are and how they are associated with probability distribution. We will discuss the concept of a random variable, its type, and its association with the random variable.

Later, we will also discuss how to calculate the mean and variance of a discrete and continuous random variable.

## What is a Random Variable in Probability?

Random variables are the numerical descriptions of the outcomes of any statistical experiment. In simple terms, a random variable is a rule that associates a numerical value with each outcome in a sample space of an experiment.

Generally, random variables are denoted by X or Y.

Let’s take an example to understand better what random variables are.

Suppose that you toss two coins, then the sample space of the experiment is the set of all possible outcomes, which are:

• HH (Heads on the both the coins)
• HT (Head on the first coin and Tail on the second coin)
• TH (Tail on the first coin and Head on the second coin)
• TT (Tails on both the coins)

Here, the probability of each outcome will be equal since the chance of getting head or getting tail while tossing a coin will always be 50%, i.e.,

P({X=HH}) = P({X=HT}) = P({X=TH}) = P({X=TT}) = 1/4

In the case of tossing two coins, the possible values of the random variable are the number of heads (or tails) that appear, i.e., 0, 1, and 2.

• HH (or TT) – When both the coins show Head (or Tails), the value will be 2.
• HT or TH – When one coin shows a head and another shows a tail, the value will be 1.
• TT – When both coins show Tail (or Head), the value will be 0.

In the above example, the value of the random variable is discrete, i.e., 0, 1, and 2, but what if the values of a random variable are continuous?

Based on the values a random variable can take, they are classified into Discrete Random and Continuous Random.

Let’s explore both types of random variables.

## Types of Random Variables

### Continuous Random Variable

A random variable that can take infinite possible values is known as a continuous random variable. The set of all the possible values of a continuous random variable is an interval of real numbers.

Example of continuous random variable includes

• heights of students
• weight of employees
• amount of rainfall.

Continuous random variables are used to estimate mean and standard deviation, hypothesis testing, and regression analysis.

### Discrete Random Variable

A random variable that can take only a countable number of distinct values, such as 0,1,2,3,4…. is known as a discrete random variable.

Example of discrete random variable includes:

• The number of heads on tossing a coin.
• Getting a king from the shuffled deck of cards.
• The number of successes in the Bernoulli trials.
• The number of cars passing through a red light in an hour.

Discrete Random Variables are used to calculate the probability of events, statistical interference, and machine learning.

Note: If a random variable can take only a finite number of distinct values, they must be discrete.

## Random Variable and Probability Distribution

A probability distribution of a random variable is a list of all possible outcomes with the corresponding probability values.

or

The probability distribution for a random variable shows how the probabilities are distributed over the values of the random variable.

Example: The probability distribution for tossing two coins is given as

There are types of probability distribution based on the types of random variables.

• Discrete Probability Distribution
• Continuous Probability Distribution

If the random variable is a discrete random variable, then its probability distribution is called Discrete Probability Distribution

### Types of Discrete Probability Distribution

If the random variable is a continuous random variable, then its probability distribution is called Continuous Probability Distribution.

### Types of Continuous Probability Distribution

Note:

• The function that represents the discrete probability distribution is known as the Probability Mass Function.
• The function representing the continuous probability distribution is the Probability Density Function.
• The value of the probability distribution always lies between 0 and 1.

## Expected Value and Variance of a Random Variables

Discrete Random Variable

• Expected Value or Mean: E[X] = Σ x * P(X=x)
• Variance: Var[X] = Σ (x-u)^2 * P (X = x)

where

X: Discrete Random Variable

P(X = x): Probability Mass Function

u: mean

Continuous Random Variable

• Expected Value or Mean: E[X] = ∫ x * P(X=x)
• Variance: Var[X] = ∫ (x-u)^2 * P (X = x)

where

X: Continuous Random Variable

P(X = x): Probability Density Function

u: mean

## Random Variable Practice Problem

Here is a list of 10 practice problems to master the concept of random variables in probability.

1. A fair coin is tossed 10 times. What is the probability of getting exactly 5 heads?
2. A die is rolled 6 times. What is the probability of getting a 6 at least once?
3. The heights of 100 randomly selected people are normally distributed with a mean 170 cm and a standard deviation 5 cm. What is the probability that a randomly selected person is taller than 175 cm?
4. The amount of rainfall in a certain city follows a Poisson distribution with a mean 10 mm per day. What is the probability that there will be more than 12 mm of rainfall in a day?
5. The number of customers arriving at a bank per hour follows a Poisson distribution with a mean 5. What is the probability that there will be at least 3 customers arriving in the next hour?
6. Let X be the number of heads in 100 coin flips. Find the probability distribution of X.
7. Let Y be the time it takes for a light bulb to burn out. Find the probability density function of Y.
8. Let Z be the score of a student on a test. Find the mean and variance of Z.
9. Let W be the amount of money won or lost in a game of roulette. Find the expected value of W.
10. Let X be the height of a randomly selected person. Find the cumulative distribution function of X.