Plots and Random #s EXCEL Functions Obtaining a Density Function Create a column with a range of values of x containing a large portion of the density Create a column that evaluates f(x) at each value of x (Specific densities below) Repeat previous step for multiple pdf’s Highlight columns with x (left-hand column) and f(x) (right hand column(s)) Chart Wizard XY (Scatter) Picture with Smooth curves/No points Families of Densities Gamma(a,b): f(x)=GAMMA.DIST(x,a,b,0) • Exponential (a=1,q=1/b) special case of Gamma • Chi-Square (a=n/2, b=2) special case of Gamma Beta(a,b): f(x)=BETA.DIST(x,a,b,0) Normal(m,s2): f(x)=NORM.DIST(x,m,s,0) t(n): f(x) = T.DIST(x,n,0) F(n1,n2): f(x) = F.DIST(x,n1,n2,0) Other densities can be obtained by directly typing in f(x) Example: Gamma(a=2,b=2) Cell A1 Cell A1500 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.002488 0.00495 0.007388 0.009802 0.012191 0.014557 0.016898 0.019216 0.02151 … … 14.95 14.96 14.97 14.98 14.99 15.00 0.002119 0.00211 0.002101 0.002092 0.002083 0.002074 =GAMMADIST(a1,2,2,0) =GAMMADIST(a1500,2,2,0) Example: Gamma(a=2,b=2) Gamma(2,2) pdf 0.2 0.18 0.16 0.14 f(x) 0.12 0.1 0.08 0.06 0.04 0.02 0 0 2 4 6 8 x 10 12 14 16 Cumulative Distribution Function Create a column with a range of values of x containing a large portion of the density Create a column that evaluates F(x) at each value of x (Specific denities below) Repeat previous step for multiple pdf’s Highlight columns with x (left-hand column) and F(x) (right hand column(s)) Chart Wizard XY (Scatter) Picture with Smooth curves/No points Families of CDF’s Gamma(a,b): F(x)=GAMMADIST(x,a,b,1) • Exponential (a=1) special case of Gamma • Chi-Square (a=n/2, b=2) special case of Gamma Normal(m,s2): F(x)=NORMDIST(x,m,s,1) Beta(a,b): F(x)=BETA.DIST(x,a,b,1) t(n): F(x) = T.DIST(x,n,1) F(n1,n2): F(x) = F.DIST(x,n1,n2,1) Others obtained by directly entering cdf Example - Gamma(a=2,b=2) Cell A1 Cell A1500 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 1.25E-05 4.97E-05 0.000111 0.000197 0.000307 0.000441 0.000598 0.000779 0.000983 … … 14.95 14.96 14.97 14.98 14.99 15.00 0.995194 0.995215 0.995236 0.995257 0.995278 0.995299 =Gammadist(a1,2,2,1) =Gammadist(a1500,2,2,1) Example - Gamma(a=2,b=2) Gamma(2,2) CDF 1.2 1 F(x) 0.8 0.6 0.4 0.2 0 0 2 4 6 8 x 10 12 14 16 Selecting Pseudo-Random Variables Select a sample size and density function In EXCEL, type: =RAND() Copy and Paste that cell to n-1 below it Highlight all n cells: • COPY PASTE SPECIAL VALUES This is a pseudo-random sample from a uniform(0,1) distribution Obtain random sample from inverting cdf Families of Distributions Labelling your U(0,1) value as p Gamma(a,b) X=GAMMA.INV(p,a,b) Normal(m,s2) X=NORM.INV(p,m,s) Beta(a,b) X=BETA.INV(p,a,b) t(n) X = T.INV(p) F(n1,n2) X = F.INV(x,n1,n2) Copy and Paste this function for all n p’s Simulating 10000 Gamma(2,2) RVs In cell A1 type: =RAND() Copy/Paste to cells A2:A10000 Copy/Paste Special/Values cells A1:A10000 In cell B1 type: =GAMMAINV(A1,2,2) Copy/Paste to cells B2:B10000 (May take a few seconds) Example 10000 Gamma(2,2) 1st 10 p 0.281723 0.681206 0.334421 0.555336 0.161319 0.521112 0.052864 0.39327 0.519182 0.10049 2.095076 4.706185 2.383676 3.723865 1.431617 3.493365 0.733489 2.714214 3.480709 1.066755 Empirical Results Mean Variance n p 0.5023 0.0839 10000 X 4.0311 8.2851 10000 1st 10 X Theoretical Values Mean Variance p 0.5000 0.0833 X 4.0000 8.0000 x 15 .5 13 12 .5 10 9 7. 5 6 4. 5 3 1. 5 1000 900 800 700 600 500 400 300 200 100 0 0 Frequency 10000 Gamma(2,2) RVs