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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Sun Mar 18 20:06:54 UTC 2007


Revision: 1618
          http://svn.sourceforge.net/rkward/?rev=1618&view=rev
Author:   tfry
Date:     2007-03-18 13:06:54 -0700 (Sun, 18 Mar 2007)

Log Message:
-----------
Bring t test up to date:
* allow to use for paired samples
* adjust to running inside local
* use rk.describe.alternative()
* add help page
* cleaner code
* use copy tag for the wizard

Modified Paths:
--------------
    trunk/rkward/rkward/plugins/analysis/t_test_two_samples.php
    trunk/rkward/rkward/plugins/analysis/t_test_two_samples.xml

Added Paths:
-----------
    trunk/rkward/rkward/plugins/analysis/t_test_two_samples.rkh

Modified: trunk/rkward/rkward/plugins/analysis/t_test_two_samples.php
===================================================================
--- trunk/rkward/rkward/plugins/analysis/t_test_two_samples.php	2007-03-18 19:20:21 UTC (rev 1617)
+++ trunk/rkward/rkward/plugins/analysis/t_test_two_samples.php	2007-03-18 20:06:54 UTC (rev 1618)
@@ -1,45 +1,57 @@
 <?
-	function preprocess () {
-	}
-	
-	function calculate () {
-?>rk.temp.x <- substitute (<? getRK ("x"); ?>)
-rk.temp.y <- substitute (<? getRK ("y"); ?>)
-rk.temp <- t.test (eval (rk.temp.x), eval (rk.temp.y), "<? getRK ("hypothesis"); ?>"<?
-if (getRK_val ("varequal")) echo (", var.equal=TRUE");
-if (($conflevel = getRK_val ("conflevel")) != "0.95") echo (", conf.level=" . $conflevel); ?>)
-rk.temp.print.conf.level <- <? if (getRK_val ("confint")) echo "TRUE"; else echo "FALSE"; ?>
+function preprocess () {
+	global $x;
+	global $y;
 
+	$x = getRK_val ("x");
+	$y = getRK_val ("y");
+?>
+names <- rk.get.description (<? echo ($x . ", " . $y); ?>)
 <?
-	}
-	
-	function printout () {
+}
+
+function calculate () {
+	global $x;
+	global $y;
+	global $varequal;
+	global $paired;
+
+	$conflevel = getRK_val ("conflevel");
+	$varequal = getRK_val ("varequal");
+	$paired = getRK_val ("paired");
+	$hypothesis = getRK_val ("hypothesis");
+
+	$options = ", alternative=\"" . $hypothesis . "\"";
+	if ($paired) $options .= ", paired=TRUE";
+	if ((!$paired) && $varequal) $options .= ", var.equal=TRUE";
+	if ($conflevel != "0.95") $options .= ", conf.level=" . $conflevel;
 ?>
-rk.header ("T-test (independent samples)", 
-	parameters=list ("Comparing", paste (rk.get.description (rk.temp.x, is.substitute=TRUE), "against", rk.get.description (rk.temp.y, is.substitute=TRUE)),
-	"H1", if (rk.temp$alternative == "less")
-		paste (rk.get.short.name (rk.temp.y), "is greater than", rk.get.short.name (rk.temp.x))
-	      else if (rk.temp$alternative == "greater")
-		paste (rk.get.short.name (rk.temp.x), "is greater than", rk.get.short.name (rk.temp.y))
-	      else
-		paste (rk.get.short.name (rk.temp.x), "and", rk.get.short.name (rk.temp.y), "differ"),
-	"Equal variances", "<? if (!getRK_val ("varequal")) echo "not"; ?> assumed"))
+result <- t.test (<? echo ($x . ", " . $y . $options); ?>)
+<?
+}
 
+function printout () {
+	global $varequal;
+	global $paired;
+?>
+rk.header (result$method, 
+	parameters=list ("Comparing", paste (names[1], "against", names[2]),
+	"H1", rk.describe.alternative (result)<?
+	if (!$paired) { ?>
+,
+	"Equal variances", "<? if (!$varequal) echo ("not"); ?> assumed"<?
+	} ?>))
+
 rk.results (list (
-	'Variable Name'=rk.get.description (rk.temp.x, rk.temp.y, is.substitute=TRUE),
-	'estimated mean'=rk.temp$estimate,
-	'degrees of freedom'=rk.temp$parameter,
-	t=rk.temp$statistic,
-	p=rk.temp$p.value<?
+	'Variable Name'=names,
+	'estimated mean'=result$estimate,
+	'degrees of freedom'=result$parameter,
+	t=result$statistic,
+	p=result$p.value<?
 	if (getRK_val ("confint")) { ?>,
-	'confidence interval percent'=(100 * attr(rk.temp$conf.int, "conf.level")),
-	'confidence interval of difference'=rk.temp$conf.int <? } ?>))
+	'confidence interval percent'=(100 * attr(result$conf.int, "conf.level")),
+	'confidence interval of difference'=result$conf.int <? } ?>))
 <?
-	}
-	
-	function cleanup () {
+}
+
 ?>
-rm (list=grep ("^rk.temp", ls (), value=TRUE))
-<?
-	}
-?>

