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
Look at ?cumsum andydolman@gmail.com 2009/4/28 Rachel Taylor <rachelt04@hotmail.com>> > 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 > > ______________________________________________ > R-help@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. >[[alternative HTML version deleted]]
?cumsum On Tue, Apr 28, 2009 at 5:30 AM, Rachel Taylor <rachelt04 at hotmail.com> wrote:> > 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 > > ______________________________________________ > 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
Look at cumsum() Alain Rachel Taylor wrote:> 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 > > ______________________________________________ > 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. > >-- Alain Guillet Statistician and Computer Scientist SMCS - Institut de statistique - Universit? catholique de Louvain Bureau d.126 Voie du Roman Pays, 20 B-1348 Louvain-la-Neuve Belgium tel: +32 10 47 30 50