Tutorials › VEE Mathematical Statistics › Encoding Binary Outcomes With Bernoulli Variables

VEE Mathematical Statistics · Bernoulli and Binomial Models · Tutorial 77 of 880

Encoding Binary Outcomes With Bernoulli Variables

Learn to represent one binary outcome precisely by defining its success event, zero-one coding, and success probability.

Beginner 9 min read

What You'll Learn

  • Define a Bernoulli random variable from a specified success event
  • State the success probability and the variable’s possible values
  • Translate verbal success and failure labels into zero-one coding
  • Reverse a coding when the chosen meaning of success changes
  • Check a Bernoulli model for a single binary outcome

Why Encode a Binary Outcome?

Many statistical questions begin with an outcome that has only two possibilities: a claim is accepted or rejected, a device passes or fails inspection, or a customer renews or does not renew. A random variable turns those labels into numbers, making it possible to describe the outcome within a probability model. For a binary result, the standard coding assigns one value to the event of interest and the other to its complement.

The coding is a choice, not a feature inherent in the event. If “claim accepted” is designated as success, it receives the value 1. If “claim rejected” is designated as success instead, the coding reverses. The probability model is only unambiguous when the event represented by 1 is stated explicitly.

Definition: Let \(A\) be a specified event for one trial or observation. The Bernoulli random variable associated with \(A\) is the indicator of \(A\): $$ X=I_A= \begin{cases} 1, & \text{if } A \text{ occurs},\\ 0, & \text{if } A \text{ does not occur}. \end{cases} $$ Its success probability is \(p=P(A)\), where \(0\leq p\leq 1\). We write \(X\sim\operatorname{Bernoulli}(p)\). Here “success” means that the specified event \(A\) occurs; it need not mean a favorable or desirable result.

A Bernoulli variable describes one binary classification. The underlying outcome can have more detail than “yes” or “no,” but the chosen event \(A\) groups the detailed outcomes into two categories: those in \(A\) and those outside \(A\). Once \(A\) is specified, the values of \(X\) follow from the definition.

The parameter \(p\) refers to the probability of the event coded as 1, not automatically to the probability of the event that sounds positive in everyday language. For example, if \(X=1\) means “inspection failure,” then \(p\) is the probability of failure. A complete model statement identifies the observation, the event assigned value 1, and that event’s probability.

From Event Labels to Zero and One

To define a Bernoulli variable in a problem, first identify the single observation being classified. Next, name the event that will count as success. Then write the zero-one rule and set \(p\) equal to the probability of that event. This prevents ambiguity when a question uses several labels such as “accepted,” “eligible,” or “flagged.”

1
Identify the observation.
Specify what one trial or unit is, such as one inspected device or one reviewed application.
2
Define the success event.
Write \(A\) in words or as a condition, such as “the device fails the test.”
3
Assign the codes.
Set \(X=1\) when \(A\) occurs and \(X=0\) when \(A\) does not occur.
4
Specify the parameter.
Write \(p=P(A)\). Check that the probability belongs to the event assigned the value 1.

The two possible values are determined by the coding, while the parameter is determined by the probability model for the event. An event can be rare or common, and either way it can be assigned the value 1. No assumption about independence from another trial is needed to define one Bernoulli variable.

Worked Example: Coding an Application Decision

A hypothetical benefit administrator reviews one application. The probability that the application is approved is 0.72. Define a Bernoulli variable \(X\) for whether this application is approved, state its success probability, and identify the value of \(X\) if the application is denied.

Method. Define the event to be coded as 1, then use its probability as the Bernoulli parameter. The observation is one reviewed application, and choose \(A=\{\text{application is approved}\}\).

By the requested coding, \(X=1\) if the application is approved and \(X=0\) if it is not approved. Therefore: $$ P(A)=0.72,\qquad p=0.72,\qquad X\sim\operatorname{Bernoulli}(0.72). $$

If the application is denied, \(A\) does not occur, so \(X=0\). The two outcomes are exhaustive under the stated approve-or-deny decision, and the probability of denial is \(1-0.72=0.28\). This checks that the coding and the supplied probability refer to opposite, complementary outcomes as required.

Common mistake avoided: Assigning \(p=0.28\) because denial is the other outcome. That would be the parameter only if denial, rather than approval, were coded as 1.

Reversing the Coding

The same underlying outcome can be encoded in either direction. If \(X=1\) represents \(A\), then \(1-X\) equals 1 exactly when \(A\) does not occur. Thus \(1-X\) is the Bernoulli variable for the complementary event, with its own success probability \(P(A^c)=1-P(A)\). This is a change in what counts as success, not a change in what happened.

$$ X=I_A \quad\Longrightarrow\quad 1-X=I_{A^c} $$

This identity follows by checking both cases. If \(A\) occurs, then \(X=1\) and \(1-X=0\); if \(A\) does not occur, then \(X=0\) and \(1-X=1\). Therefore \(1-X\) is precisely the indicator of the complement. This is useful when a problem supplies the probability of a non-event but asks for a variable representing the event, or vice versa.

Worked Example: A Sensor Alert With the Opposite Coding

A hypothetical building sensor issues an alert on 6% of monitored days. Define \(Y\) so that \(Y=1\) means “no alert is issued,” rather than “an alert is issued.” State the event represented by \(Y=1\), its parameter, and the value of \(Y\) on an alert day.

Method. Translate the requested meaning of 1 before selecting the parameter. Let \(A=\{\text{no alert is issued}\}\). This event is the complement of the alert event.

