[rkward-cvs] SF.net SVN: rkward: [1646] trunk/rkward/rkward/plugins/analysis/moments

sjar at users.sourceforge.net sjar at users.sourceforge.net
Mon Mar 19 22:39:44 UTC 2007


Revision: 1646
          http://svn.sourceforge.net/rkward/?rev=1646&view=rev
Author:   sjar
Date:     2007-03-19 15:39:43 -0700 (Mon, 19 Mar 2007)

Log Message:
-----------
Updates to the distribution tests:
* adjustments for local()
* more elegant iteration
* move require to preprocess
* no try()s for the length() statements, as these are safe
* indentation fixes
* evaluate each substitute only once, and explicitely in globalenv()

Modified Paths:
--------------
    trunk/rkward/rkward/plugins/analysis/moments/agostino_test.php
    trunk/rkward/rkward/plugins/analysis/moments/anscombe_test.php
    trunk/rkward/rkward/plugins/analysis/moments/bonett_test.php

Modified: trunk/rkward/rkward/plugins/analysis/moments/agostino_test.php
===================================================================
--- trunk/rkward/rkward/plugins/analysis/moments/agostino_test.php	2007-03-19 21:35:58 UTC (rev 1645)
+++ trunk/rkward/rkward/plugins/analysis/moments/agostino_test.php	2007-03-19 22:39:43 UTC (rev 1646)
@@ -20,6 +20,7 @@
 		results[i, 'skewness estimator (skew)'] <- t$statistic["skew"]
 		results[i, 'transformation (z)'] <- t$statistic["z"]
 		results[i, 'p-value'] <- t$p.value
+		results[i, 'Alternative Hypothesis']<- rk.describe.alternative (t)
 <?	if (getRK_val ("length")) { ?>
 		results[i, 'Length'] <- length (var)
 <?	}

Modified: trunk/rkward/rkward/plugins/analysis/moments/anscombe_test.php
===================================================================
--- trunk/rkward/rkward/plugins/analysis/moments/anscombe_test.php	2007-03-19 21:35:58 UTC (rev 1645)
+++ trunk/rkward/rkward/plugins/analysis/moments/anscombe_test.php	2007-03-19 22:39:43 UTC (rev 1646)
@@ -1,49 +1,43 @@
 <?
-	function preprocess () {
-	}
+function preprocess () { ?>
+require(moments)
+<?
+}
 
-	function calculate () {
+function calculate () {
 	$vars = "substitute (" . str_replace ("\n", "), substitute (", trim (getRK_val ("x"))) . ")";
 
 ?>
-require(moments)
+objects <- list (<? echo ($vars); ?>)
+results <- data.frame ('Variable Name'=rep (NA, length (objects)), check.names=FALSE)
 
-rk.temp.objects <- list (<? echo ($vars); ?>)
-rk.temp.results <- data.frame ('Variable Name'=rep (NA, length (rk.temp.objects)), check.names=FALSE)
-local({
-	i=0;
-	for (var in rk.temp.objects) {
-		i = i+1
-		rk.temp.results$'Variable Name'[i] <<- rk.get.description (var, is.substitute=TRUE)
-		try ({
-		rk.temp.t <- anscombe.test (eval (var), alternative = "<? getRK ("alternative"); ?>")
-		rk.temp.results$'Kurtosis estimator (tau)'[i] <<- rk.temp.t$statistic["kurt"]
-		rk.temp.results$'Transformation (z)'[i] <<- rk.temp.t$statistic["z"]
-		rk.temp.results$'p-value'[i] <<- rk.temp.t$p.value
-		rk.temp.results$'Alternative Hypothesis'[i] <<- rk.describe.alternative (rk.temp.t)
-		})
-		<? if (getRK_val ("length")) { ?>
-		try (rk.temp.results$'Length'[i] <<- length (eval (var)))
-		<? }
-		if (getRK_val ("nacount")) { ?>
-		try (rk.temp.results$'NAs'[i] <<- length (which(is.na(eval (var)))))
-		<? } ?>
-	}
-})
+for (i in 1:length(objects)) {
+	results[i, 'Variable Name'] <- rk.get.description (objects[[i]], is.substitute=TRUE)
+	var <- eval(objects[[i]])
+	results[i, 'Error'] <- tryCatch ({
+		t <- anscombe.test (var, alternative = "<? getRK ("alternative"); ?>")
+		results[i, 'Kurtosis estimator (tau)'] <- t$statistic["kurt"]
+		results[i, 'Transformation (z)'] <- t$statistic["z"]
+		results[i, 'p-value'] <- t$p.value
+		results[i, 'Alternative Hypothesis']<- rk.describe.alternative (t)
+<?	if (getRK_val ("length")) { ?>
+		results[i, 'Length'] <- length (var)
+<?	}
+	if (getRK_val ("nacount")) { ?>
+		results[i, 'NAs'] <- length (which(is.na(var)))
+<? 	} ?>
+		NA				# no error
+	}, error=function (e) e$message)	# catch any errors
+}
+if (all (is.na (results$'Error'))) results$'Error' <- NULL
 <?
-        }
+}
 
 function printout () {
 ?>
 rk.header ("Anscombe-Glynn test of kurtosis",
 	parameters=list ("Alternative Hypothesis", "<? getRK ("alternative"); ?>"))
-rk.results (rk.temp.results)
+rk.results (results)
 <?
 }
