calc_p <-
function(observed_stats, theoretical_stats){
  stopifnot(is.list(observed_stats), is.list(theoretical_stats),
            identical(length(observed_stats), length(theoretical_stats)),
            isTRUE(all(names(observed_stats) == names(theoretical_stats))))
  m <- length(observed_stats)
  stopifnot(m == length(theoretical_stats))
  output <- vector(mode = "list", length = m)
  names(output) <- names(observed_stats)
  for(i in seq_len(m)){
    output[i] <- mean(observed_stats[[i]] <= theoretical_stats[[i]])
  }
  return(output)
}
