% Generated by roxygen2: do not edit by hand % Please edit documentation in R/ars.R \name{ars} \alias{ars} \title{Adaptive Rejection Sampling \code{ars}} \usage{ ars(f, N = 1000, bounds = c(-Inf, Inf), ...) } \arguments{ \item{f}{function to sample from (must fit log-concave properties)} \item{N}{number of observations outputted} \item{bounds}{vector of length 2 containing the lower and upper bounds for the distribution function f} \item{...}{additional arguments to pass to f (e.g. mean, sd, shape, etc.)} } \value{ Returns vector of samples, length N, from the distribution f(x) } \description{ Adaptive rejection sampling (ARS) is a sampling algorithm for log-concave univariate functions. One could use Rejection Sampling, but ARS is less computationally expensive through assumption of log-concavity and the unique function of updating the envelope and squeeze functions. } \examples{ library(ars) # Example 1: Sample 1500 values from a gamma distribution (Gammma(2,5)) N <- 1500 samples <- ars(dgamma, N, bounds=c(0,Inf), shape = 2, rate = 5) # plot a histogram and curve of actual to check for similarity hist(samples, prob= TRUE, breaks = 50) curve(dgamma(x, shape = 2, rate = 5), col="darkblue", lwd=2, add=TRUE, yaxt="n") # Example 2: Sample 1000 values from a beta distribution (Beta(2,6)) f <- dbeta samples <- ars(f, bounds=c(0,1), shape1 = 2, shape2 = 6) # plot a histogram and curve of actual to check for similarity hist(samples, prob= TRUE) curve(dbeta(x, shape1 = 2, shape2 = 6), col="darkblue", lwd=2, add=TRUE, yaxt="n") } \references{ Gilks, W. R., & Wild, P. (1992). Adaptive Rejection Sampling for Gibbs Sampling. \emph{Journal of the Royal Statistical Society. Series C (Applied Statistics)}, 41(2), 337–348. Markou, S. (Dec 2022). \emph{Adaptive rejection sampling.} Random walks. https://random-walks.org/content/misc/ars/ars.html Wickham, H. (2015). \emph{R packages.} O'Reilly Media. https://r-pkgs.org/testing-basics.html } \author{ Kristoffer Hernandez, Leon Weingartner, Nikita Mehandru }