[rkward-cvs] SF.net SVN: rkward: [1631] trunk/rkward/rkward/plugins
kapatp at users.sourceforge.net
kapatp at users.sourceforge.net
Mon Mar 19 06:00:37 UTC 2007
Revision: 1631
http://svn.sourceforge.net/rkward/?rev=1631&view=rev
Author: kapatp
Date: 2007-03-18 23:00:36 -0700 (Sun, 18 Mar 2007)
Log Message:
-----------
Poisson CLT
Modified Paths:
--------------
trunk/rkward/rkward/plugins/under_development.pluginmap
Added Paths:
-----------
trunk/rkward/rkward/plugins/distributions/clt/plot_poisson_clt.php
trunk/rkward/rkward/plugins/distributions/clt/plot_poisson_clt.rkh
trunk/rkward/rkward/plugins/distributions/clt/plot_poisson_clt.xml
Added: trunk/rkward/rkward/plugins/distributions/clt/plot_poisson_clt.php
===================================================================
--- trunk/rkward/rkward/plugins/distributions/clt/plot_poisson_clt.php (rev 0)
+++ trunk/rkward/rkward/plugins/distributions/clt/plot_poisson_clt.php 2007-03-19 06:00:36 UTC (rev 1631)
@@ -0,0 +1,121 @@
+<?php
+function preprocess () {
+}
+
+function calculate () {
+}
+
+function printout () {
+ doPrintout (true);
+}
+
+function preview () {
+ preprocess ();
+ calculate ();
+ doPrintout (false);
+}
+
+function doPrintout ($final) {
+ $fun = getRK_val ("function");
+ $mean = getRK_val ("mean");
+ $nAvg = getRK_val ("nAvg"); // number of observations to calculate the averages
+ $nDist = getRK_val ("nDist"); // number of sample to construct the distribution
+
+ $scalenorm = getRK_val ("scalenorm"); // if variables should to normalised..
+ $drawnorm = getRK_val ("drawnorm");
+
+ $distExp = $mean; // mean of the distribution of sample averages
+ $distVar = $mean/$nAvg; // variance of the distribution of sample averages
+
+ if ($scalenorm) {
+ $normMu = 0; // mean for normal
+ $normSigma = 1; // std dev for normal
+ } else {
+ $normMu = $distExp;
+ $normSigma = sqrt($distVar);
+ }
+
+ $plotoptions = getRK_val("plotoptions.code.printout");
+ if ($fun == "hist") {
+ $normFun = "dnorm"; // draw normal density on the histogram
+ $histcalcoptions = getRK_val ("histogram_opt.code.calculate"); // options that goes into hist() function
+ $histplotoptions = getRK_val ("histogram_opt.code.printout"); // options that goes into plot.histogram()
+ $histplotoptions .= $plotoptions; // generic plot options
+ } elseif ($fun == "dist") {
+ $ecdfoptions = "";
+ $col_y0 = getRK_val ("col_y0.code.printout");
+ $col_y1 = getRK_val ("col_y1.code.printout");
+ if (($col_y0 != "") && ($col_y1 != "")) {
+ $ecdfoptions .= ", col.01line=c({$col_y0},{$col_y1})";
+ } elseif (($col_y0 != "") || ($col_y1 != "")) {
+ $ecdfoptions .= ", col.01line={$col_y0}{$col_y1}";
+ } // col.01line option to plot.ecdf()
+
+ $normFun = "pnorm"; // draw normal cdf on the ecdf plot
+ $plotoptions .= $ecdfoptions . getRK_val ("dist_stepfun.code.printout"); // plot.ecdf() and plot.stepfun() options
+ }
+
+ $yLim = ""; // initialise the ylim option
+?>
+# generate the entire data:
+data <- matrix(rpois(n=<? echo ($nAvg*$nDist); ?>, lambda=<? echo ($mean); ?>), nrow=<? echo ($nAvg); ?>);
+# get the sample averages:
+avg <- colMeans(data);
+<?
+ if ($scalenorm) {
+?>
+# mean for the sample averages:
+dist.mean <- <? echo ($distExp); ?>;
+# variance for the sample averages:
+dist.var <- <? echo ($distVar); ?>;
+# normalise the variables:
+avg <- (avg - dist.mean)/sqrt(dist.var);
+<?
+ }
+ if ($drawnorm) {
+?>
+# generate random normal samples:
+normX <- seq(from=min(avg), to=max(avg), length=<? echo ($nDist); ?>);
+normY <- <? echo ($normFun); ?> (normX, mean = <? echo ($normMu); ?>, sd = <? echo ($normSigma); ?>);
+<?
+ }
+ if ($fun == "hist") {
+?>
+dist.hist <- hist(avg, plot=FALSE<? echo ($histcalcoptions); ?>);
+<?
+ if ($drawnorm) {
+?>
+# calculate the ylims appropriately:
+ylim <- c(0,max(c(dist.hist$density, normY)));
+<?
+ $yLim = ', ylim=ylim';
+ }
+ }
+ if ($final) {
+?>
+rk.graph.on ()
+try ({
+<?
+ }
+ if ($fun == "hist") {
+?>
+ plot(dist.hist<? echo ($yLim); echo ($histplotoptions); ?>)
+<?
+ } elseif ($fun == "dist") {
+?>
+ plot(ecdf(avg)<? echo ($plotoptions); ?>)
+<?
+ }
+ if ($drawnorm) {
+?>
+ lines (x=normX, y=normY, type="<? getRK ("normpointtype"); ?>"<? getRK ("normlinecol.code.printout"); ?>)
+<?
+ }
+ if ($final) {
+?>
+ })
+rk.graph.off ()
+<?
+ }
+}
+?>
Added: trunk/rkward/rkward/plugins/distributions/clt/plot_poisson_clt.rkh
===================================================================
--- trunk/rkward/rkward/plugins/distributions/clt/plot_poisson_clt.rkh (rev 0)
+++ trunk/rkward/rkward/plugins/distributions/clt/plot_poisson_clt.rkh 2007-03-19 06:00:36 UTC (rev 1631)
@@ -0,0 +1,40 @@
+<!DOCTYPE rkhelp>
+<document>
+ <summary>
+ Normal approximation to Poisson Sample averages. For any generic option refer to the RKWard help page on <link href="rkward://component/plot_binomial_clt"/> for detailed descriptions.
+ </summary>
+ <usage>
+ Choose the Poisson parameter, the sample sizes needed for CLT and a choice of function.
+ </usage>
+ <settings>
+ <caption id="tab_plot_distrib_clt"/>
+ <setting id="frame_poissonparam">See RKWard help on <link href="rkward://component/plot_poisson_distribution"/>.</setting>
+ <setting id="nAvg"></setting>
+ <setting id="nDist"></setting>
+ <setting id="function"></setting>
+ <setting id="scalenorm"></setting>
+ <setting id="drawnorm">For all the above see 'Binomial CLT'.</setting>
+ <setting id="normpointtype">Pointtype for the Normal curve.</setting>
+ <setting id="normlinecol">Color of the Normal curve.</setting>
+ <setting id="plotoptions">Various plot options.</setting>
+ <setting id="preview">Preview button.</setting>
+ <caption id="tab_histoptions"/>
+ <setting id="histogram_opt">See Binomial CLT for details.</setting>
+ <caption id="tab_distfunction"/>
+ <setting id="dist_stepfun">See Binomial CLT for details.</setting>
+ <setting id="frame_col_y0"></setting>
+ <setting id="frame_col_y1">See Binomial CLT for details.</setting>
+ </settings>
+ <related>
+ <ul>
+ <li><link href="rkward://component/plot_binomial_clt"/></li>
+ <li><link href="rkward://component/plot_poisson_distribution"/></li>
+ <li><link href="rkward://component/plot_stepfun_options"/></li>
+ <li><link href="rkward://rhelp/Poisson"/></li>
+ <li><link href="rkward://rhelp/Normal"/></li>
+ <li><link href="rkward://rhelp/hist"/></li>
+ <li><link href="rkward://rhelp/rect"/></li>
+ </ul>
+ </related>
+</document>
+
Added: trunk/rkward/rkward/plugins/distributions/clt/plot_poisson_clt.xml
===================================================================
--- trunk/rkward/rkward/plugins/distributions/clt/plot_poisson_clt.xml (rev 0)
+++ trunk/rkward/rkward/plugins/distributions/clt/plot_poisson_clt.xml 2007-03-19 06:00:36 UTC (rev 1631)
@@ -0,0 +1,93 @@
+<!DOCTYPE rkplugin>
+<document>
+ <code file="plot_poisson_clt.php" />
+ <help file="plot_poisson_clt.rkh" />
+ <logic>
+ <set id="plotoptions.allow_log" to="false"/>
+ <set id="plotoptions.allow_type" to="false"/>
+ <set id="plotoptions.default_main" to="Poisson"/>
+ <set id="plotoptions.default_xlab" to="Sample Averages"/>
+
+ <set id="normlinecol.default_color" to="red" />
+
+ <set id="histogram_opt.varname" to="avg" />
+ <set id="histogram_opt.allow_freq" to="false" />
+ <set id="histogram_opt.allow_barlabels" to="true" />
+ <set id="histogram_opt.allow_addtoplot" to="false" />
+
+ <convert id="isHistogram" sources="function.string" mode="equals" standard="hist"/>
+ <connect client="tab_histoptions.enabled" governor="isHistogram"/>
+
+ <convert id="isDist" sources="function.string" mode="equals" standard="dist"/>
+ <connect client="tab_distfunction.enabled" governor="isDist"/>
+
+ <connect client="normpointtype.enabled" governor="drawnorm.state"/>
+ <connect client="normlinecol.color.enabled" governor="drawnorm.state"/>
+
+ <set id="dist_stepfun.allow_addtoplot" to="false" />
+ <set id="dist_stepfun.default_verticals" to="false" />
+
+ <set id="col_y0.argument" to=""/>
+ <set id="col_y1.argument" to=""/>
+ </logic>
+ <dialog label="Central Limit Theorem: Poisson to Normal" >
+ <tabbook>
+ <tab id="tab_plot_distrib_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 id="frame_poissonparam" label="Poisson Parameters">
+ <spinbox type="real" id="mean" min="0.01" initial="5" label="Mean" />
+ </frame>
+ </column>
+ <column>
+ <radio id="function" label="Choose type of function plot" >
+ <option value="hist" label="Histogram and Density" checked="true"/>
+ <option value="dist" label="ECDF and Distribution"/>
+ </radio>
+ <checkbox id="scalenorm" label="Use normalised random variable" value="1" value_unchecked="0"/>
+ <frame id="frame_lineoptions" label="Nomral Curve Options">
+ <checkbox id="drawnorm" label="Draw normal curve" value="1" value_unchecked="0" checked="true"/>
+ <dropdown id="normpointtype" label="Type of points/lines" >
+ <option value="p" label="Individual points " />
+ <option value="l" label="Lines" checked="true"/>
+ <option value="b" label="Points connected by lines (both)" />
+ <option value="o" label="Points overlaid by lines " />
+ <option value="h" label="Vertical lines (high-density)" />
+ <option value="s" label="Step-function on left edge" />
+ <option value="S" label="Step-function on right edge" />
+ </dropdown>
+ <embed id="normlinecol" component="rkward::color_chooser" label="Color" />
+ </frame>
+ </column>
+ </row>
+ <stretch/>
+ <row>
+ <embed id="plotoptions" component="rkward::plot_options" as_button="true" label="Plot Options" />
+ <preview id="preview" label="Preview"/>
+ </row>
+ </tab>
+
+ <tab id="tab_histoptions" label="Histogram">
+ <embed id="histogram_opt" component="rkward::histogram_options" label="Histogram Options"/>
+ </tab>
+
+ <tab id="tab_distfunction" label="ECDF options">
+ <embed id="dist_stepfun" component="rkward::plot_stepfun_options" label=""/>
+ <row>
+ <frame id="frame_col_y0" label="For y = 0 line">
+ <embed id="col_y0" component="rkward::color_chooser" label="Color"/>
+ </frame>
+ <frame id="frame_col_y1" label="For y = 1 line">
+ <embed id="col_y1" component="rkward::color_chooser" label="Color"/>
+ </frame>
+ </row>
+ <stretch/>
+ </tab>
+
+ </tabbook>
+ </dialog>
+</document>
Modified: trunk/rkward/rkward/plugins/under_development.pluginmap
===================================================================
--- trunk/rkward/rkward/plugins/under_development.pluginmap 2007-03-19 05:40:35 UTC (rev 1630)
+++ trunk/rkward/rkward/plugins/under_development.pluginmap 2007-03-19 06:00:36 UTC (rev 1631)
@@ -6,6 +6,7 @@
<component type="standard" id="plot_geometric_clt" file="distributions/clt/plot_geometric_clt.xml" label="Geometric CLT" />
<component type="standard" id="plot_hypergeometric_clt" file="distributions/clt/plot_hypergeometric_clt.xml" label="Hypergeometric CLT" />
<component type="standard" id="plot_negbinomial_clt" file="distributions/clt/plot_negbinomial_clt.xml" label="Negative Binomial CLT" />
+ <component type="standard" id="plot_poisson_clt" file="distributions/clt/plot_poisson_clt.xml" label="Poisson CLT" />
<component type="standard" id="moment" file="analysis/moments/moment.xml" label="Moment" />
<component type="standard" id="bonett_test" file="analysis/moments/bonett_test.xml" label="Bonett-Seier test of Geary's kurtosis" />
@@ -88,6 +89,9 @@
<menu id="negative_binomial_distribution" label="Negative Binomial">
<entry component="plot_negbinomial_clt" label="Negative Binomial CLT" index="2"/>
</menu>
+ <menu id="poisson_distribution" label="Poisson">
+ <entry component="plot_poisson_clt" label="Poisson 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