Re: [R] Question

From: Joris Meys <jorismeys_at_gmail.com>
Date: Wed, 16 Jun 2010 17:11:08 +0200

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

______________________________________________
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.
Received on Wed 16 Jun 2010 - 15:14:09 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 16 Jun 2010 - 19:30:31 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive