I have created an approxfun
function from the Binsmooth
package for finding means from binned data.
binedges <- c(10000,15000,20000,25000,30000,35000,40000,45000,
50000,60000,75000,100000,125000,150000,200000,NA)
bincounts <- c(157532,97369,102673,100888,90835,94191,87688,90481,
79816,153581,195430,240948,155139,9452,92166,103217)
splb <- splinebins(binedges, bincounts, 76091)
typing splb$splineCDF(x)
will return y, but I want to find the median value.
I understand that this function is supposed to achieve this goal, but it doesn't appear to work for functions created with the Binsmooth
package.
get x-value given y-value: general root finding for linear / non-linear interpolation function
I've put together a simple way that will find an approximate value, but it is not very satisfying and very computer intensive:
splb$splineCDF(50000)
fn(1000)
probability<- 0
income<- 0
while(probability< 0.5){
probability<- splb$splineCDF(income)
income<- income+ 10
}
Any ideas?