From a Probability Question to a Software Command
Once a binomial or geometric model has been selected, software can calculate probabilities quickly and accurately. The challenge is translating the question into the function’s inputs: a point probability, a cumulative probability, or a tail probability can require different commands, even when the same random variable is involved.
This tutorial uses two common environments: R and spreadsheet functions such as those in Excel. Their commands differ, and geometric functions use a convention that may not match the way a waiting time is described in words. The safest approach is to define the random variable, write the event precisely, and then match the event to the software’s output.
For a binomial random variable, the R functions are dbinom for a point probability and pbinom for a cumulative probability. In Excel, BINOM.DIST uses the inputs number of successes, number of trials, success probability, and cumulative. Set cumulative to FALSE for a point probability and TRUE for a cumulative probability.
R’s pbinom(q, size, prob) returns \(P(X\le q)\). Its optional argument lower.tail=FALSE returns \(P(X>q)\), not \(P(X\ge q)\). Excel’s cumulative binomial result is likewise \(P(X\le x)\); its point result is \(P(X=x)\).
Binomial Point and Cumulative Probabilities
Consider a hypothetical binomial setting with \(n=12\) trials and success probability \(p=0.20\). Its probability mass function is
Software evaluates this expression directly. A cumulative command adds the probabilities from the smallest possible count through the specified boundary. That boundary matters: a command returning \(P(X\le 2)\) does not include \(X=3\).
Worked Example: Exactly Three Successes
Suppose, hypothetically, that 12 independent components are each classified as successful with probability 0.20. Let \(X\) be the number of successful components. The fixed trial count, common success probability, and independent-trial assumption make a binomial model appropriate for this calculation.
To find the probability of exactly three successes, use the point-probability function. In R, the command is dbinom(3, size=12, prob=0.20). In Excel, use BINOM.DIST(3, 12, 0.20, FALSE).
The calculation behind either result is
Thus the probability of exactly three successful components is about 0.2362, or 23.62%. The commands agree because both request a point probability, rather than a cumulative result.
Worked Example: At Least Three Successes
Using the same hypothetical model, find the probability of at least three successes. The event is \(X\ge3\), so it is not the same as the cumulative event \(X\le3\). One direct strategy is to subtract the probability of fewer than three successes from 1.
In R, use 1 - pbinom(2, size=12, prob=0.20). The boundary is 2 because “fewer than three” means \(X\le2\). In Excel, use 1 - BINOM.DIST(2, 12, 0.20, TRUE).
The cumulative probability is
Therefore,
The probability of at least three successes is about 0.4417, or 44.17%. In R, an equivalent upper-tail command is pbinom(2, size=12, prob=0.20, lower.tail=FALSE). It returns \(P(X>2)\), which is exactly \(P(X\ge3)\) because \(X\) is integer-valued.
Translate Tail and Interval Events Carefully
The R option lower.tail=FALSE is useful, but its meaning should be read literally: it returns the probability above the supplied boundary. Thus pbinom(k, ..., lower.tail=FALSE) gives \(P(X>k)\). To obtain \(P(X\ge k)\), use \(1-P(X\le k-1)\), or give \(k-1\) as the boundary for the upper tail.
For an inclusive interval of integer counts \(a\le X\le b\), subtract cumulative probabilities:
The subtraction removes all outcomes below \(a\), leaving the probability from \(a\) through \(b\). In R, this can be calculated as pbinom(b, size=n, prob=p) - pbinom(a-1, size=n, prob=p). In Excel, subtract the two corresponding cumulative BINOM.DIST results.
A short justification also explains why the “at least” boundary shifts by one. Since \(X\) takes integer values, the events \(X\ge k\) and \(X>k-1\) contain exactly the same possible outcomes. The complement of \(X\ge k\) is \(X\le k-1\); therefore \(P(X\ge k)=1-P(X\le k-1)\).
Geometric Probabilities and the Failure-Count Convention
In the course convention, \(T\) denotes the trial number on which the first success occurs, so \(T\) can be 1, 2, 3, and so on. The geometric probability mass function is
R’s geometric functions and Excel’s GEOM.DIST use a different input: the number \(F\) of failures before the first success. Consequently, \(F=T-1\), so a first success on trial \(t\) corresponds to \(t-1\) failures. In R, dgeom(x, prob=p) gives \(P(F=x)\), and pgeom(q, prob=p) gives \(P(F\le q)\). In Excel, GEOM.DIST(x, p, FALSE) gives a point probability and setting the final argument to TRUE gives a cumulative probability through \(x\) failures.
The conversion follows directly from the definitions: before a first success on trial \(t\), there are exactly \(t-1\) failures. In particular, a cumulative geometric call at \(t-1\) failures includes first successes on trials 1 through \(t\), not just on trial \(t\).
Worked Example: First Success on Trial Four
Suppose, hypothetically, that a device passes an independent test with probability \(p=0.25\) on each attempt. Let \(T\) be the attempt number of the first pass. The constant pass probability and independence support a geometric model. Find the probability that the first pass occurs on attempt four.
Attempt four means three failures followed by a success. Therefore, enter \(3\), not \(4\), in a geometric software function. In R, use dgeom(3, prob=0.25); in Excel, use GEOM.DIST(3, 0.25, FALSE).
The probability is
Thus the probability that the first pass occurs on attempt four is about 0.1055, or 10.55%. Entering 4 would instead ask for four failures before the first pass, which corresponds to the first pass on attempt five.
Worked Example: First Success Between Trials Three and Six
For the same type of hypothetical independent testing, suppose the probability of success on each trial is \(p=0.30\). Let \(T\) be the first-success trial. Find \(P(3\le T\le6)\). The trials have a fixed success probability and are assumed independent, as required by the geometric model.
The interval \(3\le T\le6\) is equivalent to \(2\le F\le5\), where \(F=T-1\). Use a difference of cumulative probabilities: \(P(F\le5)-P(F\le1)\). In R, the command is pgeom(5, prob=0.30) - pgeom(1, prob=0.30). In Excel, use GEOM.DIST(5, 0.30, TRUE) - GEOM.DIST(1, 0.30, TRUE).
The two cumulative probabilities are
Therefore,
The probability that the first success occurs on trials three through six, inclusive, is about 0.3724, or 37.24%. The upper cumulative boundary is 5 failures and the lower one is 1 failure; those boundaries reflect the shift from trial numbers to failure counts.
A Practical Checking Routine
Before relying on a software result, verify the model, inputs, event boundaries, and output convention. The following sequence makes common translation errors easier to catch.
For a binomial calculation, state the number of successes in \(n\) trials. For a geometric calculation, state whether the variable is the first-success trial \(T\) or the failure count \(F\).
Confirm the fixed binomial trial count and common probability, or the geometric independent trials and common probability. Enter \(n\) and \(p\) for a binomial calculation, and \(p\) plus the correct failure-count boundary for a geometric calculation.
For example, “at least 3” is \(X\ge3\), so a cumulative complement uses \(X\le2\). Convert trial numbers to failures before using a geometric function.
Use a point function for equality, a cumulative function for “at most,” and a complement or difference of cumulative probabilities for other tails or intervals.
Probabilities must be between 0 and 1. Confirm that the result refers to the event asked about, then report a suitable rounded value and describe the event and its context.
Common Mistakes and Why Software Does Not Prevent Them
A calculator or function evaluates the request it receives; it cannot determine whether the request matches the question. Several checks are especially useful:
- Using a cumulative command for an exact count. A cumulative function returns a probability through a boundary, such as \(P(X\le3)\), not \(P(X=3)\). Use a point function or set the spreadsheet cumulative argument to FALSE.
- Confusing “at least” with “greater than.” “At least 3” includes 3, while “greater than 3” does not. For integer-valued \(X\), \(P(X\ge3)=1-P(X\le2)\), whereas \(P(X>3)=1-P(X\le3)\).
- Entering the trial number into a geometric function. R and Excel expect failures before the first success. A first success on trial 4 requires input 3.
- Assuming an upper-tail option includes its boundary. R’s lower.tail=FALSE gives \(P(X>q)\). To calculate \(P(X\ge k)\), use the boundary \(k-1\) or subtract \(P(X\le k-1)\) from 1.
For example, an answer to “at least three” that uses the upper tail above 3 omits the probability at exactly 3. The correction is to use the upper tail above 2, or the complement of the cumulative probability through 2. Writing the event before typing a command exposes this off-by-one difference.
Check Your Understanding
For each question, identify the relevant software convention or probability boundary before calculating.
- For a binomial variable \(X\), which R command structure returns \(P(X=4)\), and what does the default pbinom(4, size=n, prob=p) return?
- Write an R expression for \(P(X\ge5)\) using a cumulative binomial function. Why is the boundary 4 rather than 5?
- A first success occurs on trial 7. What failure count should be entered into dgeom or GEOM.DIST?
- In R, what event is represented by pgeom(3, prob=p) in terms of the first-success trial \(T\)?
- How would you calculate \(P(a\le X\le b)\) for a binomial variable using cumulative probabilities?