计算R中偏正态分布的对数似然

时间:2018-11-12 19:51:17

标签: r normal-distribution skew log-likelihood

library(sn)
library(fGarch)
library(maxLik)

set.seed(12)
nl = 100
locl = 0
scalel = 1
shapel = 1

#data
y = c(rsn(n=nl, xi=locl, omega=scalel, alpha=shapel, tau=0, dp=NULL))

假设只有形状参数未知。

snormFit <- function(x, ...){   
   start = c(mean = 0, sd = 1, xi = 1)

   # Log-likelihood Function:
  loglik = function(x, y = x){ 
    f = -sum(log(dsnorm(y, 0, 1, x[3])))
    f 
   }
   # Minimization:
   fit = nlminb(start = start, objective = loglik, lower = c(-Inf, 0,   0), 
                upper = c( Inf, Inf, Inf), y = x)

   # Return Value:
   fit
 }   


shape.l = snormFit(y)$par
Warning message:
In nlminb(start = start, objective = loglik, lower = c(-Inf, 0,  :
  NA/NaN function evaluation
> shape.l
     mean        sd        xi 
0.0000000 1.0000000 0.8216856 

#可能性

logLik.sn = sum(log(dnorm(shape.l*y)))
Warning message:
In shape.l * y :
  longer object length is not a multiple of shorter object length
 logLik.sn
[1] -112.9638

我计算对数似然性的方法正确吗?但是,我收到一些警告消息。这是什么原因呢?还有其他方法可以计算skew normal distributionR的对数似然率吗?

谢谢。

0 个答案:

没有答案