[rkward-cvs] SF.net SVN: rkward: [1594] trunk/rkward/rkward/plugins/analysis/moments/ agostino_test.php

tfry at users.sourceforge.net tfry at users.sourceforge.net
Thu Mar 15 23:32:33 UTC 2007


Revision: 1594
          http://svn.sourceforge.net/rkward/?rev=1594&view=rev
Author:   tfry
Date:     2007-03-15 16:32:32 -0700 (Thu, 15 Mar 2007)

Log Message:
-----------
Sample code for agostino.test. @Stefan: comments follow by mail

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

Modified: trunk/rkward/rkward/plugins/analysis/moments/agostino_test.php
===================================================================
--- trunk/rkward/rkward/plugins/analysis/moments/agostino_test.php	2007-03-15 21:59:31 UTC (rev 1593)
+++ trunk/rkward/rkward/plugins/analysis/moments/agostino_test.php	2007-03-15 23:32:32 UTC (rev 1594)
@@ -1,48 +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 <- agostino.test (eval (var), alternative = "<? getRK ("alternative"); ?>")
-			rk.temp.results$'skewness estimator (skew)'[i] <<- rk.temp.t$statistic["skew"]
-			rk.temp.results$'transformation (z)'[i] <<- rk.temp.t$statistic["z"]
-			rk.temp.results$'p-value'[i] <<- rk.temp.t$p.value
-		})
-		<? 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)
+i=0;
+for (var in objects) {
+	i = i+1
+	results[i, 'Variable Name'] <- rk.get.description (var, is.substitute=TRUE)
+	var <- eval (var)
+	results[i, 'Error'] <- tryCatch ({
+		t <- agostino.test (var, alternative = "<? getRK ("alternative"); ?>")
+		results[i, 'skewness estimator (skew)'] <- t$statistic["skew"]
+		results[i, 'transformation (z)'] <- t$statistic["z"]
+		results[i, 'p-value'] <- t$p.value
+<?	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 ("D'Agostino test of skewness",
 	parameters=list ("Alternative Hypothesis", "<? getRK ("alternative"); ?>"))
-rk.results (rk.temp.results)
+rk.results (results)
 <?
 }
 
-function cleanup () {
 ?>
-rm (list=grep ("^rk.temp", ls (), value=TRUE))
-<?
-}
-?>


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