Trying to figure out what an error message actually means can be difficult. However, once you understand what is going on they sometimes make sense. The “initial value in ‘vmmin’ is not finite” is such an error message. While not every detail of the wording of this message becomes clear, once you know what causes it, the message at least makes some sense.
The circumstances of this error.
This error message occurs when using one of several complex functions. The problem occurs when there is an “NA” value is entered.
> set.seed(101)
> x = matrix(rnorm(10), ncol=1)
> y = cbind(1,rnorm(10),rnorm(10))
> ad = function(am,x,y){
+ i = nrow(y)
+ j = ncol(y)
+ an1 = am[j+1]
+ logl = -0.5*i*log(2*pi)-(i/(an1))
+ return(-logl)
+ }
>
> ad(c(1,1,1),x=x,y=y)
[1] NA
>
> p = optim(c(1,1,1),ad, method=”BFGS”, hessian=TRUE, x=x, y=y)
Error in optim(c(1, 1, 1), ad, method = “BFGS”, hessian = TRUE, x = x, :
initial value in ‘vmmin’ is not finite
In this example, the optim() function is used but this error shows up in other functions as well. The key to understanding this error message is the presence of an “NA” value being returned for the function being optimized.
What is causing this error?
What causes this error message is entering an “NA” value into a function that is looking for a numeric value. This is why the message says “value is not finite” and why the program produces an error message. In the example above, the problem is that it is missing a parameter in “ad(c(1,1,1),x=x,y=y).” The “c(1,1,1)” has only three parameters when you should have four. The “NA” value is not a numerically finite value and that is what the optim() function is looking for.
How to fix this error.
Fixing this error is quite simple, you just need to add the fourth parameter to “c(1,1,1)” and make it “c(1,1,1,1)” as Illustrated below.
> set.seed(101)
> x = matrix(rnorm(10), ncol=1)
> y = cbind(1,rnorm(10),rnorm(10))
> ad = function(am,x,y){
+ i = nrow(y)
+ j = ncol(y)
+ an1 = am[j+1]
+ logl = -0.5*i*log(2*pi)-(i/(an1))
+ return(-logl)
+ }
>
> ad(c(1,1,1,1),x=x,y=y)
[1] 19.18939
>
> p = optim(c(1,1,1,1),ad, method=”BFGS”, hessian=TRUE, x=x, y=y)
This small adjustment to the code fixes this error, at least for this case of the optim() function. Ultimately, the problem is entering an “NA” value into a function that is looking for a numeric value. If you are getting this error message, check all the values that you are entering into the function that is triggering the error message to see if any of them are an “NA” value. If you find one, it is this parameter that you need to correct. Correcting that “NA” value will fix the error regardless of the function. Finding the precise reason for the “NA” value may be more difficult and harder to correct.