Mice data

  • 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

Graphical summaries

Permutation statistics (difference of means)

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) 
}

Permutation distribution of \(\bar{x} - \bar{y}\)

p-value calculations

# 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

Permutation Test (difference of medians)

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) 
}

Perumation distribution of \(\tilde{x}-\tilde{y}\)

P-value

# 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