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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Aug 8 14:11:32 CEST 2012


Author: ingmarvisser
Date: 2012-08-08 14:11:32 +0200 (Wed, 08 Aug 2012)
New Revision: 560

Modified:
   pkg/depmixS4/R/EM.R
Log:
- missing values were not treated in mix models in EM; fixed by a quick hack ...

Modified: pkg/depmixS4/R/EM.R
===================================================================
--- pkg/depmixS4/R/EM.R	2012-08-08 11:03:44 UTC (rev 559)
+++ pkg/depmixS4/R/EM.R	2012-08-08 12:11:32 UTC (rev 560)
@@ -83,6 +83,10 @@
 		
 	} else {
 		# initial expectation
+		# treat missing values: FIX ME WITH NA.ALLOW OPTION OR SO. 
+		# WHY NOT USE fb TO COMPUTE LL AND GAMMA?
+		B <- object at dens
+		B <- replace(B,is.na(B) & !is.nan(B),1)
 		B <- apply(object at dens,c(1,3),prod)
 		
 		if(clsf == "hard") {
@@ -119,18 +123,20 @@
 		}
 		
 		# expectation
+		# treat missing values: FIX ME WITH NA.ALLOW OPTION OR SO. 
+		# WHY NOT USE fb TO COMPUTE LL AND GAMMA?
+		B <- object at dens
+		B <- replace(B,is.na(B) & !is.nan(B),1)
 		B <- apply(object at dens,c(1,3),prod)
+		
 		if(clsf == "hard") {
 		  gamma <- t(apply(object at init*B,1,ind.max))
 		  LL <- sum(log(rowSums(gamma*B)))
 		} else {
-		  gamma <- object at init*B
-		  LL <- sum(log(rowSums(gamma)))
-		  # normalize
-		  gamma <- gamma/rowSums(gamma)
-	}
-	
-		# gamma <- object at init*B 		
+			fbo <- fb(init=object at init,matrix(0,1,1),B=object at dens,ntimes=ntimes(object))
+			gamma <- fbo$gamma
+		  LL <- fbo$logLike
+		}
 		
 		# print stuff
 		if(verbose&((j%%5)==0)) {



More information about the depmix-commits mailing list