mirror of
https://github.com/MartinThoma/LaTeX-examples.git
synced 2025-04-19 11:38:05 +02:00
Add normal-distribution-z
This commit is contained in:
parent
45e56d0320
commit
1f5881a6e0
5 changed files with 220 additions and 0 deletions
28
documents/normal-distribution-z/Makefile
Normal file
28
documents/normal-distribution-z/Makefile
Normal file
|
@ -0,0 +1,28 @@
|
|||
SOURCE=normal-distribution-z
|
||||
DELAY = 80
|
||||
DENSITY = 300
|
||||
WIDTH = 512
|
||||
|
||||
make:
|
||||
pdflatex $(SOURCE).tex -output-format=pdf
|
||||
make clean
|
||||
|
||||
clean:
|
||||
rm -rf $(TARGET) *.class *.html *.log *.aux *.out
|
||||
|
||||
png:
|
||||
make
|
||||
make svg
|
||||
inkscape $(SOURCE).svg -w $(WIDTH) --export-png=$(SOURCE).png
|
||||
|
||||
transparentGif:
|
||||
convert $(SOURCE).pdf -transparent white result.gif
|
||||
make clean
|
||||
|
||||
svg:
|
||||
#inkscape $(SOURCE).pdf --export-plain-svg=$(SOURCE).svg
|
||||
pdf2svg $(SOURCE).pdf $(SOURCE).svg
|
||||
# Necessary, as pdf2svg does not always create valid svgs:
|
||||
inkscape $(SOURCE).svg --export-width=$(WIDTH) --export-plain-svg=$(SOURCE)1.svg
|
||||
rsvg-convert -a -w 720 -f svg $(SOURCE)1.svg -o $(SOURCE).svg
|
||||
rm $(SOURCE)1.svg
|
10
documents/normal-distribution-z/README.md
Normal file
10
documents/normal-distribution-z/README.md
Normal file
|
@ -0,0 +1,10 @@
|
|||
[Download PDF](https://github.com/MartinThoma/LaTeX-examples/raw/master/documents/normal-distribution/normal-distribution.pdf)
|
||||
|
||||
Compiled example
|
||||
----------------
|
||||

|
||||
|
||||
## Credits
|
||||
|
||||
Thanks to [Jake](http://tex.stackexchange.com/users/2552/jake) for the
|
||||
plot of the normal distribution ([link](http://tex.stackexchange.com/a/100030/5645))
|
17
documents/normal-distribution-z/generate_numbers.py
Executable file
17
documents/normal-distribution-z/generate_numbers.py
Executable file
|
@ -0,0 +1,17 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Generate the LaTeX code for a table of the PPF of a normal distribution.
|
||||
|
||||
PPF stands for Percent point function (inverse of cdf - percentiles).
|
||||
"""
|
||||
|
||||
from scipy.stats import norm
|
||||
from numpy import arange
|
||||
|
||||
for x in arange(0.0, 1.0, 0.1):
|
||||
line = "\\textbf{%0.1f} & " % x
|
||||
values = [norm.ppf(x + dx) for dx in arange(0.00, 0.09 + 0.01, 0.01)]
|
||||
values = ["%0.4f" % el for el in values]
|
||||
line += " & ".join(values)
|
||||
print(line + "\\\\")
|
88
documents/normal-distribution-z/normal-distribution-z.tex
Normal file
88
documents/normal-distribution-z/normal-distribution-z.tex
Normal file
|
@ -0,0 +1,88 @@
|
|||
\documentclass[a4paper]{article}
|
||||
\usepackage[margin=20mm]{geometry}
|
||||
\usepackage[english]{babel}
|
||||
\usepackage[utf8]{inputenc}
|
||||
\usepackage{amssymb,amsmath}
|
||||
\usepackage{slashbox}
|
||||
\usepackage{booktabs}
|
||||
\usepackage[table,x11names]{xcolor}
|
||||
\usepackage{pgfplots}
|
||||
|
||||
\setlength{\intextsep}{1pt}
|
||||
|
||||
\begin{document}
|
||||
\pagenumbering{gobble}
|
||||
\section*{Percent point function (PPF) of the normal distribution}
|
||||
|
||||
\pgfmathdeclarefunction{gauss}{3}{%
|
||||
\pgfmathparse{1/(#3*sqrt(2*pi))*exp(-((#1-#2)^2)/(2*#3^2))}%
|
||||
}
|
||||
|
||||
\begin{figure}[!h]
|
||||
\centering
|
||||
\begin{tikzpicture}
|
||||
\begin{axis}[
|
||||
no markers,
|
||||
domain=0:6,
|
||||
samples=100,
|
||||
ymin=0,
|
||||
axis lines*=left,
|
||||
xlabel=$x$,
|
||||
every axis y label/.style={at=(current axis.above origin),anchor=south},
|
||||
every axis x label/.style={at=(current axis.right of origin),anchor=west},
|
||||
height=4cm,
|
||||
width=12cm,
|
||||
xtick=\empty,
|
||||
ytick=\empty,
|
||||
enlargelimits=false,
|
||||
clip=false,
|
||||
axis on top,
|
||||
grid = major,
|
||||
hide y axis
|
||||
]
|
||||
|
||||
\addplot [very thick,cyan!50!black] {gauss(x, 3, 1)};
|
||||
|
||||
\pgfmathsetmacro\valueA{gauss(1,3,1)}
|
||||
\pgfmathsetmacro\valueB{gauss(2,3,1)}
|
||||
\draw [gray] (axis cs:1,0) -- (axis cs:1,\valueA)
|
||||
(axis cs:5,0) -- (axis cs:5,\valueA);
|
||||
\draw [gray] (axis cs:2,0) -- (axis cs:2,\valueB)
|
||||
(axis cs:4,0) -- (axis cs:4,\valueB);
|
||||
\draw [yshift=1.4cm, latex-latex](axis cs:2, 0) -- node [fill=white] {$0.683$} (axis cs:4, 0);
|
||||
\draw [yshift=0.3cm, latex-latex](axis cs:1, 0) -- node [fill=white] {$0.954$} (axis cs:5, 0);
|
||||
|
||||
\node[below] at (axis cs:1, 0) {$\mu - 2\sigma$};
|
||||
\node[below] at (axis cs:2, 0) {$\mu - \sigma$};
|
||||
\node[below] at (axis cs:3, 0) {$\mu$};
|
||||
\end{axis}
|
||||
\end{tikzpicture}
|
||||
\end{figure}
|
||||
|
||||
\begin{table}[!h]
|
||||
\centering
|
||||
\begin{tabular}{c|ccccc|ccccc}
|
||||
\toprule
|
||||
\backslashbox{$x$}{$\Delta x$} & \textbf{0.00} & \textbf{0.01} & \textbf{0.02} & \textbf{0.03} & \textbf{0.04} & \textbf{0.05} & \textbf{0.06} & \textbf{0.07} & \textbf{0.08} & \textbf{0.09} \\\midrule
|
||||
\textbf{0.0} & -inf & -2.3263 & -2.0537 & -1.8808 & -1.7507 & -1.6449 & -1.5548 & -1.4758 & -1.4051 & -1.3408\\
|
||||
\textbf{0.1} & -1.2816 & -1.2265 & -1.1750 & -1.1264 & -1.0803 & -1.0364 & -0.9945 & -0.9542 & -0.9154 & -0.8779\\
|
||||
\textbf{0.2} & -0.8416 & -0.8064 & -0.7722 & -0.7388 & -0.7063 & -0.6745 & -0.6433 & -0.6128 & -0.5828 & -0.5534\\
|
||||
\textbf{0.3} & -0.5244 & -0.4959 & -0.4677 & -0.4399 & -0.4125 & -0.3853 & -0.3585 & -0.3319 & -0.3055 & -0.2793\\
|
||||
\textbf{0.4} & -0.2533 & -0.2275 & -0.2019 & -0.1764 & -0.1510 & -0.1257 & -0.1004 & -0.0753 & -0.0502 & -0.0251\\
|
||||
\textbf{0.5} & 0.0000 & 0.0251 & 0.0502 & 0.0753 & 0.1004 & 0.1257 & 0.1510 & 0.1764 & 0.2019 & 0.2275\\
|
||||
\textbf{0.6} & 0.2533 & 0.2793 & 0.3055 & 0.3319 & 0.3585 & 0.3853 & 0.4125 & 0.4399 & 0.4677 & 0.4959\\
|
||||
\textbf{0.7} & 0.5244 & 0.5534 & 0.5828 & 0.6128 & 0.6433 & 0.6745 & 0.7063 & 0.7388 & 0.7722 & 0.8064\\
|
||||
\textbf{0.8} & 0.8416 & 0.8779 & 0.9154 & 0.9542 & 0.9945 & 1.0364 & 1.0803 & 1.1264 & 1.1750 & 1.2265\\
|
||||
\textbf{0.9} & 1.2816 & 1.3408 & 1.4051 & 1.4758 & 1.5548 & 1.6449 & 1.7507 & 1.8808 & 2.0537 & 2.3263\\
|
||||
\bottomrule
|
||||
\end{tabular}
|
||||
\caption{Approximations of $\Phi_{0;1}^{-1}(x + \Delta x)$}
|
||||
\end{table}
|
||||
\begin{align*}
|
||||
\Phi_{0;1}(x) &= \frac{1}{\sqrt{2 \pi}} \int_{-\infty}^{x} e^{- t^2 / 2} \mathrm{d} t &
|
||||
\Phi_{0;1}(1.65) &\approx 0.9505\\
|
||||
\Phi_{\mu; \sigma^2}(x) &= \Phi_{0;1} \left (\frac{x-\mu}{\sigma} \right ) &
|
||||
\Phi_{0;1}(-x) &= 1 - \Phi_{0;1}(x)\\
|
||||
z_\alpha &= \Phi_{0;1}^{-1}(1-\alpha)
|
||||
\end{align*}
|
||||
\end{document}
|
77
documents/normal-distribution-z/slashbox.sty
Normal file
77
documents/normal-distribution-z/slashbox.sty
Normal file
|
@ -0,0 +1,77 @@
|
|||
% slashbox.sty by Koichi Yasuoka, May 27, 1993
|
||||
% minor modification by Toru Sato, May 31, 1993
|
||||
\typeout{slashbox style by K.Yasuoka, May 1993.}%
|
||||
\newbox\@slashboxa
|
||||
\newbox\@slashboxb
|
||||
\newbox\@slashboxc
|
||||
\newcount\@slashboxwd
|
||||
\newcount\@slashboxht
|
||||
\newdimen\@slashsepl
|
||||
\newdimen\@slashsepr
|
||||
\def\slashbox{%
|
||||
\def\@slashboxpicture##1{%
|
||||
\put(0,0){\line(##1,1){\@slashboxwd}}%
|
||||
\put(0,\@slashboxht){\makebox(0,0)[tl]{\box\@slashboxa}}%
|
||||
\put(\@slashboxwd,0){\makebox(0,0)[br]{\box\@slashboxb}}%
|
||||
}%
|
||||
\@slashbox
|
||||
}%
|
||||
\def\backslashbox{%
|
||||
\def\@slashboxpicture##1{%
|
||||
\put(0,\@slashboxht){\line(##1,-1){\@slashboxwd}}%
|
||||
\put(0,0){\makebox(0,0)[bl]{\box\@slashboxa}}%
|
||||
\put(\@slashboxwd,\@slashboxht){\makebox(0,0)[tr]{\box\@slashboxb}}%
|
||||
}%
|
||||
\@slashbox
|
||||
}%
|
||||
\def\@slashbox{\@ifnextchar [{\@@slashbox}{\@@slashbox[0pt]}}
|
||||
\def\@@slashbox[#1]{\@ifnextchar [{\@@@slashbox[#1]}{\@@@slashbox[#1][c]}}
|
||||
\def\@@@slashbox[#1][#2]#3#4{%
|
||||
% #1: width, #2: suppression of \tabcolsep on `l', `r', or `lr' side
|
||||
% #3: left item, #4: right item
|
||||
\@slashsepl=\tabcolsep
|
||||
\@slashsepr=\tabcolsep
|
||||
\@tfor\@tempa :=#2\do{\expandafter\let
|
||||
\csname @slashsep\@tempa\endcsname=\z@}%
|
||||
\setbox\@slashboxa=\hbox{\strut\hskip\tabcolsep\shortstack[l]{#3}}%
|
||||
\setbox\@slashboxb=\hbox{\shortstack[r]{#4}\hskip\tabcolsep\strut}%
|
||||
\setbox\@slashboxa=\hbox{\raise\dp\@slashboxa\box\@slashboxa}%
|
||||
\setbox\@slashboxb=\hbox{\raise\dp\@slashboxb\box\@slashboxb}%
|
||||
\setbox\@slashboxc=\hbox{%
|
||||
\@tempdima=\wd\@slashboxa
|
||||
\advance\@tempdima by \wd\@slashboxb
|
||||
\advance\@tempdima by \@slashsepl
|
||||
\advance\@tempdima by \@slashsepr
|
||||
\@tempdimb=#1\relax%
|
||||
\ifdim\@tempdimb>\@tempdima \@tempdima=\@tempdimb\fi%
|
||||
\@tempdimb=\ht\@slashboxa
|
||||
\advance\@tempdimb by \dp\@slashboxa
|
||||
\advance\@tempdimb by \ht\@slashboxb
|
||||
\advance\@tempdimb by \dp\@slashboxb
|
||||
\@tempcnta=\@tempdima
|
||||
\@tempcntb=\@tempdimb
|
||||
\advance\@tempcnta by \@tempcntb
|
||||
\advance\@tempcnta by -1
|
||||
\divide\@tempcnta by \@tempcntb
|
||||
\ifnum\@tempcnta>6 \@tempcnta=6
|
||||
\@tempdimb=0.166666666\@tempdima
|
||||
\else
|
||||
\ifnum\@tempcnta<1 \@tempcnta=1\fi
|
||||
\@tempdima=\@tempdimb
|
||||
\multiply\@tempdima by \@tempcnta
|
||||
\fi%
|
||||
\advance\@tempdima by -\@slashsepl
|
||||
\advance\@tempdima by -\@slashsepr
|
||||
\@slashboxwd=\@tempdima
|
||||
\@slashboxht=\@tempdimb
|
||||
\@tempcntb=\@slashsepl
|
||||
\setlength{\unitlength}{1sp}%
|
||||
\begin{picture}(\@slashboxwd,\@slashboxht)(\@tempcntb,0)
|
||||
\advance\@tempdima by \@slashsepl
|
||||
\advance\@tempdima by \@slashsepr
|
||||
\@slashboxwd=\@tempdima
|
||||
\@slashboxpicture{\@tempcnta}
|
||||
\end{picture}%
|
||||
}%
|
||||
$\vcenter{\box\@slashboxc}$%
|
||||
}%
|
Loading…
Add table
Add a link
Reference in a new issue