Skip to content

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

5 messages · Daniel Davis, Moshe Olshansky, Matthias Kohl +1 more

3 days later
#
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 <paperprint at gmail.com> wrote:

            
#
Well, I made a mistake - your lambda should be 400 and not 40!!!
--- On Thu, 18/9/08, Moshe Olshansky <m_olshansky at yahoo.com> wrote:

            
#
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:

  
    
#
Daniel Davis wrote:
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)
Exercise for the reader....