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

kapatp at users.sourceforge.net kapatp at users.sourceforge.net
Mon Mar 19 05:24:55 UTC 2007


Revision: 1629
          http://svn.sourceforge.net/rkward/?rev=1629&view=rev
Author:   kapatp
Date:     2007-03-18 22:24:55 -0700 (Sun, 18 Mar 2007)

Log Message:
-----------
Negative Binomial CLT

Modified Paths:
--------------
    trunk/rkward/rkward/plugins/under_development.pluginmap

Added Paths:
-----------
    trunk/rkward/rkward/plugins/distributions/clt/plot_negbinomial_clt.php
    trunk/rkward/rkward/plugins/distributions/clt/plot_negbinomial_clt.rkh
    trunk/rkward/rkward/plugins/distributions/clt/plot_negbinomial_clt.xml

Added: trunk/rkward/rkward/plugins/distributions/clt/plot_negbinomial_clt.php
===================================================================
--- trunk/rkward/rkward/plugins/distributions/clt/plot_negbinomial_clt.php	                        (rev 0)
+++ trunk/rkward/rkward/plugins/distributions/clt/plot_negbinomial_clt.php	2007-03-19 05:24:55 UTC (rev 1629)
@@ -0,0 +1,131 @@
+<?php
+function preprocess () {
+}
+
+function calculate () {
+}
+
+function printout () {
+	doPrintout (true);
+}
+
+function preview () {
+	preprocess ();
+	calculate ();
+	doPrintout (false);
+}
+
+function doPrintout ($final) {
+	$fun = getRK_val ("function");
+	$paramType = getRK_val ("param");
+ 	if ( $paramType == "pprob") {
+		$size = getRK_val ("size_trial");
+		$prob = getRK_val ("prob");
+		$paramTag = ", prob=" . $prob;
+	} else {
+		$size = getRK_val ("size_disp");
+		$mu = getRK_val ("mu");
+		$paramTag = ", mu=" . $mu;
+		$prob = $size/($size + $mu);
+	}
+	$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 = $size*(1-$prob)/$prob; // mean of the distribution of sample averages
+	$distVar = $size*(1-$prob)/($prob*$prob*$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(rnbinom(n=<? echo ($nAvg*$nDist); ?>, size=<? echo ($size); ?><? echo ($paramTag); ?>), 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_negbinomial_clt.rkh
===================================================================
--- trunk/rkward/rkward/plugins/distributions/clt/plot_negbinomial_clt.rkh	                        (rev 0)
+++ trunk/rkward/rkward/plugins/distributions/clt/plot_negbinomial_clt.rkh	2007-03-19 05:24:55 UTC (rev 1629)
@@ -0,0 +1,40 @@
+<!DOCTYPE rkhelp>
+<document>
+	<summary>
+		Normal approximation to Negative Binomial 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 Negative Binomial parameter, the sample sizes needed for CLT and a choice of function.
+	</usage>
+	<settings>
+		<caption id="tab_plot_distrib_clt"/>
+		<setting id="frame_negbinomparam">See RKWard help on <link href="rkward://component/plot_negbinomial_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_negbinomial_distribution"/></li>
+			<li><link href="rkward://component/plot_stepfun_options"/></li>
+			<li><link href="rkward://rhelp/NegBinomial"/></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_negbinomial_clt.xml
===================================================================
--- trunk/rkward/rkward/plugins/distributions/clt/plot_negbinomial_clt.xml	                        (rev 0)
+++ trunk/rkward/rkward/plugins/distributions/clt/plot_negbinomial_clt.xml	2007-03-19 05:24:55 UTC (rev 1629)
@@ -0,0 +1,113 @@
+<!DOCTYPE rkplugin>
+<document>
+	<code file="plot_negbinomial_clt.php" />
+	<help file="plot_negbinomial_clt.rkh" />
+	<logic>
+		<set id="plotoptions.allow_log" to="false"/>
+		<set id="plotoptions.allow_type" to="false"/>
+		<set id="plotoptions.default_main" to="Negative Binomial"/>
+		<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=""/>
+
+		<convert id="useprob" mode="equals" sources="param.string" standard="pprob" />
+		<connect client="prob.enabled" governor="useprob" />
+		<connect client="size_trial.visible" governor="useprob" />
+		<convert id="usemu" mode="equals" sources="param.string" standard="pmu" />
+		<connect client="mu.enabled" governor="usemu" />
+		<connect client="size_disp.visible" governor="usemu" />
+	</logic>
+	<dialog label="Central Limit Theorem: Negative Binomial 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_negbinomparam" label="Negative Binomial Parameters">
+							<spinbox type="integer" id="size_trial" min="1" initial="12" label="Target number of successful trials" />
+							<spinbox id="size_disp" min="0.01" initial="12.00" label="Dispersion"/>
+							<row>
+								<column>
+									<spinbox default_precision="2" type="real" id="prob" initial="0.75" min="0" max="1" label="Success probability" />
+									<spinbox default_precision="2" type="real" id="mu" initial="4" min="0.01" label="Mean (mu)" />
+								</column>
+								<column>
+									<radio id="param" label="Type of Parameterization" >
+										<option value="pprob" label="Success probability" />
+										<option value="pmu" label="Mean (mu)" />
+									</radio>
+								</column>
+							</row>
+						</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-18 23:57:59 UTC (rev 1628)
+++ trunk/rkward/rkward/plugins/under_development.pluginmap	2007-03-19 05:24:55 UTC (rev 1629)
@@ -5,6 +5,7 @@
 		<component type="standard" id="plot_binomial_clt" file="distributions/clt/plot_binomial_clt.xml" label="Binomial CLT" />
 		<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="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" />
@@ -84,6 +85,9 @@
 				<menu id="hypergeometric_distribution" label="Hypergeometric">
 					<entry component="plot_hypergeometric_clt" label="Hypergeometric CLT" index="2"/>
 				</menu>
+				<menu id="negative_binomial_distribution" label="Negative Binomial">
+					<entry component="plot_negbinomial_clt" label="Negative 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