Solve the problem using three (numerical) techniques:
-
using a for loop with an if() clause and accumulator (Hint: The strategy is to sample 3 fishes without replacement from sample_space,
sample_space <- c(rep("Y",3),rep("B",7)) n <- 1000000
and count how many fishes were yellow. If only one is yellow, then this is a successful case. In this case, add 1 to the accumulator. Repeat the procedure n times. The frequentist result will be accumulator/n.
- using a for loop with an ifelse() function and accumulator
- Vectorial approach using sapply (no loops, no if() or ifelse(), no accumulator).
The answer for all should be the same, .525.
Aucun commentaire:
Enregistrer un commentaire