#' Sample distribution functions
#'
#' Generates random samples from distribution functions/objects
#'
#' \code{sampleDistribution} can be used for any distribution object generated by
#' \code{\link{makeDistribution}} or by functions in the \code{distr} package.
#' It is a wrapper around \code{\link[distr:r]{dist::r}}.
#'
#' @encoding UTF-8
#' @author Jens Åström
#' @name sampleDistribution
#'
#' @import distr
#'
#' @param dist distribution object to sample
#' @param nSamples `integer` size of sample
#' @return a numeric vector containing the sample
#'
#' @export
#' @examples
#' myDist <- makeDistribution(input = "logNormal", distParams = list("mean" = 1, "sd" = 0.2))
#' sampleDistribution(dist = myDist, nSamples = 10)
#'
#' myDist <- makeDistribution(input = "Poisson", distParams = list("lambda" = 3))
#' sampleDistribution(myDist, 10)
#'
#' myProbs <- data.frame("est" = c(0.2, 0.23, 0.34, 0.4), "probs" = c(0.1, 0.4, 0.4, 0.1 ))
#' myDist <- makeDistribution(myProbs)
#' sampleDistribution(myDist, 10)
#'
#' codaSamples <- rnorm(10000, mean = 0.87, sd = 0.3)
#' myDist <- makeDistribution(codaSamples)
#' mean(sampleDistribution(myDist, 10000))
#'
#' @seealso \code{\link{makeDistribution}}
sampleDistribution <- function(dist, nSamples = 10){
out <- distr::r(dist)(nSamples)
return(out)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.