@@ -106,10 +106,70 @@ var y = dist.cdf( 0.5 );
106106<!-- eslint no-undef: "error" -->
107107
108108``` javascript
109- var objectKeys = require ( ' @stdlib/utils/keys' );
109+ var invgammaRandomFactory = require ( ' @stdlib/random/base/invgamma' ).factory ;
110+ var filledarrayBy = require ( ' @stdlib/array/filled-by' );
111+ var variance = require ( ' @stdlib/stats/base/variance' );
112+ var linspace = require ( ' @stdlib/array/base/linspace' );
113+ var gamma = require ( ' @stdlib/stats/base/dists/gamma' );
114+ var mean = require ( ' @stdlib/stats/base/mean' );
115+ var abs = require ( ' @stdlib/math/base/special/abs' );
110116var invgamma = require ( ' @stdlib/stats/base/dists/invgamma' );
111117
112- console .log ( objectKeys ( invgamma ) );
118+ // Define the shape and scale parameters:
119+ var alpha = 5.0 ; // shape parameter (α)
120+ var beta = 1.0 ; // scale parameter (β)
121+
122+ // Generate an array of x values:
123+ var x = linspace ( 0.01 , 3.0 , 100 );
124+
125+ // Compute the PDF for each x:
126+ var invgammaPDF = invgamma .pdf .factory ( alpha, beta );
127+ var pdf = filledarrayBy ( x .length , ' float64' , invgammaPDF );
128+
129+ // Compute the CDF for each x:
130+ var invgammaCDF = invgamma .cdf .factory ( alpha, beta );
131+ var cdf = filledarrayBy ( x .length , ' float64' , invgammaCDF );
132+
133+ // Output the PDF and CDF values:
134+ console .log ( ' x values:' , x );
135+ console .log ( ' PDF values:' , pdf );
136+ console .log ( ' CDF values:' , cdf );
137+
138+ // Compute statistical properties:
139+ var theoreticalMean = invgamma .mean ( alpha, beta );
140+ var theoreticalVariance = invgamma .variance ( alpha, beta );
141+ var theoreticalSkewness = invgamma .skewness ( alpha, beta );
142+ var theoreticalKurtosis = invgamma .kurtosis ( alpha, beta );
143+
144+ console .log ( ' Theoretical Mean:' , theoreticalMean );
145+ console .log ( ' Theoretical Variance:' , theoreticalVariance );
146+ console .log ( ' Skewness:' , theoreticalSkewness );
147+ console .log ( ' Kurtosis:' , theoreticalKurtosis );
148+
149+ // Generate random samples from the inverse gamma distribution:
150+ var rinvGamma = invgammaRandomFactory ( alpha, beta );
151+ var n = 1000 ;
152+ var samples = filledarrayBy ( n, ' float64' , rinvGamma );
153+
154+ // Compute sample mean and variance:
155+ var sampleMean = mean ( n, samples, 1 );
156+ var sampleVariance = variance ( n, 1 , samples, 1 );
157+
158+ console .log ( ' Sample Mean:' , sampleMean );
159+ console .log ( ' Sample Variance:' , sampleVariance );
160+
161+ // Compare sample statistics to theoretical values:
162+ console .log ( ' Difference in Mean:' , abs ( mean - sampleMean ) );
163+ console .log ( ' Difference in Variance:' , abs ( variance - sampleVariance ) );
164+
165+ // Demonstrate the relationship between inverse gamma and gamma distributions:
166+ var y = 0.5 ;
167+ var invGammaCDF = invgamma .cdf ( y, alpha, beta );
168+ var gammaCDF = 1.0 - gamma .cdf ( 1.0 / y, alpha, 1.0 / beta );
169+
170+ console .log ( ' Inverse Gamma CDF at y =' , y, ' :' , invGammaCDF );
171+ console .log ( ' 1 - Gamma CDF at 1/y =' , 1 / y, ' :' , gammaCDF );
172+ console .log ( ' Difference:' , abs ( invGammaCDF - gammaCDF ) );
113173```
114174
115175</section >
0 commit comments