Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added size option to bootstrap, updated clojure.jar (updated tests to…

… use clojure.test), updated clojure-contrib.jar (fixing add-break-thread)
  • Loading branch information...
commit 093d5042cc2ab1081292c4f3753c2a029c6ee608 1 parent 865ce0a
@liebke liebke authored
View
25 docs/api/index.html
@@ -1799,24 +1799,27 @@
(assoc som :fit fit)
(let [new-som (som-update-weights r total-cycles (som-update-cells data som)
alpha-init beta-init)]
- (recur (inc r) new-som (conj fit (som-fitness data new-som)))))))))</pre></div></div></dd></dl></li></ol></div></div><div class="library"><a name="library-incanter.stats"/><div class="library-name"><span class="library-contents-toggle">[ <a id="library-contents-toggle-incanter.stats" href="javascript:toggle(&apos;library-contents-incanter.stats&apos;, &apos;library-contents-toggle-incanter.stats&apos;, &apos;-&apos;, &apos;+&apos;)">-</a> ] </span>incanter.stats</div><div class="library-contents" id="library-contents-incanter.stats"><div class="library-member-links"><a class="lib-member-link" href="#member-incanter.stats-bootstrap">bootstrap</a> <a class="lib-member-link" href="#member-incanter.stats-cdf-beta">cdf-beta</a> <a class="lib-member-link" href="#member-incanter.stats-cdf-binomial">cdf-binomial</a> <a class="lib-member-link" href="#member-incanter.stats-cdf-chisq">cdf-chisq</a> <a class="lib-member-link" href="#member-incanter.stats-cdf-exp">cdf-exp</a> <a class="lib-member-link" href="#member-incanter.stats-cdf-f">cdf-f</a> <a class="lib-member-link" href="#member-incanter.stats-cdf-gamma">cdf-gamma</a> <a class="lib-member-link" href="#member-incanter.stats-cdf-neg-binomial">cdf-neg-binomial</a> <a class="lib-member-link" href="#member-incanter.stats-cdf-normal">cdf-normal</a> <a class="lib-member-link" href="#member-incanter.stats-cdf-poisson">cdf-poisson</a> <a class="lib-member-link" href="#member-incanter.stats-cdf-t">cdf-t</a> <a class="lib-member-link" href="#member-incanter.stats-cdf-uniform">cdf-uniform</a> <a class="lib-member-link" href="#member-incanter.stats-chisq-test">chisq-test</a> <a class="lib-member-link" href="#member-incanter.stats-correlation">correlation</a> <a class="lib-member-link" href="#member-incanter.stats-covariance">covariance</a> <a class="lib-member-link" href="#member-incanter.stats-cumulative-mean">cumulative-mean</a> <a class="lib-member-link" href="#member-incanter.stats-detabulate">detabulate</a> <a class="lib-member-link" href="#member-incanter.stats-indicator">indicator</a> <a class="lib-member-link" href="#member-incanter.stats-kurtosis">kurtosis</a> <a class="lib-member-link" href="#member-incanter.stats-linear-model">linear-model</a> <a class="lib-member-link" href="#member-incanter.stats-mean">mean</a> <a class="lib-member-link" href="#member-incanter.stats-median">median</a> <a class="lib-member-link" href="#member-incanter.stats-pdf-beta">pdf-beta</a> <a class="lib-member-link" href="#member-incanter.stats-pdf-binomial">pdf-binomial</a> <a class="lib-member-link" href="#member-incanter.stats-pdf-chisq">pdf-chisq</a> <a class="lib-member-link" href="#member-incanter.stats-pdf-exp">pdf-exp</a> <a class="lib-member-link" href="#member-incanter.stats-pdf-f">pdf-f</a> <a class="lib-member-link" href="#member-incanter.stats-pdf-gamma">pdf-gamma</a> <a class="lib-member-link" href="#member-incanter.stats-pdf-neg-binomial">pdf-neg-binomial</a> <a class="lib-member-link" href="#member-incanter.stats-pdf-normal">pdf-normal</a> <a class="lib-member-link" href="#member-incanter.stats-pdf-poisson">pdf-poisson</a> <a class="lib-member-link" href="#member-incanter.stats-pdf-t">pdf-t</a> <a class="lib-member-link" href="#member-incanter.stats-pdf-uniform">pdf-uniform</a> <a class="lib-member-link" href="#member-incanter.stats-permute">permute</a> <a class="lib-member-link" href="#member-incanter.stats-principal-components">principal-components</a> <a class="lib-member-link" href="#member-incanter.stats-quantile">quantile</a> <a class="lib-member-link" href="#member-incanter.stats-quantile-normal">quantile-normal</a> <a class="lib-member-link" href="#member-incanter.stats-quantile-t">quantile-t</a> <a class="lib-member-link" href="#member-incanter.stats-sample">sample</a> <a class="lib-member-link" href="#member-incanter.stats-sample-beta">sample-beta</a> <a class="lib-member-link" href="#member-incanter.stats-sample-binomial">sample-binomial</a> <a class="lib-member-link" href="#member-incanter.stats-sample-chisq">sample-chisq</a> <a class="lib-member-link" href="#member-incanter.stats-sample-dirichlet">sample-dirichlet</a> <a class="lib-member-link" href="#member-incanter.stats-sample-exp">sample-exp</a> <a class="lib-member-link" href="#member-incanter.stats-sample-gamma">sample-gamma</a> <a class="lib-member-link" href="#member-incanter.stats-sample-multivariate-normal">sample-multivariate-normal</a> <a class="lib-member-link" href="#member-incanter.stats-sample-neg-binomial">sample-neg-binomial</a> <a class="lib-member-link" href="#member-incanter.stats-sample-normal">sample-normal</a> <a class="lib-member-link" href="#member-incanter.stats-sample-permutations">sample-permutations</a> <a class="lib-member-link" href="#member-incanter.stats-sample-poisson">sample-poisson</a> <a class="lib-member-link" href="#member-incanter.stats-sample-t">sample-t</a> <a class="lib-member-link" href="#member-incanter.stats-sample-uniform">sample-uniform</a> <a class="lib-member-link" href="#member-incanter.stats-sample-wishart">sample-wishart</a> <a class="lib-member-link" href="#member-incanter.stats-sd">sd</a> <a class="lib-member-link" href="#member-incanter.stats-skewness">skewness</a> <a class="lib-member-link" href="#member-incanter.stats-sweep">sweep</a> <a class="lib-member-link" href="#member-incanter.stats-t-test">t-test</a> <a class="lib-member-link" href="#member-incanter.stats-tabulate">tabulate</a> <a class="lib-member-link" href="#member-incanter.stats-variance">variance</a></div><ol class="library-members"><li class="library-member"><a name="member-incanter.stats-bootstrap"/><dl class="library-member-table"><dt class="library-member-name">bootstrap</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([data statistic &amp; options])</span></div><div class="library-member-docs"><div class="library-member-doc-line"> Returns a bootstrap sample of the given statistic on the given data</div><div class="library-member-doc-line"><span class="library-member-doc-whitespace"> </span></div><div class="library-member-doc-line"><span class="library-member-doc-whitespace"> </span></div><div class="library-member-doc-line"> Examples:</div><div class="library-member-doc-line"> (use &apos;(incanter core stats datasets charts))</div><div class="library-member-doc-line"> (def x (sel (get-dataset :flow-meter) :cols 1))</div><div class="library-member-doc-line"> (view (histogram x :density true))</div><div class="library-member-doc-line"> (median x)</div><div class="library-member-doc-line"><span class="library-member-doc-whitespace"> </span></div><div class="library-member-doc-line"> (def boot-median (bootstrap x median))</div><div class="library-member-doc-line"> (mean boot-median)</div><div class="library-member-doc-line"> (median boot-median)</div><div class="library-member-doc-line"> (sd boot-median)</div><div class="library-member-doc-line"> (count boot-median)</div><div class="library-member-doc-line"> (view (histogram boot-median :density true))</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-incanter.stats-bootstrap&apos;)" id="linkto-membersource-incanter.stats-bootstrap">Show Source</a> ]</div><div class="library-member-source" id="membersource-incanter.stats-bootstrap"><pre>(defn bootstrap
+ (recur (inc r) new-som (conj fit (som-fitness data new-som)))))))))</pre></div></div></dd></dl></li></ol></div></div><div class="library"><a name="library-incanter.stats"/><div class="library-name"><span class="library-contents-toggle">[ <a id="library-contents-toggle-incanter.stats" href="javascript:toggle(&apos;library-contents-incanter.stats&apos;, &apos;library-contents-toggle-incanter.stats&apos;, &apos;-&apos;, &apos;+&apos;)">-</a> ] </span>incanter.stats</div><div class="library-contents" id="library-contents-incanter.stats"><div class="library-member-links"><a class="lib-member-link" href="#member-incanter.stats-bootstrap">bootstrap</a> <a class="lib-member-link" href="#member-incanter.stats-cdf-beta">cdf-beta</a> <a class="lib-member-link" href="#member-incanter.stats-cdf-binomial">cdf-binomial</a> <a class="lib-member-link" href="#member-incanter.stats-cdf-chisq">cdf-chisq</a> <a class="lib-member-link" href="#member-incanter.stats-cdf-exp">cdf-exp</a> <a class="lib-member-link" href="#member-incanter.stats-cdf-f">cdf-f</a> <a class="lib-member-link" href="#member-incanter.stats-cdf-gamma">cdf-gamma</a> <a class="lib-member-link" href="#member-incanter.stats-cdf-neg-binomial">cdf-neg-binomial</a> <a class="lib-member-link" href="#member-incanter.stats-cdf-normal">cdf-normal</a> <a class="lib-member-link" href="#member-incanter.stats-cdf-poisson">cdf-poisson</a> <a class="lib-member-link" href="#member-incanter.stats-cdf-t">cdf-t</a> <a class="lib-member-link" href="#member-incanter.stats-cdf-uniform">cdf-uniform</a> <a class="lib-member-link" href="#member-incanter.stats-chisq-test">chisq-test</a> <a class="lib-member-link" href="#member-incanter.stats-correlation">correlation</a> <a class="lib-member-link" href="#member-incanter.stats-covariance">covariance</a> <a class="lib-member-link" href="#member-incanter.stats-cumulative-mean">cumulative-mean</a> <a class="lib-member-link" href="#member-incanter.stats-detabulate">detabulate</a> <a class="lib-member-link" href="#member-incanter.stats-indicator">indicator</a> <a class="lib-member-link" href="#member-incanter.stats-kurtosis">kurtosis</a> <a class="lib-member-link" href="#member-incanter.stats-linear-model">linear-model</a> <a class="lib-member-link" href="#member-incanter.stats-mean">mean</a> <a class="lib-member-link" href="#member-incanter.stats-median">median</a> <a class="lib-member-link" href="#member-incanter.stats-pdf-beta">pdf-beta</a> <a class="lib-member-link" href="#member-incanter.stats-pdf-binomial">pdf-binomial</a> <a class="lib-member-link" href="#member-incanter.stats-pdf-chisq">pdf-chisq</a> <a class="lib-member-link" href="#member-incanter.stats-pdf-exp">pdf-exp</a> <a class="lib-member-link" href="#member-incanter.stats-pdf-f">pdf-f</a> <a class="lib-member-link" href="#member-incanter.stats-pdf-gamma">pdf-gamma</a> <a class="lib-member-link" href="#member-incanter.stats-pdf-neg-binomial">pdf-neg-binomial</a> <a class="lib-member-link" href="#member-incanter.stats-pdf-normal">pdf-normal</a> <a class="lib-member-link" href="#member-incanter.stats-pdf-poisson">pdf-poisson</a> <a class="lib-member-link" href="#member-incanter.stats-pdf-t">pdf-t</a> <a class="lib-member-link" href="#member-incanter.stats-pdf-uniform">pdf-uniform</a> <a class="lib-member-link" href="#member-incanter.stats-permute">permute</a> <a class="lib-member-link" href="#member-incanter.stats-principal-components">principal-components</a> <a class="lib-member-link" href="#member-incanter.stats-quantile">quantile</a> <a class="lib-member-link" href="#member-incanter.stats-quantile-normal">quantile-normal</a> <a class="lib-member-link" href="#member-incanter.stats-quantile-t">quantile-t</a> <a class="lib-member-link" href="#member-incanter.stats-sample">sample</a> <a class="lib-member-link" href="#member-incanter.stats-sample-beta">sample-beta</a> <a class="lib-member-link" href="#member-incanter.stats-sample-binomial">sample-binomial</a> <a class="lib-member-link" href="#member-incanter.stats-sample-chisq">sample-chisq</a> <a class="lib-member-link" href="#member-incanter.stats-sample-dirichlet">sample-dirichlet</a> <a class="lib-member-link" href="#member-incanter.stats-sample-exp">sample-exp</a> <a class="lib-member-link" href="#member-incanter.stats-sample-gamma">sample-gamma</a> <a class="lib-member-link" href="#member-incanter.stats-sample-multivariate-normal">sample-multivariate-normal</a> <a class="lib-member-link" href="#member-incanter.stats-sample-neg-binomial">sample-neg-binomial</a> <a class="lib-member-link" href="#member-incanter.stats-sample-normal">sample-normal</a> <a class="lib-member-link" href="#member-incanter.stats-sample-permutations">sample-permutations</a> <a class="lib-member-link" href="#member-incanter.stats-sample-poisson">sample-poisson</a> <a class="lib-member-link" href="#member-incanter.stats-sample-t">sample-t</a> <a class="lib-member-link" href="#member-incanter.stats-sample-uniform">sample-uniform</a> <a class="lib-member-link" href="#member-incanter.stats-sample-wishart">sample-wishart</a> <a class="lib-member-link" href="#member-incanter.stats-sd">sd</a> <a class="lib-member-link" href="#member-incanter.stats-skewness">skewness</a> <a class="lib-member-link" href="#member-incanter.stats-sweep">sweep</a> <a class="lib-member-link" href="#member-incanter.stats-t-test">t-test</a> <a class="lib-member-link" href="#member-incanter.stats-tabulate">tabulate</a> <a class="lib-member-link" href="#member-incanter.stats-variance">variance</a></div><ol class="library-members"><li class="library-member"><a name="member-incanter.stats-bootstrap"/><dl class="library-member-table"><dt class="library-member-name">bootstrap</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([data statistic &amp; options])</span></div><div class="library-member-docs"><div class="library-member-doc-line"> Returns a bootstrap sample of the given statistic on the given data</div><div class="library-member-doc-line"><span class="library-member-doc-whitespace"> </span></div><div class="library-member-doc-line"><span class="library-member-doc-whitespace"> </span></div><div class="library-member-doc-line"> Examples:</div><div class="library-member-doc-line"><span class="library-member-doc-whitespace"> </span></div><div class="library-member-doc-line"> (use &apos;(incanter core stats datasets charts))</div><div class="library-member-doc-line"> ;; example from Data Analysis by Resampling Concepts and Applications</div><div class="library-member-doc-line"> ;; Clifford E. Lunneborg (pages 119-122)</div><div class="library-member-doc-line"><span class="library-member-doc-whitespace"> </span></div><div class="library-member-doc-line"> ;; weights (in grams) of 50 randomly sampled bags of preztels</div><div class="library-member-doc-line"> (def x [464 447 446 454 450 457 </div><div class="library-member-doc-line"> 450 442 433 452 449 454 </div><div class="library-member-doc-line"> 450 438 448 449 457 451 </div><div class="library-member-doc-line"> 456 452 450 463 464 453 </div><div class="library-member-doc-line"> 452 447 439 449 468 443</div><div class="library-member-doc-line"> 433 460 452 447 447 446 </div><div class="library-member-doc-line"> 450 459 466 433 445 453 </div><div class="library-member-doc-line"> 454 446 464 450 456 456 </div><div class="library-member-doc-line"> 447 469])</div><div class="library-member-doc-line"><span class="library-member-doc-whitespace"> </span></div><div class="library-member-doc-line"> (median x)</div><div class="library-member-doc-line"> (def t* (bootstrap x median :size 2000))</div><div class="library-member-doc-line"> (mean t*)</div><div class="library-member-doc-line"> (sd t*)</div><div class="library-member-doc-line"><span class="library-member-doc-whitespace"> </span></div><div class="library-member-doc-line"> ;; 90% standard normal CI</div><div class="library-member-doc-line"> (+ (median x) (* (quantile-normal 0.05) (sd t*)))</div><div class="library-member-doc-line"> (+ (median x) (* (quantile-normal 0.95) (sd t*)))</div><div class="library-member-doc-line"><span class="library-member-doc-whitespace"> </span></div><div class="library-member-doc-line"> ;; 90% symmetric percentile CI</div><div class="library-member-doc-line"> (quantile t* :probs [0.05 0.95])</div><div class="library-member-doc-line"><span class="library-member-doc-whitespace"> </span></div><div class="library-member-doc-line"><span class="library-member-doc-whitespace"> </span></div><div class="library-member-doc-line"> ;; 90% non-symmetric percentile CI</div><div class="library-member-doc-line"> (- (* 2 (median x)) (quantile t* :probs 0.95))</div><div class="library-member-doc-line"> (- (* 2 (median x)) (quantile t* :probs 0.05))</div><div class="library-member-doc-line"><span class="library-member-doc-whitespace"> </span></div><div class="library-member-doc-line"> ;; calculate bias</div><div class="library-member-doc-line"> (- (mean t*) (median x))</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-incanter.stats-bootstrap&apos;)" id="linkto-membersource-incanter.stats-bootstrap">Show Source</a> ]</div><div class="library-member-source" id="membersource-incanter.stats-bootstrap"><pre>(defn bootstrap
&quot; Returns a bootstrap sample of the given statistic on the given data...&quot;
([data statistic &amp; options]
(let [opts (if options (apply assoc {} options) nil)
+ size (when (:size opts) (:size opts))
+ replacement (if (false? (:replacement opts)) false true)
B1 100
B2 25
max-iter 10
D 0.01
- n (if (:n opts) (:n opts) (count data))
- replacement (if (false? (:replacement opts)) false true)]
- (loop [stats (for [_ (range B1)] (statistic (sample data :size n :replacement replacement)))
- k 0]
- (let [stats2 (concat stats (for [_ (range B2)] (statistic (sample data :size n :replacement replacement))))
- se1 (sd stats)
- se2 (sd stats2)]
- (if (or (= k max-iter) (&lt; (* (- 1 D) se1) se2 (* (+ 1 D) se1)))
- stats2
- (recur stats2 (inc k))))))))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-incanter.stats-cdf-beta"/><dl class="library-member-table"><dt class="library-member-name">cdf-beta</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([x &amp; options])</span></div><div class="library-member-docs"><div class="library-member-doc-line"> Returns the Beta cdf of the given value of x. It will return a sequence </div><div class="library-member-doc-line"> of values, if x is a sequence. This is equivalent to R&apos;s pbeta function. </div><div class="library-member-doc-line"><span class="library-member-doc-whitespace"> </span></div><div class="library-member-doc-line"> Options: </div><div class="library-member-doc-line"> :alpha (default 1) </div><div class="library-member-doc-line"> :beta (default 1)</div><div class="library-member-doc-line"> :lower-tail (default true)</div><div class="library-member-doc-line"><span class="library-member-doc-whitespace"> </span></div><div class="library-member-doc-line"> See also: </div><div class="library-member-doc-line"> pdf-beta and sample-beta</div><div class="library-member-doc-line"><span class="library-member-doc-whitespace"> </span></div><div class="library-member-doc-line"> References: </div><div class="library-member-doc-line"> http://incanter.org/docs/parallelcolt/api/cern/jet/random/tdouble/Beta.html</div><div class="library-member-doc-line"> http://en.wikipedia.org/wiki/Beta_distribution</div><div class="library-member-doc-line"> http://en.wikipedia.org/wiki/Cumulative_distribution_function</div><div class="library-member-doc-line"><span class="library-member-doc-whitespace"> </span></div><div class="library-member-doc-line"> Example: </div><div class="library-member-doc-line"> (cdf-beta 0.5 :alpha 1 :beta 2)</div><div class="library-member-doc-line"> (cdf-beta 0.5 :alpha 1 :beta 2 :lower-tail false)</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-incanter.stats-cdf-beta&apos;)" id="linkto-membersource-incanter.stats-cdf-beta">Show Source</a> ]</div><div class="library-member-source" id="membersource-incanter.stats-cdf-beta"><pre>(defn cdf-beta
+ n (if (:n opts) (:n opts) (count data))]
+ (if (nil? size)
+ (loop [stats (for [_ (range B1)] (statistic (sample data :size n :replacement replacement)))
+ k 0]
+ (let [stats2 (concat stats (for [_ (range B2)] (statistic (sample data :size n :replacement replacement))))
+ se1 (sd stats)
+ se2 (sd stats2)]
+ (if (or (= k max-iter) (&lt; (* (- 1 D) se1) se2 (* (+ 1 D) se1)))
+ stats2
+ (recur stats2 (inc k)))))
+ (statistic (sample data :size n :replacement replacement))))))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-incanter.stats-cdf-beta"/><dl class="library-member-table"><dt class="library-member-name">cdf-beta</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([x &amp; options])</span></div><div class="library-member-docs"><div class="library-member-doc-line"> Returns the Beta cdf of the given value of x. It will return a sequence </div><div class="library-member-doc-line"> of values, if x is a sequence. This is equivalent to R&apos;s pbeta function. </div><div class="library-member-doc-line"><span class="library-member-doc-whitespace"> </span></div><div class="library-member-doc-line"> Options: </div><div class="library-member-doc-line"> :alpha (default 1) </div><div class="library-member-doc-line"> :beta (default 1)</div><div class="library-member-doc-line"> :lower-tail (default true)</div><div class="library-member-doc-line"><span class="library-member-doc-whitespace"> </span></div><div class="library-member-doc-line"> See also: </div><div class="library-member-doc-line"> pdf-beta and sample-beta</div><div class="library-member-doc-line"><span class="library-member-doc-whitespace"> </span></div><div class="library-member-doc-line"> References: </div><div class="library-member-doc-line"> http://incanter.org/docs/parallelcolt/api/cern/jet/random/tdouble/Beta.html</div><div class="library-member-doc-line"> http://en.wikipedia.org/wiki/Beta_distribution</div><div class="library-member-doc-line"> http://en.wikipedia.org/wiki/Cumulative_distribution_function</div><div class="library-member-doc-line"><span class="library-member-doc-whitespace"> </span></div><div class="library-member-doc-line"> Example: </div><div class="library-member-doc-line"> (cdf-beta 0.5 :alpha 1 :beta 2)</div><div class="library-member-doc-line"> (cdf-beta 0.5 :alpha 1 :beta 2 :lower-tail false)</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-incanter.stats-cdf-beta&apos;)" id="linkto-membersource-incanter.stats-cdf-beta">Show Source</a> ]</div><div class="library-member-source" id="membersource-incanter.stats-cdf-beta"><pre>(defn cdf-beta
&quot; Returns the Beta cdf of the given value of x. It will return a sequence ...&quot;
([x &amp; options]
(let [opts (if options (apply assoc {} options) nil)
View
BIN  incanter.jar
Binary file not shown
View
BIN  lib/clojure-contrib.jar
Binary file not shown
View
BIN  lib/clojure.jar
Binary file not shown
View
61 src/incanter/stats.clj
@@ -1530,37 +1530,62 @@
Examples:
+
(use '(incanter core stats datasets charts))
- (def x (sel (get-dataset :flow-meter) :cols 1))
- (view (histogram x :density true))
+ ;; example from Data Analysis by Resampling Concepts and Applications
+ ;; Clifford E. Lunneborg (pages 119-122)
+
+ ;; weights (in grams) of 50 randomly sampled bags of preztels
+ (def x [464 447 446 454 450 457
+ 450 442 433 452 449 454
+ 450 438 448 449 457 451
+ 456 452 450 463 464 453
+ 452 447 439 449 468 443
+ 433 460 452 447 447 446
+ 450 459 466 433 445 453
+ 454 446 464 450 456 456
+ 447 469])
+
(median x)
+ (def t* (bootstrap x median :size 2000))
+ (mean t*)
+ (sd t*)
+
+ ;; 90% standard normal CI
+ (+ (median x) (* (quantile-normal 0.05) (sd t*)))
+ (+ (median x) (* (quantile-normal 0.95) (sd t*)))
+
+ ;; 90% symmetric percentile CI
+ (quantile t* :probs [0.05 0.95])
- (def boot-median (bootstrap x median))
- (mean boot-median)
- (median boot-median)
- (sd boot-median)
- (count boot-median)
- (view (histogram boot-median :density true))
+ ;; 90% non-symmetric percentile CI
+ (- (* 2 (median x)) (quantile t* :probs 0.95))
+ (- (* 2 (median x)) (quantile t* :probs 0.05))
+ ;; calculate bias
+ (- (mean t*) (median x))
"
([data statistic & options]
(let [opts (if options (apply assoc {} options) nil)
+ size (when (:size opts) (:size opts))
+ replacement (if (false? (:replacement opts)) false true)
B1 100
B2 25
max-iter 10
D 0.01
- n (if (:n opts) (:n opts) (count data))
- replacement (if (false? (:replacement opts)) false true)]
- (loop [stats (for [_ (range B1)] (statistic (sample data :size n :replacement replacement)))
- k 0]
- (let [stats2 (concat stats (for [_ (range B2)] (statistic (sample data :size n :replacement replacement))))
- se1 (sd stats)
- se2 (sd stats2)]
- (if (or (= k max-iter) (< (* (- 1 D) se1) se2 (* (+ 1 D) se1)))
- stats2
- (recur stats2 (inc k))))))))
+ n (if (:n opts) (:n opts) (count data))]
+ (if (nil? size)
+ (loop [stats (for [_ (range B1)] (statistic (sample data :size n :replacement replacement)))
+ k 0]
+ (let [stats2 (concat stats (for [_ (range B2)] (statistic (sample data :size n :replacement replacement))))
+ se1 (sd stats)
+ se2 (sd stats2)]
+ (if (or (= k max-iter) (< (* (- 1 D) se1) se2 (* (+ 1 D) se1)))
+ stats2
+ (recur stats2 (inc k)))))
+ (statistic (sample data :size n :replacement replacement))))))
View
2  tests/runtests.clj
@@ -19,7 +19,7 @@
(ns tests.runtests
- (:use (clojure.contrib test-is)
+ (:use [clojure.test :only (run-tests)]
(tests test-cases)
(incanter core io stats charts bayes)))
View
2  tests/test_cases.clj
@@ -23,7 +23,7 @@
;; (run-tests 'incanter.tests.test-cases)
(ns tests.test-cases
- (:use (clojure.contrib test-is)
+ (:use clojure.test
(incanter core io stats charts bayes optimize datasets censored som)
(examples bayes)))
Please sign in to comment.
Something went wrong with that request. Please try again.