Skip to content

creating a vector of sums

4 messages · Rachel Taylor, Andrew Dolman, jim holtman +1 more

#
Hi,
 
I am trying to create a function for a goodness-of-fit test for the Pareto Distribution for some loss data that I have.
So far I have the following:
 
function(X=OTOL)
{
n <- length(X)-1 #calculated the number of values (extra as 0 included)
i <- 2:640 #values of i
j <- 1:639 #values of i-1
Y <- (n-j+1)*((X[i])-(X[j])) #First part of GoF model
Y
}
 
Where OTOL is the ordered loss data (decreasing), and Y is a vector of length 639
 
What I need to do next is create another vector TY (of the same length) that is the the sum of part of the Y vector.
So TY[1]=Y[1]
TY[2]=Y[1]+Y[2]
TY[3]=Y[1]+Y[2]+Y[3]
and so on.
 
I have tried to do a sum(Y[j]) but it just comes out with a single value.
 
Any help is greatly appreciated, thank you.
 
Rachel
#
?cumsum
On Tue, Apr 28, 2009 at 5:30 AM, Rachel Taylor <rachelt04 at hotmail.com> wrote:

  
    
#
Look at cumsum()

Alain
Rachel Taylor wrote: