Why the Coding Convention Matters
A Bernoulli model describes a two-outcome experiment using the numbers 0 and 1. The numbers are a convenient representation, not an intrinsic feature of the outcomes: a clinical trial has response and no response, a device either passes or fails inspection, and a test result may be positive or negative. Before assigning a Bernoulli parameter, specify which outcome is coded as 1. The parameter is the probability of that outcome.
This distinction matters whenever a question changes the meaning of “success.” If success means response, the parameter is the response probability. If success instead means no response, the parameter is the probability of no response. The experiment has not changed, but the Bernoulli variable and its parameter have.
The indicator notation \(\mathbf{1}_A\) makes the coding explicit: the event \(A\), not the word “success” by itself, determines which result receives the value 1. The complementary event \(A^c\) receives 0. In particular, a Bernoulli parameter is the probability of the event assigned 1; it is not automatically the probability of whichever outcome sounds favorable.
From Outcome Labels to a Bernoulli Variable
To code a two-category result, first state the categories and then state the coding rule. For instance, “positive is 1 and negative is 0” defines one variable; “negative is 1 and positive is 0” defines another. Both are valid Bernoulli codings, but they generally have different parameters.
Suppose a test has positive-result event \(A\), with \(P(A)=p\). Coding positive as 1 gives \(X=\mathbf{1}_A\), whose parameter is \(p\). Coding negative as 1 gives \(Z=\mathbf{1}_{A^c}\), whose parameter is \(1-p\). A written label such as “positive” is not itself the numerical value of a Bernoulli variable; it must be translated using the stated convention.
Worked Example: Coding a Clinical Response
In a study, the probability that a randomly selected patient responds to treatment is \(0.72\). Define a Bernoulli variable that records response, and give its distribution.
Let \(A\) be the event that the patient responds. The question assigns success to response, so set \(X=1\) for response and \(X=0\) for no response. Thus \(P(X=1)=P(A)=0.72\), and \(P(X=0)=1-0.72=0.28\). Therefore \(X\) is Bernoulli with parameter \(0.72\).
If instead the study records nonresponse as 1, the recorded variable is \(Z=1\) for no response and \(Z=0\) for response. Then \(P(Z=1)=0.28\). The event probabilities have not changed; only the event represented by the value 1 has changed.
Worked Example: Converting Labels in a Data Record
A device inspection records the labels pass and fail. The convention is that pass is coded 1 and fail is coded 0. Suppose the pass probability is \(0.96\). Translate the labels for the record “pass, fail, pass, pass, fail” and state the Bernoulli parameter.
Apply the coding rule to each recorded outcome: pass becomes 1, while fail becomes 0. The numerical record is therefore \(1,0,1,1,0\). For one inspection, the Bernoulli variable equals 1 exactly on the event “the device passes.” Its parameter is consequently \(P(\text{pass})=0.96\), and the probability of code 0 is \(P(\text{fail})=1-0.96=0.04\).
The sample record contains three 1s and two 0s, but those counts do not redefine the model parameter. The parameter specified in the problem is the pass probability, \(0.96\); the observed record is a particular set of outcomes.
Reversing Success and Failure
Reversing the coding means assigning 1 to the outcome that previously received 0, and assigning 0 to the outcome that previously received 1. This operation can be described using the complement of an event. If \(X=\mathbf{1}_A\), then the reversed indicator is \(Z=\mathbf{1}_{A^c}\). For every outcome, exactly one of \(A\) and \(A^c\) occurs, so \(Z=1-X\).
Proof. Since \(X\) takes only the values 0 and 1, \(Z=1-X\) also takes only the values 0 and 1. Moreover, \(Z=1\) exactly when \(X=0\), and \(Z=0\) exactly when \(X=1\). Therefore
These are the two probabilities of a Bernoulli variable with parameter \(1-p\). Hence \(Z\) is Bernoulli with that parameter. \(\square\)
This result identifies precisely what changes and what does not. The support remains \(\{0,1\}\), and the two outcome probabilities are the same probabilities as before, attached to the opposite numerical codes. The parameter changes from \(p\) to \(1-p\) because the event assigned code 1 changes from \(A\) to \(A^c\). At the boundary values, the result still holds: if \(p=0\), then \(X=0\) with probability 1 and \(Z=1\) with probability 1; if \(p=1\), the reverse occurs.
Worked Example: Reversing a Quality-Control Indicator
A manufactured part passes inspection with probability \(0.93\). Let \(X=1\) for a pass and \(X=0\) for a failure. Define \(Z=1-X\) and determine the probability assigned to each value of \(Z\).
The original parameter is \(P(X=1)=P(\text{pass})=0.93\), so \(P(X=0)=P(\text{failure})=0.07\). Under the reversed coding, \(Z=1\) exactly when \(X=0\), which is exactly when the part fails. Thus
Therefore \(Z\) is Bernoulli with parameter \(0.07\). The inspection process is unchanged; the new parameter is the failure probability because failure is now coded as 1.
Choosing the Event Before Naming the Parameter
A reliable way to interpret any Bernoulli parameter is to ask, “What event makes the variable equal to 1?” This question works whether outcomes are described with words, symbols, or existing data codes. If the event is \(A\), then the parameter is \(P(A)\). The probability of code 0 is then \(P(A^c)=1-P(A)\).
For example, if a response indicator is defined by \(X=1\) for improvement and \(X=0\) for no improvement, its parameter is the probability of improvement. If the same two categories are coded the other way around, the parameter is the probability of no improvement. Do not infer the parameter from a variable name such as “outcome” or from the order in which category labels are listed. Find the event assigned 1.
Worked Example: Two Valid Codings of a Test Result
A screening test is positive with probability \(0.08\) in a specified population. Write both Bernoulli codings, one with positive as 1 and one with negative as 1, and identify each parameter.
Let \(A\) be the event of a positive result. With positive coded as 1, define \(X=\mathbf{1}_A\). Then \(P(X=1)=P(A)=0.08\), so \(X\) is Bernoulli with parameter \(0.08\); also \(P(X=0)=0.92\).
With negative coded as 1, define \(Z=\mathbf{1}_{A^c}\). A negative result has probability \(1-0.08=0.92\), so \(P(Z=1)=0.92\) and \(P(Z=0)=0.08\). Thus \(Z\) is Bernoulli with parameter \(0.92\). The two parameters sum to 1 because the events positive and negative are complementary.
What Coding Does—and Does Not—Change
Coding determines the numerical representation of the two outcomes and therefore determines which event probability is called the Bernoulli parameter. It does not alter the real-world experiment or make an unlikely outcome more likely. The probability attached to an outcome label remains the same; only the numerical value assigned to that label changes.
This is why a coding rule should be recorded alongside a Bernoulli model. “\(X\) is Bernoulli with parameter \(p\)” says that \(X=1\) has probability \(p\), but the interpretation in context still requires knowing what \(X=1\) means. A parameter value without the success definition may be numerically correct yet easy to misinterpret.
Common Mistakes
- Keeping the parameter after reversing the coding. If \(X=1\) means success with probability \(p\), then \(1-X=1\) means failure, whose probability is \(1-p\), not \(p\).
- Assuming “success” always means the favorable outcome. In a model, success is the outcome assigned value 1. A problem may define failure, disease, or an adverse event as success for the purpose of coding.
- Treating outcome labels as numerical codes. The word “pass” is not automatically 1. It is 1 only if the coding convention assigns it that value.
- Confusing the observed count with the parameter. A short data record may contain more zeros than ones even when the specified probability of 1 is large. The model parameter is an event probability, not the proportion in every particular record.
Check Your Understanding
For each question, identify the event represented by 1 before stating the Bernoulli parameter.
- A patient improves with probability \(0.65\). If improvement is coded 1, what is the parameter? What is it if no improvement is coded 1?
- A coin lands heads with probability \(0.5\). Define one Bernoulli variable with heads coded 1 and another with tails coded 1. Give both parameters.
- A data set uses 1 for a failed inspection and 0 for a passed inspection. If the pass probability is \(0.97\), what is the parameter of this Bernoulli variable?
- Explain why reversing \(X\) to \(1-X\) does not change the inspection or treatment outcome probabilities, even though it changes the Bernoulli parameter.
- A variable is described as Bernoulli with parameter \(0.2\), but the meaning of code 1 is omitted. What contextual information is needed to interpret the parameter?