discrete probability distribution

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

discrete probability distribution

Robin Hankin
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?


--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: discrete probability distribution

Prof. Dr. Matthias Kohl
Hi,

have a look at
http://mathworld.wolfram.com/GeometricDistribution.html
respectively
http://mathworld.wolfram.com/NegativeBinomialDistribution.html
with r = 1.

In R have a look at
?rnbinom
with n = 1 and in your case: prob = 1-p

hth
Matthias

>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?
>
>
>--
>Robin Hankin
>Uncertainty Analyst
>National Oceanography Centre, Southampton
>European Way, Southampton SO14 3ZH, UK
>  tel  023-8059-7743
>
>______________________________________________
>[hidden email] mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>  
>


--
StaMatS - Statistik + Mathematik Service
Dr. rer. nat. Matthias Kohl
Gottlieb-Keim-Straße 60
95448 Bayreuth
Phone: +49 921 50736457
E-Mail: [hidden email]
Home: www.stamats.de

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: discrete probability distribution

Ted.Harding
In reply to this post by Robin Hankin
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) <[hidden email]>
Fax-to-email: +44 (0)870 094 0861
Date: 23-Feb-06                                       Time: 09:18:50
------------------------------ XFMail ------------------------------

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html