Created
December 2, 2025 13:25
-
-
Save carlislerainey/20b49faaf105db2211b72765c74d14b7 to your computer and use it in GitHub Desktop.
Tasting Tea Simulation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ---- set up experiment | |
| cups <- c( | |
| rep("Milk First", 4), | |
| rep("Tea First", 4) | |
| ) | |
| cups | |
| randomization <- sample(cups) | |
| # ---- where are the milk-first cups? | |
| # actually | |
| truth <- which(randomization == "Milk First") | |
| truth | |
| # guesses | |
| guesses <- sample(1:8, 4) | |
| guesses | |
| # ---- how many guesses are correct | |
| correct <- intersect(truth, guesses) | |
| correct | |
| length(correct) | |
| # ---- now do this many times and track number correct | |
| n_iter <- 10000 | |
| n_correct <- numeric(n_iter) | |
| for (i in 1:n_iter) { | |
| # randomize and guess | |
| randomization <- sample(cups) | |
| truth <- which(randomization == "Milk First") | |
| guesses <- sample(1:8, 4) | |
| correct <- intersect(truth, guesses) | |
| # track number of correct guesses | |
| n_correct[i] <- length(correct) | |
| } | |
| table(n_correct) # raw counts | |
| prop.table(table(n_correct)) # convert to proportions |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment