根据百分位数排列生成分布

may*_*bra -2 statistics r

考虑到以下分数和百分位数,我想在R中生成分布.

x <- 1:10
PercRank <- c(1, 7, 12, 23, 41, 62, 73, 80, 92, 99)
Run Code Online (Sandbox Code Playgroud)

PercRank = 1例如,告诉我1%的数据有一个value/score <= 1(x的第一个值).同样,PercRank = 7告诉我们有7%的数据有value/score <= 2等等.

我不知道如何找到基础分布.如果我能从pdf如此多的信息中获得有关如何获得基础分布的指导,我会很高兴.

Aru*_*run 9

来自维基百科:

分数的百分位数是其频率分布中与其相同或更低的分数的百分比.

为了说明这一点,让我们创建一个分布,比如a normal distribution,with mean=2sd=2,以便我们以后可以测试(我们的代码).

# 1000 samples from normal(2,2)
x1 <- rnorm(1000, mean=2, sd=2)
Run Code Online (Sandbox Code Playgroud)

现在,让我们采取percentile rank您在帖子中提到的相同内容.让它除以100,使它们代表累积概率.

cum.p <- c(1, 7, 12, 23, 41, 62, 73, 80, 92, 99)/100
Run Code Online (Sandbox Code Playgroud)

scores这些百分位数相对应的值()是多少?

# generating values similar to your x.
x <- c(t(quantile(x1, cum.p)))
> x
 [1] -2.1870396 -1.4707273 -1.1535935 -0.8265444 -0.2888791  
         0.2781699  0.5893503  0.8396868  1.4222489  2.1519328
Run Code Online (Sandbox Code Playgroud)

这意味着1%的数据小于-2.18.7%的数据小于-1.47等...现在,我们有xcum.p(相当于你的PercRank).让我们忘记x1这个应该是正态分布的事实.为了找出它可能是什么分布,让我们通过使用diff得到第n和第(n-1)个元素之间的差来从累积概率中得到实际概率.

prob <- c( cum.p[1], diff(cum.p), .01)
> prob
# [1] 0.01 0.06 0.05 0.11 0.18 0.21 0.11 0.07 0.12 0.07 0.01
Run Code Online (Sandbox Code Playgroud)

现在,我们所要做的就是为x的每个间隔生成大小的样本,比如100(可以是任意数字),(x[1]:x[2], x[2]:x[3] ...)然后最终从这个巨大的数据中抽取你需要的多个点数(例如10000) ),具有上述概率.

这可以通过以下方式完成:

freq <- 10000 # final output size that we want

# Extreme values beyond x (to sample)
init <- -(abs(min(x)) + 5) 
fin  <- abs(max(x)) + 5

ival <- c(init, x, fin) # generate the sequence to take pairs from
len <- 100 # sequence of each pair

s <- sapply(2:length(ival), function(i) {
    seq(ival[i-1], ival[i], length.out=len)
})
# sample from s, total of 10000 values with probabilities calculated above
out <- sample(s, freq, prob=rep(prob, each=len), replace = T)
Run Code Online (Sandbox Code Playgroud)

现在,我们有来自分发的10000个样本.我们来看看它是怎么回事.它应该类似于正态分布,均值= 2且sd = 2.

> hist(out)
Run Code Online (Sandbox Code Playgroud)

normal_dist

> c(mean(out), sd(out))
# [1] 1.954834 2.170683
Run Code Online (Sandbox Code Playgroud)

这是一个正态分布(从直方图)与mean = 1.95sd = 2.17 (~ 2).

注意:我所解释的一些事情可能是环形交叉和/或代码"可能/可能不会"与其他一些发行版一起使用.这篇文章的重点只是用一个简单的例子来解释这个概念.

编辑:为了澄清@Dwin's一点,我尝试使用x = 1:10与OP的问题相对应的相同代码,使用相同的代码替换x的值.

cum.p <- c(1, 7, 12, 23, 41, 62, 73, 80, 92, 99)/100
prob <- c( cum.p[1], diff(cum.p), .01)
x <- 1:10

freq <- 10000 # final output size that we want

# Extreme values beyond x (to sample)
init <- -(abs(min(x)) + 1) 
fin  <- abs(max(x)) + 1

ival <- c(init, x, fin) # generate the sequence to take pairs from
len <- 100 # sequence of each pair

s <- sapply(2:length(ival), function(i) {
    seq(ival[i-1], ival[i], length.out=len)
})
# sample from s, total of 10000 values with probabilities calculated above
out <- sample(s, freq, prob=rep(prob, each=len), replace = T)

> quantile(out, cum.p) # ~ => x = 1:10
# 1%     7%    12%    23%    41%    62%    73%    80%    92%    99% 
# 0.878  1.989  2.989  4.020  5.010  6.030  7.030  8.020  9.050 10.010 

> hist(out)
Run Code Online (Sandbox Code Playgroud)

hist_OPs_data