好吧,所以我这里有一个最奇怪的问题.当我们用一个独立变量X的特定分位数划分空格时,我正在取一个因变量Y的均值.
我的问题是,R中的分位数函数没有返回我的自变量X范围内的值,但是当它打印到屏幕上时返回的值是正确的值.是什么让这个陌生人只会发生特定的分位数.
一些示例代码来演示这种奇怪的效果:
x<-c(1.49,rep(1.59,86))
quantile(x,0.05) # returns 1.59, the correct value
# However both of these return all values as false
table(x>=quantile(x,0.05))
table(x==quantile(x,0.05))
# But if we take a quantile at 0.075 it works correctly
table(x>=quantile(x,0.075))
Run Code Online (Sandbox Code Playgroud)
你们可以提供的任何见解将不胜感激.
分位数不完全是 1.59:
> quantile(x, 0.05)[[1]] == 1.59
[1] FALSE
> quantile(x, 0.05)[[1]] == 1.5900000000000003
[1] TRUE
Run Code Online (Sandbox Code Playgroud)
quantile(..., type = 7)似乎替换1.59用0.7000000000000001 * 1.59 + 0.3 * 1.59,这引入了禁止使用精确的相等的一个微小的误差.