Commit 227ed913 authored by Thomas Friedrichsmeier's avatar Thomas Friedrichsmeier
Browse files

Further progress on the mass-conversion of distribution plugins.

TODO: Complete help pages, add tests.
parent 5b742e59
......@@ -38,7 +38,7 @@
<component type="standard" id="chi_squared_probabilities" file="chi_squared.xml" label="Chi-squared distribution calculator" />
<component type="standard" id="plot_chi_squared_distribution" file="plot_chi_squared_distribution.xml" label="Plot Chi-squared distribution" />
<component type="standard" id="exponential_probabilities" file="exponential.xml" label="Exponential probabilities" />
<component type="standard" id="exponential_probabilities" file="exponential.xml" label="Exponential distribution calculator" />
<component type="standard" id="plot_exponential_distribution" file="plot_exponential_distribution.xml" label="Plot Exponential distribution" />
<component type="standard" id="f_probabilities" file="f.xml" label="F distribution calculator" />
......
include ("dist_common.js");
function getDistSpecifics () {
return initDistSpecifics (i18n ('Beta distribution'), 'beta', ["shape1", "shape2", "ncp"], [0, 1], true);
return initDistSpecifics (i18n ('Beta distribution'), 'beta', ["shape1", "shape2", "ncp"], [0, 1], continuous);
}
include ("dist_common.js");
function getDistSpecifics () {
var dist = initDistSpecifics (i18n ('Binomial distribution'), 'binom', ["size", "prob"], [0, getString ("size")], false);
var dist = initDistSpecifics (i18n ('Binomial distribution'), 'binom', ["size", "prob"], [0, getString ("size")], discrete);
return dist;
}
......@@ -4,8 +4,9 @@
<help file="binomial.rkh" />
<logic>
<insert snippet="dialog_logic"/>
<set id="ui_note.visible" to="true"/>
<set id="ui_note.text" to="Note: For the binomial distribution, quantiles can be interpreted as number of successes in the given number of trials."/>
<script><![CDATA[
gui.setValue ("ui_note.text", i18n (noquote ("Quantiles can be interpreted as number of successes in the given number of trials.")));
]]></script>
</logic>
<snippets>
<snippet id="dist_options">
......
include ("dist_common.js");
function getDistSpecifics () {
return initDistSpecifics (i18n ('Cauchy distribution'), 'cauchy', ["location", "scale"]);
return initDistSpecifics (i18n ('Cauchy distribution'), 'cauchy', ["location", "scale"], [], continuous);
}
<!DOCTYPE rkhelp>
<document>
<snippets>
<include file="dist_help_snippets.xml"/>
</snippets>
<summary>
Provides a calculator for probabilities, quantiles, and densities in the Cauchy distribution.
</summary>
<insert snippet="dialog_usage"/>
<settings>
<insert snippet="dialog_settings"/>
<setting id="location">Location parameter (median) of the Cauchy distribution</setting>
<setting id="scale">Scale parameter of the Cauchy distribution</setting>
</settings>
<related>
<ul>
<li><link href="rkward://rhelp/Cauchy"/></li>
<li><link href="rkward://component/rkward/plot_cauchy_distribution"/></li>
</ul>
</related>
</document>
include ("dist_common.js");
function getDistSpecifics () {
return initDistSpecifics (i18n ('Chi-squared distribution'), 'chisq', ["df", "ncp"]);
var df = Number (getString ("df"));
return initDistSpecifics (i18n ('Chi-squared distribution'), 'chisq', ["df", "ncp"],
[Math.max (0, Math.floor (df * .6 - 4)), Math.floor (df * 1.4 + 4)], // NOTE: crude self-made heuristic for covering the likely range of interest for auto-quantiles
continuos);
}
<!DOCTYPE rkhelp>
<document>
<snippets>
<include file="dist_help_snippets.xml"/>
</snippets>
<summary>
Provides a calculator for probabilities, quantiles, and densities in the Chi-squared (χ²) distribution.
</summary>
<insert snippet="dialog_usage"/>
<settings>
<insert snippet="dialog_settings"/>
<setting id="df">Degrees of freedom</setting>
<setting id="ncp">Non-centrality parameter</setting>
</settings>
<related>
<ul>
<li><link href="rkward://rhelp/Chisquare"/></li>
<li><link href="rkward://component/rkward/plot_chi_squared_distribution"/></li>
</ul>
</related>
</document>
......@@ -4,7 +4,11 @@ var dist;
var invar;
var outvar;
function initDistSpecifics (title, stem, params, range, continuous) {
const continuous = 1;
const discrete = 2;
// NOTE: range
function initDistSpecifics (title, stem, params, range, type) {
var dist = new Object ();
var header = new Header (title);
var par = "";
......@@ -15,9 +19,9 @@ function initDistSpecifics (title, stem, params, range, continuous) {
dist["header"] = header;
dist["params"] = par;
dist["funstem"] = stem;
dist["min"] = Number (range[0]);
dist["max"] = Number (range[1]);
dist["cont"] = continuous;
dist["min"] = range[0];
dist["max"] = range[1];
dist["cont"] = (type == continuous);
return dist;
}
......@@ -45,24 +49,28 @@ function calculate () {
if (mode == "q") values = getList ("p.0");
else values = getList ("q.0");
if (values.length < 1) {
// NOTE: making this an even number is somewhat important. Otherwise, the middle number will be something very close to (but not quite) 0 in many cases,
// resulting in very ugly number formatting
var max_auto_sequence_length = 20;
if (invar == 'q') {
if (!dist["cont"]) {
var span = dist["max"] - dist["min"];
var span = Number (dist["max"]) - Number (dist["min"]) - 1;
if (span <= max_auto_sequence_length) {
values = String (dist["min"]) + ':' + String (dist["max"]);
} else {
values = 'seq.int (' + String (dist["min"]) + ', ' + String (dist["max"]) + ', by=' + String (Math.ceil (span / max_auto_sequence_length)) + ')';
}
} else {
values = 'seq (' + String (dist["min"]) + ', ' + String (dist["max"]) + ', length.out=' + String (max_auto_sequence_length+1) + ')';
if (dist["min"] === undefined) dist["min"] = 'q' + dist["funstem"] + ' (.01' + dist["params"] + ')';
if (dist["max"] === undefined) dist["max"] = 'q' + dist["funstem"] + ' (.99' + dist["params"] + ')';
values = 'seq (' + String (dist["min"]) + ', ' + String (dist["max"]) + ', length.out=' + String (max_auto_sequence_length) + ')';
}
} else { // invar == 'p'
if (logpd) {
values = '-' + String (max_auto_sequence_length) + ':0';
} else {
values = 'seq (0, 1, length.out=' + String (max_auto_sequence_length+1) + ')';
values = 'seq (0, 1, length.out=' + String (max_auto_sequence_length) + ')';
}
}
} else {
......
......@@ -10,7 +10,8 @@
<connect client="q.visible" governor="do_q.not"/>
<connect client="p.visible" governor="do_q"/>
<set id="ui_note.visible" to="false"/>
<convert id="have_ui_note" mode="notequals" sources="ui_note.text" standard=""/>
<connect client="ui_note.visible" governor="have_ui_note"/>
</snippet>
<snippet id="dialog_layout">
<dropdown id="mode" label="Mode">
......
include ("dist_common.js");
function getDistSpecifics () {
return initDistSpecifics (i18n ('Exponential distribution'), 'exp', ["rate"]);
var rate = Number (getString ("rate"));
return initDistSpecifics (i18n ('Exponential distribution'), 'exp', ["rate"], [0, Math.floor (5/rate)], continuous);
}
<!DOCTYPE rkhelp>
<document>
<snippets>
<include file="dist_help_snippets.xml"/>
</snippets>
<summary>
Provides a calculator for probabilities, quantiles, and densities in the Exponential distribution.
</summary>
<insert snippet="dialog_usage"/>
<settings>
<insert snippet="dialog_settings"/>
<setting id="rate">Rate parameter λ (1/mean)</setting>
</settings>
<related>
<ul>
<li><link href="rkward://component/rkward/gamma_probabilities"/> (of which the exponential distribution is a special case)</li>
<li><link href="rkward://rhelp/Exponential"/></li>
<li><link href="rkward://component/rkward/plot_exponential_distribution"/></li>
</ul>
</related>
</document>
......@@ -7,7 +7,7 @@
</logic>
<snippets>
<snippet id="dist_options">
<spinbox default_precision="2" type="real" min="0" initial="1" id="rate" label="vector of rates"/>
<spinbox default_precision="1" type="real" min="0" initial="1" id="rate" label="Rates"/>
</snippet>
<include file="dist_snippets.xml"/>
</snippets>
......
include ("dist_common.js");
function getDistSpecifics () {
return initDistSpecifics (i18n ('F distribution'), 'f', ["df1", "df2", "ncp"]);
return initDistSpecifics (i18n ('F distribution'), 'f', ["df1", "df2", "ncp"], [0, undefined], continuous);
}
<!DOCTYPE rkhelp>
<document>
<snippets>
<include file="dist_help_snippets.xml"/>
</snippets>
<summary>
Provides a calculator for probabilities, quantiles, and densities in the F distribution.
</summary>
<insert snippet="dialog_usage"/>
<settings>
<insert snippet="dialog_settings"/>
<setting id="df1">Numerator degrees of freedom</setting>
<setting id="df2">Denominator degrees of freedom</setting>
<setting id="ncp">Non-centrality parameter</setting>
</settings>
<related>
<ul>
<li><link href="rkward://rhelp/Fdist"/></li>
<li><link href="rkward://component/rkward/plot_f_distribution"/></li>
</ul>
</related>
</document>
......@@ -7,9 +7,9 @@
</logic>
<snippets>
<snippet id="dist_options">
<spinbox default_precision="2" type="real" initial="1" id="df1" min="0" label="Numerator degree of Freedom"/>
<spinbox default_precision="2" type="real" initial="1" id="df2" min="0" label="Denominator degree of Freedom"/>
<spinbox default_precision="2" type="real" initial="0" id="ncp" min="0" label="non-centrality parameter"/>
<spinbox default_precision="1" type="real" initial="1" id="df1" min="0" label="Numerator degrees of Freedom"/>
<spinbox default_precision="1" type="real" initial="10" id="df2" min="0" label="Denominator degrees of Freedom"/>
<spinbox default_precision="1" type="real" initial="0" id="ncp" min="0" label="non-centrality parameter"/>
</snippet>
<include file="dist_snippets.xml"/>
</snippets>
......
include ("dist_common.js");
function getDistSpecifics () {
return initDistSpecifics (i18n ('Gamma distribution'), 'gamma', ["shape", "rate"]);
return initDistSpecifics (i18n ('Gamma distribution'), 'gamma', ["shape", "rate"], [0, undefined], continuous);
}
<!DOCTYPE rkhelp>
<document>
<snippets>
<include file="dist_help_snippets.xml"/>
</snippets>
<summary>
Provides a calculator for probabilities, quantiles, and densities in the gamma distribution.
</summary>
<insert snippet="dialog_usage"/>
<settings>
<insert snippet="dialog_settings"/>
<setting id="shape">Shape parameter (k)</setting>
<setting id="rate">Rate parameter β (inverse of scale parameter)</setting>
</settings>
<related>
<ul>
<li><link href="rkward://component/rkward/exponential_probabilities"/> (a special case of the gamma distribution with shape=1)</li>
<li><link href="rkward://rhelp/GammaDist">R help on Gamma Distribution functions</link></li>
<li><link href="rkward://component/rkward/plot_gamma_distribution"/></li>
</ul>
</related>
</document>
......@@ -7,8 +7,8 @@
</logic>
<snippets>
<snippet id="dist_options">
<spinbox default_precision="2" type="real" min="0" initial="1" id="shape" label="Shape"/>
<spinbox default_precision="2" type="real" min="0" initial="1" id="rate" label="Rate"/>
<spinbox default_precision="1" type="real" min="0" initial="1" id="shape" label="Shape"/>
<spinbox default_precision="1" type="real" min="0" initial="1" id="rate" label="Rate"/>
</snippet>
<include file="dist_snippets.xml"/>
</snippets>
......
include ("dist_common.js");
function getDistSpecifics () {
return initDistSpecifics (i18n ('Geometric distribution'), 'geom', ["prob"]);
var prob = Number (getString ("prob"));
return initDistSpecifics (i18n ('Geometric distribution'), 'geom', ["prob"], [0, Math.floor (5/prob)], discrete);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment