[R] How can I generate this numbers
Ben Bolker
bolker at zoo.ufl.edu
Tue Oct 3 00:52:41 CEST 2006
Ricardo Rios <alfilnegro.sv <at> gmail.com> writes:
>
> Hi Rolf Turner, I have a statistical model, it model need this
> numbers for calculate the probability. This numbers must be random.
>
> For example I need that
> >magicfunction(3)
> >[1] 0.3152460 0.5231614 0.1615926
> >magicfunction(3)
> >[1] 0.6147933 0.3122999 0.0729068
>
> but the argument of the function is arbitrary , does somebody
> know if exist this function in R?
>
> On 10/2/06, Rolf Turner <rolf <at> erdos.math.unb.ca> wrote:
> >
> > This sounds so simple it must be a homework problem, no?
> >
> > cheers,
> >
> > Rolf Turner
> > rolf <at> math.unb.ca
> >
Hmmm. You're basically asking for random probabilities of
a composition. There are many possible distributions (and it's
hard to imagine that it doesn't matter which one you choose,
or what it's parameters are!
you may need to think about this some more), e.g. additive
log ratio or Dirichlet. Dirichlet (the multivariate analogue
of the beta distribution) is most common and simplest, although
not very flexible. rdirichlet() exists in several different
packages: try RSiteSearch("rdirichlet").
(actually, for what you're looking for
magicfunction <- function(n) {
r <- runif(n)
r/sum(r)
}
should satisfy your needs -- you can substitute any non-negative
probability distribution for runif -- but, again, you may need
to think more about what you're doing ...)
good luck
Ben Bolker
More information about the R-help
mailing list