Random Number Distributions
This chapter describes the functions for generating random variates and computing their probability distributions provided by the PLT Scheme Science Collection.
The functions described in this chapter are defined in the random-distributions sub-collection of the science collection. All of the modules in the random-distributions sub-collection can be made available using the form:
(require (planet "random-distributions.ss" ("williams" "science.plt")))
The random distribution graphics are provided as separate modules. To include the random distribution graphics routines, use the following form:
(require (planet "random-distributions-with-graphics.ss" ("williams" "science.plt")))
The individual modules in the random-distributions sub-collection can also be made available as described in the sections below.
7.1 The Beta Distribution
The beta distribution functions are defined in the beta.ss file in the random-distributions sub-collection of the science-collection and are made available using the form:
(require (planet "beta.ss" ("williams" "science.plt") "random-distributions"))
7.1.1 Random Variates from the Beta Distribution
Function:
(random-beta s a b) (random-beta a b) |
Contract: (case-> (-> random-source? real? real? (real-in 0.0 1.0)) (-> real? real? (real-in 0.0 1.0))) |
|
Example: Histogram of random variates from the beta distribution with parameters 2.0 and 3.0.
(require (planet "beta.ss" ("williams" "science.plt") "random-distributions")) (require (planet "histogram-with-graphics.ss" ("williams" "science.plt"))) (let ((h (make-histogram-with-ranges-uniform 40 0.0 1.0))) (do ((i 0 (+ i 1))) ((= i 10000) (void)) (histogram-increment! h (random-beta 2.0 3.0))) (histogram-plot h "Histogram of Beta Distribution"))
Figure 20 shows the resulting histogram.
|
7.1.2 Beta Distribution Density Functions
Function:
(beta-pdf x a b) |
Contract: (-> real? real? real? (>=/c 0.0)) |
|
Function:
(beta-cdf x a b) |
Contract: (-> real? real? real? (real-in 0.0 1.0)) |
|
7.1.3 Beta Distribution Graphics
The beta distribution graphics functions are defined in the file beta-graphics.ss in the random-distributions sub-collection of the science collection and are made available using the form:
(require (planet "beta-graphics.ss" ("williams" "science.plt") "random-distributions"))
Function:
(beta-plot a b) |
Contract: (-> real? real? any) |
|
Example: Plot of probability density and cummulative density of the beta distribution with parameters 2.0 and 3.0.
(require (planet "beta-graphics.ss" ("williams" "science.plt") "random-distributions")) (beta-plot 2.0 3.0)
Figure 21 shows the resulting plot.
|
7.2 The Bivariate Gaussian Distribution
The bivariate Gaussian distribution functions are defined in the bivariate-gaussian.ss file in the random-distributions sub-collection of the science-collection and are made available using the form:
(require (planet "bivatiate-gaussian.ss" ("williams" "science.plt") "random-distributions"))
7.2.1 Random Variates from the Bivariate Gaussian Distribution
Function:
(random-bivariate-gaussian s sigma-x sigma-y rho) (random-bivariate-gaussian sigma-x sigma-y rho) |
Contract: (case-> (-> random-source? (>=/c 0.0) (>=/c 0.0) (real-in -1.0 1.0) (values real? real?)) (-> (>=/c 0.0) (>=/c 0.0) (real-in -1.0 1.0) (values real? real?)) |
|
Example: Histogram of random variates from the bivariate Gaussian distribution standard deviations 1.0 and 1.0 in the x and y directions and correlation coefficient 0.0.
(require (planet "bivariate-gaussian.ss" ("williams" "science.plt") "random-distributions")) (require (planet "histogram-2d-with-graphics.ss" ("williams" "science.plt"))) (let ((h (make-histogram-2d-with-ranges-uniform 20 20 -3.0 3.0 -3.0 3.0))) (do ((i 0 (+ i 1))) ((= i 10000) (void)) (let-values (((x y) (random-bivariate-gaussian 1.0 1.0 0.0))) (histogram-2d-increment! h x y))) (histogram-2d-plot h "Histogram of Bivariate Gaussian Distribution"))
Figure 22 shows the resulting 2D histogram.
|
7.2.2 Bivariate Gaussian Distribution Density Functions
Function:
(bivariate-gaussian-pdf x y sigma-x sigma-y rho) |
Contract: (-> real? real? (>=/c 0.0 (>=/c 0.0) (real-in -1.0 0.0) real?) |
|
7.2.3 Bivariate Gaussian Distribution Graphics
The bivariate Gaussian distribution graphics functions are defined in the file bivariate- gaussian-graphics.ss in the random-distributions sub-collection of the science collection and are made available using the form:
(require (planet "bivariate-gaussian-graphics.ss" ("williams" "science.plt") "random-distributions"))
Function:
(bivariate-gaussian-plot sigma-x sigma-y rho) |
Contract: (-> (>=/c 0.0) (>=/c 0.0) (real-in -1.0 1.0) any) |
|
Example: Plot of probability density of the bivariate Gaussian distribution with standard deviations 1.0 and 1.0 in the x and y directions and correlation coefficient 0.0.
(require (planet "bivariate-gaussian-graphics.ss" ("williams" "science.plt") "random-distributions")) (bivariate-gaussian-plot 1.0 1.0 0.0)
Figure 23 shows the resulting plot.
|
7.3 The Chi-Squared Distribution
The chi-squared distribution functions are defined in the chi-squared.ss file in the random-distributions sub-collection of the science-collection and are made available using the form:
(require (planet "chi-squared.ss" ("williams" "science.plt") "random-distributions"))
7.3.1 Random Variates from the Chi-Squared Distribution
Function:
(random-chi-squared s nu) (random-chi-squared nu) |
Contract: (case-> (-> random-source? real? (>=/c 0.0)) (-> real? (>=/c 0.0))) |
|
Example: Histogram of random variates from the chi squared distribution with 3.0 degrees of freedom.
(require (planet "chi-squared.ss" ("williams" "science.plt") "random-distributions")) (require (planet "histogram-with-graphics.ss" ("williams" "science.plt"))) (let ((h (make-histogram-with-ranges-uniform 40 0.0 10.0))) (do ((i 0 (+ i 1))) ((= i 10000) (void)) (histogram-increment! h (random-chi-squared 3.0))) (histogram-plot h "Histogram of Chi Squared Distribution"))
Figure 24 shows the resulting histogram.
|
7.3.2 Chi-Squared Distribution Density Functions
Function:
(chi-squared-pdf x nu) |
Contract: (-> real? real? (>=/c 0.0)) |
|
Function:
(chi-squared-cdf x nu) |
Contract: (-> real? real? (real-in 0.0 1.0)) |
|
7.3.3 Chi-Squared Distribution Graphics
The chi squared distribution graphics functions are defined in the file chi-squared-graphics.ss in the random-distributions sub-collection of the science collection and are made available using the form:
(require (planet "chi-squared-graphics.ss" ("williams" "science.plt") "random-distributions"))
Function:
(chi-squared-plot nu) |
Contract: (-> real? any) |
|
Example: Plot of probability density and cummulative density of the chi squared distribution with 3.0 degrees of freedom.
(require (planet "chi-squared-graphics.ss" ("williams" "science.plt") "random-distributions")) (chi-squared-plot 3.0)
Figure 25 shows the resulting plot.
|
7.4 The Exponential Distribution
The exponential distribution functions are defined in the exponential.ss file in the random-distributions sub-collection of the science-collection and are made available using the form:
(require (planet "exponential.ss" ("williams" "science.plt") "random-distributions"))
7.4.1 Random Variates from the Exponential Distribution
Function:
(random-exponential s mu) (random-exponential mu) |
Contract: (case-> (-> random-source? (>/c 0.0) (>=/c 0.0)) (-> (>/c 0.0) (>=/c 0.0))) |
|
Example: Histogram of random variates from the exponential distribution with mean 1.0.
(require (planet "exponential.ss" ("williams" "science.plt") "random-distributions")) (require (planet "histogram-with-graphics.ss" ("williams" "science.plt"))) (let ((h (make-histogram-with-ranges-uniform 40 0.0 8.0))) (do ((i 0 (+ i 1))) ((= i 10000) (void)) (histogram-increment! h (random-exponential 1.0))) (histogram-plot h "Histogram of Exponential Distribution"))
Figure 26 shows the resulting histogram.
|
7.4.2 Exponential Distribution Density Functions
Function:
(exponential-pdf x mu) |
Contract: (-> real? real? (>=/c 0.0)) |
|
Function:
(exponential-cdf x mu) |
Contract: (-> real? real? (real-in 0.0 1.0)) |
|
7.4.3 Exponential Distribution Graphics
The exponential distribution graphics functions are defined in the file exponential-graphics.ss in the random-distributions sub-collection of the science collection and are made available using the form:
(require (planet "exponential-graphics.ss" ("williams" "science.plt") "random-distributions"))
Function:
(exponential-plot mu) |
Contract: (-> (>=/c 0.0) any) |
|
Example: Plot of probability density and cummulative density of the exponential distribution with mean 3.0.
(require (planet "exponential-graphics.ss" ("williams" "science.plt") "random-distributions")) (exponential-plot 3.0)
Figure 27 shows the resulting plot.
|
7.5 The F-Distribution
The F-distribution functions are defined in the f-distribution.ss file in the random-distributions sub-collection of the science-collection and are made available using the form:
(require (planet "f-distribution.ss" ("williams" "science.plt") "random-distributions"))
7.5.1 Random Variates from the F-Distribution
Function:
(random-f-distribution s nu1 nu2) (random-f-distribution nu1 nu2) |
Contract: (case-> (-> random-source? real? real? (>=/c 0.0)) (-> real? real? (>=/c 0.0))) |
|
Example: Histogram of random variates from the F-distribution with 2.0 and 3.0 degrees of freedom.
(require (planet "f-distribution.ss" ("williams" "science.plt") "random-distributions")) (require (planet "histogram-with-graphics.ss" ("williams" "science.plt"))) (let ((h (make-histogram-with-ranges-uniform 40 0.0 10.0))) (do ((i 0 (+ i 1))) ((= i 10000) (void)) (histogram-increment! h (random-f-distribution 2.0 3.0))) (histogram-plot h "Histogram of F-Distribution"))
Figure 28 shows the resulting histogram.
|
7.5.2 F-Distribution Density Functions
Function:
(f-distribution-pdf x nu1 nu2) |
Contract: (-> real? real? real? (>=/c 0.0)) |
|
Function:
(f-distribution-pdf x nu1 nu2) |
Contract: (-> real? real? real? (real-in 0.0 1.0)) |
|
7.5.3 F-Distribution Graphics
The exponential distribution graphics functions are defined in the file f-distribution-graphics.ss in the random-distributions sub-collection of the science collection and are made available using the form:
(require (planet "f-distribution-graphics.ss" ("williams" "science.plt") "random-distributions"))
Function:
(f-distribution-plot nu1 nu2) |
Contract: (-> (>=/c 0.0) any) |
|
Example: Plot of probability density of the F-distribution distribution with 2.0 and 3.0 degrees of freedom.
(require (planet "f-distribution-graphics.ss" ("williams" "science.plt" 2 0) "random-distributions")) (f-distribution-plot 2.0 3.0)
Figure 29 shows the resulting plot.
|
7.6 The Flat (Uniform) Distribution
The flat (uniform) distribution functions are defined in the flat.ss file in the random-distributions sub-collection of the science-collection and are made available using the form:
(require (planet "flat.ss" ("williams" "science.plt") "random-distributions"))
7.6.1 Random Variates from the Flat Distribution
Function:
(random-flat s a b) (random-flat a b) |
Contract: (case-> (->r ((s random-source?) (a real?) (b (>/c a)) real?) (->r ((a real?) (b (>/c a)) real?)) |
|
Example: Histogram of random variates from the flat (uniform) distribution from 1.0 to 4.0.
(require (planet "flat.ss" ("williams" "science.plt") "random-distributions")) (require (planet "histogram-with-graphics.ss" ("williams" "science.plt"))) (let ((h (make-histogram-with-ranges-uniform 40 1.0 4.0))) (do ((i 0 (+ i 1))) ((= i 10000) (void)) (histogram-increment! h (random-flat 1.0 4.0))) (histogram-plot h "Histogram of Flat (Uniform) Distribution"))
Figure 30 shows the resulting histogram.
|
7.6.2 Flat Distribution Density Functions
Function:
(flat-pdf x a b) |
Contract: (->r ((x real?) (a real?) (b (>/c a))) (>=/c 0.0)) |
|
Function:
(flat-cdf x a b) |
Contract: (->r ((x real?) (a real?) (b (>/c a))) (real-in 0.0 1.0)) |
|
7.6.3 Flat Distribution Graphics
The flat (uniform) distribution graphics functions are defined in the file flat-graphics-.ss in the random-distributions sub-collection of the science collection and are made available using the form:
(require (planet "flat-graphics.ss" ("williams" "science.plt") "random-distributions"))
Function:
(flat-plot a b) |
Contract: (->r ((a real?) (b (>/c a))) any) |
|
Example: Plot of probability density and cumulative density of the flat (uniform) distribution from 1.0 to 4.0.
(require (planet "flat-graphics.ss" ("williams" "science.plt") "random-distributions")) (flat-plot 1.0 4.0)
Figure 31 shows the resulting plot.
|
7.7 The Gamma Distribution
The gamma distribution functions are defined in the gamma.ss file in the random-distributions sub-collection of the science-collection and are made available using the form:
(require (planet "gamma.ss" ("williams" "science.plt") "random-distributions"))
7.7.1 Random Variates from the Gamma Distribution
Function:
(random-gamma s a b)(random-gamma a b) |
Contract: (case-> (-> random-source? (>/c 0.0) real? (>=/c 0.0)) (-> (>/c 0.0 real? (>=/c 0.0))) |
|
Example: Histogram of random variates from the gamma distribution with parameters 3.0 and 3.0.
(require (planet "gamma.ss" ("williams" "science.plt") "random-distributions")) (require (planet "histogram-with-graphics.ss" ("williams" "science.plt"))) (let ((h (make-histogram-with-ranges-uniform 40 0.0 24.0))) (do ((i 0 (+ i 1))) ((= i 10000) (void)) (histogram-increment! h (random-gamma 3.0 3.0))) (histogram-plot h "Histogram of Gamma Distribution"))
Figure 32 shows the resulting histogram.
|
7.7.2 Gamma Distribution Density Functions
Function:
(gamma-pdf x a b) |
Contract: (-> real? (>/c 0.0) real? (>=/c 0.0)) |
|
Function:
(gamma-cdf x a b) |
Contract: (-> real? (>/c 0.0) real? (real-in 0.0 1.0)) |
|
7.7.3 Gamma Distribution Graphics
The gamma distribution graphics functions are defined in the file gamma-graphics.ss in the random-distributions sub-collection of the science collection and are made available using the form:
(require (planet "gamma-graphics.ss" ("williams" "science.plt") "random-distributions"))
Function:
(gamma-plot a b) |
Contract: (-> (>/c 0.0) real?) |
|
Example: Plot of probability density and cummulative density of the gamma distribution with parameters 3.0 and 3.0.
(require (planet "gamma-graphics.ss" ("williams" "science.plt") "random-distributions")) (gamma-plot 3.0 3.0)
Figure 33 shows the resulting plot.
|
7.8 The Gaussian Distribution
The Gaussian distribution functions are defined in the gaussian.ss file in the random-distributions sub-collection of the science-collection and are made available using the form:
(require (planet "gaussian.ss" ("williams" "science.plt") "random-distributions"))
7.8.1 Random Variates from the Gaussian Distribution
Function:
(random-gaussian s mu sigma) (random-gaussian mu sigma) |
Contract: (case-> (-> random-source? real? (>=/c 0.0) real?) (-> real? (>=/c 0.0) real?)) |
|
Example: Histogram of random variates from the Gaussian (normal) distribution with mean 10.0 and standard deviation 2.0.
(require (planet "gaussian.ss" ("williams" "science.plt") "random-distributions")) (require (planet "histogram-with-graphics.ss" ("williams" "science.plt"))) (let ((h (make-histogram-with-ranges-uniform 40 4.0 16.0))) (do ((i 0 (+ i 1))) ((= i 10000) (void)) (histogram-increment! h (random-gaussian 10.0 2.0))) (histogram-plot h "Histogram of Gaussian Distribution"))
Figure 34 shows the resulting histogram.
|
Function:
(random-unit-gaussian s) (random-unit-gaussian) |
Contract: (case-> (-> random-source? real?) (-> real?)) |
|
Example: Histogram of random variates from the unit Gaussian (normal) distribution.
(require (planet "gaussian.ss" ("williams" "science.plt") "random-distributions")) (require (planet "histogram-with-graphics.ss" ("williams" "science.plt"))) (let ((h (make-histogram-with-ranges-uniform 40 -3.0 3.0))) (do ((i 0 (+ i 1))) ((= i 10000) (void)) (histogram-increment! h (random-unit-gaussian))) (histogram-plot h "Histogram of Unit Gaussian Distribution"))
Figure 35 shows the resulting histogram.
|
Function:
(random-gaussian-ratio-method s mu sigma) (random-gaussian-ratio-method mu sigma) |
Contract: (case-> (-> random-source? real? (>=/c 0.0) real?) (-> real? (>=/c 0.0) real?)) |
|
random-unit-gaussian-ratio-method
Function:
(random-unit-gaussian-ratio-method s) (random-unit-gaussian-ratio-method) |
Contract: (case-> (-> random-source? real?) (-> real?)) |
|
7.8.2 Gaussian Distribution Density Functions
Function:
(gaussian-pdf x mu sigma) |
Contract: (-> real? real? (>/c 0.0) (>=/c 0.0)) |
|
Function:
(gaussian-cdf x mu sigma) |
Contract: (-> real? real? (>/c 0.0) (real-in 0.0 1.0)) |
|
Function:
(unit-gaussian-pdf x) |
Contract: (-> real? (>=/c 0.0)) |
|
Function:
(unit-gaussian-cdf x) |
Contract: (-> real? (real-in 0.0 1.0)) |
|
7.8.3 Gaussian Distribution Graphics
The Gaussian distribution graphics functions are defined in the file gaussian-graphics-.ss in the random-distributions sub-collection of the science collection and are made available using the form:
(require (planet "gaussian-graphics.ss" ("williams" "science.plt") "random-distributions"))
Function:
(gaussian-plot mu sigma) |
Contract: (-> real? (>/c 0.0) any) |
|
Example: Plot of probability density and cumulative density of the Gaussian (normal) distribution with mean 10.0 and standard deviation 2.0.
(require (planet "gaussian-graphics.ss" ("williams" "science.plt") "random-distributions")) (gaussian-plot 10.0 2.0)
Figure 36 shows the resulting plot.
|
Function:
(unit-gaussian-plot) |
Contract: (-> any) |
|
Example: Plot of probability density and cumulative density of the Gaussian (normal) distribution with mean 0.0 and standard deviation 1.0.
(require (planet "gaussian-graphics.ss" ("williams" "science.plt") "random-distributions")) (unit-gaussian-plot)
Figure 37 shows the resulting plot.
|
7.9 The Gaussian Tail Distribution
The Gaussian tail distribution functions are defined in the gaussian-tail.ss file in the random-distributions sub-collection of the science-collection and are made available using the form:
(require (planet "gaussian-tail.ss" ("williams" "science.plt") "random-distributions"))
7.9.1 Random Variates from the Gaussian Tail Distribution
Function:
(random-gaussian-tail s a mu sigma) (random-gaussian-tail a mu sigma |
Contract: (case-> (-> random-source? real? real? (>/c 0.0) real?) (-> real? real? (>/c 0.0) real?)) |
|
Function:
(random-unit-gaussian-tail s a) (random-unit-gaussian-tail a |
Contract: (case-> (-> random-source? (>/c 0.0) (>/c 0.0)) (-> (>/c 0.0))) |
|
Example: Histogram of random variates from the upper tail greater than 16.0 of the Gaussian distribution with mean 10.0 and standard deviation 2.0.
(require (planet "gaussian-tail.ss" ("williams" "science.plt") "random-distributions")) (require (planet "histogram-with-graphics.ss" ("williams" "science.plt"))) (let ((h (make-histogram-with-ranges-uniform 40 16.0 22.0))) (do ((i 0 (+ i 1))) ((= i 10000) (void)) (histogram-increment! h (random-gaussian-tail 16.0 10.0 2.0))) (histogram-plot h "Histogram of Gaussian Tail Distribution"))
Figure 38 shows the resulting histogram.
|
Example: Histogram of random variates from the upper tail greater than 3.0 of the unit Gaussian distribution.
(require (planet "gaussian-tail.ss" ("williams" "science.plt") "random-distributions")) (require (planet "histogram-with-graphics.ss" ("williams" "science.plt"))) (let ((h (make-histogram-with-ranges-uniform 40 3.0 6.0))) (do ((i 0 (+ i 1))) ((= i 10000) (void)) (histogram-increment! h (random-unit-gaussian-tail 3.0))) (histogram-plot h "Histogram of Unit Gaussian Tail Distribution"))
Figure 39 shows the resulting histogram.
|
7.9.2 Gaussian Tail Distribution Density Functions
Function:
(gaussian-tail-pdf x a mu sigma) |
Contract: (-> real? real? real? (>/c 0.0) (>=/c 0.0)) |
|
Function:
(unit-gaussian-tail-pdf x a) |
Contract: (-> real? (>=/c 0.0) (>=/c 0.0)) |
|
7.9.3 Gaussian Tail Distribution Graphics
The Gaussian tail distribution graphics functions are defined in the file gaussian- tail-graphics.ss in the random-distributions sub-collection of the science collection and are made available using the form:
(require (planet "gaussian-tail-graphics.ss" ("williams" "science.plt") "random-distributions"))
Function:
(gaussian-tail-plot a mu sigma) |
Contract: (-> real? real? (>/c 0.0) any) |
|
Example: Plot of probability density and cumulative density of the upper tail greater than 16.0 of the Gaussian distribution with mean 10.0 and standard deviation 2.0.
(require (planet "gaussian-tail-graphics.ss" ("williams" "science.plt" 2 0) "random-distributions")) (gaussian-tail-plot 16.0 10.0 2.0)
Figure 40 shows the resulting plot.
|
Function:
(unit-gaussian-tail-plot a) |
Contract: (-> (>=/c 0.0) any) |
|
Example: Plot of probability density and cumulative density of the upper tail greater than 3.0 of the Gaussian distribution with mean 0.0 and standard deviation 1.0.
(require (planet "gaussian-tail-graphics.ss" ("williams" "science.plt") "random-distributions")) (unit-gaussian-tail-plot 3.0)
Figure 41 shows the resulting plot.
|
7.10 The Log Normal Distribution
The log normal distribution functions are defined in the lognormal.ss file in the random-distributions sub-collection of the science-collection and are made available using the form:
(require (planet "lognormal.ss" ("williams" "science.plt") "random-distributions"))
7.10.1 Random Variates from the Log Normal Distribution
Function:
(random-lognormal s mu sigma) (random-lognormal mu sigma) |
Contract: (case-> (-> random-source? real? (>=/c 0.0) real?) (-> real? real?)) |
|
Example: Histogram of random variates from the log normal distribution with mean 0.0 and standard deviation 1.0.
(require (planet "lognormal.ss" ("williams" "science.plt") "random-distributions")) (require (planet "histogram-with-graphics.ss" ("williams" "science.plt"))) (let ((h (make-histogram-with-ranges-uniform 40 0.0 6.0))) (do ((i 0 (+ i 1))) ((= i 10000) (void)) (histogram-increment! h (random-lognormal 0.0 1.0))) (histogram-plot h "Histogram of Log Normal Distribution"))
Figure 42 shows the resulting histogram.
|
7.10.2 Log Normal Distribution Density Functions
Function:
(lognormal-pdf x mu sigma) |
Contract: (-> real? real? (>/c 0.0) (>=/c 0.0)) |
|
Function:
(lognormal-cdf x mu sigma) |
Contract: (-> real? real? (>/c 0.0) (real-in 0.0 1.0)) |
|
7.10.3 Log Normal Distribution Graphics
The log normal distribution graphics functions are defined in the file lognormal-graphics.ss in the random-distributions sub-collection of the science collection and are made available using the form:
(require (planet "lognormal-graphics.ss" ("williams" "science.plt") "random-distributions"))
Function:
(lognormal-plot mu sigma) |
Contract: (-> real? (>/c 0.0) any) |
|
Example: Plot of probability density and cumulative density of the log normal distribution with mean 0.0 and standard deviation 1.0.
(require (planet "lognormal-graphics.ss" ("williams" "science.plt") "random-distributions")) (lognormal-plot 0.0 1.0)
Figure 43 shows the resulting plot.
|
7.11 The Pareto Distribution
The Pareto distribution functions are defined in the pareto.ss file in the random-distributions sub-collection of the science-collection and are made available using the form:
(require (planet "pareto.ss" ("williams" "science.plt") "random-distributions"))
7.11.1 Random Variates from the Pareto Distribution
Function:
(random-pareto s a b) (random-pareto a b) |
Contract: (case-> (-> random-source? real? real? real?) (-> real? real? real?)) |
|
Example: Histogram of random variates from the Pareto distribution with parameters 1.0 and 1.0.
(require (planet "pareto.ss" ("williams" "science.plt") "random-distributions")) (require (planet "histogram-with-graphics.ss" ("williams" "science.plt"))) (let ((h (make-histogram-with-ranges-uniform 40 1.0 21.0))) (do ((i 0 (+ i 1))) ((= i 10000) (void)) (histogram-increment! h (random-pareto 1.0 1.0))) (histogram-plot h "Histogram of Pareto Distribution"))
Figure 44 shows the resulting histogram.
|
7.11.2 Pareto Distribution Density Functions
Function:
(pareto-pdf x a b) |
Contract: (-> real? real? real? (>=/c 0.0)) |
|
Function:
(pareto-cdf x a b) |
Contract: (-> real? real? real? (real-in 0.0 1.0)) |
|
7.11.3 Pareto Distribution Graphics
The Pareto distribution graphics functions are defined in the file pareto-graphics.ss in the random-distributions sub-collection of the science collection and are made available using the form:
(require (planet "pareto-graphics.ss" ("williams" "science.plt") "random-distributions"))
Function:
(pareto-plot a b) |
Contract: (-> real? real? any) |
|
Example: Plot of probability density and cumulative density of the Pareto distribution with parameters 1.0 and 1.0.
(require (planet "pareto-graphics.ss" ("williams" "science.plt") "random-distributions")) (pareto-plot 1.0 1.0)
Figure 45 shows the resulting plot.
|
7.12 The T-Distribution
The t-distribution functions are defined in the t-distribution.ss file in the random-distributions sub-collection of the science-collection and are made available using the form:
(require (planet "t-distribution.ss" ("williams" "science.plt") "random-distributions"))
7.12.1 Random Variates from the T-Distribution
Function:
(random-t-distribution s nu) (random-t-distribution nu) |
Contract: (case-> (-> random-source? real? real?)+ (-> real? real?)) |
|
Example: Histogram of random variates from the t-distribution with 1.0 degrees of freedom.
(require (planet "t-distribution.ss" ("williams" "science.plt") "random-distributions")) (require (planet "histogram-with-graphics.ss" ("williams" "science.plt"))) (let ((h (make-histogram-with-ranges-uniform 40 -6.0 6.0))) (do ((i 0 (+ i 1))) ((= i 10000) (void)) (histogram-increment! h (random-t-distribution 1.0))) (histogram-plot h "Histogram of t-Distribution"))
Figure 46 shows the resulting histogram.
|
7.12.2 T-Distribution Density Functions
Function:
(t-distribution-pdf x nu) |
Contract: (-> real? real? (>=/c 0.0)) |
|
Function:
(t-distribution-cdf x nu) |
Contract: (-> real? real? (real-in 0.0 1.0)) |
|
7.12.3 T-Distribution Graphics
The t-distribution graphics functions are defined in the file t-distribution-graphics .ss in the random-distributions sub-collection of the science collection and are made available using the form:
(require (planet "t-distribution-graphics.ss" ("williams" "science.plt") "random-distributions"))
Function:
(t-distribution-plot nu) |
Contract: (-> real? any) |
|
Example: Plot of probability density and cummulative density of the t-distribution with 1.0 degrees of freedom.
(require (planet "t-distribution-graphics.ss" ("williams" "science.plt") "random-distributions")) (t-distribution-plot 1.0)
Figure 47 shows the resulting plot.
|
7.13 The Triangular Distribution
The triangular distribution functions are defined in the triangular.ss file in the random-distributions sub-collection of the science-collection and are made available using the form:
(require (planet "triangular.ss" ("williams" "science.plt") "random-distributions"))
7.13.1 Random Variates from the Triangular Distribution
Function:
(random-triangular s a b c) (random-triangular a b c) |
Contract: (case-> (->r ((s random-source?) (a real?) (b (>/c a)) (c (real-in a b))) real?) (->r ((a real?) (b (>/c a)) (c (real-in a b))) real?)) |
|
Example: Histogram of random variates from the triangular distribution with minimum value 1.0, maximum value 4.0, and most likely value 2.0.
(require (planet "triangular.ss" ("williams" "science.plt") "random-distributions")) (require (planet "histogram-with-graphics.ss" ("williams" "science.plt"))) (let ((h (make-histogram-with-ranges-uniform 40 1.0 4.0))) (do ((i 0 (+ i 1))) ((= i 10000) (void)) (histogram-increment! h (random-triangular 1.0 4.0 2.0))) (histogram-plot h "Histogram of Triangular Distribution"))
Figure 48 shows the resulting histogram.
|
7.13.2 Triangular Distribution Density Functions
Function:
(triangular-pdf x a b c) |
Contract: (->r ((x real?) (a real?) (b (>/c a)) (c (real-in a b))) (>=/c 0.0)) |
|
Function:
(triangular-cdf x a b c) |
Contract: (->r ((x real?) (a real?) (b (>/c a)) (c (real-in a b))) (real-in 0.0 1.0)) |
|
7.13.3 Triangular Distribution Graphics
The triangular distribution graphics functions are defined in the file triangular-graphics.ss in the random-distributions sub-collection of the science collection and are made available using the form:
(require (planet "triangular-graphics.ss" ("williams" "science.plt") "random-distributions"))
Function:
(triangular-plot a b c) |
Contract: (->r ((a real?) (b (>/c a)) (c (real-in a b))) any) |
|
Example: Plot of probability density of the triangular distribution with minimum value 1.0, maximum value 4.0, and most likely value 2.0.
(require (planet "triangular-graphics.ss" ("williams" "science.plt") "random-distributions")) (triangular-plot 1.0 4.0 2.0)
Figure 49 shows the resulting plot.
|
7.14 The Bernoulli Distribution
The Bernoulli distribution functions are defined in the bernoulli.ss file in the random-distributions sub-collection of the science-collection and are made available using the form:
(require (planet "bernoulli.ss" ("williams" "science.plt") "random-distributions"))
7.14.1 Random Variates from the Bernoulli Distribution
Function:
(random-bernoulli s p) (random-bernoulli p) |
Contract: (case-> (-> random-source? (real-in 0.0 1.0) (integer-in 0 1)) (-> (real-in 0.0 1.0) (integer-in 0 1))) |
|
Example: Histogram of random variates from the Bernoulli distribution with probability 0.6.
(require (planet "bernoulli.ss" ("williams" "science.plt") "random-distributions")) (require (planet "discrete-histogram-with-graphics.ss" ("williams" "science.plt"))) (let ((h (make-discrete-histogram))) (do ((i 0 (+ i 1))) ((= i 10000) (void)) (discrete-histogram-increment! h (random-bernoulli 0.6))) (discrete-histogram-plot h "Histogram of Bernoulli Distribution"))
Figure 50 shows the resulting histogram.
|
7.14.2 Bernoulli Distribution Density Functions
Function:
(bernoulli-pdf k p) |
Contract: (-> integer? (real-in 0.0 1.0) (>=/c 0.0)) |
|
Function:
(bernoulli-cdf k p) |
Contract: (-> integer? (real-in 0.0 1.0) (real-in 0.0 1.0)) |
|
7.14.3 Bernoulli Distribution Graphics
The Bernoulli distribution graphics functions are defined in the file bernoulli-graphics.ss in the random-distributions sub-collection of the science collection and are made available using the form:
(require (planet "bernoulli-graphics.ss" ("williams" "science.plt") "random-distributions"))
Function:
(bernoulli-plot p) |
Contract: (-> (real-in 0.0 1.0) any) |
|
Example: Plot of probability density of the Berboulli distribution with probability 0.6.
(require (planet "bernoulli-graphics.ss" ("williams" "science.plt") "random-distributions")) (bernoulli-plot 0.6)
Figure 51 shows the resulting plot.
|
7.15 The Binomial Distribution
The binomial distribution functions are defined in the binomial.ss file in the random-distributions sub-collection of the science-collection and are made available using the form:
(require (planet "binomial.ss" ("williams" "science.plt") "random-distributions"))
7.15.1 Random Variates from the Binomial Distribution
Function:
(random-binomial s p n) (random-binomial p n) |
Contract: (case-> (-> random-source? (real-in 0.0 1.0) natural-number? natural-number?) (-> (real-in 0.0 1.0) natural-number? natural-number?)) |
|
Example: Histogram of random variates from the binomial distribution with parameters 0.5 and 20.
(require (planet "binomial.ss" ("williams" "science.plt") "random-distributions")) (require (planet "discrete-histogram-with-graphics.ss" ("williams" "science.plt"))) (let ((h (make-discrete-histogram))) (do ((i 0 (+ i 1))) ((= i 10000) (void)) (discrete-histogram-increment! h (random-binomial 0.5 20))) (discrete-histogram-plot h "Histogram of Binomial Distribution"))
Figure 52 shows the resulting histogram.
|
7.15.2 Binomial Distribution Density Functions
Function:
((binomial-pdf k p n) |
Contract: (-> integer? (real-in 0.0 1.0) natural-number? (>=/c 0.0)) |
|
7.15.3 Binomial Distribution Graphics
The binomial distribution graphics functions are defined in the file binomial-graphics-.ss in the random-distributions sub-collection of the science collection and are made available using the form:
(require (planet "binomial-graphics.ss" ("williams" "science.plt") "random-distributions"))
Function:
(binomial-plot p n) |
Contract: (-> (real-in 0.0 1.0) natural-number? any) |
|
Example: Plot of probability density of the binomial distribution with parameters 0.5 and 20.
(require (planet "binomial-graphics.ss" ("williams" "science.plt") "random-distributions")) (binomial-plot 0.5 20)
Figure 53 shows the resulting plot.
|
7.16 The Geometric Distribution
The geometric distribution functions are defined in the geometric.ss file in the random-distributions sub-collection of the science-collection and are made available using the form:
(require (planet "geometric.ss" ("williams" "science.plt") "random-distributions"))
7.16.1 Random Variates from the Geometric Distribution
Function:
(random-geometric s p) (random-geometric p) |
Contract: (case-> (-> random-source? (real-in 0.0 1.0) natural-number?) (-> (real-in 0.0 1.0) natural-number?)) |
|
Example: Histogram of random variates from the geometric distribution with probability 0.5.
(require (planet "geometric.ss" ("williams" "science.plt") "random-distributions")) (require (planet "discrete-histogram-with-graphics.ss" ("williams" "science.plt"))) (let ((h (make-discrete-histogram))) (do ((i 0 (+ i 1))) ((= i 10000) (void)) (discrete-histogram-increment! h (random-geometric 0.5))) (discrete-histogram-plot h "Histogram of Geometric Distribution"))
Figure 54 shows the resulting histogram.
|
7.16.2 Geometric Distribution Density Functions
Function:
(geometric-pdf k p) |
Contract: (-> integer? (real-in 0.0 1.0) (>=/c 0.0)) |
|
7.16.3 Geometric Distribution Graphics
The geometric distribution graphics functions are defined in the file geometric-graphics.ss in the random-distributions sub-collection of the science collection and are made available using the form:
(require (planet "geometric-graphics.ss" ("williams" "science.plt") "random-distributions"))
Function:
(geometric-plot p) |
Contract: (-> (real-in 0.0 1.0) any) |
|
Example: Plot of probability density of the geometric distribution with probability 0.5.
(require (planet "geometric-graphics.ss" ("williams" "science.plt") "random-distributions")) (binomial-plot 0.5)
Figure 55 shows the resulting plot.
|
7.17 The Logarithmic Distribution
The logarithmic distribution functions are defined in the logarithmic.ss file in the random-distributions sub-collection of the science-collection and are made available using the form:
(require (planet "logarithmic.ss" ("williams" "science.plt") "random-distributions"))
7.17.1 Random Variates from the Logarithmic Distribution
Function:
(random-logarithmic s p) (random-logarithmic p) |
Contract: (case-> (-> random-source? (real-in 0.0 1.0) natural-number?) (-> (real-in 0.0 1.0) natural-number?)) |
|
Example: Histogram of random variates from the logarithmic distribution with probability 0.5.
(require (planet "logarithmic.ss" ("williams" "science.plt") "random-distributions")) (require (planet "discrete-histogram-with-graphics.ss" ("williams" "science.plt"))) (let ((h (make-discrete-histogram))) (do ((i 0 (+ i 1))) ((= i 10000) (void)) (discrete-histogram-increment! h (random-logarithmic 0.5))) (discrete-histogram-plot h "Histogram of Logarithmic Distribution"))
Figure 56 shows the resulting histogram.
|
7.17.2 Logarithmic Distribution Density Functions
Function:
(logarithmic-pdf k p) |
Contract: (-> integer? (real-in 0.0 1.0) (>=/c 0.0)) |
|
7.17.3 Logarithmic Distribution Graphics
The logarithmic distribution graphics functions are defined in the file logarithmic-graphics.ss in the random-distributions sub-collection of the science collection and are made available using the form:
(require (planet "logarithmic-graphics.ss" ("williams" "science.plt") "random-distributions"))
Function:
(logarithmic-plot p) |
Contract: (-> (real-in 0.0 1.0) any) |
|
Example: Plot of probability density of the logarithmic distribution with probability 0.5.
(require (planet "logarithmic-graphics.ss" ("williams" "science.plt") "random-distributions")) (logarithmic-plot 0.5)
Figure 57 shows the resulting plot.
|
7.18 The Poisson Distribution
The Poisson distribution functions are defined in the poisson.ss file in the random-distributions sub-collection of the science-collection and are made available using the form:
(require (planet "poisson.ss" ("williams" "science.plt") "random-distributions"))
7.18.1 Random Variates from the Poisson Distribution
Function:
(random-poisson s mu) (random-poisson mu) |
Contract: (case-> (-> random-source? real? natural-number?) (-> real? natural-number?)) |
|
Example: Histogram of random variates from the Poisson distribution with mean 10.0.
(require (planet "poisson.ss" ("williams" "science.plt") "random-distributions")) (require (planet "discrete-histogram-with-graphics.ss" ("williams" "science.plt"))) (let ((h (make-discrete-histogram))) (do ((i 0 (+ i 1))) ((= i 10000) (void)) (discrete-histogram-increment! h (random-poisson 10.0))) (discrete-histogram-plot h "Histogram of Poisson Distribution"))
Figure 58 shows the resulting histogram.
|
7.18.2 Poisson Distribution Density Functions
Function:
(poisson-pdf k mu) |
Contract: (-> integer? real? (>=/c 0.0)) |
|
7.18.3 Poisson Distribution Graphics
The Poisson distribution graphics functions are defined in the file poisson-graphics.ss in the random-distributions sub-collection of the science collection and are made available using the form:
(require (planet "poisson-graphics.ss" ("williams" "science.plt") "random-distributions"))
Function:
(poisson-plot mu) |
Contract: (-> (>/c 0.0) any) |
|
Example: Plot of probability density of the Poisson distribution with mean 10.0.
(require (planet "poisson-graphics.ss" ("williams" "science.plt") "random-distributions")) (poisson-plot 10.0)
Figure 59 shows the resulting plot.
|
7.19 The General Discrete Distribution
The discrete distribution functions are defined in the discrete.ss file in the random-distributions sub-collection of the science-collection and are made available using the form:
(require (planet "discrete.ss" ("williams" "science.plt") "random-distributions"))
Function:
(discrete? x) |
Contract: (-> any? boolean?) |
|
7.19.1 Creating Discrete Distributions
Function:
(make-discrete weights) |
Contract: (-> (vectorof real?) discrete?) |
|
7.19.2 Random Variates from a Discrete Distribution
Function:
(random-discrete s d) (random-discrete d) |
Contract: (case-> (-> random-source? discrete?) (-> discrete?)) |
|
Example: Histogram of random variates from a discrete distribution with weights #(.1 .4 .9 .8 .7 .6 .5 .4 .3 .2 .1).
(require (planet "discrete.ss" ("williams" "science.plt") "random-distributions")) (require (planet "discrete-histogram-with-graphics.ss" ("williams" "science.plt"))) (let ((h (make-discrete-histogram)) (d (make-discrete #(.1 .4 .9 .8 .7 .6 .5 .4 .3 .2 .1)))) (do ((i 0 (+ i 1))) ((= i 10000) (void)) (discrete-histogram-increment! h (random-discrete d))) (discrete-histogram-plot h "Histogram of Discrete Distribution"))
Figure 60 shows the resulting histogram.
|
7.19.3 Discrete Distribution Density Functions
Function:
(discrete-pdf d k) |
Contract: (-> discrete? integer? (real-in 0.0 1.0)) |
|
Function:
(discrete-cdf d k) |
Contract: (-> discrete? integer? (real-in 0.0 1.0) |
|
7.19.4 General Discrete Distribution Graphics
The general discrete distribution graphics functions are defined in the file discrete-graphics.ss in the random-distributions sub-collection of the science collection and are made available using the form:
(require (planet "discrete-graphics.ss" ("williams" "science.plt") "random-distributions"))
Function:
(discrete-plot d) |
Contract: (-> discrete? any) |
|
Example: Plot of probability density of the Poisson distribution with mean 10.0.
(require (planet "discrete.ss" ("williams" "science.plt") "random-distributions")) (require (planet "discrete-graphics.ss" ("williams" "science.plt") "random-distributions")) (let ((d (make-discrete #(.1 .4 .9 .8 .7 .6 .5 .4 .3 .2 .1)))) (discrete-plot d))
Figure 61 shows the resulting plot.
|