2
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 distributionin的对数似然R吗?

先感谢您。

4

0 回答 0