[Depmix-commits] r406 - pkg/depmixS4/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Mar 10 16:46:09 CET 2010


Author: maarten
Date: 2010-03-10 16:46:08 +0100 (Wed, 10 Mar 2010)
New Revision: 406

Modified:
   pkg/depmixS4/R/responseMVN.R
Log:
- removed warning messages from dm_dmvnorm; now checks whether eigenvalues of the covariance matrix are >= 0 and if not, returns NaN without warning

Modified: pkg/depmixS4/R/responseMVN.R
===================================================================
--- pkg/depmixS4/R/responseMVN.R	2010-03-09 19:12:49 UTC (rev 405)
+++ pkg/depmixS4/R/responseMVN.R	2010-03-10 15:46:08 UTC (rev 406)
@@ -39,8 +39,11 @@
         x <- matrix(x, ncol = length(x))
     }
     if (missing(mean)) {
-        mean <- rep(0, length = ncol(x))
+        mean <- matrix(0, ncol = ncol(x))
     }
+    if(is.vector(mean)) {
+    	mean <- matrix(mean, ncol = ncol(x))
+    }
     if(missing(invSigma)) {
     	if (missing(sigma)) {
         	sigma <- diag(ncol(x))
@@ -57,11 +60,15 @@
 	if (NCOL(invSigma) != NCOL(mean)) {
 		stop("mean and sigma have non-conforming size")
 	}
+	if(missing(logdet)) {
+		ev <- eigen(sigma, symmetric = TRUE, only.values = TRUE)$values
+		if(!all(ev >= 0)) return(rep(NaN,nrow(x))) else logdet <- sum(log(ev))
+	}
 	if(NROW(mean) == NROW(x)) {
 		# varying means
 		
 		# from "mahalanobis":    
-		x <- as.matrix(x) - mean
+		x <- x - mean
     	distval <- rowSums((x %*% invSigma) * x)
     	#names(retval) <- rownames(x)
    	 	#retval
@@ -72,7 +79,6 @@
 		}
 		distval <- mahalanobis(x, center = mean, cov = invSigma, inverted=TRUE)
 	}	
-    if(missing(logdet)) logdet <- sum(log(eigen(sigma, symmetric = TRUE, only.values = TRUE)$values))
     logretval <- -(ncol(x) * log(2 * pi) + logdet + distval)/2
     if (log) {
         return(logretval)



More information about the depmix-commits mailing list