First of all a warning
is just that, a warning, it could be a problem or not, and ignored. If in this case we are facing a problem, I can not say it because my knowledge of statistics is very limited, although I am inclined to think that these warnings could well be ignored.
Where is the problem? as the error says, in one of the several times you call the base function dgamma()
is passed parameter shape
with a value less than 0. Which is clearly documented and not allowed. The example of the problem would be something like this:
> dgamma(c(1,2,3), shape = -1)
[1] NaN NaN NaN
Warning message:
In dgamma(c(1, 2, 3), shape = -1) : NaNs produced
Even without knowing what gammamixEM()
does, I told you that I was inclined to think that we can avoid these warnings
, basically because it is a non-deterministic routine, that is to say it tends to give you results different from according to the moment in which you execute it, this is because at some point of the function a runif()
is made, so the final result does not fully depend on the input vector or any parameter, so at some point will generate the conditions for this warning
to occur (in fact, I do not know if you have noticed but at some point you may even get an error message, not an error), this makes me think that it is simply a condition not entirely well controlled by the function.
Some examples:
library(mixtools)
x <- c(34.290, 34.798, 34.798, 185.420, 28.448, 29.718, 32.766, 21.844, 36.576)
# Con esta semilla aleatoria, la ejecución funcionará perfectamente
set.seed(1)
g <- gammamixEM(x)
Note: Choosing new starting values.
Note: Choosing new starting values.
number of iterations= 14
# Con esta otra semilla, y con los mismos datos obtendremos los warnings
set.seed(11)
g <- gammamixEM(x)
Note: Choosing new starting values.
Note: Choosing new starting values.
Note: Choosing new starting values.
Note: Choosing new starting values.
Note: Choosing new starting values.
Note: Choosing new starting values.
Note: Choosing new starting values.
Note: Choosing new starting values.
Note: Choosing new starting values.
Note: Choosing new starting values.
number of iterations= 16
Warning messages:
1: In dgamma(x, shape = alpha[j], scale = beta[j]) : NaNs produced
2: In dgamma(x, shape = alpha[j], scale = beta[j]) : NaNs produced
If you will eventually need to hide those warnings
you could try using suppressWarnings()
like this:
set.seed(11)
g <- suppressWarnings(gammamixEM(x))