Say I have the follow dataset that shows a list of three observations for each state for a hypothetical experiment:
state <- c("Iowa", "Minnesota", "Illinois")
outcome <- list(c(5, 11, 11), c(3, 12, 8), c(9, 14, 2))
dat <- tibble(state, outcome)
Each row contains the state's name, as well as the results of an experiment that are aligned vertically by position. (The first row holds the results for the first experiment, the second row the second experiment, etc.) I'm trying to determine the probability of a state having the median value in an experiment. For example:
- In the first experiment, Iowa had the median value of 5.
- In the second experiment, Minnesota had the median value of 11.
- In the third experiment, Minnesota had the median value of 8.
Therefore, we would assign the following probabilities to each state given our small sample:
- Iowa's probability of being the median:
1 / 3 = 33% - Minnesota's probability of being the median:
2 / 3 = 67% - Illinois's probability of being the median:
0 / 3 = 0%
How does one calculate the probabilities of a state being the median using R? Thanks in advance.