[R] generate random number

Spencer Graves spencer.graves at pdf.com
Tue Dec 2 18:00:14 CET 2003


      Please note that "a" is given by "b" (or vice versa), because the 
integral from x1 to x2 of f(x)dx must be 1. 

      I have solved this kind of problem by writing density functions, 
cumulative distribution functions, quantile and random number functions 
as a set of 4, using different ones to help check the others.  If your 
distribution is "ss", then the standard S naming convention would have 
dss, pss, qss, and rss for density, probability (cdf), quantile (inverse 
cdf) and random number generation.  See, e.g., "?runif" for a typical 
argument convention. 

      Note that rss <- function(n, ...)pss(runif(n), ...)

      hope this helps.  spencer graves

Ragnhild Sørum wrote:

> Hi
>
> I would like to generate some(ss) random numbers from a density 
> distribution f(x).
> In my case f(x) = a*exp(b*x),  ex. a=2, b=0.5,   and x is only defined 
> between x1 and x2,  ex.  from -6 to -2.5.
>
> Any suggestions? Can I use rexp?
>
> Thanks,
> Ragnhild
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help




More information about the R-help mailing list