notes and paren matching.
[CommonLispStat.git] / src / algorithms / bootstrap.lisp
blob828229980e829eaac2bce32534c70b7f74318b5e
1 ;;; -*- mode: lisp -*-
3 ;;; Time-stamp: <2009-03-12 17:46:34 tony>
4 ;;; Creation: <2008-03-11 19:18:34 user>
5 ;;; File: bootstrap.lisp
6 ;;; Author: AJ Rossini <blindglobe@gmail.com>
7 ;;; Copyright: (c)2009--, AJ Rossini. BSD, LLGPL, or GPLv2, depending
8 ;;; on how it arrives.
9 ;;; Purpose: bootstrapping algorithms for lispstat
11 ;;; What is this talk of 'release'? Klingons do not make software
12 ;;; 'releases'. Our software 'escapes', leaving a bloody trail of
13 ;;; designers and quality assurance people in its wake.
15 (in-package :cls-algorithms-bootstrap)
17 ;;; implememented through general macros for a lispy approach. There
18 ;;; could be a functional approach as well, i.e.
19 ;;; (bootstrap data #'function args)
20 ;;;
22 (defmacro with-data-bootstrap (n (list-of-sources-and-vars) @body)
23 "A proposed lispy implementation, such as:
24 (with-data-bootstrap n
25 ((a dataset1)
26 (b dataset2))
27 (some-form-with-inputs a b c))
28 where there could be multiple datasets, with a and b, etc, being
29 bootstrap realizations of dataset1 and dataset2."
30 (Destructure list-of-sources-and-var)
31 (loop repeat n
32 (progn (pull-samples sources)
33 @body)
34 accumulate in result-list))
36 ;; (defmacro with-correlated-data-bootstrap ())
38 ;; The point of this goes away when we have assurance that
39 ;; observations are independent. And by being able to embed complex
40 ;; objects (temporal / spatial / network structures) into the dataset
41 ;; as typed variables, we now are able to assure such a probability
42 ;; structure.
44 ;;; functional approach
46 (defgeneric bootstrap-sample (data &optional n replace)
47 (:documentation "generate a dataset of N obs from DATA either with
48 or without replace(ment)")
49 (:default-method (data &optional n replace)))
51 (defgeneric bootstrap (data function args)
52 (:documentation "used such as: (bootstrap dataset t-test :significance 0.5)")
53 (:default-method (funcall #'function (bootstrap-sample data) (values args))))
57 2 possible paradigms:
59 (with-data-bootstrap ((a dataset1))
60 (t-test a :significance 0.05))
62 (bootstrap #'t-test a :significance 0.05)