Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R bbmle中的NaN错误_R_Nan_Mle - Fatal编程技术网

R bbmle中的NaN错误

R bbmle中的NaN错误,r,nan,mle,R,Nan,Mle,这个问题与我之前的问题和论文中提供的数据集有关。对于这些数据,我们采用了Ben Bolker提出的代码 library(stats4) library(bbmle) x <- scan(textConnection("115 181 255 418 441 461 516 739 743 789 807 865 924 983 1024 1062 1063 1165 1191 1222 1222 1251 1277 1290 1357 1369 1408 1455 1478 1549 1

这个问题与我之前的问题和论文中提供的数据集有关。对于这些数据,我们采用了Ben Bolker提出的代码

library(stats4)
library(bbmle)

x <- scan(textConnection("115 181 255 418 441 461 516 739 743 789
807 865 924 983 1024 1062 1063 1165 1191 1222 1222 1251 1277 1290 1357 1369 1408 1455 1478 1549 1578 1578 1599 1603 1605 1696 1735 1799 1815 1852"))

dd  <- data.frame(x)

dLE <- function(x,lambda,theta,log=TRUE){
    r <- log(lambda+theta*x)-(lambda*x+(theta/2)*x^2)
    if (log) return(r) else return(exp(r))
}

svec <- list(lambda=0.0009499,theta=0.000002)
m1 <- mle2( x ~ dLE(lambda,theta),
      data=dd,
      start=svec,
      control=list(parscale=unlist(svec)))
coef(m1)
库(stats4)
图书馆(bbmle)

经过一番探索,我的观点是,这篇论文的结果根本不正确。我从
optim()
得到的结果比论文中报道的结果要好得多。我总是会错过一些东西;我建议你联系通讯作者

(警告不一定是一个问题——它们意味着优化器尝试了一些组合,这些组合会导致记录负数,这并不意味着最终结果是错误的——但我同意,解决警告总是一个好主意,以防它们以某种方式破坏结果。)

预备赛 结果 图表 让我们仔细检查一下,看看是否可以从论文中复制这个数字:


使用纸张匹配参数绘制的ecdf和CDF;使用此处估计的参数绘制的CDF要好得多(事实上,它看起来比本文中报告的KLE拟合更好,并且具有更低的对数可能性)。我的结论是,这篇论文中的文章有严重错误。

非常感谢。是的,我对他们的结果感到困惑,尤其是我得到的负面结果。我还没有检查其他安装型号的参数
library(bbmle)
## load data, in a format as similar to original table
## as possible (looking for typos)
x <- scan(textConnection("115 181 255 418 441 461 516 739 743 789
                          807 865 924 983 1024 1062 1063 1165 1191 1222
                         1222 1251 1277 1290 1357 1369 1408 1455 1478 1549
                         1578 1578 1599 1603 1605 1696 1735 1799 1815 1852"))
dd  <- data.frame(x)  
## parameters listed in table 2
svec <- list(lambda=9.499e-4,theta=2e-6)
## PDF (as above)
dLE <- function(x,lambda,theta,log=TRUE){
    r <- log(lambda+theta*x)-(lambda*x+(theta/2)*x^2)
    if (log) return(r) else return(exp(r))
}
## CDF (for checking)    
pLE <- function(x,lambda,theta) {
    1-exp(-(lambda*x+(theta/2)*x^2))
}
m1 <- mle2( x ~ dLE(lambda,theta),
      data=dd,
      start=svec,
      control=list(parscale=unlist(svec)),
      method="L-BFGS-B",
      lower=c(0,0))
coef(m1)
##      lambda        theta 
## 0.000000e+00 1.316733e-06 
-logLik(m1)  ## 305.99 (much better than 335, reported in the paper)
png("SO55032275.png")
par(las=1)
plot(ecdf(dd$x),col="red")
with(svec,curve(pLE(x,lambda,theta),add=TRUE,col=1))
with(as.list(coef(m1)),curve(pLE(x,lambda,theta),add=TRUE,col=3,lty=2))
legend("topleft",col=c(2,1,3),lty=c(NA,1,3),pch=c(16,NA,NA),
       c("ecdf","paper (lam=9e-4, th=2e-6)","ours (lam=0, th=1.3e-6)"))
dev.off()