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

nono_231 at users.sourceforge.net nono_231 at users.sourceforge.net
Sat Apr 14 08:18:21 UTC 2007


Revision: 1814
          http://svn.sourceforge.net/rkward/?rev=1814&view=rev
Author:   nono_231
Date:     2007-04-14 01:18:20 -0700 (Sat, 14 Apr 2007)

Log Message:
-----------
Added crosstab.plugin under under_development/analysis

Added Paths:
-----------
    trunk/rkward/rkward/plugins/analysis/crosstab.php
    trunk/rkward/rkward/plugins/analysis/crosstab.xml

Added: trunk/rkward/rkward/plugins/analysis/crosstab.php
===================================================================
--- trunk/rkward/rkward/plugins/analysis/crosstab.php	                        (rev 0)
+++ trunk/rkward/rkward/plugins/analysis/crosstab.php	2007-04-14 08:18:20 UTC (rev 1814)
@@ -0,0 +1,78 @@
+<?
+function preprocess () {
+?>
+require(xtable)
+<?
+}
+	
+function calculate () {
+}
+
+function printout () {
+	doPrintout (true);
+}
+	
+	
+function preview () {
+	preprocess ();
+	calculate ();
+	doPrintout (false);
+}
+	
+function doPrintout ($final) {
+	$x = getRK_val ("x") ;
+	$y = getRK_val ("y") ;
+	$labels = getRK_val ("labels")=="TRUE";
+	
+?>
+x <- (<? echo ($x); ?>)
+y <- (<? echo ($y); ?>)
+
+rk.header ("Crosstabs", list ("Variable", rk.get.description (<? echo ($x); ?>), "Group", rk.get.description (<? echo ($y); ?>)))
+xy<-table(x,y)
+
+<?	if ($final) { ?>
+rk.print(xtable(cbind(xy)))
+<?	if (getRK_val ("chisq") == "TRUE") { ?>
+rk.header ("Pearson's Chi Square Test for Crosstabs", list ("Variable", rk.get.description (<? echo ($x); ?>), "Group", rk.get.description (<? echo ($y); ?>), "Monte Carlo", "<? getRK ("monte"); ?>" <? if (getRK_val ("monte") == "TRUE") { ?>,  "Number of replicates", <? getRK ("B"); }?> ))
+xsquared<-cbind(
+chisq.test(x,y <?if (getRK_val ("monte") == "TRUE") { ?>,B=(<? getRK ("B"); ?>) <?}?> )$statistic,
+ chisq.test(x,y <?if (getRK_val ("monte") == "TRUE") { ?>,B=(<? getRK ("B"); ?>) <?}?> )$parameter,
+ chisq.test(x,y <?if (getRK_val ("monte") == "TRUE") { ?>,B=(<? getRK ("B"); ?>) <?}?> )$p.value)
+ colnames(xsquared)<-c("Statistic", "df", "p-value")
+ rk.print(xtable(xsquared))
+<? } ?>
+<?	if (getRK_val ("barplot") == "TRUE") { ?>
+rk.header ("Barplot for Crosstabs", list ("Variable", rk.get.description (<? echo ($x); ?>), "Group", rk.get.description (<? echo ($y); ?>) <?	if (getRK_val ("barplot") == "TRUE") { ?> , "Rainbow colors", "<? getRK ("rainbow"); ?>", "Beside", "<? getRK ("beside"); ?>", "Legend", "<? getRK ("legend"); ?>"<? } ?>)) 
+rk.graph.on ()
+<?	} 
+}
+if (getRK_val ("barplot") == "TRUE") {
+?>
+try ({
+par(bg="gray95") 
+<?	if (getRK_val ("beside") == "TRUE") { ?>
+<?		if ($labels) { ?>
+# adjust the range so that the labels will fit
+yrange <- range (xy, na.rm=TRUE) * 1.2
+if (yrange[1] > 0) yrange[1] <- 0
+if (yrange[2] < 0) yrange[2] <- 0
+<?		} ?>
+bplot <- barplot((xy)<? if (getRK_val ("rainbow")=="TRUE") { ?>, col=rainbow( if(is.matrix(xy)) dim(xy) else length(xy)) <? } ?>, beside=<? getRK ("beside"); ?>, legend.text=<? getRK ("legend"); ?><? if ($labels) echo (", ylim = yrange"); ?>)
+<?		if ($labels) { ?>
+text(bplot, xy, labels=xy, pos=<? getRK ("place"); ?>, offset=.5)
+<?		}
+	} else { ?>
+barplot((xy)<? if (getRK_val ("rainbow")=="TRUE") { ?>, col=rainbow( if(is.matrix(xy)) dim(xy) else length(xy)) <? } ?>, legend.text=<? getRK ("legend"); ?>)
+<?	}
+	?>
+})
+
+<?	}
+if ($final) { ?>
+<?	if (getRK_val ("barplot") == "TRUE") { ?>
+rk.graph.off ()
+<? } 
+}
+}
+?>

