On 29/04/2010 5:40 AM, Nick Crosbie wrote:
Hi,
In S+/R, is there an easy way to generate random numbers with a
probability distribution specified by an exact user-defined function?
For example, I have a function:
f(x) = 1/(365 * x), which should be fitted for values of x between 1 and
100,000
How do I generate random numbers with a probability distribution that
exactly maps the above function?
You can use sample() with the prob argument set to the values of f(x).
You probably want replace=TRUE as well.
Duncan Murdoch
Nick
This email and any attachments may contain information t...{{dropped:15}}
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.