本文介绍了如何找到均匀分布的MLE?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用R查找给定均匀分布X〜UNIF(1,3)的最大似然估计a_hat和b_hat.以下是我的代码及其输出:

I am trying to find the maximum likelihood estimators a_hat and b_hat for a given uniform distribution X ~ UNIF(1,3) using R. Below is my code and its output:

##Example: Uniform Distribution
x<-runif(100,1,3)
n<-length(x)
ll<-function(a,b){

  -sum(1/(b-a)^n,log=TRUE)

}
m0<-mle2(ll,start=list(a=1,b=2))
summary(m0)

> summary(m0)

最大似然估计

Call:
mle2(minuslogl = ll, start = list(a = 1, b = 2))

Coefficients:
Estimate Std. Error z value Pr(z)
a   1.5159         NA      NA    NA
b   1.4841         NA      NA    NA

-2 log L: -1.542595e+150
Warning message:
In sqrt(diag(object@vcov)) : NaNs produced

我无法解释为什么我的系数与原始值如此不同.我非常确定我正在使用正确的似然函数进行均匀分布,但是对于某些地方的语法以及语法我也可能是错误的.我正在使用library(bbmle)

I am not able to reason why my coefficients are so off from the original values. I am pretty much sure I am using the correct likelihood function for uniform distribution, but I may be wrong for it as well syntax somewhere. I am using library(bbmle)

推荐答案

感谢所有提供帮助的人.

Thanks everyone who helped.

  1. 我联系了我的教授,结果发现我无法对不可区分的分布使用"bbmle".
  2. 在这种情况下,log(constant = 1/b-a)不可微分以获得最大值.
  3. 还有一个名为" ExtDist "的R包,该包对于所有发行版(对于我来说到目前为止,包括统一版)都很好地输出MLE,但不提供它们的标准错误,实际上是"bbmle". 确实
  1. I contacted my professor and it turned out I can't use the "bbmle" for distributions which are not differentiable.
  2. In this case log(constant=1/b-a) is not differentiable to get a maxima.
  3. There is another R package called "ExtDist" which output MLE very well for all distributions (so far for me, including uniform) but doesn't provide standard error of them, which infact "bbmle" does

只是为了帮助将来可能会偶然发现此帖子的任何人:

Just to help anyone who may stumble upon this post in future:

正常,"bbmle":

Normal, "bbmle":

#Comparison of mentioned packages
  #Example for normal distribution
  set.seed(123)
  library("bbmle")
  x<-rnorm(100,1,3) #mean=1, sd = 3
  n<-length(x)
  ll<-function(a,b){
    -sum(dnorm(x,a,b,log=TRUE))
  }
  m0<-mle2(ll,start=list(a=1,b=2))
  summary(m0)

结果:

Maximum likelihood estimation

 Call:
 mle2(minuslogl = ll, start = list(a = 1, b = 2))

 Coefficients:
   Estimate Std. Error z value     Pr(z)
 a  1.27122    0.27247  4.6655 3.079e-06 ***
 b  2.72473    0.19267 14.1421 < 2.2e-16 ***
 ---
 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

 -2 log L: 484.2609

正常,"ExtDist":

Normal, "ExtDist":

library("ExtDist")
  m1<-eNormal(X=x,method = "unbiased.MLE")
  m1

结果:

 Parameters for the Normal distribution.
 (found using the  unbiased.MLE method.)

  Parameter     Type Estimate      S.E.
       mean location 1.271218 0.2738448
         sd    scale 2.738448 0.1946130

制服,"bbmle":

Uniform , "bbmle":

#Example for uniform distribution
  set.seed(123)
  x<-runif(100,1,3) #minimum =1, maximum = 3
  range(x)  #To know beforehand the original minimum and maximum before the      package estimates
 [1] 1.00125 2.98854
  n<-length(x)
  ll<-function(a,b){
    -sum(dunif(x,a,b,log=TRUE))
  }
 m3<-mle2(ll,start=list(a=1,b=2))
 Error in optim(par = c(1, 2), fn = function (p)  :
   initial value in 'vmmin' is not finite
  summary(m3)

错误消息:

 Error in optim(par = c(1, 2), fn = function (p)  :
 initial value in 'vmmin' is not finite

统一的"ExtDist":

Uniform, "ExtDist":

 m4<-eUniform(X=x,method = "unbiased.MLE")
  m4

 Parameters for the Uniform distribution.
 (found using the  numerical.MLE method.)

  Parameter     Type Estimate
          a boundary 1.001245
          b boundary 2.988544

这篇关于如何找到均匀分布的MLE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-17 21:27