[R] combining distributions

Rachel Taylor rachelt04 at hotmail.com
Tue Apr 28 16:09:13 CEST 2009


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.  
 
It is basically simulating loss values, where the losses per year are Poisson distributed, and the values are Pareto distributed.  I wanted a vector with total loss in each year.
 
My function for bounded pareto values is 
 
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
}

And so far for this function I have 
 
function(n)
{
Y <- rpois(n,33.63)
i <- 1:n
m <- 2*sum(Y)
S <- rboundpareto(m)
G <- sample(S, Y[i], replace=FALSE)
G
}

As you can see, my theory was to sample from a set S of Pareto values.  It does output values, I think it is just outputting one sample.
 
Any help would be greatly appreciated
 
Rachel
_________________________________________________________________
[[elided Hotmail spam]]




More information about the R-help mailing list