[R] help on sampling from the truncated normal/gamma distribution on the far end (probability is very low)
Peter Dalgaard
p.dalgaard at biostat.ku.dk
Fri Sep 19 08:41:55 CEST 2008
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
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help
mailing list