R/Rayleigh.R

Defines functions Rayleigh

Documented in Rayleigh

#' @title Generating samples from Rayleigh distribution
#' @descriptionuse Generating samples from Rayleigh distribution by using antithetic variables
#' @param n the number of samples
#' @param sigma the parameter of Rayleigh distribution
#' @param ant whether using antithetic variables
#' @return a random sample of size \code{n}
#' @examples
#' sample <- Rayleigh(1000,4)
#' head(sample,20)
#' @export
Rayleigh <- function(n,sigma,ant = T){
  m <- floor(n/2)
  u <- runif(m)
  if(ant) v <- 1-u else v <- runif(m)
  u <- c(u,v)
  sample <- numeric(length(u))
  sample <- (-(2*sigma^2)*(log(1-u)))^(1/2)
  return(sample)
}
pikachuuu108/StatComp18018 documentation built on May 19, 2019, 9:38 p.m.