Statistics/Normal distribution: Difference between revisions

Content added Content deleted
(+Stata)
Line 2,657: Line 2,657:


=={{header|Stata}}==
=={{header|Stata}}==
Here, a normal density is added to the histogram for comparison. See '''[http://www.stata.com/help.cgi?histogram histogram]''' in Stata help.
Pairs of normal numbers are generated from pairs of uniform numbers using the polar form of [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
number of observations (_N) was 0, now 100,000
number of observations (_N) was 0, now 100,000
. gen x=rnormal()
. gen u=runiform()
. gen v=runiform()
. summarize x
. gen r=sqrt(-2*log(u))
. gen x=r*cos(2*_pi*v)
. gen y=r*sin(2*_pi*v)
. gen z=rnormal()
. summarize x y z


Variable | Obs Mean Std. Dev. Min Max
Variable | Obs Mean Std. Dev. Min Max
-------------+---------------------------------------------------------
-------------+---------------------------------------------------------
x | 100,000 -.00149 .9995225 -4.24247 4.057799
x | 100,000 .0025861 1.002346 -4.508192 4.164336
y | 100,000 .0017389 1.001586 -4.631144 4.460274
. hist(x), normal</lang>
z | 100,000 .005054 .9998861 -5.134265 4.449522
. hist x, normal
. hist y, normal
. hist z, normal
. qqplot x z, msize(tiny)</lang>


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