Simulate sign errors: changing probabilities
In the previous exercise, each simulation had a fixed probability of a sign error at each step.
In the original question as posed, the probability of a sign error can be different at each step; the only requirement is that each probability is less than 0.50.
Here, let us simulate a math problem with 2 steps in which the probability of a switch on each step is 0.49 and 0.01, meaning that there is a high probability of becoming incorrect on the first step and a low probability of switching back.
Este exercício faz parte do curso
Probability Puzzles in R
Instruções do exercício
- Use the
sapply
function with therbinom
function to simulate the switches within one problem, with switch probabilities of 0.49 and 0.01 for the first and second steps, respectively. - Determine the total number of switches that occurred.
- Determine whether the answer to the math problem would be correct or not.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
set.seed(1)
counter <- 0
for(i in 1:10000){
# Simulate switches
each_switch <- sapply(___)
# Count switches
num_switches <-
# Check solution
if(___){
counter <- counter + 1
}
}
print(counter/10000)