Added: trunk/rkward/rkward/plugins/analysis/crosstab.xml
===================================================================
--- trunk/rkward/rkward/plugins/analysis/crosstab.xml	                        (rev 0)
+++ trunk/rkward/rkward/plugins/analysis/crosstab.xml	2007-04-14 08:18:20 UTC (rev 1814)
@@ -0,0 +1,62 @@
+<!DOCTYPE rkplugin>
+<document>
+	<code file="crosstab.php"/>
+		<logic>
+		<convert id="chisqvalue" mode="equals" sources="chisq.state" standard="TRUE" />
+		<connect client="chi_options.enabled" governor="chisqvalue" />
+		<convert id="barplotvalue" mode="equals" sources="barplot.state" standard="TRUE" />
+		<connect client="preview.enabled" governor="barplotvalue" />
+		<connect client="plot_options.enabled" governor="barplotvalue" />
+		<convert id="besidevalue" mode="equals" sources="beside.string" standard="TRUE" />
+		<connect client="labels.enabled" governor="besidevalue" />
+		<convert id="labelsvalue" mode="equals" sources="labels.string" standard="TRUE" />
+		<convert id="labelsvalue2" mode="and" sources="labelsvalue;labels.enabled" />
+		<connect client="place.enabled" governor="labelsvalue2" />
+		<convert id="montevalue" mode="equals" sources="monte.string" standard="TRUE" />
+		<connect client="B.enabled" governor="montevalue" />
+	</logic>
+	<dialog label="Crosstabs" >
+		<tabbook>
+			<tab label="Variables" id="variables_tab">
+				<row>
+					<varselector id="vars"/>
+					<column>						
+						<varslot multi="false" id="x" source="vars" label="variable" required="true" />
+						<varslot multi="false" id="y" source="vars" label="Group" required="true" />
+						<checkbox id="chisq" label="Chisquare" value="TRUE" value_unchecked="FALSE" checked="false" />		<checkbox id="barplot" label="Draw Barplot?" value="TRUE" value_unchecked="FALSE" checked="false" />						
+						<stretch/>
+						<preview id="preview"/>
+					</column>
+				</row>
+			</tab>
+			<tab label="Chisquare Options" id="chi_options">
+				<radio id="monte" label="Method">
+					<option value="FALSE" label="Asymptotic"  checked="true" />				
+					<option value="TRUE" label="Monte Carlo" />
+				</radio>
+				<frame label="Number of replicates">
+					<input id="B" initial="10000" label="Number of replicates used in the Monte Carlo Method" />
+				</frame>
+				<stretch/>
+			</tab>
+			<tab label="Barplot Options" id="plot_options">
+				<checkbox id="legend" label="Legend" value="TRUE" value_unchecked="FALSE" checked="false"/>
+				<checkbox id="rainbow" label="Rainbow colors" value="TRUE" value_unchecked="FALSE" checked="true"/>
+				<radio id="beside" label="Type" >
+					<option value="TRUE" label="Juxtaposed" />
+					<option value="FALSE" label="Stacked" checked="true"/>
+				</radio>
+				<radio id="labels" label="Label values" >
+					<option value="TRUE" label="Display" />
+					<option value="FALSE" label="Do not Display" checked="true"/>					
+				</radio>
+				<radio id="place" label="Display label values">
+					<option value="3" label="Above Bars" checked="true"/>
+					<option value="2" label="Beside Bars"/>
+					<option value="1" label="Inside Bars"/>
+				</radio>
+			</tab>
+		</tabbook>			
+	</dialog>
+
+</document>


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