2.1 Random Variables: Discrete and Continuous =============================================== :bolditalic:`Key Terms` :bolditalic:`Random variable(隨機變數)` A rule that assigns a real number to each outcome in a sample space. :bolditalic:`Value of a random variable(隨機變數值)` The numerical result produced by the random variable after an outcome is observed. :bolditalic:`Range(值域)` The set of possible values that a random variable can take. :bolditalic:`Indicator variable(指示變數)` A random variable that uses 1 for one condition and 0 for the opposite condition. :bolditalic:`Discrete random variable(離散型隨機變數)` A random variable whose possible values form a finite or countably infinite set. :bolditalic:`Continuous random variable(連續型隨機變數)` A random variable that can take any value in an interval of real numbers. :bolditalic:`Finite(有限)` Having a limited number of possible values. :bolditalic:`Countably infinite(可數無限)` Having infinitely many values that can still be listed in a sequence. :bolditalic:`Count data(計數資料)` Data obtained by counting individual occurrences. :bolditalic:`Measurement data(測量資料)` Data obtained by measuring on a continuous scale. 2.1.2 Learning Outcomes ----------------------- After completing this section, students should be able to: - explain what a random variable is; - distinguish an outcome from the value of a random variable; - explain the difference between :math:`X` and :math:`x`; - identify the range of a simple random variable; - explain why several outcomes may produce the same value; - recognize that an expression such as :math:`X=1` represents a set of outcomes; - construct a simple indicator random variable; - distinguish discrete and continuous random variables; - explain why a discrete random variable may be finite or countably infinite; - use the practical distinction between counting and measuring; - explain why rounding does not necessarily change the nature of an underlying measurement. 2.1.3 From Outcomes to Numbers ------------------------------ A random experiment produces an outcome in a sample space. A random variable adds a numerical description to that outcome. A **random variable** is a function that assigns a real number to each outcome in the sample space. A random variable is usually written with a capital letter such as :math:`X`. A particular value of the random variable is usually written with a lowercase letter such as :math:`x`. For example, toss a fair coin twice and define .. math:: X=\text{number of heads}. The four outcomes are mapped to numerical values as shown below. .. image:: ../_static/figures/random_variables/figure_2_1_1_outcomes_to_values.png :width: 70% :align: center :alt: The outcomes HH, HT, TH, and TT are mapped to the numbers 2, 1, 1, and 0 by a random variable that counts heads. Here, :math:`X` is the rule. After an outcome is observed, the rule produces a value. For example, .. math:: X(HT)=1. Thus, ``HT`` is an outcome, :math:`X` is the random variable, and 1 is the value assigned to that outcome. 2.1.4 Example 1: Number of Heads in Two Tosses ---------------------------------------------- The sample space is .. math:: S=\{HH,HT,TH,TT\}. Let .. math:: X=\text{number of heads}. Then: .. list-table:: :header-rows: 1 :widths: 40 30 30 * - Outcome - :math:`X` - Meaning * - ``HH`` - 2 - Two heads * - ``HT`` - 1 - One head * - ``TH`` - 1 - One head * - ``TT`` - 0 - No heads Therefore, the range of :math:`X` is .. math:: \{0,1,2\}. Notice that ``HT`` and ``TH`` are different outcomes but both produce :math:`X=1`. A random variable therefore does not have to assign a different number to every outcome. Several outcomes may be summarized by the same numerical value. 2.1.5 A Random-Variable Value Represents an Event ------------------------------------------------- For the two-coin experiment, .. math:: X=1 means that exactly one head occurred. The outcomes that produce this value are .. math:: \{HT,TH\}. Therefore, the event associated with this value can be written as .. math:: \{X=1\}=\{HT,TH\}. Similarly, .. math:: \{X=2\}=\{HH\} and .. math:: \{X=0\}=\{TT\}. This is the connection between the sample space and random-variable notation: a statement about the value of a random variable corresponds to a set of outcomes from the original experiment. At this stage, we are identifying the possible values and the outcomes that produce them. Probabilities assigned to these values are introduced in the separate handout on probability distributions. 2.1.6 Different Random Variables for the Same Experiment -------------------------------------------------------- A random variable records a numerical feature chosen for the analysis. The same experiment can therefore have more than one useful random variable. For one die roll, define .. math:: X=\text{number shown on the die}. Then .. math:: X\in\{1,2,3,4,5,6\}. For the same die roll, we could instead define .. math:: Y= \begin{cases} 1, & \text{if the result is even},\\ 0, & \text{if the result is odd}. \end{cases} Then .. math:: Y\in\{0,1\}. The experiment is unchanged. What changes is the numerical feature being recorded. A 0--1 random variable such as :math:`Y` is called an **indicator variable**. 2.1.7 Discrete and Continuous Random Variables ---------------------------------------------- Random variables are commonly classified according to the structure of their possible values. .. image:: ../_static/figures/random_variables/figure_2_1_2_discrete_vs_continuous.png :width: 72% :align: center :alt: A discrete random variable has separate countable values, while a continuous random variable can take any value in an interval. A **discrete random variable** has possible values that can be counted. A **continuous random variable** can take any value in an interval of real numbers. The distinction concerns the possible values of the variable, not whether the values happen to be written with or without decimals. 2.1.8 Discrete Random Variables ------------------------------- A discrete random variable may have a finite number of possible values. For example, if .. math:: X=\text{number of heads in three coin tosses}, then .. math:: X\in\{0,1,2,3\}. The range is finite. A discrete random variable may also have countably infinitely many possible values. Suppose a coin is tossed until the first head occurs and let .. math:: X=\text{number of tosses required}. Then .. math:: X\in\{1,2,3,4,\ldots\}. There is no largest possible value, but the values can still be listed in sequence. .. note:: **Discrete does not mean only finite.** A discrete random variable may have finitely many or countably infinitely many possible values. Discrete random variables often arise from counting and answer questions such as “How many?” Examples include: - number of heads in five tosses; - number of defective parts in a sample; - number of students absent from a class; - number of cards drawn before the first ace. 2.1.9 Continuous Random Variables --------------------------------- A continuous random variable can take any value in an interval of real numbers. Continuous random variables commonly arise from measurement. Examples include: - waiting time; - height; - weight; - temperature; - distance; - lifetime of a component. For example, let :math:`Y` be the waiting time for the next bus, measured in minutes, and suppose .. math:: 0\leq Y\leq10. In theory, :math:`Y` may take any real value in this interval. Values such as :math:`3.2`, :math:`3.21`, and :math:`3.215` are all possible descriptions at different levels of measurement precision. 2.1.10 Count Versus Measure --------------------------- A useful introductory distinction is discrete -> count continuous -> measure. This is a practical guideline rather than a substitute for the formal definitions. .. list-table:: :header-rows: 1 :widths: 55 20 25 * - Variable - Type - Reason * - Number of heads in 4 tosses - Discrete - Count * - Number shown on one die - Discrete - Separate values * - Number of cards drawn before an ace - Discrete - Count * - Waiting time - Continuous - Measure * - Weight - Continuous - Measure * - Temperature - Continuous - Measure 2.1.11 Measurement Precision ---------------------------- A digital instrument may display a measurement only to a fixed number of decimal places. This does not necessarily mean that the underlying physical quantity is fundamentally discrete. The quantity may vary continuously even though the recorded display is rounded. For introductory classification problems, ask what the variable represents: is it fundamentally a count of separate occurrences, or a measurement on a continuous scale? .. note:: Classification should be based on the underlying quantity and the model being used, not only on the number of decimal places shown by an instrument. 2.1.12 A Simple Method ---------------------- When defining and classifying a random variable, ask: 1. What is the random experiment? 2. What are the possible outcomes? 3. What numerical feature do we want to record? 4. What rule defines the random variable? 5. What values can the random variable actually take? 6. Are those values separate and countable, or can any value in an interval occur? If the values are separate and countable, classify the variable as discrete. If any real value in an interval may occur, classify the variable as continuous. 2.1.13 Common Mistakes ---------------------- A common mistake is to confuse an outcome with a random-variable value. For two coin tosses, ``HT`` is an outcome, while :math:`X=1` is the numerical value when :math:`X` counts heads. Another mistake is to think that different outcomes must produce different values. The outcomes ``HT`` and ``TH`` are different but both give :math:`X=1`. A third mistake is to think that a discrete variable must have only a small or finite number of values. A countably infinite variable is still discrete. Another mistake is to think that every numerical variable is continuous. The number shown on a die is numerical but discrete. Finally, do not classify a quantity only from how many decimal places are displayed. A rounded measurement may still represent an underlying continuous quantity. 2.1.14 Summary -------------- A random variable is a numerical rule applied to the outcome of a random experiment. A capital letter such as :math:`X` represents the random variable. A lowercase letter such as :math:`x` represents a possible numerical value. Different outcomes may produce the same value, and an expression such as :math:`X=x` represents all outcomes that produce that value. A discrete random variable has a finite or countably infinite range. A continuous random variable can take any value in an interval of real numbers. A useful practical distinction is discrete -> count continuous -> measure. Probability distributions for discrete random variables are introduced in the next handout, not in this section. .. 2.1.15 Short Review Questions .. ----------------------------- .. 1. What is a random variable? .. 2. What is the difference between an outcome and a random-variable value? .. 3. Toss two coins and let :math:`X` be the number of heads. What is the range of :math:`X`? .. 4. Which outcomes belong to the event :math:`X=1`? .. 5. Can a discrete random variable have infinitely many possible values? .. 6. Is waiting time discrete or continuous? Why? .. 7. Why does rounding a measurement not necessarily make the underlying quantity discrete?