我正在寻找一个 R 代码,它可以帮助我在以数字形式给出 pdf 时找到分位数。也就是说,假设我的数据是
x = c(0.00,0.05,0.10,0.15,0.20,0.25,0.30,0.35,0.40,0.45,0.50,0.55,0.60,0.65,0.70,0.75,0.80,0.85,0.90,0.95,1.00)
对应的pdf值为
pdf = c(0.000000000,1.221759375,1.968300000,2.349028125,2.457600000,2.373046875,2.160900000,1.874315625,1.555200000,1.235334375,0.937500000,0.676603125,0.460800000,0.292621875,0.170100000,0.087890625,0.038400000,0.012909375,0.002700000,0.000178125,0.000000000)
我想找到第 95 个分位数。我找到了一个例子here,但是,在这个例子中pdf被认为是一个函数,这不是我的情况。提前感谢您的帮助。
你可以尝试
approxfun
如下
> y <- cumsum(pdf) / sum(pdf)
> k <- !duplicated(y)
> approxfun(y[k],x[k])(0.95)
[1] 0.5577952