# Author: Adolfo J. Rumbos # Date: September 23, 2008 # Defining a cumulative distribution function CumDist() # # The function takes on the two arguments: X and v, where # X is a vector that contains values for a test statistic obtined from # the sample space of an experiment, and v is a value. # The result is the proportion of samples that yield a value less than # or equal to v # # CumDist <- function(X,v) # Sets up to define the function Phat { L<-length(X) # Computes length of X NYes <- 0 # Sets up counter of "yeses" for (i in 1:L) # Sets up loop through vector X { NYes <- NYes + (X[i]<=v) # adds 1 to counter if X[i]<= v } result <- NYes/L # Computes proportion of NYes in L return(result) # Returns cumulative distribution value }