# How To Fix R Error Message: initial value in ‘vmmin’ is not finite

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))
+ i = nrow(y)
+ j = ncol(y)
+ an1 = am[j+1]
+ logl = -0.5*i*log(2*pi)-(i/(an1))
+ return(-logl)
+ }
>
 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))
+ i = nrow(y)
+ j = ncol(y)
+ an1 = am[j+1]
+ logl = -0.5*i*log(2*pi)-(i/(an1))
+ return(-logl)
+ }
>