[rkward-cvs] SF.net SVN: rkward: [1417] trunk/rkward/rkward/plugins
kapatp at users.sourceforge.net
kapatp at users.sourceforge.net
Tue Feb 20 05:27:14 UTC 2007
Revision: 1417
http://svn.sourceforge.net/rkward/?rev=1417&view=rev
Author: kapatp
Date: 2007-02-19 21:27:14 -0800 (Mon, 19 Feb 2007)
Log Message:
-----------
Beta and Binomial CLT plugins
Modified Paths:
--------------
trunk/rkward/rkward/plugins/under_development.pluginmap
Added Paths:
-----------
trunk/rkward/rkward/plugins/distributions/plot_beta_clt.php
trunk/rkward/rkward/plugins/distributions/plot_beta_clt.xml
trunk/rkward/rkward/plugins/distributions/plot_binomial_clt.php
trunk/rkward/rkward/plugins/distributions/plot_binomial_clt.xml
Added: trunk/rkward/rkward/plugins/distributions/plot_beta_clt.php
===================================================================
--- trunk/rkward/rkward/plugins/distributions/plot_beta_clt.php (rev 0)
+++ trunk/rkward/rkward/plugins/distributions/plot_beta_clt.php 2007-02-20 05:27:14 UTC (rev 1417)
@@ -0,0 +1,101 @@
+<?php
+ function preprocess () {
+ }
+
+ function calculate () {
+ }
+
+ function printout () {
+ doPrintout (true);
+ }
+
+ function cleanup () {
+?>
+rm(rk.temp.cltdistrib)
+<?
+ }
+
+function preview () {
+ preprocess ();
+ calculate ();
+ doPrintout (false);
+ cleanup ();
+}
+
+function doPrintout ($final) {
+ $fun = getRK_val ("function");
+ $a = getRK_val ("a");
+ $b = getRK_val ("b");
+ $ncp = getRK_val ("ncp");
+ $nAvg = getRK_val ("nAvg");
+ $nDist = getRK_val ("nDist");
+
+ $scalenorm = getRK_val ("scalenorm");
+ $drawnorm = getRK_val ("drawnorm");
+
+ $distExp = $a/($a+$b);
+ $distVar = $a*$b;
+ $distVar /= (($a+$b)^2)*($a+$b+1);
+ $distVar /= $nAvg;
+
+ if ($scalenorm) {
+ $normMu = 0;
+ $normSigma = 1;
+ } else {
+ $normMu = $distExp;
+ $normSigma = sqrt($distVar);
+ }
+
+ if ($fun == "hist") {
+ $histoptions = ", breaks=";
+
+ $histbreaks = getRK_val ("histbreaksFunction");
+ if ($histbreaks == "cells") $histoptions .= getRK_val ("histbreaks_ncells");
+ else $histoptions .= "\"" . $histbreaks . "\"";
+
+ $histlty = getRK_val ("histlinetype");
+ $histoptions .= ", lty=" . "\"" . $histlty . "\"";
+ if ($histlty != "blank") {
+ $density = getRK_val ("density");
+ $histoptions .= ", density=" . $density;
+
+ if ($density > 0) $histoptions .= ", angle=" . getRK_val ("angle");
+
+ $histbordercol = getRK_val ("histbordercol");
+ if (($histbordercol != "FALSE") & ($histbordercol != "TRUE")) $histbordercol = "\"" . $histbordercol . "\"";
+ $histfillcol = getRK_val ("histfillcol");
+ if ($histfillcol != "NULL") $histfillcol = "\"" . $histfillcol . "\"";
+
+ $histoptions .= ", border=" . $histbordercol . ", col=" . $histfillcol;
+ }
+ $histoptions .= getRK_val("plotoptions.code.printout");
+ }
+?>
+rk.temp.cltdistrib <- list()
+rk.temp.cltdistrib$data <- matrix(rbeta(n=<? echo ($nAvg*$nDist); ?>, shape1 = <? echo ($a); ?>, shape2=<? echo ($b); ?>, ncp=<? echo ($ncp); ?>), nrow=<? echo ($nAvg); ?>);
+rk.temp.cltdistrib$avg <- colMeans(rk.temp.cltdistrib$data);
+rk.temp.cltdistrib$mean <- c(<? echo ($distExp); ?>)
+rk.temp.cltdistrib$var <- c(<? echo ($distVar); ?>)
+if (<? echo ($scalenorm); ?>) rk.temp.cltdistrib$avg <- (rk.temp.cltdistrib$avg - rk.temp.cltdistrib$mean)/sqrt(rk.temp.cltdistrib$var)
+rk.temp.cltdistrib$normX <- seq(from=min(rk.temp.cltdistrib$avg), to=max(rk.temp.cltdistrib$avg), length=<? echo ($nDist); ?>)
+rk.temp.cltdistrib$normY <- dnorm (rk.temp.cltdistrib$normX, mean = <? echo ($normMu); ?>, sd = <? echo ($normSigma); ?>)
+<?
+ if ($final) { ?>
+rk.graph.on ()
+<? }
+ if ($fun == "hist") {
+?>
+rk.temp.cltdistrib$hist <- hist(rk.temp.cltdistrib$avg, plot=FALSE)
+rk.temp.cltdistrib$ylim <- c(0,max(c(rk.temp.cltdistrib$hist$density, rk.temp.cltdistrib$normY)))
+try( plot(rk.temp.cltdistrib$hist, freq=FALSE, ylim=rk.temp.cltdistrib$ylim<? echo ($histoptions); ?>) )
+<?
+ }
+?>
+if (<? echo ($drawnorm); ?>) {
+ try (lines (x=rk.temp.cltdistrib$normX, y=rk.temp.cltdistrib$normY, type="<? getRK ("normpointtype"); ?>", col="<? getRK ("normlinecol"); ?>"))
+}
+<? if ($final) { ?>
+rk.graph.off ()
+<? }
+}
+?>
Added: trunk/rkward/rkward/plugins/distributions/plot_beta_clt.xml
===================================================================
--- trunk/rkward/rkward/plugins/distributions/plot_beta_clt.xml (rev 0)
+++ trunk/rkward/rkward/plugins/distributions/plot_beta_clt.xml 2007-02-20 05:27:14 UTC (rev 1417)
@@ -0,0 +1,122 @@
+<!DOCTYPE rkplugin>
+<document>
+ <code file="plot_beta_clt.php" />
+ <help file="plot_beta_clt.rkh" />
+ <logic>
+ <set id="plotoptions.allow_log" to="false"/>
+ <set id="plotoptions.allow_type" to="false"/>
+ <set id="plotoptions.main.text" to="Histogram for Beta"/>
+ <set id="plotoptions.xlab.text" to="Samples"/>
+
+ <convert id="isbreaks_cells" sources="histbreaksFunction.string" mode="equals" standard="cells"/>
+ <connect client="histbreaks_ncells.enabled" governor="isbreaks_cells"/>
+
+ <convert id="isdensityGT0" mode="range" sources="density.int" min="1" />
+ <connect client="angle.enabled" governor="isdensityGT0"/>
+
+ <convert id="ishistlty_notblank" sources="histlinetype.string" mode="notequals" standard="blank" />
+ <connect client="density.enabled" governor="ishistlty_notblank"/>
+ <connect client="histbordercol.enabled" governor="ishistlty_notblank"/>
+ <connect client="histfillcol.enabled" governor="ishistlty_notblank"/>
+
+ <convert id="isdensityGT0ishistlty_notblank" mode="and" sources="isdensityGT0;ishistlty_notblank" />
+ <connect client="angle.enabled" governor="isdensityGT0ishistlty_notblank"/>
+
+ <convert id="isHistogram" sources="function.string" mode="equals" standard="hist"/>
+ <connect client="moreohistptions.enabled" governor="isHistogram"/>
+
+ <convert id="show_NormalCurveOptions" mode="and" sources="isHistogram;drawnorm.state"/>
+ <connect client="lineoptionsFrame.enabled" governor="show_NormalCurveOptions"/>
+ </logic>
+ <dialog label="Central Limit Theorem: Beta to Normal" >
+ <tabbook>
+ <tab id="plot_binom_clt" label="Parameters" >
+ <row>
+ <column>
+ <frame label="CLT Samples" >
+ <spinbox type="integer" min = "1" id="nAvg" initial="10" label="Samples for Average" />
+ <spinbox type="integer" min = "10" id="nDist" initial="1000" label="Samples for distribution" />
+ </frame>
+ <frame label="Beta Parameters">
+ <spinbox id="a" initial="2" min="0.01" label="Shape1 (a)" />
+ <spinbox id="b" initial="2" min="0.01" label="Shape2 (b)" />
+ <spinbox id="ncp" initial="0" min="0" label="Non-centrality parameter (ncp)" />
+ </frame>
+ </column>
+ <column>
+ <radio id="function" label="Choose type of function plot" >
+ <option value="hist" label="Plot Histogram" />
+ <option value="dist" label="Plot distribution" />
+ <option value="qq" label="Plot QQ-plot" />
+ </radio>
+ <checkbox id="scalenorm" label="Use normalised random variable" value="1" value_unchecked="0"/>
+ <checkbox id="drawnorm" label="Draw normal curve" value="1" value_unchecked="0" checked="true"/>
+ <stretch/>
+ <preview id="preview" label="Preview"/>
+ <embed id="plotoptions" component="rkward::plot_options" as_button="true" label="Plot Options" />
+ </column>
+ </row>
+ </tab>
+ <tab id="moreohistptions" label="More Histogram Options">
+ <row>
+ <column>
+ <radio id="histbreaksFunction" label="Method of setting breakpoints" >
+ <option value="Sturges" label="Sturges" checked="true" />
+ <option value="Scott" label="Scott" />
+ <option value="FD" label="Friedman-Diaconis" />
+ <option value="cells" label="Equally spaced cells" />
+ </radio>
+ <spinbox id="histbreaks_ncells" label="Suggested number of cells" type="integer" min="1" initial="10"/>
+ <frame id="lineoptionsFrame" label="Nomral Curve Options">
+ <dropdown id="normpointtype" label="Type of points/lines" >
+ <option value="p" label="Plot individual points " />
+ <option value="l" label="Plot lines" checked="true"/>
+ <option value="b" label="Plot points connected by lines (both)" />
+ <option value="o" label="Plot points overlaid by lines " />
+ <option value="h" label="Plot vertical lines (high-density)" />
+ <option value="s" label="Step-function plots: left edge" />
+ <option value="S" label="Step-function plots: right edge" />
+ </dropdown>
+ <dropdown id="normlinecol" label="Normal curve color">
+ <option value="azure" label="Azure" />
+ <option value="black" label="Black" />
+ <option value="blue" label="Blue" />
+ <option value="red" label="Red" checked="true"/>
+ </dropdown>
+ </frame>
+ </column>
+ <column>
+ <frame id="histoptions" label="Histogram plot options">
+ <dropdown id="histlinetype" label="Line type for histogram" >
+ <option value="blank" label="Blank (No lines)" />
+ <option value="solid" label="Solid" checked="true"/>
+ <option value="dashed" label="Dashed" />
+ <option value="dotted" label="Dotted" />
+ <option value="dotdash" label="Dot-Dash" />
+ <option value="longdash" label="Long-dash" />
+ <option value="twodash" label="Two-dash" />
+ </dropdown>
+ <spinbox id="density" label="Density of shading lines" type="integer" min="-1" initial="-1" default_precision="1"/>
+ <spinbox id="angle" label="Angle of shading lines" min="0" max = "360" initial="45" default_precision="0"/>
+ <dropdown id="histbordercol" label="Histogram border color">
+ <option value="FALSE" label="Supress borders" />
+ <option value="TRUE" label="Use fill color" checked="true" />
+ <option value="azure" label="Azure" />
+ <option value="black" label="Black" />
+ <option value="blue" label="Blue" />
+ <option value="red" label="Red" />
+ </dropdown>
+ <dropdown id="histfillcol" label="Histogram fill color">
+ <option value="NULL" label="Do not fill" checked="true"/>
+ <option value="azure" label="Azure" />
+ <option value="black" label="Black" />
+ <option value="blue" label="Blue" />
+ <option value="red" label="Red" />
+ </dropdown>
+ </frame>
+ </column>
+ </row>
+ </tab>
+ </tabbook>
+ </dialog>
+</document>
Added: trunk/rkward/rkward/plugins/distributions/plot_binomial_clt.php
===================================================================
--- trunk/rkward/rkward/plugins/distributions/plot_binomial_clt.php (rev 0)
+++ trunk/rkward/rkward/plugins/distributions/plot_binomial_clt.php 2007-02-20 05:27:14 UTC (rev 1417)
@@ -0,0 +1,98 @@
+<?php
+ function preprocess () {
+ }
+
+ function calculate () {
+ }
+
+ function printout () {
+ doPrintout (true);
+ }
+
+ function cleanup () {
+?>
+rm(rk.temp.cltdistrib)
+<?
+ }
+
+function preview () {
+ preprocess ();
+ calculate ();
+ doPrintout (false);
+ cleanup ();
+}
+
+function doPrintout ($final) {
+ $fun = getRK_val ("function");
+ $size = getRK_val ("size");
+ $prob = getRK_val ("prob");
+ $nAvg = getRK_val ("nAvg");
+ $nDist = getRK_val ("nDist");
+
+ $scalenorm = getRK_val ("scalenorm");
+ $drawnorm = getRK_val ("drawnorm");
+
+ $distExp = $size*$prob;
+ $distVar = $size*$prob*(1-$prob)/$nAvg;
+
+ if ($scalenorm) {
+ $normMu = 0;
+ $normSigma = 1;
+ } else {
+ $normMu = $distExp;
+ $normSigma = sqrt($distVar);
+ }
+
+ if ($fun == "hist") {
+ $histoptions = ", breaks=";
+
+ $histbreaks = getRK_val ("histbreaksFunction");
+ if ($histbreaks == "cells") $histoptions .= getRK_val ("histbreaks_ncells");
+ else $histoptions .= "\"" . $histbreaks . "\"";
+
+ $histlty = getRK_val ("histlinetype");
+ $histoptions .= ", lty=" . "\"" . $histlty . "\"";
+ if ($histlty != "blank") {
+ $density = getRK_val ("density");
+ $histoptions .= ", density=" . $density;
+
+ if ($density > 0) $histoptions .= ", angle=" . getRK_val ("angle");
+
+ $histbordercol = getRK_val ("histbordercol");
+ if (($histbordercol != "FALSE") & ($histbordercol != "TRUE")) $histbordercol = "\"" . $histbordercol . "\"";
+ $histfillcol = getRK_val ("histfillcol");
+ if ($histfillcol != "NULL") $histfillcol = "\"" . $histfillcol . "\"";
+
+ $histoptions .= ", border=" . $histbordercol . ", col=" . $histfillcol;
+ }
+ $histoptions .= getRK_val("plotoptions.code.printout");
+ }
+?>
+rk.temp.cltdistrib <- list()
+rk.temp.cltdistrib$data <- matrix(rbinom(n=<? echo ($nAvg*$nDist); ?>, size = <? echo ($size); ?>, prob=<? echo ($prob); ?>), nrow=<? echo ($nAvg); ?>);
+rk.temp.cltdistrib$avg <- colMeans(rk.temp.cltdistrib$data);
+rk.temp.cltdistrib$mean <- c(<? echo ($distExp); ?>)
+rk.temp.cltdistrib$var <- c(<? echo ($distVar); ?>)
+if (<? echo ($scalenorm); ?>) rk.temp.cltdistrib$avg <- (rk.temp.cltdistrib$avg - rk.temp.cltdistrib$mean)/sqrt(rk.temp.cltdistrib$var)
+rk.temp.cltdistrib$normX <- seq(from=min(rk.temp.cltdistrib$avg), to=max(rk.temp.cltdistrib$avg), length=<? echo ($nDist); ?>)
+rk.temp.cltdistrib$normY <- dnorm (rk.temp.cltdistrib$normX, mean = <? echo ($normMu); ?>, sd = <? echo ($normSigma); ?>)
+<?
+ if ($final) { ?>
+rk.graph.on ()
+<? }
+ if ($fun == "hist") {
+?>
+rk.temp.cltdistrib$hist <- hist(rk.temp.cltdistrib$avg, plot=FALSE)
+rk.temp.cltdistrib$ylim <- c(0,max(c(rk.temp.cltdistrib$hist$density, rk.temp.cltdistrib$normY)))
+try( plot(rk.temp.cltdistrib$hist, freq=FALSE, ylim=rk.temp.cltdistrib$ylim<? echo ($histoptions); ?>) )
+<?
+ }
+?>
+if (<? echo ($drawnorm); ?>) {
+ try (lines (x=rk.temp.cltdistrib$normX, y=rk.temp.cltdistrib$normY, type="<? getRK ("normpointtype"); ?>", col="<? getRK ("normlinecol"); ?>"))
+}
+<? if ($final) { ?>
+rk.graph.off ()
+<? }
+}
+?>
Added: trunk/rkward/rkward/plugins/distributions/plot_binomial_clt.xml
===================================================================
--- trunk/rkward/rkward/plugins/distributions/plot_binomial_clt.xml (rev 0)
+++ trunk/rkward/rkward/plugins/distributions/plot_binomial_clt.xml 2007-02-20 05:27:14 UTC (rev 1417)
@@ -0,0 +1,121 @@
+<!DOCTYPE rkplugin>
+<document>
+ <code file="plot_binomial_clt.php" />
+ <help file="plot_binomial_clt.rkh" />
+ <logic>
+ <set id="plotoptions.allow_log" to="false"/>
+ <set id="plotoptions.allow_type" to="false"/>
+ <set id="plotoptions.main.text" to="Histogram for Binomial"/>
+ <set id="plotoptions.xlab.text" to="Samples"/>
+
+ <convert id="isbreaks_cells" sources="histbreaksFunction.string" mode="equals" standard="cells"/>
+ <connect client="histbreaks_ncells.enabled" governor="isbreaks_cells"/>
+
+ <convert id="isdensityGT0" mode="range" sources="density.int" min="1" />
+ <connect client="angle.enabled" governor="isdensityGT0"/>
+
+ <convert id="ishistlty_notblank" sources="histlinetype.string" mode="notequals" standard="blank" />
+ <connect client="density.enabled" governor="ishistlty_notblank"/>
+ <connect client="histbordercol.enabled" governor="ishistlty_notblank"/>
+ <connect client="histfillcol.enabled" governor="ishistlty_notblank"/>
+
+ <convert id="isdensityGT0ishistlty_notblank" mode="and" sources="isdensityGT0;ishistlty_notblank" />
+ <connect client="angle.enabled" governor="isdensityGT0ishistlty_notblank"/>
+
+ <convert id="isHistogram" sources="function.string" mode="equals" standard="hist"/>
+ <connect client="moreohistptions.enabled" governor="isHistogram"/>
+
+ <convert id="show_NormalCurveOptions" mode="and" sources="isHistogram;drawnorm.state"/>
+ <connect client="lineoptionsFrame.enabled" governor="show_NormalCurveOptions"/>
+ </logic>
+ <dialog label="Central Limit Theorem: Binomial to Normal" >
+ <tabbook>
+ <tab id="plot_binom_clt" label="Parameters" >
+ <row>
+ <column>
+ <frame label="CLT Samples" >
+ <spinbox type="integer" min = "1" id="nAvg" initial="10" label="Samples for Average" />
+ <spinbox type="integer" min = "10" id="nDist" initial="1000" label="Samples for distribution" />
+ </frame>
+ <frame label="Binomial Parameters">
+ <spinbox type="integer" id="size" min="1" initial="12" label="Number of trials" />
+ <spinbox default_precision="2" type="real" id="prob" initial="0.5" min="0" max="1" label="Probability of success on each trial" />
+ </frame>
+ </column>
+ <column>
+ <radio id="function" label="Choose type of function plot" >
+ <option value="hist" label="Plot Histogram" />
+ <option value="dist" label="Plot distribution" />
+ <option value="qq" label="Plot QQ-plot" />
+ </radio>
+ <checkbox id="scalenorm" label="Use normalised random variable" value="1" value_unchecked="0"/>
+ <checkbox id="drawnorm" label="Draw normal curve" value="1" value_unchecked="0" checked="true"/>
+ <stretch/>
+ <preview id="preview" label="Preview"/>
+ <embed id="plotoptions" component="rkward::plot_options" as_button="true" label="Plot Options" />
+ </column>
+ </row>
+ </tab>
+ <tab id="moreohistptions" label="More Histogram Options">
+ <row>
+ <column>
+ <radio id="histbreaksFunction" label="Method of setting breakpoints" >
+ <option value="Sturges" label="Sturges" checked="true" />
+ <option value="Scott" label="Scott" />
+ <option value="FD" label="Friedman-Diaconis" />
+ <option value="cells" label="Equally spaced cells" />
+ </radio>
+ <spinbox id="histbreaks_ncells" label="Suggested number of cells" type="integer" min="1" initial="10"/>
+ <frame id="lineoptionsFrame" label="Nomral Curve Options">
+ <dropdown id="normpointtype" label="Type of points/lines" >
+ <option value="p" label="Plot individual points " />
+ <option value="l" label="Plot lines" checked="true"/>
+ <option value="b" label="Plot points connected by lines (both)" />
+ <option value="o" label="Plot points overlaid by lines " />
+ <option value="h" label="Plot vertical lines (high-density)" />
+ <option value="s" label="Step-function plots: left edge" />
+ <option value="S" label="Step-function plots: right edge" />
+ </dropdown>
+ <dropdown id="normlinecol" label="Normal curve color">
+ <option value="azure" label="Azure" />
+ <option value="black" label="Black" />
+ <option value="blue" label="Blue" />
+ <option value="red" label="Red" checked="true"/>
+ </dropdown>
+ </frame>
+ </column>
+ <column>
+ <frame id="histoptions" label="Histogram plot options">
+ <dropdown id="histlinetype" label="Line type for histogram" >
+ <option value="blank" label="Blank (No lines)" />
+ <option value="solid" label="Solid" checked="true"/>
+ <option value="dashed" label="Dashed" />
+ <option value="dotted" label="Dotted" />
+ <option value="dotdash" label="Dot-Dash" />
+ <option value="longdash" label="Long-dash" />
+ <option value="twodash" label="Two-dash" />
+ </dropdown>
+ <spinbox id="density" label="Density of shading lines" type="integer" min="-1" initial="-1" default_precision="1"/>
+ <spinbox id="angle" label="Angle of shading lines" min="0" max = "360" initial="45" default_precision="0"/>
+ <dropdown id="histbordercol" label="Histogram border color">
+ <option value="FALSE" label="Supress borders" />
+ <option value="TRUE" label="Use fill color" checked="true" />
+ <option value="azure" label="Azure" />
+ <option value="black" label="Black" />
+ <option value="blue" label="Blue" />
+ <option value="red" label="Red" />
+ </dropdown>
+ <dropdown id="histfillcol" label="Histogram fill color">
+ <option value="NULL" label="Do not fill" checked="true"/>
+ <option value="azure" label="Azure" />
+ <option value="black" label="Black" />
+ <option value="blue" label="Blue" />
+ <option value="red" label="Red" />
+ </dropdown>
+ </frame>
+ </column>
+ </row>
+ </tab>
+ </tabbook>
+ </dialog>
+</document>
Modified: trunk/rkward/rkward/plugins/under_development.pluginmap
===================================================================
--- trunk/rkward/rkward/plugins/under_development.pluginmap 2007-02-20 05:23:08 UTC (rev 1416)
+++ trunk/rkward/rkward/plugins/under_development.pluginmap 2007-02-20 05:27:14 UTC (rev 1417)
@@ -5,6 +5,8 @@
<component type="standard" id="export_x11_device_new" file="x11device/export_new.xml" label="Export (new)" />
<component type="standard" id="setworkdir" file="00saveload/setworkdir.xml" label="Set Working Directory" />
+ <component type="standard" id="plot_binomial_clt" file="distributions/plot_binomial_clt.xml" label="Binomial CLT" />
+ <component type="standard" id="plot_beta_clt" file="distributions/plot_beta_clt.xml" label="Beta CLT" />
</components>
<hierarchy>
@@ -23,6 +25,16 @@
</menu>
<menu id="distributions" label="Distributions" index="7">
+ <menu id="univariate_continuous_distributions" label="Univariate continuous distributions" index="2">
+ <menu id="beta_distribution" label="Beta" index="0">
+ <entry component="plot_beta_clt" label="Beta CLT" index="2"/>
+ </menu>
+ </menu>
+ <menu id="univariate_discrete_distributions" label="Univariate discrete distributions" index="2">
+ <menu id="binomial_distribution" label="Binomial" index="0">
+ <entry component="plot_binomial_clt" label="Binomial CLT" index="2"/>
+ </menu>
+ </menu>
</menu>
</hierarchy>
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