简体   繁体   中英

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). 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. 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? 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.

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. Let's say the value from that list you really care about is a1, then you could do

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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