Sorry for my bad english.
I need a function in R that calculates x values similar as the quantile function does, but considering that the x values were already calculated with a quantile function.
As example: I have a simple data frame that consists of two columns as given:
probs | x |
---|---|
0.06 | -120 |
0.1 | -100 |
0.2 | -97 |
0.24 | -90 |
0.3 | -80 |
0.5 | -70 |
0.7 | -60 |
0.89 | -50 |
1 | -40 |
(in fact the data is more detailed but for an example it will be enough)
The x values are calculated by a quantile function in the past but I have no access to the original x data. Is there a function like the quantile function that doesn't ignore the weighting and that calculates more quantiles in between those values?
CodePudding user response:
I think you just want to do a linear interpolation. For example,
dat <- structure(list(probs = c(0.06, 0.1, 0.2, 0.24, 0.3, 0.5, 0.7,
0.89, 1), x = c(-120, -100, -97, -90, -80, -70, -60, -50, -40
)), class = "data.frame", row.names = c(NA, -9L))
fn <- approxfun(dat$probs, dat$x)
fn(c(0.1, 0.15, 0.2))
#> [1] -100.0 -98.5 -97.0
Created on 2022-02-15 by the reprex package (v2.0.1.9000)