Last data update: 2014.03.03

R: Random Draw Generator
random.functionR Documentation

Random Draw Generator

Description

This function generates random draws of a continuous random variable given either its density or its cumulative distribution function.

Usage

random.function(n = 1, f, lower = -Inf, upper = Inf, kind = "density")

Arguments

n

number of draws, default 1.

f

either a density (default) or cumulative distribution function of the random variable.

lower

lower limit of the support of the random variable, default -Inf.

upper

upper limit of the support of the random variable, default Inf.

kind

character string with the function used to identify the distribution, either "density" (default) or "cumulative", as alternative.

Details

random.function uses the method of the inverse of the cdf to generate random draws from f.

Value

A vector of length n with n draws from a random variable with density (or cumulative distribution) function given by f.

Note

random.function is called by dgeometric.test when the corresponding r- function (random generator of f) is not available in the environment. random.function generates random samples from the null hypothesis density function specified in dgeometric.test.

Author(s)

Jose M. Pavia

See Also

dgeometric.test, integrate, inverse and support.facto.

Examples

f0 <- function(x) ifelse(x>=0 & x<=1, 2-2*x, 0)
random.function(10, f0, lower=0, upper=1, kind="density")

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(GoFKernel)
Loading required package: KernSmooth
KernSmooth 2.23 loaded
Copyright M. P. Wand 1997-2009
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/GoFKernel/random.function.Rd_%03d_medium.png", width=480, height=480)
> ### Name: random.function
> ### Title: Random Draw Generator
> ### Aliases: random.function
> 
> ### ** Examples
> 
> f0 <- function(x) ifelse(x>=0 & x<=1, 2-2*x, 0)
> random.function(10, f0, lower=0, upper=1, kind="density")
 [1] 0.2854115 0.2678258 0.3176206 0.4743786 0.3013391 0.2921981 0.1439444
 [8] 0.5226034 0.4526106 0.2873319
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>