Generate random Bernoulli draws

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

Generate random Bernoulli draws

DavidMarino
Dear All,

I would like to generate N random Bernoulli draws given a probability
function F(x)=1-exp(-2.5*x) in which x follows  uniform distribution, say
x~U(0,2).

Can some one leave me some code lines for implementing this?

Thanks in advance.

David

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Generate random Bernoulli draws

Bert Gunter-2
Is this homework?

(There is an informal no-homework policy on this list).

Cheers,
Bert



Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )

On Thu, Jul 5, 2018 at 10:23 PM, Marino David <[hidden email]>
wrote:

> Dear All,
>
> I would like to generate N random Bernoulli draws given a probability
> function F(x)=1-exp(-2.5*x) in which x follows  uniform distribution, say
> x~U(0,2).
>
> Can some one leave me some code lines for implementing this?
>
> Thanks in advance.
>
> David
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Generate random Bernoulli draws

DavidMarino
Dear Bert,

I know it is a simple question. But for me, at current, I fail to implement
it. So, I ask for help here.

It is not homework.

Best,

David

2018-07-06 13:32 GMT+08:00 Bert Gunter <[hidden email]>:

> Is this homework?
>
> (There is an informal no-homework policy on this list).
>
> Cheers,
> Bert
>
>
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along and
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
> On Thu, Jul 5, 2018 at 10:23 PM, Marino David <[hidden email]>
> wrote:
>
>> Dear All,
>>
>> I would like to generate N random Bernoulli draws given a probability
>> function F(x)=1-exp(-2.5*x) in which x follows  uniform distribution, say
>> x~U(0,2).
>>
>> Can some one leave me some code lines for implementing this?
>>
>> Thanks in advance.
>>
>> David
>>
>>         [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posti
>> ng-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Generate random Bernoulli draws

Ben Tupper-2
Hi,

I haven't any idea about what you ask, but I do know that Rseek.org <http://rseek.org/> is a gold mine!  Check out...

https://rseek.org/?q=Bernoulli+random+variable <https://rseek.org/?q=Bernoulli+random+variable>

Cheers,
Ben

> On Jul 6, 2018, at 1:35 AM, Marino David <[hidden email]> wrote:
>
> Dear Bert,
>
> I know it is a simple question. But for me, at current, I fail to implement
> it. So, I ask for help here.
>
> It is not homework.
>
> Best,
>
> David
>
> 2018-07-06 13:32 GMT+08:00 Bert Gunter <[hidden email]>:
>
>> Is this homework?
>>
>> (There is an informal no-homework policy on this list).
>>
>> Cheers,
>> Bert
>>
>>
>>
>> Bert Gunter
>>
>> "The trouble with having an open mind is that people keep coming along and
>> sticking things into it."
>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>>
>> On Thu, Jul 5, 2018 at 10:23 PM, Marino David <[hidden email]>
>> wrote:
>>
>>> Dear All,
>>>
>>> I would like to generate N random Bernoulli draws given a probability
>>> function F(x)=1-exp(-2.5*x) in which x follows  uniform distribution, say
>>> x~U(0,2).
>>>
>>> Can some one leave me some code lines for implementing this?
>>>
>>> Thanks in advance.
>>>
>>> David
>>>
>>>        [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posti
>>> ng-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Ecological Forecasting: https://eco.bigelow.org/






        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Generate random Bernoulli draws

DavidMarino
Dear Ben,

Thanks a lot for your reply.

Best,

David

2018-07-06 19:33 GMT+08:00 Ben Tupper <[hidden email]>:

> Hi,
>
> I haven't any idea about what you ask, but I do know that Rseek.org is a
> gold mine!  Check out...
>
> https://rseek.org/?q=Bernoulli+random+variable
>
> Cheers,
> Ben
>
> On Jul 6, 2018, at 1:35 AM, Marino David <[hidden email]> wrote:
>
> Dear Bert,
>
> I know it is a simple question. But for me, at current, I fail to implement
> it. So, I ask for help here.
>
> It is not homework.
>
> Best,
>
> David
>
> 2018-07-06 13:32 GMT+08:00 Bert Gunter <[hidden email]>:
>
> Is this homework?
>
> (There is an informal no-homework policy on this list).
>
> Cheers,
> Bert
>
>
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along and
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
> On Thu, Jul 5, 2018 at 10:23 PM, Marino David <[hidden email]>
> wrote:
>
> Dear All,
>
> I would like to generate N random Bernoulli draws given a probability
> function F(x)=1-exp(-2.5*x) in which x follows  uniform distribution, say
> x~U(0,2).
>
> Can some one leave me some code lines for implementing this?
>
> Thanks in advance.
>
> David
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posti
> ng-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.
>
>
> Ben Tupper
> Bigelow Laboratory for Ocean Sciences
> 60 Bigelow Drive
> <https://maps.google.com/?q=60+Bigelow+Drive&entry=gmail&source=g>, P.O.
> Box 380
> East Boothbay, Maine 04544
> http://www.bigelow.org
>
> Ecological Forecasting: https://eco.bigelow.org/
>
>
>
>
>
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Generate random Bernoulli draws

Berry, Charles
In reply to this post by DavidMarino
A liitle math goes along way. See below.

> On Jul 5, 2018, at 10:35 PM, Marino David <[hidden email]> wrote:
>
> Dear Bert,
>
> I know it is a simple question. But for me, at current, I fail to implement
> it. So, I ask for help here.
>
> It is not homework.
>
> Best,
>
> David
>
> 2018-07-06 13:32 GMT+08:00 Bert Gunter <[hidden email]>:
>
>> Is this homework?
>>
>> (There is an informal no-homework policy on this list).
>>
>> Cheers,
>> Bert
>>
>>
>>
>> Bert Gunter
>>
>> "The trouble with having an open mind is that people keep coming along and
>> sticking things into it."
>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>>
>> On Thu, Jul 5, 2018 at 10:23 PM, Marino David <[hidden email]>
>> wrote:
>>
>>> Dear All,
>>>
>>> I would like to generate N random Bernoulli draws given a probability
>>> function F(x)=1-exp(-2.5*x) in which x follows  uniform distribution, say
>>> x~U(0,2).

If each Bernoulli draw is based on its own draw of x, then

        rbinom( N, 1, 0.8013476 )

is what you want.

It is left as an exercise for the reader to verify that the constant 0.8013476 is correct up to approximation error, and to prove that such a Bernoulli mixture is also Bernoulli. Perhaps,

        ?integrate

will help.

But if the x's are shared you need to use runif, expm1, and (possibly) rep to produce a vector to be used in place of  the prob argument.

HTH,

Chuck


>>>
>>> Can some one leave me some code lines for implementing this?
>>>
>>> Thanks in advance.
>>>
>>> David
>>>
>>>        [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posti
>>> ng-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>>
>
> [[alternative HTML version deleted]]
>

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Generate random Bernoulli draws

Göran Broström-3


On 2018-07-06 19:18, Berry, Charles wrote:

> A liitle math goes along way. See below.
>
>> On Jul 5, 2018, at 10:35 PM, Marino David
>> <[hidden email]> wrote:
>>
>> Dear Bert,
>>
>> I know it is a simple question. But for me, at current, I fail to
>> implement it. So, I ask for help here.
>>
>> It is not homework.
>>
>> Best,
>>
>> David
>>
>> 2018-07-06 13:32 GMT+08:00 Bert Gunter <[hidden email]>:
>>
>>> Is this homework?
>>>
>>> (There is an informal no-homework policy on this list).
>>>
>>> Cheers, Bert
>>>
>>>
>>>
>>> Bert Gunter
>>>
>>> "The trouble with having an open mind is that people keep coming
>>> along and sticking things into it." -- Opus (aka Berkeley
>>> Breathed in his "Bloom County" comic strip )
>>>
>>> On Thu, Jul 5, 2018 at 10:23 PM, Marino David
>>> <[hidden email]> wrote:
>>>
>>>> Dear All,
>>>>
>>>> I would like to generate N random Bernoulli draws given a
>>>> probability function F(x)=1-exp(-2.5*x) in which x follows
>>>> uniform distribution, say x~U(0,2).
>
> If each Bernoulli draw is based on its own draw of x, then
>
> rbinom( N, 1, 0.8013476 )
>
> is what you want.

Maybe it is what he wants, but note that F(x) as defined is a random
variable, not a (cumulative) probability function.

G,

>
> It is left as an exercise for the reader to verify that the constant
> 0.8013476 is correct up to approximation error, and to prove that
> such a Bernoulli mixture is also Bernoulli. Perhaps,
>
> ?integrate
>
> will help.
>
> But if the x's are shared you need to use runif, expm1, and
> (possibly) rep to produce a vector to be used in place of  the prob
> argument.
>
> HTH,
>
> Chuck
>
>
>>>>
>>>> Can some one leave me some code lines for implementing this?
>>>>
>>>> Thanks in advance.
>>>>
>>>> David
>>>>
>>>> [[alternative HTML version deleted]]
>>>>
>>>> ______________________________________________
>>>> [hidden email] mailing list -- To UNSUBSCRIBE and more,
>>>> see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read
>>>> the posting guide http://www.R-project.org/posti ng-guide.html
>>>> and provide commented, minimal, self-contained, reproducible
>>>> code.
>>>>
>>>
>>>
>>
>> [[alternative HTML version deleted]]
>>
>
> ______________________________________________ [hidden email]
> mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Generate random Bernoulli draws

Duncan Murdoch-2
In reply to this post by Berry, Charles
On 06/07/2018 1:18 PM, Berry, Charles wrote:

> A liitle math goes along way. See below.
>
>> On Jul 5, 2018, at 10:35 PM, Marino David <[hidden email]> wrote:
>>
>> Dear Bert,
>>
>> I know it is a simple question. But for me, at current, I fail to implement
>> it. So, I ask for help here.
>>
>> It is not homework.
>>
>> Best,
>>
>> David
>>
>> 2018-07-06 13:32 GMT+08:00 Bert Gunter <[hidden email]>:
>>
>>> Is this homework?
>>>
>>> (There is an informal no-homework policy on this list).
>>>
>>> Cheers,
>>> Bert
>>>
>>>
>>>
>>> Bert Gunter
>>>
>>> "The trouble with having an open mind is that people keep coming along and
>>> sticking things into it."
>>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>>>
>>> On Thu, Jul 5, 2018 at 10:23 PM, Marino David <[hidden email]>
>>> wrote:
>>>
>>>> Dear All,
>>>>
>>>> I would like to generate N random Bernoulli draws given a probability
>>>> function F(x)=1-exp(-2.5*x) in which x follows  uniform distribution, say
>>>> x~U(0,2).
>
> If each Bernoulli draw is based on its own draw of x, then
>
> rbinom( N, 1, 0.8013476 )
>
> is what you want.
>
> It is left as an exercise for the reader to verify that the constant 0.8013476 is correct up to approximation error, and to prove that such a Bernoulli mixture is also Bernoulli. Perhaps,
>
> ?integrate
>
> will help.
>
> But if the x's are shared you need to use runif, expm1, and (possibly) rep to produce a vector to be used in place of  the prob argument.

That may be correct from a mathematical perspective (I haven't checked),
but seems like a *really* bad idea from a programming perspective.  It
would be much better to write

x <- runif(N, 0, 2)
rbinom(N, 1, 1 - exp(-2.5*x))

because it is so much more clearly related to the original problem
statement.  Perhaps it would be a few microseconds slower, but that
would be saved many times over when any aspect of the problem statement
was modified.

Duncan Murdoch

>
> HTH,
>
> Chuck
>
>
>>>>
>>>> Can some one leave me some code lines for implementing this?
>>>>
>>>> Thanks in advance.
>>>>
>>>> David
>>>>
>>>>         [[alternative HTML version deleted]]
>>>>
>>>> ______________________________________________
>>>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>>> PLEASE do read the posting guide http://www.R-project.org/posti
>>>> ng-guide.html
>>>> and provide commented, minimal, self-contained, reproducible code.
>>>>
>>>
>>>
>>
>> [[alternative HTML version deleted]]
>>
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Generate random Bernoulli draws

Berry, Charles


> On Jul 6, 2018, at 3:31 PM, Duncan Murdoch <[hidden email]> wrote:
>
> On 06/07/2018 1:18 PM, Berry, Charles wrote:
>> A liitle math goes along way. See below.
>>> On Jul 5, 2018, at 10:35 PM, Marino David <[hidden email]> wrote:
>>>
>>> Dear Bert,
>>>
>>> I know it is a simple question. But for me, at current, I fail to implement
>>> it. So, I ask for help here.
>>>
>>> It is not homework.
>>>
>>> Best,
>>>
>>> David
>>>
>>> 2018-07-06 13:32 GMT+08:00 Bert Gunter <[hidden email]>:
>>>
>>>> Is this homework?
>>>>
>>>> (There is an informal no-homework policy on this list).
>>>>
>>>> Cheers,
>>>> Bert
>>>>
>>>>
>>>>
>>>> Bert Gunter
>>>>
>>>> "The trouble with having an open mind is that people keep coming along and
>>>> sticking things into it."
>>>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>>>>
>>>> On Thu, Jul 5, 2018 at 10:23 PM, Marino David <[hidden email]>
>>>> wrote:
>>>>
>>>>> Dear All,
>>>>>
>>>>> I would like to generate N random Bernoulli draws given a probability
>>>>> function F(x)=1-exp(-2.5*x) in which x follows  uniform distribution, say
>>>>> x~U(0,2).
>> If each Bernoulli draw is based on its own draw of x, then
>> rbinom( N, 1, 0.8013476 )
>> is what you want.
>> It is left as an exercise for the reader to verify that the constant 0.8013476 is correct up to approximation error, and to prove that such a Bernoulli mixture is also Bernoulli. Perhaps,
>> ?integrate
>> will help.
>> But if the x's are shared you need to use runif, expm1, and (possibly) rep to produce a vector to be used in place of the prob argument.
>
> That may be correct from a mathematical perspective (I haven't checked), but seems like a *really* bad idea from a programming perspective.  It would be much better to write

Well of course it would.  I was hoping that my somewhat obscure one-liner would suggest


>
> x <- runif(N, 0, 2)
> rbinom(N, 1, 1 - exp(-2.5*x))
>
> because it is so much more clearly related to the original problem statement.  Perhaps it would be a few microseconds slower, but that would be saved many times over when any aspect of the problem statement was modified.
>
> Duncan Murdoch
>
>> HTH,
>> Chuck
>>>>>
>>>>> Can some one leave me some code lines for implementing this?
>>>>>
>>>>> Thanks in advance.
>>>>>
>>>>> David
>>>>>
>>>>>        [[alternative HTML version deleted]]
>>>>>
>>>>> ______________________________________________
>>>>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>>>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>>>> PLEASE do read the posting guide http://www.R-project.org/posti
>>>>> ng-guide.html
>>>>> and provide commented, minimal, self-contained, reproducible code.
>>>>>
>>>>
>>>>
>>>
>>> [[alternative HTML version deleted]]
>>>
>> ______________________________________________
>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>> 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.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Generate random Bernoulli draws

Berry, Charles
Sorry about the last incomplete post. Accidentally hit send.

Meant to say that I was hoping that a correct, but  obscure response from me would motivate David to step back and think about his problem long enough to see that it has an easy solution.

Sorry if that was out-of-line.

Chuck

> On Jul 6, 2018, at 4:27 PM, Charles Berry <[hidden email]> wrote:
>
>> On Jul 6, 2018, at 3:31 PM, Duncan Murdoch <[hidden email]> wrote:
>>
>> On 06/07/2018 1:18 PM, Berry, Charles wrote:
>>> A liitle math goes along way. See below.
>>>> On Jul 5, 2018, at 10:35 PM, Marino David <[hidden email]> wrote:
>>>>
>>>> Dear Bert,
>>>>
>>>> I know it is a simple question. But for me, at current, I fail to implement
>>>> it. So, I ask for help here.
>>>>
>>>> It is not homework.
>>>>
>>>> Best,
>>>>
>>>> David
>>>>
>>>> 2018-07-06 13:32 GMT+08:00 Bert Gunter <[hidden email]>:
>>>>
>>>>> Is this homework?
>>>>>
>>>>> (There is an informal no-homework policy on this list).
>>>>>
>>>>> Cheers,
>>>>> Bert
>>>>>
>>>>>
>>>>>
>>>>> Bert Gunter
>>>>>
>>>>> "The trouble with having an open mind is that people keep coming along and
>>>>> sticking things into it."
>>>>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>>>>>
>>>>> On Thu, Jul 5, 2018 at 10:23 PM, Marino David <[hidden email]>
>>>>> wrote:
>>>>>
>>>>>> Dear All,
>>>>>>
>>>>>> I would like to generate N random Bernoulli draws given a probability
>>>>>> function F(x)=1-exp(-2.5*x) in which x follows  uniform distribution, say
>>>>>> x~U(0,2).
>>> If each Bernoulli draw is based on its own draw of x, then
>>> rbinom( N, 1, 0.8013476 )
>>> is what you want.
>>> It is left as an exercise for the reader to verify that the constant 0.8013476 is correct up to approximation error, and to prove that such a Bernoulli mixture is also Bernoulli. Perhaps,
>>> ?integrate
>>> will help.
>>> But if the x's are shared you need to use runif, expm1, and (possibly) rep to produce a vector to be used in place of the prob argument.
>

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Generate random Bernoulli draws

DavidMarino
Hi Chuck and all,

Thanks for your response. It is really helpful for me.

David

2018-07-07 7:30 GMT+08:00 Berry, Charles <[hidden email]>:

> Sorry about the last incomplete post. Accidentally hit send.
>
> Meant to say that I was hoping that a correct, but  obscure response from
> me would motivate David to step back and think about his problem long
> enough to see that it has an easy solution.
>
> Sorry if that was out-of-line.
>
> Chuck
>
> > On Jul 6, 2018, at 4:27 PM, Charles Berry <[hidden email]> wrote:
> >
> >> On Jul 6, 2018, at 3:31 PM, Duncan Murdoch <[hidden email]>
> wrote:
> >>
> >> On 06/07/2018 1:18 PM, Berry, Charles wrote:
> >>> A liitle math goes along way. See below.
> >>>> On Jul 5, 2018, at 10:35 PM, Marino David <[hidden email]>
> wrote:
> >>>>
> >>>> Dear Bert,
> >>>>
> >>>> I know it is a simple question. But for me, at current, I fail to
> implement
> >>>> it. So, I ask for help here.
> >>>>
> >>>> It is not homework.
> >>>>
> >>>> Best,
> >>>>
> >>>> David
> >>>>
> >>>> 2018-07-06 13:32 GMT+08:00 Bert Gunter <[hidden email]>:
> >>>>
> >>>>> Is this homework?
> >>>>>
> >>>>> (There is an informal no-homework policy on this list).
> >>>>>
> >>>>> Cheers,
> >>>>> Bert
> >>>>>
> >>>>>
> >>>>>
> >>>>> Bert Gunter
> >>>>>
> >>>>> "The trouble with having an open mind is that people keep coming
> along and
> >>>>> sticking things into it."
> >>>>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
> >>>>>
> >>>>> On Thu, Jul 5, 2018 at 10:23 PM, Marino David <
> [hidden email]>
> >>>>> wrote:
> >>>>>
> >>>>>> Dear All,
> >>>>>>
> >>>>>> I would like to generate N random Bernoulli draws given a
> probability
> >>>>>> function F(x)=1-exp(-2.5*x) in which x follows  uniform
> distribution, say
> >>>>>> x~U(0,2).
> >>> If each Bernoulli draw is based on its own draw of x, then
> >>>     rbinom( N, 1, 0.8013476 )
> >>> is what you want.
> >>> It is left as an exercise for the reader to verify that the constant
> 0.8013476 is correct up to approximation error, and to prove that such a
> Bernoulli mixture is also Bernoulli. Perhaps,
> >>>     ?integrate
> >>> will help.
> >>> But if the x's are shared you need to use runif, expm1, and (possibly)
> rep to produce a vector to be used in place of the prob argument.
> >
>
>
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.