[R] combining distributions
Ben Bolker
bolker at ufl.edu
Tue Apr 28 16:47:02 CEST 2009
Rachel Taylor-2 wrote:
>
>
> Hi all,
>
> I am trying to generate a series of random numbers. What I want to do is
> create n random Poisson numbers (easily done with the rpois function) and
> then use those generated numbers as the number of genenerated from another
> distribution (in this case, a function for the bounded Pareto distribution
> I have created).
>
> Or, to put it in a less convoluted way, say rpois generates the values
> 40,35,32,28,46. I then want to use my Pareto random number generator to
> generate 40, 35, 32, etc... numbers. My prefered final output will be a
> vector with 1000 values, each value being the sum of (random poisson)
> pareto random numbers.
>
I think this works:
rboundpareto <- function(n,gamma=0.7,alpha=5000000,beta=10000000000)
{
U <- runif(n)
A <- U*beta^gamma
B <- U*alpha^gamma
C <- beta^gamma
Num <- -(A-B-C)
D <- alpha^gamma
E <- beta^gamma
Denom <- D*E
Frac <- Num/Denom
Power <- -(1/gamma)
Val <- Frac^Power
Val
}
pp <- rpois(1000,20)
bb <- rboundpareto(sum(pp))
tapply(bb,rep(1:1000,pp),sum)
--
View this message in context: http://www.nabble.com/combining-distributions-tp23278204p23278600.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list