Added: trunk/rkward/rkward/plugins/analysis/t_test_two_samples.rkh
===================================================================
--- trunk/rkward/rkward/plugins/analysis/t_test_two_samples.rkh	                        (rev 0)
+++ trunk/rkward/rkward/plugins/analysis/t_test_two_samples.rkh	2007-03-18 20:06:54 UTC (rev 1618)
@@ -0,0 +1,28 @@
+<!DOCTYPE rkhelp>
+<document>
+	<summary>
+Two variable t-test (paired or independent samples).
+	</summary>
+
+	<usage>
+Chose two numeric vectors to compare against each other. Specify, whether the variables are paired or independent samples. For details, see below.
+	</usage>
+
+	<settings>
+		<caption id="tab_variables"/>
+		<setting id="x">A numeric vector for the first variable</setting>
+		<setting id="y">A numeric vector for the second variable</setting>
+		<setting id="hypothesis">Alternative hypothesis (H1) of the test.</setting>
+		<setting id="paired">Whether the samples are paired (repeated measurements on the same subject) or independent. For a paired test, if the two vectors are not of equal length, there will be an error.</setting>
+		<caption id="tab_options"/>
+		<setting id="varequal">Whether to assume equal variances for the two samples. This option is implied for a paired test.</setting>
+		<setting id="conflevel">Confidence level to use.</setting>
+		<setting id="confint">Whether to print the confidence interval of the estimated mean.</setting>
+	</settings>
+	<related>
+		<ul>
+			<li><link href="rkward://rhelp/cor"/></li>
+			<li><link href="rkward://rhelp/cor.test"/></li>
+		</ul>
+	</related>
+</document>

Modified: trunk/rkward/rkward/plugins/analysis/t_test_two_samples.xml
===================================================================
--- trunk/rkward/rkward/plugins/analysis/t_test_two_samples.xml	2007-03-18 19:20:21 UTC (rev 1617)
+++ trunk/rkward/rkward/plugins/analysis/t_test_two_samples.xml	2007-03-18 20:06:54 UTC (rev 1618)
@@ -1,14 +1,17 @@
 <!DOCTYPE rkplugin>
-
-<!-- This is a simple example, of how a "plugin" might be configured. -->
-
 <document>
 	<code file="t_test_two_samples.php"/>
+	<help file="t_test_two_samples.rkh"/>
 
-	<dialog label="Independed Samples T-Test">
+	<logic>
+		<convert id="notpaired" mode="equals" sources="paired.state" standard="0"/>
+		<connect client="varequal.enabled" governor="notpaired"/>
+	</logic>
+
+	<dialog label="Two Variable t-Test">
 		<tabbook>
 			<tab label="Basic settings">
-				<row>
+				<row id="basic_settings_row">
 					<varselector id="vars"/>
 					<column>
 						<varslot type="numeric" id="x" source="vars" required="true" label="compare"/>
@@ -18,44 +21,31 @@
 							<option value="greater" label="First is greater"/>
 							<option value="less" label="Second is greater"/>
 						</radio>
+						<checkbox id="paired" label="Samples are paired" value="1" value_unchecked="0" />
 					</column>
 				</row>
 			</tab>
 			<tab label="Options">
 				<checkbox id="varequal" label="assume equal variances" value="1" value_unchecked="0"/>
-				<frame label="Confidence Interval">
-					<checkbox id="confint" label="print confidence interval" value="1" checked="true"/>
+				<frame label="Confidence Interval" id="confint_frame">
 					<spinbox type="real" id="conflevel" label="confidence level" min="0" max="1" initial="0.95"/>
+					<checkbox id="confint" label="print confidence interval" value="1" checked="true"/>
 				</frame>
+				<stretch/>
 			</tab>
 		</tabbook>
 	</dialog>
-	<wizard label="Independed Samples T-Test">
+	<wizard label="Two Variable t-Test">
 		<page>
 			<text>As a first step, select the two variables you want to compare against each other. And specify, which one you theorize to be greater. Select two-sided, if your theory does not tell you, which variable is greater.</text>
-			<row>
-				<column>
-					<varselector id="vars"/>
-				</column>
-				<column>
-					<varslot type="numeric" id="x" source="vars" required="true" label="compare"/>
-					<varslot type="numeric" id="y" source="vars" required="true" label="against"/>
-					<radio id="hypothesis" label="using test hypothesis">
-						<option value="two.sided" label="Two-sided"/>
-						<option value="greater" label="First is greater"/>
-						<option value="less" label="Second is greater"/>
-					</radio>
-				</column>
-			</row>
+			<copy id="basic_settings_row"/>
 		</page>
 		<page>
 			<text>Below are some advanced options. It's generally safe not to assume the variables have equal variances. An appropriate correction will be applied then. Chosing "assume equal variances" may increase test-strength, however.</text>
-			<checkbox id="varequal" label="assume equal variances" value="1" value_unchecked="0"/>
+			<copy id="varequal"/>
 			<text>Sometimes it's helpful to get an estimate of the confidence interval of the difference in means. Below you can specify whether one should be shown, and which confidence-level should be applied (95% corresponds to a 5% level of significance).</text>
-			<frame label="Confidence Interval">
-				<checkbox id="confint" label="print confidence interval" value="1" checked="true"/>
-				<spinbox type="real" id="conflevel" label="confidence level" min="0" max="1" initial="0.95"/>
-			</frame>
+			<copy id="confint_frame"/>
+			<stretch/>
 		</page>
 	</wizard>
 	


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