Re: [R] discrete probability distribution

From: Ted Harding <Ted.Harding_at_nessie.mcc.ac.uk>
Date: Thu 23 Feb 2006 - 20:18:55 EST


On 23-Feb-06 Robin Hankin wrote:
> Hi
>
> I want to sample from a discrete random variable X, defined on
> the non-negative integers, with
>
> prob(X=0) = (1-p)
> prob(X=1) = (1-p)*p
> ...
> prob(X=i)=(1-p)*p^i
> ...
>
>
>
> Before reinventing the wheel,
> is there a ready-made R function to give me such a thing?

Use rgeom(n,(1-p))

Note (from ?rgeom) that these functions use the definition

  P(n) = p*(1-p)^n

i.e. the complementary value of p to the one in your description.

Best wishes,
Ted.



E-Mail: (Ted Harding) <Ted.Harding@nessie.mcc.ac.uk> Fax-to-email: +44 (0)870 094 0861
Date: 23-Feb-06                                       Time: 09:18:50
------------------------------ XFMail ------------------------------

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Feb 23 20:26:19 2006

This archive was generated by hypermail 2.1.8 : Thu 23 Feb 2006 - 21:08:45 EST