[Sem-additions-commits] r6 - pkg/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Apr 24 23:14:59 CEST 2010


Author: jebyrnes
Date: 2010-04-24 23:14:59 +0200 (Sat, 24 Apr 2010)
New Revision: 6

Modified:
   pkg/R/update.model.r
Log:


Modified: pkg/R/update.model.r
===================================================================
--- pkg/R/update.model.r	2010-04-21 06:38:21 UTC (rev 5)
+++ pkg/R/update.model.r	2010-04-24 21:14:59 UTC (rev 6)
@@ -115,27 +115,52 @@
     pathType<-"->"
     if(op=="~~") pathType <-"<->"
     a.formula<-clean.modline(a.model[i])
-    y<-response(a.formula)
-    x<-strip.white(strsplit(predictors(a.formula), "+", fixed=T)[[1]])
+
+	#is this a latent or observed variable?
+    if(op=="=~"){
+    		x<-response(a.formula)
+    		y<-strip.white(strsplit(predictors(a.formula), "+", fixed=T)[[1]])
+    		ram<-rbind(ram, c( paste(x,"<->",x, sep=""),  paste(x,"error", sep="."), NA))
+    	}else{
+    		y<-response(a.formula)
+    		x<-strip.white(strsplit(predictors(a.formula), "+", fixed=T)[[1]])
+    		}
   
-    #iterate over each predictor variable
-    for(j in 1:length(x)){
-    	#construct a new path
-    	path<-paste(x[j], y, sep=pathType)
+    #iterate over each response, in case this is a latent variable
+    for (q in 1:length(y)){
+     #iterate over each predictor variable
+     for(j in 1:length(x)){
+     	#see if this is a fixed parameter values
+    	     if(op=="=~"){
+ 		   isFixed<-strsplit(y[q], '*', fixed=T)[[1]]
+		   if(length(isFixed)>1) y[q]<-isFixed[2]
+		 }else{
+			isFixed<-strsplit(x[j], '*', fixed=T)[[1]]
+			if(length(isFixed)>1) x[j]<-isFixed[2]
+			}
+     	
+     	
+     	#construct a new path
+     	path<-paste(x[j], y[q], sep=pathType)
 
-    	#see if this is a fixed parameter values
-    	isFixed<-strsplit(x[j], '*', fixed=T)[[1]]
-    	if(length(isFixed)>1) {
-    	  coef<-NA
-    	  startValue<-isFixed[1]
-    	 #otherwise....
-    	 }else{
-    	  #create a new coefficient name
-    	  coef<-paste(x[j], y, sep=".")
-    	  if(pathType=="<->") coef<-paste(coef, "cov", sep=".")
-    	  startValue<-NA
+
+
+    	 if(length(isFixed)>1) {
+    	   coef<-NA
+    	   startValue<-isFixed[1]
+    	  #otherwise....
+    	  }else{
+    	   #create a new coefficient name
+    	   coef<-paste(x[j], y[q], sep=".")
+    	   if(pathType=="<->") {
+    	   	ifelse((x[j]==y[q]),
+    	   		coef<-paste(coef, "var", sep="."), 
+    	   		coef<-paste(coef, "cov", sep="."))
+    	   	}
+    	   startValue<-NA
+    	  }
+    	 ram<-rbind(ram, c(path, coef, startValue))
     	 }
-    	ram<-rbind(ram, c(path, coef, startValue))
     	}
    }
   }
@@ -148,17 +173,19 @@
   return(ram)	
 }
 
+
+
 ###example
-#a.model<-'y~x+z
-#		  x~3*z
-#		  z=~a+b+c
-#		  y~~c
-#'
-#
-#cat(a.model)
-#model.to.ram(a.model)
+a.model<-'y~x+z
+		  x~3*z
+		  z=~a+b+c
+		  y~~c
+'
 
+cat(a.model)
+model.to.ram(a.model)
 
+
 ###
 #can we go back?
 #we'll need to know which are latent variables



More information about the Sem-additions-commits mailing list