简体   繁体   English

基于牛顿-拉夫森和矩量法的最大似然估计

[英]Maximum Likelihood estimation based on Newton-Raphson and the method of moments

I am conducting a small simulation study to examine the properties of the method of moments and the maximum likelihood estimators asymptotically. 我正在进行一项小型仿真研究,以渐近地研究矩量法和最大似然估计器的性质。

The method of moments estimator is easy to obtain(it is given by the second line of my code) but for the mle I had to write a Newton-Raphson algoritmh(which works perfectly well for one sample). 矩估计器的方法很容易获得(由我的代码的第二行给出),但是对于我来说,我不得不编写一个Newton-Raphson算法(对于一个样本来说效果很好)。 The mle needs to use the method of moments estimator as a starting point(the a0) as it enjoys some optimal statistical properties this way. MLE需要使用矩估计器的方法作为起点(a0),因为它以这种方式具有一些最佳的统计特性。 Here goes 开始

x<-rbeta(500,0.5,3)
mom<-3*mean(x)/(1-mean(x))

mlea<-function(x,a0,numstp=100,eps=0.001){
    n=length(x)
    numfin=numstp
    ic=0
    istop=0
    while(istop==0){
        ic=ic+1
        lprime=n/a0+n/(a0+1)+n/(a0+2)+sum(log(x))
        ldprime=-n/a0^2-n/(a0+1)^2-n/(a0+2)^2
        a1=a0-(lprime/ldprime)
        check=abs((a1-a0)/a0) 
        if(check<eps){istop=1} 
        a0=a1
    }
    list(a1=a1,check=check,realnumstps=ic)
}

This works for one sample but could I obtain these estimates for say 1000 samples? 这适用于一个样本,但是我能否获得1000个样本的估计值? How could I easily generalize this process? 我如何轻松地概括这个过程? My main difficulty is caused by the fact that the mle needs the mom as a starting point and both of these need to be computed from the same sample. 我的主要困难是由于以下事实引起的:the鼠需要妈妈作为起点,而这两者都需要从同一样本中计算得出。

Thank you in advance. 先感谢您。

I think you want to do this? 我想你想这样做吗?

n<-100
replicate(n, { 
    x<-rbeta(500,0.5,3)
    mom<-3*mean(x)/(1-mean(x))
    mlea(x, mom) 
})

Now a vector of numbers won't be returned because your function mlea returns a list. 现在,将不返回数字向量,因为您的函数mlea返回了一个列表。 Let's say the value from that list you really care about is a1, then you could do 假设您真正关心的清单中的值是a1,那么您可以

n<-100
replicate(n, { 
    x<-rbeta(500,0.5,3)
    mom<-3*mean(x)/(1-mean(x))
    mlea(x, mom)$a1 
})

notice I call the $a1 at the end of the function call. 注意,我在函数调用结束时调用了$ a1。

So what's going on here is replicate will pull 500 new observations from your beta distribution for each iteration in replicate (which will iterate n times), then calculate the mom based on that x, and then give the result of mlea 因此,这里发生的事情是复制将为复制中的每个迭代从您的Beta分布中提取500个新观察值(将迭代n次),然后基于该x计算妈妈,然后给出mlea的结果

My results? 我的结果?

replicate(3, {
            x<-rbeta(500,0.5,3)
            mom<-3*mean(x)/(1-mean(x))
            list(a1=mlea(x, mom)$a1, mom=mom)
        })
#    [,1]      [,2]      [,3]     
#a1  0.494497  0.522325  0.5153832
#mom 0.4955767 0.5083678 0.5206997

where each column here is an observation 这里的每一列都是一个观察

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM