# LOOP TO DETERMINE L-Kurtosis based on Regional "h" findLK05 <- function(initLmoments) { newhvalue=0.05 lowb=round(0.25*(5*initLmoments[3]^2-2),digits=3) # From Hosking and Wallis p. 24 uppb=0.999 # must be less than one posslk=seq(lowb,uppb,0.0005) potentialh={} for (j in posslk) { initLmoments[4]=j potentialh=c(potentialh,try(pelkap(initLmoments),silent=TRUE)[4]) } potentialh=as.numeric(potentialh) aaa=which.min(abs(potentialh-newhvalue))[1] # which h is the closest to orig lkurtnew=posslk[aaa] #pick that l-kurtosis value return(lkurtnew) } findLK05_optim <- function(init){ library(lmomRFA) lowb=0.25*(5*init[3]^2-2) # From Hosking and Wallis p. 24 uppb=0.999 # must be less than one f = function(x,init){ y = try(pelkap(c(init,x)),silent=TRUE)[4] objective = if(is.na(y)) 99999 + abs(x) else abs(y-0.05) return(objective) } o = optimize(f,lower=lowb,upper=uppb,init=init) return(o$minimum) }