简体   繁体   中英

maximize log likelihood function with R

So I wanted to maximize a likelihood function in order to get the estimation of four variables (a, b, c, sigma^2) with R but it doesnt work I dont know why. Here I am estimating for age 30,60, and 90. And for each age I truncate it with 30, so as you can see for age 30 the x become 0, for 60 it become 30 and so on. But the optimization wont work I dont know why; can somebody kindly help me?

d30 <- 2975.1
d60 <- 11456.38
d90 <- 2977.08
r30 <- 1531956.05
r60 <- 650404.58
r90 <- 9728.47
Logg <- function(a,b,c,s)
{
  (d30*log((((a*exp(b*0))/(1+((s*a/b)*(exp(b*0)-1))))+c)*r30)-log(factorial(d30))-((((a*exp(b*0))/(1+((s*a/b)*(exp(b*0)-1))))+c)*r30))+
    (d60*log((((a*exp(b*30))/(1+((s*a/b)*(exp(b*30)-1))))+c)*r60)-log(factorial(d60))-((((a*exp(b*30))/(1+((s*a/b)*(exp(b*30)-1))))+c)*r60))+
    (d90*log((((a*exp(b*60))/(1+((s*a/b)*(exp(b*60)-1))))+c)*r90)-log(factorial(d90))-((((a*exp(b*60))/(1+((s*a/b)*(exp(b*60)-1))))+c)*r90))
}
Logg(1,1,1,1)
optim(c(0,0,0,0),Logg,control = list(fnscale=-1))

log-likelihood function

对数似然函数

lambda definition

lambda 定义

mu definition

亩定义

maybe this is because you try to numerically compute the factorial of very high number? For such high number R will just return infinty:

> d30<-2975.1
> factorial(d30)
[1] Inf

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