Learn R Programming

OOmisc (version 1.2)

accept.reject: Function to generate categorical random numbers from the specified psuedo-distribution by Accept-Reject Method.

Description

Generates random numbers from the desired categorical distribution with given probabilities. Utilizes discrete uniform distribution.

Usage

accept.reject(prob, a, b, n)

Arguments

prob
a vector of probabilities
a
a numeric value which denotes the lower bound of the discrete uniform
b
a numeric value which denotes the upper bound of the discrete uniform
n
a numeric value for sample size

Value

returns a vector of simulated sample of size n.

Details

b-a+1 should be equal to the number of levels of the desired variable.

Examples

Run this code
accept.reject(prob=c(0.3,0.4,0.2,0.1),a=0,b=3,n=100)

Run the code above in your browser using DataLab