The probability of no alert is: $$ P(A)=1-P(\text{alert})=1-0.06=0.94. $$ Thus \(Y=1\) on a no-alert day, \(Y=0\) on an alert day, and \(Y\sim\operatorname{Bernoulli}(0.94)\).

On an alert day, the event \(A\) does not occur, so \(Y=0\). As a check, the probability assigned to the value-1 event is 0.94, and the probability of the opposite outcome is \(1-0.94=0.06\), matching the stated alert probability.

Common mistake avoided: Writing \(Y\sim\operatorname{Bernoulli}(0.06)\) merely because 0.06 is the probability explicitly provided. The parameter must match the event coded as 1; here that event is no alert.

How the Event Probability Relates to the Coding

The defining rule gives a direct reason that the parameter of a Bernoulli variable is the probability of its success event. The event that \(X\) equals 1 is exactly \(A\): if \(A\) occurs, the definition sets \(X=1\); if \(A\) does not occur, it sets \(X=0\). Consequently, the events \(\{X=1\}\) and \(A\) are the same event, so their probabilities are equal.

$$ \{X=1\}=A \quad\Longrightarrow\quad P(X=1)=P(A)=p $$

This argument is about matching an event to a code. It does not require calculating a probability from a probability mass function. The probability \(p\) must come from the stated model or supplied information about \(A\). If that probability is unknown, the variable can still be defined, but its parameter remains unspecified.

Worked Example: Defining a Binary Quality Flag

A hypothetical shipment contains one randomly selected component. The component is classified as “within tolerance” if its measurement is between 9.8 and 10.2 units, inclusive. The probability of being within tolerance is 0.91. Define a Bernoulli variable \(Z\) for whether the component is outside tolerance, state its parameter, and give \(Z\) for measurements of 10.0 and 10.3 units.

Method. Represent the requested category “outside tolerance” directly as the event assigned value 1. Define \(B=\{\text{measurement is less than }9.8\text{ or greater than }10.2\}\). Because the endpoints are included in the within-tolerance category, they are not in \(B\).

The event \(B\) is the complement of being within tolerance. Hence: $$ P(B)=1-0.91=0.09. $$ Set \(Z=1\) when the component is outside tolerance and \(Z=0\) otherwise. The parameter is \(p=P(B)=0.09\), so \(Z\sim\operatorname{Bernoulli}(0.09)\).

For a measurement of 10.0, the component is within tolerance because \(9.8\leq 10.0\leq 10.2\). Therefore \(B\) does not occur and \(Z=0\). For a measurement of 10.3, the component is above 10.2, so \(B\) occurs and \(Z=1\).

The check is consistent: the two categories, within tolerance and outside tolerance, exhaust all possible measurements, and their probabilities sum to \(0.91+0.09=1.00\). The inclusive boundary condition also confirms that a measurement exactly equal to 9.8 or 10.2 would receive \(Z=0\).

Common mistake avoided: Treating 10.2 as outside tolerance because it is a boundary. The problem says the tolerance interval is inclusive, so 10.2 is within tolerance and is coded 0.

Common Traps and a Reliable Check

The most frequent error is not an arithmetic error; it is assigning the parameter to the wrong event. If a problem says that 4% of items are defective and asks for a variable equal to 1 for a satisfactory item, the parameter is 0.96, not 0.04. Always attach \(p\) to a phrase: “\(p\) is the probability that the event coded 1 occurs.”

A second trap is failing to state the observation. “Let \(X\) be a Bernoulli variable with parameter \(p\)” is incomplete in an applied problem unless the success event is already unambiguous. State whether one observation is a customer, a claim, a component, or another unit, and define the event for that unit.

A third trap is using more than two categories without defining a binary grouping. If a review outcome can be “approved,” “denied,” or “pending,” an indicator for approval is still Bernoulli: it is 1 for approved and 0 for either denied or pending. But a variable that takes three distinct codes is not itself a Bernoulli variable. The event defining the 1-value category must be clear, and every outcome outside that event receives 0.

Key takeaway: A Bernoulli variable is an indicator for one explicitly chosen event. Specify the observation, define what counts as success, assign 1 to that event and 0 to its complement, and set \(p\) equal to the probability of the event coded 1.

Check Your Understanding

For each situation, identify the event coded 1, state the Bernoulli parameter, and determine the requested value or coding.

  1. A hypothetical electronic payment is declined with probability 0.03. Let \(X=1\) mean it is accepted. State \(p\) and the value of \(X\) if the payment is declined. (Answer: \(p=0.97\); declined means \(X=0\).)
  2. A review flag has probability 0.12 of being triggered. Define \(Y=1\) when the flag is triggered. State the distribution and the value on an unflagged review. (Answer: \(Y\sim\operatorname{Bernoulli}(0.12)\); unflagged means \(Y=0\).)
  3. A hypothetical sensor detects smoke with probability 0.08. Define \(Z=1\) for no detection. What is \(p\), and what value does \(Z\) take when smoke is detected? (Answer: \(p=0.92\); detection means \(Z=0\).)
  4. A part passes a test if its measured length is from 24.5 through 25.5 millimeters, inclusive. The probability of passing is 0.86. Define \(W=1\) for failure. Give \(p\) and the value for a part measuring exactly 25.5 millimeters. (Answer: \(p=0.14\); the boundary is a pass, so \(W=0\).)
  5. A hypothetical claim outcome is approved, denied, or held for further review. The probability of approval is 0.70, and the probability of a hold is 0.10. Define \(V=1\) for “not approved.” State the event represented by 1, its parameter, and \(V\) for a held claim. (Answer: The event is denied or held; \(p=0.30\); a held claim has \(V=1\).)
Clinical Biostats