MLE error in R: initial value in 'vmmin' is not finite

后端 未结 3 1691
误落风尘
误落风尘 2020-12-18 21:16

Suppose I have 2 data.frame objects:

df1 <- data.frame(x = 1:100)
df1$y <- 20 + 0.3 * df1$x + rnorm(100)
df2 <- data.frame(x = 1:200000         


        
相关标签:
3条回答
  • 2020-12-18 21:52

    I had the same problem when minimizin a log-likelihood function. After some debugging I found that the problem was in my starting values. They caused one specific matrix to have a determinant = 0, which caused an error when a log was taken of it. Therefore, it could not find any "finite" value, but that was because the function returned an error to optim.

    Bottomline: consider if your function is not returning an error when you run it using the starting values.

    PS.: Marius Hofert is completely right. Never suppress warnings.

    0 讨论(0)
  • 2020-12-18 21:55

    known bug in R, bugzilla ID 17703. Notoriously difficult to reproduce.

    0 讨论(0)
  • 2020-12-18 22:03

    The value of R becomes zero at some point; it leads to a non-finite value of the function to be minimized and returns an error.

    Using the argument log=TRUE handles better this issue, see function LL3 below. The following gives some warnings but a result is returned, with parameter estimates close to the true parameters.

    require(stats4)
    set.seed(123)
    e <- rnorm(200000)
    x <- 1:200000
    df3 <- data.frame(x)
    df3$y <- 20 + 0.3 * df3$x + e
    LL3 <- function(a, b, mu, sigma) {
      -sum(dnorm(df3$y - a- b * df3$x, mu, sigma, log=TRUE))
    }
    mle3 <- mle(LL3, start = list(a = 20, b = 0.3,  sigma=0.5),
      fixed = list(mu = 0))
    Warning messages:
    1: In dnorm(df3$y - a - b * df3$x, mu, sigma, log = TRUE) : NaNs produced
    2: In dnorm(df3$y - a - b * df3$x, mu, sigma, log = TRUE) : NaNs produced
    3: In dnorm(df3$y - a - b * df3$x, mu, sigma, log = TRUE) : NaNs produced
    4: In dnorm(df3$y - a - b * df3$x, mu, sigma, log = TRUE) : NaNs produced
    5: In dnorm(df3$y - a - b * df3$x, mu, sigma, log = TRUE) : NaNs produced
    6: In dnorm(df3$y - a - b * df3$x, mu, sigma, log = TRUE) : NaNs produced
    7: In dnorm(df3$y - a - b * df3$x, mu, sigma, log = TRUE) : NaNs produced
    8: In dnorm(df3$y - a - b * df3$x, mu, sigma, log = TRUE) : NaNs produced
    
    > mle3
    Call:
    mle(minuslogl = LL3, start = list(a = 20, b = 0.3, sigma = 0.5), 
        fixed = list(mu = 0))
    
    Coefficients:
            a         b        mu     sigma 
    19.999166  0.300000  0.000000  1.001803 
    
    0 讨论(0)
提交回复
热议问题