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.
Diese Übung ist Teil des Kurses
Probability Puzzles in R
Anleitung zur Übung
- Use the
sapplyfunction with therbinomfunction 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.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
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)