Alright, so I have the strangest issue here. I'm taking the mean of a dependent variable Y, when we partition a space by a particular quantile of an independent variable X.

My issue is, the quantile function in R is not returning a value within the range of my independent variable X, however the value it is returning, when printed to the screen is the correct value. What makes this stranger is it only happens with particular quantiles.

Some example code to demonstrate this weird effect:

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))

Any insight you guys can provide would be appreciated.

有帮助吗?

解决方案

The quantile isn't exactly 1.59:

> quantile(x, 0.05)[[1]] == 1.59
[1] FALSE
> quantile(x, 0.05)[[1]] == 1.5900000000000003
[1] TRUE

quantile(..., type = 7) appears to be replacing 1.59 with 0.7000000000000001 * 1.59 + 0.3 * 1.59, which introduces a tiny error that bars the use of exact equality.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top