[R] how can generate h(u)=min{a,log(u)} for 0<u<1 in R ?

Daniel Malter daniel at umd.edu
Tue Dec 22 12:34:09 CET 2009


Hi,

if "a" is a constant, and "u" is a vector of random variables of arbitrary
length, each of which is uniformly distributed between 0 and 1, then h(u) is
a random sample of the function f.

So, if you adjust the code to the desired "a" and to the desired length "n,"
then you get a random sample of h(u) of length n. If that is not what you
want to do, you need to state your question more precisely.

Daniel

-------------------------
cuncta stricte discussurus
-------------------------

-----Original Message-----
From: khazaei at ceremade.dauphine.fr [mailto:khazaei at ceremade.dauphine.fr] 
Sent: Monday, December 21, 2009 3:33 PM
To: Daniel Malter
Subject: RE: [R] how can generate h(u)=min{a,log(u)} for 0<u<1 in R ?

Hello Dear
thank you for your answer, but I need to generate a sample from the
function h(u) not compute the h(u).
best
khazaei


> Hi, see the example below. There must be a way to do this with apply or
> tapply, but it always returned an error "incorrect number of dimensions.
> At
> least the code below works
>
> n=100
> a=rnorm(n)
> u=runif(n)
>
> f=function(x){min(x[,1],log(x[,2]))}
>
> x=data.frame(a,u)
>
> apply(x,1,f) #does not work
>
> #this works
> y=NULL
> for(i in 1:n) y[i]=f(x[i,])
>
> HTH,
> Daniel
>
> -------------------------
> cuncta stricte discussurus
> -------------------------
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
> On
> Behalf Of khazaei at ceremade.dauphine.fr
> Sent: Monday, December 21, 2009 5:17 AM
> To: r-help at r-project.org
> Subject: [R] how can generate h(u)=min{a,log(u)} for 0<u<1 in R ?
>
> Hello,
>
> How can generate a sample from h(u)=min{a,log(u)} for 0<u<1   in R,please?
>
> thank you
> khazaei
>
> ______________________________________________
> 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.
>
>




More information about the R-help mailing list