说我有从两个分布中采样的值,和. 也就是说,我有一个样本和一个样本. 我将如何寻找对于任何给定的值和?
我知道我可以使用以下代码相当容易地获得自举解决方案:
bootstrapProcedure <- function(A, B, sample.size = 100) {
# Calculates the fraction of times a sample of size (sample.size) from A is
# greater than a sample of the same size from B (both drawn with replacement).
#
# Args:
# A: vector of values for sample 1
# B: vector of values for sample 2
# sample.size: integer of the size of the bootstrapped sample to draw
#
# Returns:
# The fraction of times the sample from A is greater than the sample from B
mean(sample(A, sample.size, replace = T) > sample(B, sample.size, replace = T))
}
# Draw 2 populations
A <- rnorm(1000, mean = 1, sd = 2)
B <- rnorm(1000, mean = 2, sd = 4)
# Get the bootstrapped probability 1,000 times
replicate(1000, bootstrapProcedure(A, B))
但似乎应该有一个简单的分析解决方案。有什么想法我应该如何找到它?