sim2.2

  1. Eight tires of different brands are ranked from 1 to 8 (best to worst) according to mileage performances.  If four of these tires are chosen at random by a customer, find the probability that the best tire among those selected by the customer is actually ranked third among the original eight. Verify with a simulation study using 10,000 replications.
::: {.cell}

```{.r .cell-code}
library(tidyverse)
```

::: {.cell-output .cell-output-stderr}

```
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.2.1     ✔ readr     2.2.0
✔ forcats   1.0.1     ✔ stringr   1.6.0
✔ ggplot2   4.0.3     ✔ tibble    3.3.1
✔ lubridate 1.9.5     ✔ tidyr     1.3.2
✔ purrr     1.2.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
```


:::

```{.r .cell-code}
library(purrrfect)
```

::: {.cell-output .cell-output-stderr}

```

Attaching package: 'purrrfect'

The following objects are masked from 'package:base':

    replicate, tabulate
```


:::
:::
tires = 1:8

one_omega = \() sample(tires, 4, replace = FALSE)

N = 10000

sim_tires = tibble(omega = base::replicate(N, one_omega(), simplify = FALSE)) %>%
  mutate(best_rank = map_int(omega, min))

sim_tires %>%
  summarise(prob_best_is_3rd = mean(best_rank == 3))
# A tibble: 1 × 1
  prob_best_is_3rd
             <dbl>
1            0.140
  1. A class contains 8 boys and 7 girls. The teacher selects 3 of the children at random and without replacement. Find the probability that the number of boys selected exceeds the number of girls selected. Verify with a simulation study using 10,000 replications.
class = rep(c("B", "G"), c(8, 7))

one_omega2 = \() sample(class, 3, replace = FALSE)

sim_class = tibble(omega = base::replicate(N, one_omega2(), simplify = FALSE)) %>%
  mutate(
    n_boys = map_int(omega, \(kids) sum(kids == "B")),
    n_girls = map_int(omega, \(kids) sum(kids == "G")),
    boys_exceed_girls = n_boys > n_girls
  )

sim_class %>%
  summarise(prob_boys_exceed = mean(boys_exceed_girls))
# A tibble: 1 × 1
  prob_boys_exceed
             <dbl>
1            0.546