R中β正常的最大似然估计

时间:2017-10-09 22:48:10

标签: r simulation mle vgam log-likelihood

我想估计beta-正态分布的参数。我使用了maxLik包

library(VGAM)
library(maxLik)
alfa=2;beta=3;mu=0;sigma=1
n=100
x=rbetanorm(n,alfa,beta,mu,sigma)
logLikFun=function(w){
  alfa=w[1]
  beta=w[2]
  mu=w[3]
  sigma=w[4]
  ll={-n*log(beta(alfa,beta))+(alfa-1)*sum(log(pnorm((x-mu)/sigma,mean=0,sd=1)))+(beta-1)*sum(log(1-pnorm((x-mu)/sigma,mean=0,sd=1)))-n*log(sigma)+sum(log(dnorm((x-mu)/sigma,mean=0,sd=1)))}
  ll
}
mle=maxLik(logLikFun,start=c(alfa=3,beta=2,mu=1,sigma=2))
summary(mle)

但是它给出了错误

----------------------------------
Maximum Likelihood estimation
Newton-Raphson maximisation, 4 iterations
Return code 2: successive function values within tolerance limit
Log-Likelihood: -86.16515 
4  free parameters
Estimates:
      Estimate Std. error t value Pr(> t)
alfa     3.000        Inf       0       1
beta     2.941        Inf       0       1
mu       1.000        Inf       0       1
sigma    2.000        Inf       0       1
--------------------------------------------

问题是错误的无限值是不可接受的。 如果有人能解决这个问题,我会很高兴。

1 个答案:

答案 0 :(得分:0)

结果非常依赖于初始值。此外,您可以将一些初始值设置为固定值。

有关代码背后的理论问题的更多信息,请参阅此link

library(VGAM)
library(maxLik)
alfa=1;beta=1;mu=0;sigma=1
n=100
x<-rbetanorm(n,alfa,beta,mu,sigma)
logLikFun<-function(w){
        alfa<-w[1]
        beta<-w[2]
        mu<-w[3]
        sigma<-w[4]
        ll<-{-n*log(beta(alfa,beta))+(alfa-1)*sum(log(pnorm((x-mu)/sigma,mean=0,sd=1)))+(beta-1)*sum(log(1-pnorm((x-mu)/sigma,mean=0,sd=1)))-n*log(sigma)+sum(log(dnorm((x-mu)/sigma,mean=0,sd=1)))}
        ll
}
mle<-maxLik(logLikFun,grad=NULL,hess=NULL,start=c(alfa=1,beta=1,mu=mean(x),sigma=1),"NR")
summary(mle)


OUTPUT:
--------------------------------------------
Maximum Likelihood estimation
Newton-Raphson maximisation, 10 iterations
Return code 2: successive function values within tolerance limit
Log-Likelihood: -139.6822 
3  free parameters
Estimates:
        Estimate Std. error t value  Pr(> t)    
alfa    0.4026     0.1190   3.384 0.000714 ***
beta    4.3981     2.9560   1.488 0.136794    
mu      2.0340     0.6135   3.315 0.000915 ***
sigma   1.0000     0.0000      NA       NA    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
--------------------------------------------