[R] Question
Joris Meys
jorismeys at gmail.com
Wed Jun 16 17:11:08 CEST 2010
Two possibilities : rescale your random vector, or resample to get
numbers within the range. But neither of these solutions will give you
a true exponential distribution. I am not aware of truncated
exponential distributions that are available in R, but somebody else
might know more about that.
# possibility I : rescaling
rsample <- rexp(5)
lim <- 0.8
rsample <- rsample*lim/max(rsample)
rsample
# possibility II : resampling
rsample <- rexp(5)
while(sum(rsample>lim)>0) {
rsample <- ifelse(rsample>lim,rexp(length(rsample)),rsample)
}
rsample
Cheers
Joris
On Wed, Jun 16, 2010 at 12:00 PM, Assieh Rashidi
<assiehrashidi at yahoo.com> wrote:
>
> Dear Mr.
> for writing program about Gibbs sampling, i have a question.
> if i want to generate data from Exponential distribution but range of X is restricted, how can i do?
> regards,
> A.Rashidi
>
>
>
>
>
> [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help at r-project.org 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.
>
>
--
Joris Meys
Statistical consultant
Ghent University
Faculty of Bioscience Engineering
Department of Applied mathematics, biometrics and process control
tel : +32 9 264 59 87
Joris.Meys at Ugent.be
-------------------------------
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php
More information about the R-help
mailing list