??
but u2 is higher than u1 ?you havent guaranteed that it wouldnt be.
You use randome numbers...
look at the information plotted, and observe the colours.
set.seed(10)
dat=runif(50,0,100)
cdf <- as.data.frame(Hmisc::Ecdf(dat))
colnames(cdf)=c("Temperature","probability")
temp=30
(percentile=predict(loess(cdf$probability ~ cdf$Temperature), temp))
lines(c(0,100),c(percentile,percentile),col="black")
set.seed(1000)
(u1 <- runif(1, 0, percentile))
lines(c(0,100),c(u1,u1),col="blue")
(d1 <- quantile(ecdf(cdf$Temperature), u1))
points(d1,u1,col="red", pch=2)
d1=as.vector(d1)
percentile2=predict(loess(cdf$probability ~ cdf$Temperature),(temp-d1))
lines(c(0,100),c(percentile2,percentile2),col="red")
(u2=runif(1, 0, percentile2))
lines(c(0,100),c(u2,u2),col="purple")
d2 <- ifelse(d1 <= temp,
quantile(ecdf(cdf$Temperature),u2),
0 )
points(d2,u2,col="red", pch=2)
d3 <- temp - (d1 + d2)