[rkward-cvs] SF.net SVN: rkward: [1906] trunk/rkward/rkward/plugins/analysis
tfry at users.sourceforge.net
tfry at users.sourceforge.net
Wed May 16 16:56:15 UTC 2007
Revision: 1906
http://svn.sourceforge.net/rkward/?rev=1906&view=rev
Author: tfry
Date: 2007-05-16 09:56:15 -0700 (Wed, 16 May 2007)
Log Message:
-----------
Restructure crosstabs plugin, and make it use barplot_embed.
Not entirely happy with some aspects, yet
Modified Paths:
--------------
trunk/rkward/rkward/plugins/analysis/crosstab.php
trunk/rkward/rkward/plugins/analysis/crosstab.xml
Modified: trunk/rkward/rkward/plugins/analysis/crosstab.php
===================================================================
--- trunk/rkward/rkward/plugins/analysis/crosstab.php 2007-05-16 16:55:20 UTC (rev 1905)
+++ trunk/rkward/rkward/plugins/analysis/crosstab.php 2007-05-16 16:56:15 UTC (rev 1906)
@@ -6,75 +6,71 @@
}
function calculate () {
+ $x = getRK_val ("x") ;
+ $yvarsstring = join (", ", split ("\n", getRK_val ("y")));
+ $labels = getRK_val ("labels")=="TRUE";
+
+?>
+x <- <? echo ($x . "\n"); ?>
+yvars <- list (substitute (<? echo ($yvarsstring); ?>))
+results <- list()
+descriptions <- list ()
+
+# calculate crosstabs
+for (i in length (yvars)) {
+ yvar <- eval (yvars[[i]], envir=globalenv ())
+ results[[i]] <- table(x, yvar)
+
+ descriptions[[i]] <- list ('Dependent'=rk.get.description (<? echo ($x); ?>), 'Independent'=rk.get.description (yvars[[i]], is.substitute=TRUE))
}
+<?
+ if (getRK_val ("chisq") == "TRUE") { ?>
+# calculate chisquares
+chisquares <- list ()
+for (i in length (results)) {
+ chisquares[[i]] <- chisq.test (results[[i]], simulate.p.value = <? getRK ("simpv");?> <?if (getRK_val ("monte") == "TRUE") { ?>,B=(<? getRK ("B"); ?>) <?}?>)
+}
+<? }
+
+}
+
function printout () {
doPrintout (true);
}
-
-
+
function preview () {
preprocess ();
calculate ();
doPrintout (false);
}
-
+
function doPrintout ($final) {
- $x = getRK_val ("x") ;
- $yvarsstring = join (", ", split ("\n", getRK_val ("y")));
- $labels = getRK_val ("labels")=="TRUE";
-
-?>
-x <- (<? echo ($x); ?>)
-y <- data.frame (<? echo ($yvarsstring); ?>)
+ if ($final) { ?>
+for (i in 1:length (results)) {
+ rk.header ("Crosstabs", parameters=list ("Dependent", descriptions[[i]][['Dependent']], "Independent", descriptions[[i]][['Independent']]))
+ rk.print (xtable (cbind (results[[i]]), digits=0))
+<? if (getRK_val ("chisq") == "TRUE") { ?>
-for (i in 1:dim(y)[2]){
-xy<-table(y[,i],x)
-rk.header ("Crosstabs", list ("Dependent", rk.get.description (<? echo ($x); ?>), "Independent", rk.get.description (<? echo ($yvarsstring); ?>)[i]))
+ rk.header ("Pearson's Chi Square Test for Crosstabs", list ("Dependent", descriptions[[i]][['Dependent']], "Independent", descriptions[[i]][['Independent']], "Simulate p vlaue", "<? getRK ("simpv");?>", "Monte Carlo", "<? getRK ("monte"); ?>" <? if (getRK_val ("monte") == "TRUE") { ?>, "Number of replicates", <? getRK ("B"); }?> ))
+ rk.results (list ('Statistic'=chisquares[[i]][['statistic']], 'df'=chisquares[[i]][['parameter']], 'p'=chisquares[[i]][['p.value']]))
+<? }
-<? if ($final) { ?>
-rk.print(xtable(cbind(xy), digits=0))
-<? if (getRK_val ("chisq") == "TRUE") { ?>
-rk.header ("Pearson's Chi Square Test for Crosstabs", list ("Dependent", rk.get.description (<? echo ($x); ?>), "Independent", rk.get.description (<? echo ($yvarsstring); ?>)[i], "Simulate p vlaue", "<? getRK ("simpv");?>", "Monte Carlo", "<? getRK ("monte"); ?>" <? if (getRK_val ("monte") == "TRUE") { ?>, "Number of replicates", <? getRK ("B"); }?> ))
-xsquared<-cbind(
-chisq.test(xy, simulate.p.value = <? getRK ("simpv");?> <?if (getRK_val ("monte") == "TRUE") { ?>,B=(<? getRK ("B"); ?>) <?}?> )$statistic,
-<?if (getRK_val ("simpv") == "FALSE") {?> chisq.test(xy, simulate.p.value = <? getRK ("simpv");?> <?if (getRK_val ("monte") == "TRUE") { ?>,B=(<? getRK ("B"); ?>) <?}?> )$parameter, <?}?>
-chisq.test(xy, simulate.p.value = <? getRK ("simpv");?> <?if (getRK_val ("monte") == "TRUE") { ?>,B=(<? getRK ("B"); ?>) <?}?> )$p.value)
- colnames(xsquared)<-c("Statistic", <?if (getRK_val ("simpv") == "FALSE") {?> "df", <?}?> "p-value")
- rk.print(xtable(xsquared))
-<? } ?>
-<? if (getRK_val ("barplot") == "TRUE") { ?>
-rk.header ("Barplot for Crosstabs", list ("Dependent", rk.get.description (<? echo ($x); ?>), "Independent", rk.get.description (<? echo ($yvarsstring); ?>)[i] <? 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
+ if (getRK_val ("barplot") == "TRUE") { ?>
+
+ rk.header ("Barplot for Crosstabs", list ("Dependent", descriptions[[i]][['Dependent']], "Independent", descriptions[[i]][['Independent']]<? getRK ('barplot_embed.code.preprocess'); ?>))
+ rk.graph.on ()
+ try ({
+<? printIndented ("\t\t", getRK_val ('barplot_embed.code.printout')); ?>
+ })
+ rk.graph.off ()
<? } ?>
-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"); ?>)
+}
+<? } else {
+ // produce a single barplot of the first result ?>
+i <- 1
+<? getRK ('barplot_embed.code.printout'); ?>
<? }
- ?>
-})
-<? }
-if ($final) { ?>
-<? if (getRK_val ("barplot") == "TRUE") { ?>
-rk.graph.off ()
-<? }
-} ?>
}
-<? }
?>
Modified: trunk/rkward/rkward/plugins/analysis/crosstab.xml
===================================================================
--- trunk/rkward/rkward/plugins/analysis/crosstab.xml 2007-05-16 16:55:20 UTC (rev 1905)
+++ trunk/rkward/rkward/plugins/analysis/crosstab.xml 2007-05-16 16:56:15 UTC (rev 1906)
@@ -1,16 +1,12 @@
<!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="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" />
+ <logic>
+ <connect client="chi_options.enabled" governor="chisq.state" />
+ <connect client="barplot_options.enabled" governor="barplot.state" />
+ <connect client="preview.enabled" governor="barplot.state"/>
+ <set id="barplot_embed.xvar" to="results[[i]]"/>
+
<convert id="montevalue" mode="equals" sources="monte.string" standard="TRUE" />
<connect client="B.enabled" governor="montevalue" />
</logic>
@@ -19,10 +15,12 @@
<tab label="Variables" id="variables_tab">
<row>
<varselector id="vars"/>
- <column>
+ <column>
<varslot multi="false" id="x" source="vars" label="Dependent" required="true" />
<varslot min_vars="1" multi="true" id="y" source="vars" required="true" label="Independent"/>
- <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" />
+ <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" />
+ <preview id="preview" label="Preview"/>
<stretch/>
</column>
</row>
@@ -30,7 +28,7 @@
<tab label="Chisquare Options" id="chi_options">
<checkbox id="simpv" label="Simulate p value" value="TRUE" value_unchecked="FALSE" checked="false" />
<radio id="monte" label="Method">
- <option value="FALSE" label="Asymptotic" checked="true" />
+ <option value="FALSE" label="Asymptotic" checked="true" />
<option value="TRUE" label="Monte Carlo" />
</radio>
<frame label="Number of replicates">
@@ -38,24 +36,10 @@
</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 label="Barplot Options" id="barplot_options">
+ <embed id="barplot_embed" component="rkward::barplot_embed"/>
</tab>
- </tabbook>
+ </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