Statistics/Normal distribution: Difference between revisions

Content added Content deleted
Line 2,694: Line 2,694:
Pairs of normal numbers are generated from pairs of uniform numbers using the [https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform Box-Muller method]. A normal density is added to the histogram for comparison. See '''[http://www.stata.com/help.cgi?histogram histogram]''' in Stata help. A [https://en.wikipedia.org/wiki/Q%E2%80%93Q_plot Q-Q plot] is also drawn.
Pairs of normal numbers are generated from pairs of uniform numbers using the [https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform Box-Muller method]. A normal density is added to the histogram for comparison. See '''[http://www.stata.com/help.cgi?histogram histogram]''' in Stata help. A [https://en.wikipedia.org/wiki/Q%E2%80%93Q_plot Q-Q plot] is also drawn.


<lang stata>. clear all
<lang stata>clear all
. set obs 100000
set obs 100000
. gen u=runiform()
gen u=runiform()
. gen v=runiform()
gen v=runiform()
. gen r=sqrt(-2*log(u))
gen r=sqrt(-2*log(u))
. gen x=r*cos(2*_pi*v)
gen x=r*cos(2*_pi*v)
. gen y=r*sin(2*_pi*v)
gen y=r*sin(2*_pi*v)
. gen z=rnormal()
gen z=rnormal()
. summarize x y z
sum x y z


Variable | Obs Mean Std. Dev. Min Max
Variable | Obs Mean Std. Dev. Min Max
Line 2,709: Line 2,709:
y | 100,000 .0017389 1.001586 -4.631144 4.460274
y | 100,000 .0017389 1.001586 -4.631144 4.460274
z | 100,000 .005054 .9998861 -5.134265 4.449522
z | 100,000 .005054 .9998861 -5.134265 4.449522
. hist x, normal
hist x, normal
. hist y, normal
hist y, normal
. hist z, normal
hist z, normal
. qqplot x z, msize(tiny)</lang>
qqplot x z, msize(tiny)</lang>


=={{header|Tcl}}==
=={{header|Tcl}}==