## Probability distributions

*October 12, 2009 at 5:41 pm* *gabrielrossman*

| Gabriel |

I wrote this little demo for my stats class to show how normal distributions result from complex processes that sum the constituent parts whereas count distributions result from complex processes where a single constituent failure is catastrophic.

*this do-file is a simple demo of how you statistical distributions are built up from additive vs sudden-death causation *this is entirely based on a simulated coin toss -- the function "round(uniform())" *one either counts how many heads out of 10 tosses or how long a streak of heads lasts *I'm building up from this simple function for pedagogical purposes, in actual programming there are much more direct functions like rnormal() *1. The normal distribution *Failure is an additive setback clear set obs 1000 forvalues var=1/10 { quietly gen x`var'=. } forvalues row=1/1000 { forvalues var=1/10 { quietly replace x`var'=round(uniform()) in `row' } } gen sumheads=x1+x2+x3+x4+x5+x6+x7+x8+x9+x10 order sumheads lab var sumheads "How Many Heads Out of 10 Flips" *show five examples list in 1/5 histogram sumheads, discrete normal graph export sumheads.png, replace *2. Count distribution *Failure is catastrophic clear set obs 1000 forvalues var=1/30 { quietly gen x`var'=. } gen streak=0 lab var streak "consecutive heads before first tails" gen fail=0 forvalues row=1/1000 { forvalues var=1/30 { quietly replace x`var'=round(uniform()) in `row' quietly replace fail=1 if x`var'==0 quietly replace streak=`var' if fail==0 } quietly replace fail=. in `row'/`row' } quietly replace streak=0 if x1==0 *show five partial examples list streak x1 x2 x3 x4 x5 in 1/5 histogram streak, discrete graph export streakheads.png, replace *have a nice day

Advertisements

Entry filed under: Uncategorized. Tags: random variables, simulation, Stata.

Recent Comments