mercredi 18 septembre 2019

What is the probability that exactly one yellow fish gets selected? Solve the problem using three numerical techniques

Solve the problem using three (numerical) techniques:

  1. 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.

  1. using a for loop with an ifelse() function and accumulator
  2. 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