I got it to work: # To get a percentile of a single-variable function: # Step 1: Integrate over the domain to ge the normalization constant: Z<-integrate(function(x) sqrt(1+x^-1), 1,2)$value Z # Step 2: Find the .975 percentile x975<-uniroot(function(t) integrate(function(x) sqrt(1+x^-1), 1, t)$value/Z-.975, lower=1, upper=2, tol=5e-4 )$root x975
# To get a percentile of a marginal of a bivariate function of (x,y): # Define and compute the marginal x distribution: fx<-function(x) {sapply(x, function(x) integrate( function(y) sqrt(sin(x)+1/y), 0,10)$value ) } # Then proceed as above in the singe-variable case. Thank you Dieter and David. Nissim Kaufmann Dept. of Mathematics and Statistics University at Albany In reply to http://www.mail-archive.com/r-help@r-project.org/msg121420.html ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.