#This function calculates the (K-1)-fold integral of the function #f_thetaj(x) = (K/(thetaj)^K)*(thetaj-x)_{+}^{K-1}. J.Func <- function(theta,thetaj,K){ Out <- NULL if(theta <= thetaj){ Out <- (factorial(K-1)/factorial(2*K-1))*(-1)^{K-1} * sum(choose(2*K-1,0:(K-1))*(-1)^{0:(K-1)}*thetaj^{2*K-1-(0:(K-1))}*theta^{0:(K-1)})+ (-1)^{K}*(factorial(K-1)/factorial(2*K-1))*(thetaj-theta)^{2*K-1} } else Out <- (factorial(K-1)/factorial(2*K-1))*(-1)^{K-1} * sum(choose(2*K-1,0:(K-1))*(-1)^{0:(K-1)}*theta^{2*K-1-(0:(K-1))}*thetaj^{0:(K-1)})+(-1)^{K}*(factorial(K-1)/factorial(2*K-1))*(theta - thetaj)^{2*K-1} Out <- (K/thetaj^{K})*Out Out }