Skip to content
Prev 32738 / 398525 Next

Simulating a variable following an arbitrary distribution

Your specific example is a scaled beta.  Therefore, "2*rbeta(1000, 4, 
1)" will generate 1000 random numbers according to that distribution. 
You can get the same distribution from "2*qbeta(runif(1000), 4, 1)".
	  We can generalize this last example to any case of interest.  Example:

df4 <- function(x)(x^3)/4
pf4 <- function(q)(q^4)/16
qf4 <- function(p)(16*p)^0.25
rf4 <- function(n)qf4(runif(n))

Then "rf4(1000)" will produce 1000 pseudo-random deviates following this 
distribution.

hth.  spencer graves
Edgar Acuna wrote: