- Treatment of mice with new medical treatment
- Efron and Tibshirani - Modern fathers of statistics
x = c(94, 197, 16, 38, 99, 141, 23) # T group y = c(52, 104, 146, 10, 51, 30, 40, 27, 46) # C group
x = c(94, 197, 16, 38, 99, 141, 23) # T group y = c(52, 104, 146, 10, 51, 30, 40, 27, 46) # C group
library(vecsets) P = 1000 # number of total permutations d = rep(0, P) # repeat 0s P times ('place holder') for(i in 1:P){ # new T group permutation x_new = sample(x = c(x, y), size = 7, replace = F) # rest of the data - C group y_new = vsetdiff(c(x,y), x_new) # new stats d[i] = mean(x_new) - mean(y_new) }
# logical condition that shows True or False larger_than_observed_difference <- d >= mean(x) - mean(y) # get count of permutations that gave stats larger than observed stats count = length(d[larger_than_observed_difference]) count
## [1] 149
# calculate p-value p_value = count/P p_value
## [1] 0.149
library(vecsets) P = 1000 # number of total permutations d = rep(0, P) # repeat 0s P times ('place holder') for(i in 1:P){ # new T group permutation x_new = sample(x = c(x, y), size = 7, replace = F) # rest of the data - C group y_new = vsetdiff(c(x,y), x_new) # new stats d[i] = median(x_new) - median(y_new) }
# count of permutations that gave stats larger than observed stats count = length(d[d >= median(x) - median(y)]) count
## [1] 170
# calculate p-value p_value = count/P p_value
## [1] 0.17