Function for plotting a simulation envelope for \(f^U(z) - \hat{f}^u(z)\)
uhcdiffdensplot <- function(densdat, densrand, xl=NULL){
mean.f <- apply(densrand,2,mean)
low.f <- apply(densrand,2,quantile, prob=0.025)
up.f <- apply(densrand,2,quantile, prob=0.975)
# Difference in density plot (f^u - hat(f)^u)
yl2 <- range(c(densdat$y-low.f, densdat$y-up.f))
if (is.null(xl)!= TRUE){
plot(densdat$x, densdat$y-mean.f, ylim=yl2,
xlab="", type="l", ylab="", xlim=xl)
}else{
plot(densdat$x, densdat$y-mean.f, ylim=yl2, xlab="", type="l", ylab="")}
lines(densdat$x, densdat$y-low.f, col="red", lty=2)
lines(densdat$x, densdat$y-up.f, col="red", lty=2)
abline(h=0)
}
spun with ezspin(“uhcplots/functions/uhcdiffdensplot.R”, out_dir = “uhcplots/output”, fig_dir=“uhcplots/figures”, keep_md=F)