1 ;;;; dists -- Lisp-Stat interface to basic probability distribution routines
3 ;;;; Copyright (c) 1991, by Luke Tierney. Permission is granted for
11 (in-package lisp-stat-basics
)
13 (in-package 'lisp-stat-basics
)
15 (export '(log-gamma uniform-rand normal-cdf normal-quant normal-dens
16 normal-rand bivnorm-cdf cauchy-cdf cauchy-quant cauchy-dens
17 cauchy-rand gamma-cdf gamma-quant gamma-dens gamma-rand
18 chisq-cdf chisq-quant chisq-dens chisq-rand beta-cdf beta-quant
19 beta-dens beta-rand t-cdf t-quant t-dens t-rand f-cdf f-quant
20 f-dens f-rand poisson-cdf poisson-quant poisson-pmf poisson-rand
21 binomial-cdf binomial-quant binomial-pmf binomial-rand
))
23 (defmacro defbaserand
(name onefun
&rest args
)
24 `(defun ,name
(n ,@args
)
27 (declare (fixnum i
) (inline ,onefun
))
28 (setf result
(cons (,onefun
,@args
) result
))))))
30 (defbaserand base-uniform-rand one-uniform-rand
)
31 (defbaserand base-normal-rand one-normal-rand
)
32 (defbaserand base-cauchy-rand one-cauchy-rand
)
33 (defbaserand base-gamma-rand one-gamma-rand a
)
34 (defbaserand base-chisq-rand one-chisq-rand df
)
35 (defbaserand base-beta-rand one-beta-rand a b
)
36 (defbaserand base-t-rand one-t-rand df
)
37 (defbaserand base-f-rand one-f-rand ndf ddf
)
38 (defbaserand base-poisson-rand one-poisson-rand a
)
39 (defbaserand base-binomial-rand one-binomial-rand a b
)
41 (make-rv-function log-gamma base-log-gamma x
)
43 (make-rv-function uniform-rand base-uniform-rand n
)
45 (make-rv-function normal-cdf base-normal-cdf x
)
46 (make-rv-function normal-quant base-normal-quant p
)
47 (make-rv-function normal-dens base-normal-dens x
)
48 (make-rv-function normal-rand base-normal-rand n
)
49 (make-rv-function bivnorm-cdf base-bivnorm-cdf x y r
)
51 (make-rv-function cauchy-cdf base-cauchy-cdf x
)
52 (make-rv-function cauchy-quant base-cauchy-quant p
)
53 (make-rv-function cauchy-dens base-cauchy-dens x
)
54 (make-rv-function cauchy-rand base-cauchy-rand n
)
56 (make-rv-function gamma-cdf base-gamma-cdf x a
)
57 (make-rv-function gamma-quant base-gamma-quant p a
)
58 (make-rv-function gamma-dens base-gamma-dens x a
)
59 (make-rv-function gamma-rand base-gamma-rand n a
)
61 (make-rv-function chisq-cdf base-chisq-cdf x df
)
62 (make-rv-function chisq-quant base-chisq-quant p df
)
63 (make-rv-function chisq-dens base-chisq-dens x df
)
64 (make-rv-function chisq-rand base-chisq-rand n df
)
66 (make-rv-function beta-cdf base-beta-cdf x a b
)
67 (make-rv-function beta-quant base-beta-quant p a b
)
68 (make-rv-function beta-dens base-beta-dens x a b
)
69 (make-rv-function beta-rand base-beta-rand n a b
)
71 (make-rv-function t-cdf base-t-cdf x df
)
72 (make-rv-function t-quant base-t-quant p df
)
73 (make-rv-function t-dens base-t-dens x df
)
74 (make-rv-function t-rand base-t-rand n df
)
76 (make-rv-function f-cdf base-f-cdf x ndf ddf
)
77 (make-rv-function f-quant base-f-quant p ndf ddf
)
78 (make-rv-function f-dens base-f-dens x ndf ddf
)
79 (make-rv-function f-rand base-f-rand n ndf ddf
)
81 (make-rv-function poisson-cdf base-poisson-cdf x a
)
82 (make-rv-function poisson-quant base-poisson-quant p a
)
83 (make-rv-function poisson-pmf base-poisson-pmf x a
)
84 (make-rv-function poisson-rand base-poisson-rand n a
)
86 (make-rv-function binomial-cdf base-binomial-cdf x a b
)
87 (make-rv-function binomial-quant base-binomial-quant p a b
)
88 (make-rv-function binomial-pmf base-binomial-pmf x a b
)
89 (make-rv-function binomial-rand base-binomial-rand n a b
)
95 (setf (documentation 'bivnorm-cdf
'function
)
97 Returns the value of the standard bivariate normal distribution function
98 with correlation R at (X, Y). Vectorized.")
100 (setf (documentation 'normal-cdf
'function
)
102 Returns the value of the standard normal distribution function at X.
105 (setf (documentation 'beta-cdf
'function
)
106 "Args: (x alpha beta)
107 Returns the value of the Beta(ALPHA, BETA) distribution function at X.
110 (setf (documentation 'gamma-cdf
'function
)
112 Returns the value of the Gamma(alpha, 1) distribution function at X.
115 (setf (documentation 'chisq-cdf
'function
)
117 Returns the value of the Chi-Square(DF) distribution function at X. Vectorized.")
119 (setf (documentation 't-cdf
'function
)
121 Returns the value of the T(DF) distribution function at X. Vectorized.")
123 (setf (documentation 'f-cdf
'function
)
125 Returns the value of the F(NDF, DDF) distribution function at X. Vectorized.")
127 (setf (documentation 'cauchy-cdf
'function
)
129 Returns the value of the standard Cauchy distribution function at X.
132 (setf (documentation 'log-gamma
'function
)
134 Returns the log gamma function of X. Vectorized.")
136 (setf (documentation 'normal-quant
'function
)
138 Returns the P-th quantile of the standard normal distribution. Vectorized.")
140 (setf (documentation 'cauchy-quant
'function
)
142 Returns the P-th quantile(s) of the standard Cauchy distribution. Vectorized.")
144 (setf (documentation 'beta-quant
'function
)
145 "Args: (p alpha beta)
146 Returns the P-th quantile of the Beta(ALPHA, BETA) distribution. Vectorized.")
148 (setf (documentation 'gamma-quant
'function
)
150 Returns the P-th quantile of the Gamma(ALPHA, 1) distribution. Vectorized.")
152 (setf (documentation 'chisq-quant
'function
)
154 Returns the P-th quantile of the Chi-Square(DF) distribution. Vectorized.")
156 (setf (documentation 't-quant
'function
)
158 Returns the P-th quantile of the T(DF) distribution. Vectorized.")
160 (setf (documentation 'f-quant
'function
)
162 Returns the P-th quantile of the F(NDF, DDF) distribution. Vectorized.")
164 (setf (documentation 'normal-dens
'function
)
166 Returns the density at X of the standard normal distribution. Vectorized.")
168 (setf (documentation 'cauchy-dens
'function
)
170 Returns the density at X of the standard Cauchy distribution. Vectorized.")
172 (setf (documentation 'beta-dens
'function
)
173 "Args: (x alpha beta)
174 Returns the density at X of the Beta(ALPHA, BETA) distribution. Vectorized.")
176 (setf (documentation 'gamma-dens
'function
)
178 Returns the density at X of the Gamma(ALPHA, 1) distribution. Vectorized.")
180 (setf (documentation 'chisq-dens
'function
)
182 Returns the density at X of the Chi-Square(DF) distribution. Vectorized.")
184 (setf (documentation 't-dens
'function
)
186 Returns the density at X of the T(DF) distribution. Vectorized.")
188 (setf (documentation 'f-dens
'function
)
190 Returns the density at X of the F(NDF, DDF) distribution. Vectorized.")
192 (setf (documentation 'uniform-rand
'function
)
194 Returns a list of N uniform random variables from the range (0, 1).
197 (setf (documentation 'normal-rand
'function
)
199 Returns a list of N standard normal random numbers. Vectorized.")
201 (setf (documentation 'cauchy-rand
'function
)
203 Returns a list of N standard Cauchy random numbers. Vectorized.")
205 (setf (documentation 't-rand
'function
)
207 Returns a list of N T(DF) random variables. Vectorized.")
209 (setf (documentation 'f-rand
'function
)
211 Returns a list of N F(NDF, DDF) random variables. Vectorized.")
213 (setf (documentation 'gamma-rand
'function
)
215 Returns a list of N Gamma(A, 1) random variables. Vectorized.")
217 (setf (documentation 'chisq-rand
'function
)
219 Returns a list of N Chi-Square(DF) random variables. Vectorized.")
221 (setf (documentation 'beta-rand
'function
)
223 Returns a list of N beta(A, B) random variables. Vectorized.")
225 (setf (documentation 'binomial-cdf
'function
)
227 Returns value of the Binomial(N, P) distribution function at X. Vectorized.")
229 (setf (documentation 'poisson-cdf
'function
)
231 Returns value of the Poisson(MU) distribution function at X. Vectorized.")
233 (setf (documentation 'binomial-pmf
'function
)
235 Returns value of the Binomial(N, P) pmf function at integer K. Vectorized.")
237 (setf (documentation 'poisson-pmf
'function
)
239 Returns value of the Poisson(MU) pmf function at integer K. Vectorized.")
241 (setf (documentation 'binomial-quant
'function
)
243 Returns x-th quantile (left continuous inverse) of Binomial(N, P) cdf.
246 (setf (documentation 'poisson-quant
'function
)
248 Returns x-th quantile (left continuous inverse) of Poisson(MU) cdf.
251 (setf (documentation 'binomial-rand
'function
)
253 Returns list of K draws from the Binomial(N, P) distribution. Vectorized.")
255 (setf (documentation 'poisson-rand
'function
)
257 Returns list of K draws from the Poisson(MU) distribution. Vectorized.")