#This function calculates the (K-1)fold integral of the empirical distribution. Integr.Fn <- function(theta,K,X){ X.s <- sort(X) n <- length(X) rank <- rank(c(theta,X.s)) if(rank[1] ==1) Output <- 0 else Output <- (1/factorial(K-1))*(1/n)*sum((theta-X.s[1:(rank[1]-1)])^{K-1}) Output }