-
-function cleanup () {
 ?>
-rm (list=grep ("^rk.temp", ls (), value=TRUE))
-<?
-}
-?>

Modified: trunk/rkward/rkward/plugins/analysis/moments/bonett_test.php
===================================================================
--- trunk/rkward/rkward/plugins/analysis/moments/bonett_test.php	2007-03-19 21:35:58 UTC (rev 1645)
+++ trunk/rkward/rkward/plugins/analysis/moments/bonett_test.php	2007-03-19 22:39:43 UTC (rev 1646)
@@ -1,49 +1,44 @@
 <?
-	function preprocess () {
-	}
+function preprocess () {
+?>
+require(moments)
+<?}
 
-	function calculate () {
+function calculate () {
 	$vars = "substitute (" . str_replace ("\n", "), substitute (", trim (getRK_val ("x"))) . ")";
 
 ?>
-require(moments)
 
-rk.temp.objects <- list (<? echo ($vars); ?>)
-rk.temp.results <- data.frame ('Variable Name'=rep (NA, length (rk.temp.objects)), check.names=FALSE)
-local({
-	i=0;
-	for (var in rk.temp.objects) {
-		i = i+1
-		rk.temp.results$'Variable Name'[i] <<- rk.get.description (var, is.substitute=TRUE)
-		try ({
-			rk.temp.t <- bonett.test (eval (var), alternative = "<? getRK ("alternative"); ?>")
-			rk.temp.results$'Kurtosis estimator (tau)'[i] <<- rk.temp.t$statistic["tau"]
-			rk.temp.results$'Transformation (z)'[i] <<- rk.temp.t$statistic["z"]
-			rk.temp.results$'p-value'[i] <<- rk.temp.t$p.value
-			rk.temp.results$'Alternative Hypothesis'[i] <<- rk.describe.alternative (rk.temp.t)
-		})
-		<? if (getRK_val ("length")) { ?>
-		try (rk.temp.results$'Length'[i] <<- length (eval (var)))
-		<? }
-		if (getRK_val ("nacount")) { ?>
-		try (rk.temp.results$'NAs'[i] <<- length (which(is.na(eval (var)))))
-		<? } ?>
-	}
-})
+objects <- list (<? echo ($vars); ?>)
+results <- data.frame ('Variable Name'=rep (NA, length (objects)), check.names=FALSE)
+
+for (i in 1:length(objects)) {
+	results[i, 'Variable Name'] <- rk.get.description (objects[[i]], is.substitute=TRUE)
+	var <- eval(objects[[i]])
+	results[i, 'Error'] <- tryCatch ({
+		t <- bonett.test (var, alternative = "<? getRK ("alternative"); ?>")
+		results[i, 'Kurtosis estimator (tau)'] <- t$statistic["tau"]
+		results[i, 'Transformation (z)'] <- t$statistic["z"]
+		results[i, 'p-value'] <- t$p.value
+		results[i, 'Alternative Hypothesis']<- rk.describe.alternative (t)
+<?	if (getRK_val ("length")) { ?>
+		results[i, 'Length'] <- length (var)
+<?	}
+	if (getRK_val ("nacount")) { ?>
+		results[i, 'NAs'] <- length (which(is.na(var)))
+<? 	} ?>
+		NA				# no error
+	}, error=function (e) e$message)	# catch any errors
+}
+if (all (is.na (results$'Error'))) results$'Error' <- NULL
 <?
-        }
+}
 
 function printout () {
 ?>
 rk.header ("Bonett-Seier test of Geary's kurtosis",
 	parameters=list ("Alternative Hypothesis", "<? getRK ("alternative"); ?>"))
-rk.results (rk.temp.results)
+rk.results (results)
 <?
 }
-
-function cleanup () {
-?>
-rm (list=grep ("^rk.temp", ls (), value=TRUE))
-<?
-}
-?>
+?>
\ No newline at end of file


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the rkward-tracker mailing list