最大似然优化误差:随机前沿模型

时间:2016-09-14 05:32:36

标签: r statistics regression

我在使用'mle'stats4函数包时遇到问题。我认为在提高似然函数时我没有犯过错误。你能帮我知道附上的消息吗?

   Error in solve.default(oout$hessian) : 
   Lapack routine dgesv: system is exactly singular: U[1,1] = 0

我正在尝试估计一个随机前沿模型(具有偏斜正态误差的回归模型)。我认为我指定的很好。我不知道出了什么问题。

    library(fdrtool) # Para generar valores aleatorios desde la Half-Normal

    set.seed(123)
    n<-100
    beta0<-10
    beta1<-1
    beta2<-2
    error<-inefficiency<-y<-x1<-x2<-c()
    for (i in 1:n){
    error[i]<-rnorm(1,0,1)
    inefficiency[i]<-rhalfnorm(1, theta=sqrt(pi/2))
    x1[i]<-runif(1,10,20)
    x2[i]<-runif(1,10,20)
    y[i]<-beta0+beta1*x1[i]+beta2*x2[i]+error[i]-inefficiency[i]
    }

    ols<-lm(y~x1+x2)
    print(summary(ols),digits=3)
    sigma<-summary(ols)$sigma

    library(stats4)
    LikelihoodFunction<-function(beta0, beta1,beta2,sigma,lambda){
      R= y - beta0-beta1*x1-beta2*x2
      R=-n*log(sigma)+sum(pnorm(-(R*lambda/sigma), log.p = TRUE))-(1/2*sigma^2)*sum(R^2)
      #print(R)
    }

    beta0.hat<-as.numeric(ols$coefficients[1])
    beta1.hat<-as.numeric(ols$coefficients[2])
    beta2.hat<-as.numeric(ols$coefficients[3])



    fit <- mle(minuslog=LikelihoodFunction, start = list(beta0 = beta0.hat, 
                                      beta1 = beta1.hat,
                                      beta2=beta2.hat,
                                      sigma=2,lambda=0.84), 
               method="BFGS")
    fit

1 个答案:

答案 0 :(得分:0)

这是由于您的LikelihoodFunction。此函数的返回值不会收敛。优化的结果显然是c(beta0 = -Inf, beta1 = -Inf, beta2 = -Inf, sigma = Inf, lambda = Inf)

fit2 <- mle(minuslogl = LikelihoodFunction, 
            start = list(beta0 = beta0.hat, beta1 = beta1.hat, 
                         beta2 = beta2.hat, sigma = 2, lambda = 0.84), 
            method="L-BFGS-B", 
            lower=c(-1.0E+6, -1.0E+6, -1.0E+6, -Inf, -Inf), 
            upper=c(Inf, Inf, Inf, 1.0E+4, 1.0E+4))
fit2
 # Coefficients:
 #  beta0  beta1  beta2  sigma lambda 
 # -1e+06 -1e+06 -1e+06  1e+04  1e+04

LikelihoodFunction(-1.0E+6, -1.0E+6, -1.0E+6, 1.0E+4, 1.0E+4)
 # [1] -4.799513e+24