help on sampling from the truncated normal/gamma distribution on the far end (probability is very low)

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

help on sampling from the truncated normal/gamma distribution on the far end (probability is very low)

Daniel Davis-7
Hi, guys,

I am trying to sample from a truncated normal/gamma distribution.
But only the far end of the distribution (where the probability is very low)
is left. e.g.

mu = - 4;
sigma = 0.1;
The distribution is Normal(mu,sigma^2) truncated on [0,+Inf];

How can I get a sample? I tried to use inverse CDF method, but got Inf as
answers. Please help me out.

Also, pls help me on the similar situation on gamma dist'n.


Thanks,
Sonia

        [[alternative HTML version deleted]]

______________________________________________
[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
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: help on sampling from the truncated normal/gamma distribution on the far end (probability is very low)

Moshe Olshansky-2
Hi Sonia,

If I did not make a mistake, the conditional distribution of X given that X > 0 is very close to exponential distribution with parameter lambda = 40, so you can sample from this distribution.


--- On Mon, 15/9/08, Daniel Davis <[hidden email]> wrote:

> From: Daniel Davis <[hidden email]>
> Subject: [R] help on sampling from the truncated normal/gamma distribution on the far end (probability is very low)
> To: [hidden email]
> Received: Monday, 15 September, 2008, 2:28 PM
> Hi, guys,
>
> I am trying to sample from a truncated normal/gamma
> distribution.
> But only the far end of the distribution (where the
> probability is very low)
> is left. e.g.
>
> mu = - 4;
> sigma = 0.1;
> The distribution is Normal(mu,sigma^2) truncated on
> [0,+Inf];
>
> How can I get a sample? I tried to use inverse CDF method,
> but got Inf as
> answers. Please help me out.
>
> Also, pls help me on the similar situation on gamma
> dist'n.
>
>
> Thanks,
> Sonia
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [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
> and provide commented, minimal, self-contained,
> reproducible code.

______________________________________________
[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
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: help on sampling from the truncated normal/gamma distribution on the far end (probability is very low)

Moshe Olshansky-2
Well, I made a mistake - your lambda should be 400 and not 40!!!


--- On Thu, 18/9/08, Moshe Olshansky <[hidden email]> wrote:

> From: Moshe Olshansky <[hidden email]>
> Subject: Re: [R] help on sampling from the truncated normal/gamma distribution on the far end (probability is very low)
> To: [hidden email], "Daniel Davis" <[hidden email]>
> Received: Thursday, 18 September, 2008, 5:00 PM
> Hi Sonia,
>
> If I did not make a mistake, the conditional distribution
> of X given that X > 0 is very close to exponential
> distribution with parameter lambda = 40, so you can sample
> from this distribution.
>
>
> --- On Mon, 15/9/08, Daniel Davis
> <[hidden email]> wrote:
>
> > From: Daniel Davis <[hidden email]>
> > Subject: [R] help on sampling from the truncated
> normal/gamma distribution on the far end (probability is
> very low)
> > To: [hidden email]
> > Received: Monday, 15 September, 2008, 2:28 PM
> > Hi, guys,
> >
> > I am trying to sample from a truncated normal/gamma
> > distribution.
> > But only the far end of the distribution (where the
> > probability is very low)
> > is left. e.g.
> >
> > mu = - 4;
> > sigma = 0.1;
> > The distribution is Normal(mu,sigma^2) truncated on
> > [0,+Inf];
> >
> > How can I get a sample? I tried to use inverse CDF
> method,
> > but got Inf as
> > answers. Please help me out.
> >
> > Also, pls help me on the similar situation on gamma
> > dist'n.
> >
> >
> > Thanks,
> > Sonia
> >
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > [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
> > and provide commented, minimal, self-contained,
> > reproducible code.
>
> ______________________________________________
> [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
> and provide commented, minimal, self-contained,
> reproducible code.

______________________________________________
[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
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: help on sampling from the truncated normal/gamma distribution on the far end (probability is very low)

Prof. Dr. Matthias Kohl
you could use package "distr" and function "Truncate"; e.g.

library(distr)
N <- Norm(mean = -4, sd = 1)
NT <- Truncate(N, lower = 0, upper = Inf)
r(NT)(10)

Unfortunatelly, your example using sd = 0.1 is very extreme and Truncate
doesn't work; see also
pnorm(0, mean = -4, sd = 0.1, lower.tail = FALSE) == 0 ## which on my
system is TRUE

Best,
Matthias

Moshe Olshansky wrote:

> Well, I made a mistake - your lambda should be 400 and not 40!!!
>
>
> --- On Thu, 18/9/08, Moshe Olshansky <[hidden email]> wrote:
>
>  
>> From: Moshe Olshansky <[hidden email]>
>> Subject: Re: [R] help on sampling from the truncated normal/gamma distribution on the far end (probability is very low)
>> To: [hidden email], "Daniel Davis" <[hidden email]>
>> Received: Thursday, 18 September, 2008, 5:00 PM
>> Hi Sonia,
>>
>> If I did not make a mistake, the conditional distribution
>> of X given that X > 0 is very close to exponential
>> distribution with parameter lambda = 40, so you can sample
>> from this distribution.
>>
>>
>> --- On Mon, 15/9/08, Daniel Davis
>> <[hidden email]> wrote:
>>
>>    
>>> From: Daniel Davis <[hidden email]>
>>> Subject: [R] help on sampling from the truncated
>>>      
>> normal/gamma distribution on the far end (probability is
>> very low)
>>    
>>> To: [hidden email]
>>> Received: Monday, 15 September, 2008, 2:28 PM
>>> Hi, guys,
>>>
>>> I am trying to sample from a truncated normal/gamma
>>> distribution.
>>> But only the far end of the distribution (where the
>>> probability is very low)
>>> is left. e.g.
>>>
>>> mu = - 4;
>>> sigma = 0.1;
>>> The distribution is Normal(mu,sigma^2) truncated on
>>> [0,+Inf];
>>>
>>> How can I get a sample? I tried to use inverse CDF
>>>      
>> method,
>>    
>>> but got Inf as
>>> answers. Please help me out.
>>>
>>> Also, pls help me on the similar situation on gamma
>>> dist'n.
>>>
>>>
>>> Thanks,
>>> Sonia
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> [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
>>> and provide commented, minimal, self-contained,
>>> reproducible code.
>>>      
>> ______________________________________________
>> [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
>> and provide commented, minimal, self-contained,
>> reproducible code.
>>    
>
> ______________________________________________
> [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
> and provide commented, minimal, self-contained, reproducible code.
>  

--
Dr. Matthias Kohl
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
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: help on sampling from the truncated normal/gamma distribution on the far end (probability is very low)

Peter Dalgaard
In reply to this post by Daniel Davis-7
Daniel Davis wrote:

> Hi, guys,
>
> I am trying to sample from a truncated normal/gamma distribution.
> But only the far end of the distribution (where the probability is very low)
> is left. e.g.
>
> mu = - 4;
> sigma = 0.1;
> The distribution is Normal(mu,sigma^2) truncated on [0,+Inf];
>
> How can I get a sample? I tried to use inverse CDF method, but got Inf as
> answers. Please help me out.
>
>  
You were on track, but you need more awareness of the cancellation
issues. Two hints: Use logarithms and look at the correct tail.  So:

T <- pnorm(0, -4, .1, lower=F, log=T)
z <- qnorm(T-rexp(1000), -4, .1, lower=F, log=T)
hist(z)

> Also, pls help me on the similar situation on gamma dist'n.
>
>  
Exercise for the reader....

--
   O__  ---- Peter Dalgaard             Ă˜ster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - ([hidden email])              FAX: (+45) 35327907

______________________________________________
[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
and provide commented, minimal, self-contained, reproducible code.