EMCluster
EMCluster copied to clipboard
dmvn() returns Inf instead of 0
Hi everyone,
I observed a strange behavior of dmvn() which returned Inf instead of 0 (the expected value):
library(EMCluster)
#> Loading required package: MASS
#> Loading required package: Matrix
x <- c(-19.599228549405947, 144.89973414229041, -20.555841134754075)
mu <- c(19.76872429537179, 19.959622749638946, 19.798540235341196)
LTsigma <- c(0.079449212030153163, -0.17890298706397012, 0.57127933704112022,
0.1791632472318318, -0.1787106300447911, 0.70387217979349481)
dmvn(x, mu, LTsigma) # this should be 0
#> [1] Inf
dmvn(round(x, 10), mu, LTsigma) # this is 0
#> [1] 0
Created on 2022-02-08 by the reprex package (v2.0.1) There is nothing special about the vectors (at least as far as I know). However, even small perturbations (like rounding) lead to the correct result of 0.
Thank you. Interesting observation indeed, but i suspect that this is happening in this case because LTsigma is near-singular (at least practically so).
eigen(LTsigma2var(LTsigma),symmetric=T)
$values
[1] 9.039314e-01 4.506694e-01 1.110223e-16
I believe that the code evaluates for singularity and exits with a Inf. Thanks for this.