Go to the MLX, M, PDF, or HTML version of this file. Go back to fan’s MEconTools Toolbox (bookdown), Matlab Code Examples Repository (bookdown), or Math for Econ with Matlab Repository (bookdown).
Examples](https://fanwangecon.github.io/M4Econ/), or** Dynamic Asset This is the example vignette for function: ff_disc_rand_var_stats from the MEconTools Package. This function summarizes statistics of matrixes stored in a container map, as well as scalar, string, function and other values stored in container maps.
Call the function with defaults.
ff_disc_rand_var_stats();
----------------------------------------
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Summary Statistics for: binom
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
----------------------------------------
fl_choice_mean
-1.0000
fl_choice_sd
2.5100
fl_choice_coefofvar
-2.5100
fl_choice_prob_zero
0.1416
fl_choice_prob_below_zero
0.5888
fl_choice_prob_above_zero
0.2696
fl_choice_prob_max
2.0589e-16
tb_disc_cumu
binomDiscreteVal binomDiscreteValProbMass CDF cumsumFrac
________________ ________________________ _________ __________
-10 2.2539e-05 0.0022539 0.00022539
-9 0.00028979 0.031233 0.0028335
-8 0.0018008 0.21132 0.01724
-7 0.0072034 0.93166 0.067664
-6 0.020838 3.0155 0.19269
-5 0.04644 7.6595 0.42489
-4 0.082928 15.952 0.75661
-3 0.12185 28.138 1.1222
-2 0.15014 43.152 1.4224
-1 0.15729 58.881 1.5797
binomDiscreteVal binomDiscreteValProbMass CDF cumsumFrac
________________ ________________________ ___ __________
11 6.0392e-06 100 1
12 1.0588e-06 100 1
13 1.5784e-07 100 1
14 1.973e-08 100 1
15 2.0293e-09 100 1
16 1.6725e-10 100 1
17 1.0619e-11 100 1
18 4.8762e-13 100 1
19 1.4412e-14 100 1
20 2.0589e-16 100 1
tb_prob_drv
percentiles binomDiscreteValPercentileValues fracOfSumHeldBelowThisPercentile
___________ ________________________________ ________________________________
0.1 -8 0.01724
1 -6 0.19269
5 -5 0.42489
10 -4 0.75661
15 -4 0.75661
20 -3 1.1222
25 -3 1.1222
35 -2 1.4224
50 -1 1.5797
65 0 1.5797
75 1 1.4694
80 1 1.4694
85 2 1.3197
90 2 1.3197
95 3 1.1865
99 5 1.0412
99.9 7 1.0052
The simplest discrete random variable has two values, zero or one. The probability of zero is 30 percent, and 70 percent is the probability of one.
% Parameters
% 1. specify the random variable
st_var_name = 'bernoulli';
ar_choice_unique_sorted = [0, 1];
ar_choice_prob = [0.3, 0.7];
% 2. percentiles of interest
ar_fl_percentiles = [0.1 5 25 50 75 95 99.9];
% 3. print resutls
bl_display_drvstats = true;
% Call Function
[ds_stats_map] = ff_disc_rand_var_stats(st_var_name, ...
ar_choice_unique_sorted, ar_choice_prob, ...
ar_fl_percentiles, bl_display_drvstats);
----------------------------------------
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Summary Statistics for: bernoulli
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
----------------------------------------
fl_choice_mean
0.7000
fl_choice_sd
0.4583
fl_choice_coefofvar
0.6547
fl_choice_prob_zero
0.3000
fl_choice_prob_below_zero
0
fl_choice_prob_above_zero
0.7000
fl_choice_prob_max
0.7000
tb_disc_cumu
bernoulliDiscreteVal bernoulliDiscreteValProbMass CDF cumsumFrac
____________________ ____________________________ ___ __________
0 0.3 30 0
1 0.7 100 1
bernoulliDiscreteVal bernoulliDiscreteValProbMass CDF cumsumFrac
____________________ ____________________________ ___ __________
0 0.3 30 0
1 0.7 100 1
tb_prob_drv
percentiles bernoulliDiscreteValPercentileValues fracOfSumHeldBelowThisPercentile
___________ ____________________________________ ________________________________
0.1 0 0
5 0 0
25 0 0
50 1 1
75 1 1
95 1 1
99.9 1 1
Poisson random variable, with mean equals to ten, summarize over umsymmetric percentiles. Note that the poisson random variable has no upper bound.
% Parameters
% 1. specify the random variable
st_var_name = 'poisson';
mu = 10;
ar_choice_unique_sorted = 0:1:50;
ar_choice_prob = poisspdf(ar_choice_unique_sorted, mu);
% 2. percentiles of interest, unsymmetric
ar_fl_percentiles = [0.1 5 10 25 50 90 95 99 99.9 99.99 99.999 99.9999];
% 3. print resutls
bl_display_drvstats = true;
% Call Function
[ds_stats_map] = ff_disc_rand_var_stats(st_var_name, ...
ar_choice_unique_sorted, ar_choice_prob, ...
ar_fl_percentiles, bl_display_drvstats);
----------------------------------------
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Summary Statistics for: poisson
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
----------------------------------------
fl_choice_mean
10
fl_choice_sd
3.1623
fl_choice_coefofvar
0.3162
fl_choice_prob_zero
4.5400e-05
fl_choice_prob_below_zero
0
fl_choice_prob_above_zero
1.0000
fl_choice_prob_max
1.4927e-19
tb_disc_cumu
poissonDiscreteVal poissonDiscreteValProbMass CDF cumsumFrac
__________________ __________________________ _______ __________
0 4.54e-05 0.00454 0
1 0.000454 0.04994 4.54e-05
2 0.00227 0.27694 0.0004994
3 0.0075667 1.0336 0.0027694
4 0.018917 2.9253 0.010336
5 0.037833 6.7086 0.029253
6 0.063055 13.014 0.067086
7 0.090079 22.022 0.13014
8 0.1126 33.282 0.22022
9 0.12511 45.793 0.33282
poissonDiscreteVal poissonDiscreteValProbMass CDF cumsumFrac
__________________ __________________________ ___ __________
41 1.3571e-13 100 1
42 3.2313e-14 100 1
43 7.5146e-15 100 1
44 1.7079e-15 100 1
45 3.7953e-16 100 1
46 8.2506e-17 100 1
47 1.7554e-17 100 1
48 3.6572e-18 100 1
49 7.4636e-19 100 1
50 1.4927e-19 100 1
tb_prob_drv
percentiles poissonDiscreteValPercentileValues fracOfSumHeldBelowThisPercentile
___________ __________________________________ ________________________________
0.1 2 0.0004994
5 5 0.029253
10 6 0.067086
25 8 0.22022
50 10 0.45793
90 14 0.86446
95 15 0.91654
99 18 0.98572
99.9 21 0.99841
99.99 24 0.99988
99.999 26 0.99998
100 28 1
% Print out full Stored Matrix
% Note that the outputs are single row arrays.
ff_container_map_display(ds_stats_map, 100, 100)
----------------------------------------
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
CONTAINER NAME: ds_stats_map ND Array (Matrix etc)
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
i idx ndim numel rowN colN sum mean std coefvari min max
_ ___ ____ _____ ____ ____ ______ _______ ______ ________ _________ ___
ar_choice_perc_fracheld 1 1 2 12 1 12 7.54 0.62833 0.435 0.69231 0.0004994 1
ar_choice_percentiles 2 2 2 12 1 12 177 14.75 8.7399 0.59254 2 28
ar_fl_percentiles 3 3 2 12 1 12 773.99 64.499 42.887 0.66492 0.1 100
xxx TABLE:ar_choice_perc_fracheld xxxxxxxxxxxxxxxxxx
c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12
_________ ________ ________ _______ _______ _______ _______ _______ _______ _______ _______ ___
r1 0.0004994 0.029253 0.067086 0.22022 0.45793 0.86446 0.91654 0.98572 0.99841 0.99988 0.99998 1
xxx TABLE:ar_choice_percentiles xxxxxxxxxxxxxxxxxx
c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12
__ __ __ __ __ __ __ __ __ ___ ___ ___
r1 2 5 6 8 10 14 15 18 21 24 26 28
xxx TABLE:ar_fl_percentiles xxxxxxxxxxxxxxxxxx
c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12
___ __ __ __ __ __ __ __ ____ _____ ______ ___
r1 0.1 5 10 25 50 90 95 99 99.9 99.99 99.999 100
----------------------------------------
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
CONTAINER NAME: ds_stats_map Scalars
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
i idx value
__ ___ __________
fl_choice_coefofvar 1 4 0.31623
fl_choice_max 2 5 50
fl_choice_mean 3 6 10
fl_choice_min 4 7 0
fl_choice_prob_above_zero 5 8 0.99995
fl_choice_prob_below_zero 6 9 0
fl_choice_prob_max 7 10 1.4927e-19
fl_choice_prob_min 8 11 4.54e-05
fl_choice_prob_zero 9 12 4.54e-05
fl_choice_sd 10 13 3.1623