我正在尝试使用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.
只是为了帮助将来可能会偶然发现此帖子的任何人:
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?
发布评论