# What is the difference between sample space and random variable?

A random variable is a set of possible values from a random experiment.

It then takes the example of flipping a coin, defines $Heads=0$ and $Tails=1$, and says that $X = \{0, 1\}$ is a random variable.

Next, it defines sample space as

A random variable's set of values is the sample space.

It then takes the example of throwing a dice, and states that the sample space is $\{1, 2, 3, 4, 5, 6\}$.

So, both terms are defined to be a set of outcomes for an experiment and, as a result, I got confused and couldn't differentiate between them.

What is the difference between sample space and random variable?

I've consulted WIkipedia too and although I can understood the article on Sample Space but the article on Random Variable appears too technical and I couldn't comprehend it.

• Intuitively ( you say you don't like technical papers) a random variable is more than just the outcomes, it is the outcomes and the probability of each outcome ( not fully correct because I would have to introduce events) – user83346 Feb 27 '17 at 8:58
• @fcop from what I recall from high school, event is any element of the power set of the set of all the outcomes. – ankit Feb 27 '17 at 14:18
• In the language of my post at stats.stackexchange.com/a/54894/919, the sample space is a set of tickets in a box and a random variable is a consistent way of writing numbers on those tickets. (Math sites rarely make this distinction because to their writers the world is built of sets. In the real world, though, a "value from an ... experiment" is a rich, complicated thing: it could be a tissue sample, a photo of a star field, or a collection of handwritten answers on a survey. It often does not start out as a numerical object: the numbers have to be added by means of measurement.) – whuber Feb 27 '17 at 14:22
• Well it is not necessarily the power set of the sample space; it should be a sigma-algebra on the sample space. Each element of the sigma-algebra should be measurable. As @whuber says the random variable is then a map from this sigma-algebra (the tickets) in the real set (the consistent way of writing numbers on the tickets). Because the tickets are measurable, (some) subsets of the real set will also be. – user83346 Feb 27 '17 at 16:45

From statistical inference by Casella and Berger,

Definition 1.1.1 The set, $S$, of all possible outcomes of a particular experiment is called the sample space for the experiment.

So sample space can be thought of as all possible observations one could make from a particular experiment. A sample space for a coin toss is a set $\{H, T\}$; a sample space for rolling a six-sided die is a set $\{1, 2, 3, 4, 5, 6\}$.

Definition 1.4.1 A random variable is a function from a sample space $S$ into the real numbers

so random variable can be thought of as a function. The notation used for random variable is an uppercase letter. So if we have a random variable that maps sample space to real numbers, we have $$X: S \to \mathbb{R}$$

No one really expresses random variables this way; instead, it's often denoted as $X$.

If that random variable $X$ is a set of possible values from a random experiment, then $$X: S \to S$$ so random variable is an identity function.

• The codomain of a random variable isn't necessarily the set of real numbers. In general, it can be any measurable set. – nbro Dec 24 '19 at 23:29

A sample space is the SET of values a random variable can take.

You can think of random variable as an unopened box. This unopened box contains each member of the sample space with some probability.

In your example of a dice roll, the sample space is {1,2,3,4,5,6}. The random variable that represents a roll of the dice has a probability of 1/6 of taking on each of these 6 values.

• You have the concept of sample space right I wouldn't characterize the random variable as an unopened box. It is the value of the side of the die that you roll and each of the possible values has a probability associated with it such that the sum of the probabilities for each side is 1. – Michael R. Chernick Oct 22 '17 at 5:02
• This is similat to what I say in my comment supra – user83346 Oct 22 '17 at 7:45
• Although often (especially in elementary texts) sample spaces are conflated with values of random variables, this doesn't generalize well. For more complicated situations it is essential to separate the concepts of "element of the sample space" and "possible value of a random variable." Please see my comment to the question. – whuber Oct 22 '17 at 16:32