DRclass_lu_Quantile {DRclass} | R Documentation |
Calculate lower and upper bounds of quantiles of marginals of a Density Ratio Class. Quantiles of the marginals of distributions proportional to the lower and upper bounding functions are also provided. See the function 'DRclass_k_Quantile' for the case in which the upper and lower bounding functions of the class are proportional.
Description
Calculate lower and upper bounds of quantiles of marginals of a Density Ratio Class. Quantiles of the marginals of distributions proportional to the lower and upper bounding functions are also provided. See the function 'DRclass_k_Quantile' for the case in which the upper and lower bounding functions of the class are proportional.
Usage
DRclass_lu_Quantile(
sample_u,
l,
u,
probs = c(0.025, 0.25, 0.5, 0.75, 0.975),
tol = 0.001,
maxiter = 100
)
Arguments
sample_u |
Sample from a distribution proportional to the upper bound of the class, often from the posterior of the upper bound of the prior in Bayesian inference. Columns represent variables, rows go across the sample. |
l |
Either a function to evaluate the lower bound of the Density Ratio Class or a vector of values of this function evaluated for the rows of 'sample_u'. Note that in the context of Bayesian inference the upper bound of the prior can be provided as only the ratio of l/u is needed and the likelihood cancels in this fraction. This saves computation time as the prior is usually computationally much cheaper to evaluate than the likelihood. |
u |
Either a function to evaluate the upper bound of the Density Ratio Class or a vector of values of this function evaluated for the rows of 'sample_u'. Note that in the context of Bayesian inference the lower bound of the prior can be provided as only the ratio of l/u is needed and the likelihood cancels in this fraction. This saves computation time as the prior is usually computationally much cheaper to evaluate than the likelihood. |
probs |
Vector of probabilities for which the quantile bounds are to be provided. |
tol |
Tolerance in quantile value for approximating the solution of the implicit equation for quantiles with the bisection algorithm. |
maxiter |
Maximum number of iterations for approximating the solution of the implicit equation for quantiles with the bisection algorithm. |
Value
Matrix of quantile bounds and quantiles (rows) for different marginal variables (columns).
Examples
# example of the application of DRclass functions:
# ------------------------------------------------
# parameter values
k <- 10
sd <- 0.5
sampsize <- 10000
# upper and lower class boundaries:
u <- function(x) { return( dnorm(x,0,sd)) }
l <- function(x) { return(1/k*dnorm(x,0,sd)) }
# generate sample:
sample_u <- cbind(rnorm(sampsize,0,sd),rnorm(sampsize,0,sd)) # example of 2d sample
# get class boundaries (back from sample):
pdf1 <- DRclass_k_Pdf(sample_u,k=k,adjust=2) # faster for l proportional to u
pdf2 <- DRclass_lu_Pdf(sample_u,l=l,u=u,adjust=2) # l and u could have different shapes
# get cdf bounds:
cdf1 <- DRclass_k_Cdf(sample_u,k=k)
cdf2 <- DRclass_lu_Cdf(sample_u,l=l,u=u)
# get quantile bounds:
quant1 <- DRclass_k_Quantile(sample_u,k=k,probs=c(0.025,0.5,0.975))
quant2 <- DRclass_lu_Quantile(sample_u,l=l,u=u,probs=c(0.025,0.5,0.975))
# plot selected features of the first component of the sample:
oldpar <- par(no.readonly=TRUE)
par(mar=c(5, 4, 1, 4) + 0.1) # c(bottom, left, top, right)
plot(pdf1[1,,c("x","u")],type="l",xaxs="i",yaxs="i",xlim=c(-2,2),xlab="x",ylab="pdf")
lines(pdf2[1,,c("x","l")])
par(new=TRUE)
plot(cdf1[1,,c("x","F_upper")],type="l",xaxs="i",yaxs="i",axes=FALSE,
xlim=c(-2,2),ylim=c(0,1),ylab="",lty="dashed")
axis(4); mtext("cdf",4,2)
lines(cdf2[1,,c("x","F_lower")],lty="dashed")
abline(v=quant1["quant_lower_0.5",1],lty="dotted")
abline(v=quant1["quant_upper_0.5",1],lty="dotted")
abline(v=quant1["quant_lower_0.025",1],lty="dotdash")
abline(v=quant1["quant_upper_0.975",1],lty="dotdash")
par(oldpar)