Re: [R] Histogram for mixed random variables

From: Stephen D. Weigand <weigand.stephen_at_charter.net>
Date: Fri 06 May 2005 - 23:04:40 EST

Dear Paul,

On May 5, 2005, at 6:43 AM, Paul Smith wrote:

> Dear All
>
> I would like to get the histogram for the following model with
> discrete and continuous random variables:
>
> * with probability 1/3, a random number is drawn from the continuous
> uniform distribution (min=0, max=1);
> * with probability 2/3, a random number is drawn from a different
> continuous uniform distribution (min=-1/2, max=1/2).
>
> Any help would be most welcome.
>
> Thanks in advance,
>
> Paul

My approach to generate the data would be

rMyfun <- function(n){

   x1 <- runif(n, 0, 1)
   x2 <- runif(n, -0.5, 0.5)
   ifelse(rbinom(n, 1, 1/3), x1, x2)
}

Hope this helps,

Stephen



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Fri May 06 23:11:01 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:37 EST