Get startedGet started for free

Sign Error Cancellations

1. Sign Error Cancellations in a Math Problem

In the final lesson of this chapter, we investigate the probability of obtaining the correct answer on a mathematics problem when some sign errors are made.

2. The inspiration

This lesson was inspired from a tweet by Bill Chen, a notable financial statistician, poker player, and author of the book The Mathematics of Poker. In a mathematics problem, a student might accidentally forget or add a negative sign at any step along the way. Bill notes that if the student does this an even number of times in the problem, they will still arrive at the correct answer. The question is, assuming no other sources of error, if the student has less than a 50 percent chance of making a sign error on each step of the problem, do they have a greater than 50 percent chance of getting the problem correct in the end?

3. The rbinom function

Let's start with reviewing the rbinom function. Here, we can use it to simulate the completion of math problems with n representing the number of iterations we want to simulate, size representing the number of steps in the problem, and prob representing the probability of making a sign error on each step. This output represents 10 different trials of completing a math problem with 5 steps, with each step having a 0 point 4 probability of making a sign error. The outputted numbers represent the number of sign errors made on each of the 10 trials.

4. Checking whether a value is even

Then, we want to know if each value is even since this would result in a correct answer under the setup of this puzzle. Recall the round function, which is used here since a value is even if its division by 2 results in an integer.

5. Using the mean function to estimate a probability

Recall that the mean function can be used to estimate a probability. The mean function can be used on a vector of TRUE and FALSE to calculate the proportion of elements that are TRUE, as shown here.

6. Revisiting the sapply function

Finally, recall that the sapply function can be used to run a function, specified by the argument FUN, on each element of a vector, specified by the argument X. In the code here, the three dots represent additional arguments to the function that can also be specified. Here we demonstrate this with the rbinom function, which requires the arguments n, size, and prob. We want to simulate something resembling a binomial situation, but with different success probabilities on each step, since the student has a different probability of making a sign error on each step of the problem. We specify those probabilities to sapply as X. We specify n and size after the FUN argument, setting them each as 1 to run one iteration of the four trials, each with the different success probabilities specified. The output shows the results of each step from one math problem. Zero indicates that a sign error was not made on that step, and 1 indicates that a sign error was made on that step. To determine how many steps had a sign error, we use the sum function on the result.

7. Let's do it!

Let's try applying these tools to our problem.