statistics - Generalised Pareto Distribution MLE R code -
i've written function calculate mle estimates of generalised pareto distribution. when utilize info though i'm getting errors
1: in log(beta * ksi) : nans produced 2: in nlm(loglik, theta, stepmax = 5000, iterlim = 1000) : na/inf replaced maximum positive value
i wondering if spot mistakes code?
mlgpd<-function(data){ xi0 <- 1 beta0 <- 360 theta <- c(xi0, beta0) excess <- info assign("tmp", excess) loglik <- function(theta){ ksi <- theta[1] beta <- theta[2] y <- ((tmp - 0.1)/beta) f <- ((1/ksi)+1)*sum(log(1+y)) + length(tmp) * log(beta*ksi) f } fit <- nlm(loglik, theta, stepmax = 5000, iterlim= 1000) return(fit) par.ests <- fit$x return(par.ests) } #checking our mle algorithm works: rgpd<-function(n,ksi, beta){ 10000+beta*(((1-runif(n, min=0, max=1))^-ksi)-1) } rgpd1 <- rgpd(100, 1, 2.5) mlgpd(rgpd1)
thanks!
r statistics
No comments:
Post a Comment