diff --git a/IMG_1631.jpeg b/IMG_1631.jpeg new file mode 100644 index 0000000..268fe97 Binary files /dev/null and b/IMG_1631.jpeg differ diff --git a/IMG_1665.jpeg b/IMG_1665.jpeg new file mode 100644 index 0000000..d816d55 Binary files /dev/null and b/IMG_1665.jpeg differ diff --git a/IMG_1666.jpeg b/IMG_1666.jpeg new file mode 100644 index 0000000..c8cab75 Binary files /dev/null and b/IMG_1666.jpeg differ diff --git a/main.tex b/main.tex new file mode 100644 index 0000000..e5a2da5 --- /dev/null +++ b/main.tex @@ -0,0 +1,837 @@ +\input{preamble.tex} +\usepackage{enumitem} +\usepackage{stmaryrd} +\usepackage{xhfill} +\usepackage{array} +\usepackage{outlines} +\usepackage{faktor} +\usepackage{tikz-cd} +\usepackage{multirow} + +\newcommand{\ra}{\rightarrow} +\renewcommand{\theta}{\vartheta} +\let\phi=\varphi +\newcommand{\E}[1]{\bE\hspace{-2pt}\left[{#1}\right]} +\newcommand{\Var}[1]{\operatorname{Var}\hspace{-2pt}\left[{#1}\right]} + + +\begin{document} + +\maketitle + +\tableofcontents + +\section{Preliminaries} + +\subsection{Witzige Definitionen} + +\begin{outline} + \1 Zufallsvariable $X$ ist eine messbare Funktion (im Allgemeinen) aus einem Wktsraum in einen messbaren Raum. + \1 Wahrscheinlichkeitsverteilung $P$ ist ein Maß $\cA \ra \R_+$ +\0 Wir können die Wahrscheinlichkeitsverteilung von $X$ in natürlicher Weise als Bildmaß $\mu_X : A \mapsto P(X^{-1}(A))$ definieren. + \1 Die Wktverteilung $\mu_X$ ist eindeutig durch $P$ festgelegt. Wir können das auf dem Erzeugendensystem von $\cB(\R)$ überprüfen, da $\mu_X((-\infty,c]) = P(X^{-1}(-\infty,c]) = P(X\leq c)$ +\0 \textbf{Spickzettel:} + \1 Wahrscheinlichkeitsverteilung (Maß) $P$ auf $(\Omega,\cA)$ + \1 Verteilung von $X$ unter $P$ definiert Wahrscheinlichkeitsverteilung auf $(\R,\cB)$ + $$\mu_X(B):=P(X^{-1}(B))$$ + Das impliziert die Formel $\int x d\mu = \int x f(x) dx$, wobei $f(x)$ die Wktsverteilung der ZV ist. + \1 Verteilungsfunktion der ZV $X:\Omega\ra\R$ + $$F_X:\R\ra [0,1], c \mapsto P(X\leq c).$$ + \1 $u$-Quantil ist ein Wert $q\in \R: P(X < q)=F(q-)\leq u$ und $F(q)\geq u$ + \1 verallgemeinerte linksstetige Inverse $\underline{G}(u)$ -- das kleinste $u$-Quantil + $$\inf \{x\in\R: F(x)\geq u\}$$ + \1 verallgemeinerte rechtsstetige Inverse $\overline{G}(u)$ -- das größte $u$-Quantil + $$\inf \{x\in\R: F(x)> u\}$$ + \1 obere / untere Konfidenzschranke $b_\alpha(T(X)) / a_\alpha(T(X))$ + \begin{align} + b_\alpha(T(X)) &:= \max \{ N : F_N(T(X)) > \alpha\} \\ + a_\alpha(T(X)) &:= \min \{ N : F_N(T(X)-)< 1-\alpha\} + \end{align} + \begin{align} + P_N&[N\leq b_\alpha(T(X))] \geq 1- \alpha \\ + P_N&[N\geq \alpha_\alpha(T(X))] \geq 1-\alpha \\ + P_N&[N\in [a_{\frac{\alpha}{2}}(T(X)),b_{\frac{\alpha}{2}}(T(X))]] \leq \alpha + \end{align} +\end{outline} + +\subsection{Whimsical Verteilungen} + +\begin{outline} + \1 Bernoulli-Verteilung \textsc{Bernoulli(p)} + \2 $P(1)=p$, $P(0)= 1-p$ + \1 Geometrische Verteilung \textsc{Geom(p,k)} + \2 Anzahl Misserfolge bis zum ersten Erfolg, $P(X=k)=p(1-p)^k$ + \1 Binomialverteilung \textsc{Bin(n,p)} = Summe von $n$ unabhängigen Zufallsvariablen mit \textsc{Bernoulli(p)} + \2 $P(k)=\binom{n}{k} p^k (1-p)^{n-k}$ + \1 Beta-Verteilung \textsc{Beta(a,b)} = für die Verteilung der Wkten aus der Binomialverteilung, \url{https://stats.stackexchange.com/questions/47771/what-is-the-intuition-behind-beta-distribution} + \1 Multinomialverteilung = Bernoulli für mehr als $2$ mögliche Ergebnisse. + \1 Poissonverteilung \textsc{Poisson($\lambda$)} = Grenzwert von $\textsc{Bin}(n,p)$ mit großem $n$ und kleinem $p:=\frac{\lambda}{n}$. Hinreichend genaue Approximation von $\textsc{Bin}(n,p)$. Parameter $\lambda$ heißt Intensität. + \2 $P(k)=\frac{\lambda^k}{k!}e^{-\lambda}$ + \1 Hypergeometrische Verteilung \textsc{Hypergeom(m,r,n)} = Ziehen $n$ Kugeln aus einer Urne mit insgesamt $m$ Kugeln, $r$ roten und $m-r$ schwarzen; ohne Zurücklegen; + \2 $k$ Anzahl gezogener roten und $n-k$ Anzahl gezogener schwarzen Kugeln ohne Zurücklegen. + \2 wenn $\frac{n}{m}<0,05$, approximiert die $\textsc{Bin}(n,p)$ + \2 $P(k)=\frac{\binom{r}{k}\binom{m-r}{n-k}}{\binom{m}{n}}$ +\end{outline} + +\subsection{Eigenschaften für Momente} + +\begin{outline} + \1 Erwartungswert (der erste zentrale Moment) = $\int_\Omega x f(x) dx$ + \2 linear und additiv + \1 Varianz (der zweite zentrale Moment) = $\E{(X-m)^2}$ = $\int_\Omega (x-m)^2f(x) dx$ + \2 nicht-negativ, $\Var{aX} = a^2\Var{X}$, translationsinvariant + \1 $\E{X^2} = \Var{X}+\E{X^2}^2$ +\end{outline} + +\section{Hypothesentests, Populationsgröße, Konfidenzintervalle} + +\marginnote[0cm]{1. Vorlesung, 09.04.24} +\subsection{Hypothesentests} +\begin{outline} + \1 $p$-Wert + \marginnote[0cm]{$p$-Wert ist das Maß des halb geschlossenen Intervals $F(x)=\mu((-\infty, a]$ oder $1-F(x-)=\mu([b,\infty)$. } + \2 links, $p_l = F(x)$ + \2 rechts, $p_r = 1-F(x-)$ + \2 beidseitig, $p=2\min (p_l,p_r)$ + \1 Fishers exakter Test +\end{outline} + +\marginnote[0cm]{2. Vorlesung, 12.04.24} +\subsection{Schätzen der Populationsgröße} +\begin{outline} +\1 \textbf{German Tank Problem}: es gibt $N$ Panzer mit Nummern $1...N$. Wie groß ist $N$? + \2 \textbf{Schätzer Y}: empirischer Mittelwert $N=2\cdot \hat{E_n}(X)-1$ + \2 \textbf{Schätzer M}: $N=\max \{ X_i : i < n+1 \}$ +\1 Welcher Schätzer ist besser? Systematischer Vergleich. + \2 Erwartungswert, Varianz eines Schätzers. Erwartungstreue. + \3 Schätzer $Y$ ist erwartungstreu, Schätzer $M$ nicht erwartungstreu + \3 $\operatorname{MSE}(Y)=E[(Y-N)^2]=Var(Y)$ + \2 Konfidenzintervall für $\theta = N$ unbekannter Parameter, $F_N(x)$ monoton fallend in $N$. + \3 Konfidenzbereich zum Konfidenzniveau $95 \%$ bzw. Signifikanzniveau $5 \%$ + \3 $P_N(N \leq b(M))$ ist nicht die Wkt, dass N unter x liegt, sondern dass N unter x liegt conditioned on N. + \3 Wenn wir das Experiment 100mal wiederholen dann in $1-\alpha$ Experimenten wäre die Bedingung erfüllt. Wir können nicht sagen, dass wir unter einem festen Wert mit einer bestimmten Wkt liegen. +\end{outline} + +\marginnote[0cm]{3. Vorlesung, 16.04.24} +\begin{outline} +\1 \textbf{Schätzung einer Tierpopulation}. Capture-Recapture-Verfahren: + \2[1.] Entnahme Zufallsstichprobe der Größe $l$ und Markierung + \2[2.] Nehme Zufallsstichprobe der Größe $n\leq N$ + \3 $H$ = Anzahl der markierten Tier in der 2. Stichprobe + \3 Modell ist $H\sim\textsc{Hyp}(N,l,n)$ + \3 Schätzer ist $N \approx \frac{nl}{H}$ + \3 untere Konfidenzschranke $$P_N(F(H)>\alpha)\geq 1- \alpha$$ + kann so umgeschrieben werden, dass $F$ nur von $N$ abhängt, also von dem Wert $a_\alpha(H)$, ab dem die Ungleichung gilt. + $$=P_N(N\geq a_\alpha(H))$$ +\end{outline} + +\newpage + +\section{Statistische Modelle und Verfahren} + +\begin{outline} + \1 Statistische Modelle und Verfahren: schließende Statistik. + \2 Ein \emph{statistisches Modell} besteht aus + \3 einer Menge $\Omega \neq \emptyset$ mit $\sigma$-Algebra $\cA$, + \3 einer Parametermenge $\Theta \neq \emptyset$ + \3 einer Familie $\{P_\theta : \theta \in \Theta\}$ von Wkn auf $(\Omega,\cA)$ + \3 einer messbaren Abbildung $X:\Omega\rightarrow S$, $(S,\cB)$ messbarer Raum. Stichprobe ist dann Realisierung dieser Abbildung $X(\omega)$ + \2 Eine \emph{Statistik} ist eine Abbildung $T(X), T:S\rightarrow \R$. + \2 Beispiel (Capture-Recapture): + \3 $\Theta = \N_{\geq \min (l,n)}$, + \3 $\Omega = {(\omega_1^{(1)},\ldots,\omega_1^{(l)}, \omega_2^{(1)},\ldots,\omega_2^{(n)})}$, $P_N = \textsc{Unif}(\Omega_N)$, $\Omega_N = \{w\in\Omega : w_i \leq N \forall i, k\}$, + \3 Statistik $H(\omega)=|...|$ +\end{outline} + +\subsection{Grundlegende Modelle} + +\begin{outline} + \1 Grundlegende Modelle: + \2 Bernoulli-Modell, Schätzer von Wkeiten: $\Theta=[0,1]$, $X=(X_1,\ldots,X_n)$, $X_i \sim \textsc{Bernoulli}(\theta)$, Statistik z. B. rel. Häufigkeit $\overline{X}_n = \frac{1}{n}\sum_i^n X_i$. + \2 Gauß-Modell, Parameterschätzung: $\Theta = \R\times\{0,\infty\}$ (Mittelwert und Varianz), $X=(X_1,\ldots,X_n)$, $X_i \sim \cN(m,v)$, Staistiken z. B. Stichprobenmittelwert, Stichprobenvarianz, etc + \3 Oft einfach angenommen, da CLT unter relativ einfachen Annahmen gilt (Mittelwert von vielen kleinen ZV ist normalverteilt) + \2 Nichtparametrische Schätzung der Verteilung bzw. Verteilungsfunktion: $\Theta = \cP(\R) =$ alle WVn auf $(\R,\cB(\R)$, unendlich-dimensional. $X=(X_1,\ldots,X_n), X_i\sim \mu$ unabhängig unter $P_\mu$. Statistiken z. B. empirische Verteilung, Verteilungsfunktion klar (Summe aller von links auftretenden Ereignissen...) + \2 Nichtparametrische Dichteschätzung: $\Theta =\{f:\R \rightarrow [0, \infty) : \int f(x) dx = 1, \exists \text{ schwache Ableitung } f''\in L^2(\R) \}$. Das heißt einfach, dass $f$ zweite Stammfunktion einer quadratintegrierbaren Funktion $g$ ist. Statistik: Faltung mit Gauß-Glockenkurven um jeden Punkt $x_i$ mit einer gewissen Varianz $v_i$. Schätzwert $$\hat{f}_n(x)=\frac{1}{n} \sum^n_i \varphi_\theta (x-X_i), \varphi_\theta (x)=\frac{1}{\sqrt{2\pi h}}e^{-\frac{y}{}}.$$ + \2 Regression $(X_1,Y_1),\ldots,(X_n,Y_n): \Omega \rightarrow \R^d \times \R$. Die Annahme ist $Y_i = f(X_i) + \sqrt{v}\varepsilon$, nichtparametrisch $\Theta = \{(v,f) : v\in(0,\infty), f:\R^d\rightarrow \R\}$, lineares Modell $f(x)=w^Tx$, $\Theta= \{(v,w):v\in)(0,\infty), w\in \R^d\}$ + \2 neuronale Netzwerke mit einer bestimmten Architektur... +\end{outline} + +\subsection{Grundlegende Verfahren} + +\begin{outline} + \1 Grundlegende Verfahren: + \marginnote[0cm]{Schätzer schätzen unbekannten Parameter $\theta$ mit Input Stichprobe $X$, sind also insb. eine Statistik und insb. eine Zufallsvariable.} + \2 \textbf{(Punkt-)Schätzer I:} Gegeben ist $g: \Theta \rightarrow \R$, gesucht wird $g(\theta)$, z. B. der Erwartungswert $m$ + \3 Ein \emph{Schätzer} für $g(\theta)$ ist eine Abbildung $\hat{g}=T(X)$, $T:S\rightarrow \R$ (also eine Statistik). + \2 Wir können verschiedene Schätzer hinsichtlich ihrer Qualität vergleichen: + \3 Der \emph{systematische Fehler} von $\hat{g}$ ist $\operatorname{Bias}_\theta(\hat{g})=E(\hat{g})-g(\theta)$. Schätzer ist \emph{erwartungstreu}, falls $\operatorname{Bias}_\theta = 0 \forall \theta \in \Omega$. + \3 Der mittlere quadratische Fehler von $\hat{g}$ ist + $$\operatorname{MSE}_\theta (\hat{g})=E_\theta ((\hat{g}-g(\theta))^2=\Var{\hat{g}}+Bias^2(\hat{g}),$$ + $$\operatorname{RMSE} = \sqrt{\operatorname{MSE}}.$$ +\end{outline} + +\marginnote[0cm]{4. Vorlesung, 19.04.24} +\begin{outline} + \1 \textbf{Schätzer II:} Anwedung und Beispiele + \2 Modell: beobachten $X=(X_1,\ldots, X_n)$, $X_i\sim \mu$ i.i.d. unter $P_\mu$ + \2 Schätzer vom \textbf{Erwartungswert} $m$: $m(\mu)=\int f(x) \mu(dx)$, Varianz $v(\mu)=\int (x-m(\mu))^2 \mu(dx)$. + \3 Erwartungswert ist eine Funktion $G:\mu \rightarrow m(\mu)$ im obigen Sinne. + \3 Beispiel: empirischer Mittelwert, siehe oben. MSE, siehe oben. + \2 Schätzer von der \textbf{Varianz} $v$: Stichprobenvarianz $= \frac{1}{n}\sum (X_i - \overline{X_n})^2$ + \3 nicht erwartungstreu, da $n-1$ Freiheitsgrade + \3 $V^* = \frac{1}{n-1}\sum (X_i - \overline{X_n})^2$ erwartungstreu + \2 Schätzer von der \textbf{Dichte} $\mu$: empirische Verteilung $\hat{\mu}_n$ + \3 relative Häufigkeit von Werten in $B$, $\hat{\mu}_n(B)=\frac{1}{n}\sum_i 1_B(x_i)$ (erwartungstreu) + \1 Vorsicht: Schätzer ohne Konfidenzbereich sind nutzlos. +\end{outline} + +\subsection{Konfidenzbereiche} + +\begin{outline} + \1 Konfidenzbereiche + \2 Sei $\alpha\in(0,1)$. Ein Konfidenzbereich für $g(\theta)$ mit Konfidenzniveau $1-\alpha$ (oder mit Sicherheit $1-\alpha$) ist eine Abbildung $C(X):S\rightarrow \cP(G), x\mapsto C(x)\subseteq G$, wobei $S = $ Stichprobe und $\cP(G) =$ die Potenzmenge von $G (\R)$, mit + $$P_\theta(g(\theta)\in C(X)) \geq 1-\alpha \qquad \forall \theta \in \Theta$$ + \2 Konkret für $G=\R$ gilt $C(X)=[a(X),b(X)]$, wobei $a(X),b(X)$ Statistiken sind. +\0 Kochrezepte für Konfidenzbereiche. + \1 über die \textbf{Verteilungsfunktion}: + \2 Es ist eine Statistik $T(x):\Omega\ra\R$ gegeben. Sie ist eine Zufallsvariable. Betrachte ihre Verteilungsfunktion $F_\theta (c) = P_\theta(T(x)\leq c)$. Die Idee war, wenn $P(T(X)\leq\alpha)$, dann verwerfen wir die Nullhypothese. + \2 $C(x):=\{g(\theta): \theta \in \Theta, F_\theta (F(x)) > \alpha \}$\\ $\implies P_\theta (g(\theta) \in C(X) ) \geq 1-\alpha \forall \theta\in\Theta$ + \2 Wir schließen die Parameterwerte aus, für die $T(x)$ verdächtig klein ist. + \2 Analog für beidseitige $(1-\frac{\alpha}{2})$ Konfidenzbereiche + \1 Standard-Schul-Beispiel: $\Theta=[0,1] \ni p$ + \2 $X_1,\ldots, X_n$ i.i.d. $\sim$ Bernoulli($p$) unter $P_p$ + \2 $H_n=\sum_i X_i$ unter $P_p$ Häufigkeit von $1$ + \2 $F_{n,p}(c)=P_p(H_n \leq c) = \sum^c_{k=0}\binom{n}{k}p^k(1-p)^{n-k}$ für $c=0\ldots n$ + \2 Ableitung von $F_{n,p}$ ausrechnen, ist streng monoton fallend, $F(p)$ als Funktion von $p$ plotten $F(1)=0, F(0)=1$, und dann suchen $F(c)=\alpha$. Dieses $c$ legt Konfidenzintervall $C(X)=[0,c]$ zum Niveau $1-\alpha$ fest. + \1 über die \textbf{Likelihood}: + \2 Idee: wir schließen Parameterwerte aus, unter denen $X$ eher unwahrscheinlich (unlikely) ist. + \2 Annahme: entweder Massen- oder Dichtefunktion. $S$ abzählbar, $f_\theta(x)=P_\theta(X=x)$ Massenfunktion oder $S=\R^d$, $P_\theta(X\in B)=\int_B f_\theta(x)dx$ Dichtefunktion. Dabei heißt $\theta \mapsto f_\theta(x)$ eine \textbf{Likelihood-Funktion}. + \2 Bestime $c_\theta$ möglichst klein, so dass $P(g(\theta)\in C(X)) \geq P(f_\theta(X) \geq c_\theta) \geq 1-\alpha$ gerade noch geht. + \1 über eine \textbf{Pivot-Statistik}: + \2 Ein Pivot für $g(\theta)$ ist eine Statistik $T(X,g(\theta))$, deren Verteilung nicht von $\theta$ abhängig ist. Sehr robust. + \marginnote[0cm]{This is what's known as $Z$-Test.} + \2 \textbf{Beispiel 1}: Gauß-Modell mit fester Varianz, schätze Mittelwert $m$. + \2 Ziehe i.i.d. $X_1, \ldots, X_n$, dann $\overline{X}\sim N(m,\frac{v}{n})$. Dann ist $Z=\frac{\overline{X}-m}{\sqrt{v/n}}$ wie $N(0,1)$ verteilt und somit \textit{die Verteilung} von $Z$ von $m$ nicht abhängt. Damit können wir ein Konfidenzintervall konstruieren. + +\marginnote[0cm]{5. Vorlesung, 23.04.24} + \marginnote[0cm]{This is what's known as Student's $t$-Test.} + \2 \textbf{Beispiel 2}: Gauß-Modell mit $m,v$ unbekannt, sprich normalverteilt mit Mittelwert $m$ und Varianz $v$. + \2 $T_n = \frac{\overline{X}_n-m}{\sqrt{V_n^*/n}}$ ist ein Pivot für $m$, Studentsche $t$-Statistik. + \2 Wir normieren $X_i$ durch $Y_i:=\frac{X_i-m}{\sqrt{r}}$, dann ist $Y_i\sim N(0,1)$. + \2 Rechne $T_n=\sqrt{n}\frac{\frac{\overline{X}_n-m}{\sqrt{r}}}{\sqrt{\frac{V_n^*}{r}}} = \sqrt{n} \frac{\overline{Y}_n}{\sqrt{\frac{1}{n-1}\sum_i^n(Y_i-\overline{Y}_n)^2}}$ und die Verteilung hängt nicht von $m$ und $v$ ab. + \2 Damit $P(|\overline{X}_n-m|\geq c\sqrt{\frac{V_n^*}{n}})=P(|T_n|\geq c) = 2P(T_n\geq c) = 2(1-F_{T_n}(c)) \leq \alpha \forall m, v$ falls $c\geq F^{-1}_{T_n}(1-\frac{\alpha}{2})$ + \2 Habe ein $(1-\alpha)$ Konfidenzintervall $\overline{X}_n\pm q_{1-\frac{\alpha}{2}} \sqrt{\frac{V_n^*}{n}}$. Die Verteilung von $T_n$ heißt Studentsche $t$-Verteilung mit $n-1$ Freiheitsgraden, kann man explizit ausrechnen. + \1 approximative Konfidenzintervalle ($\ra$ Normalapproximation) + \2 Beispiel: Bernoulli-/Binomialmodell, $\Theta = [0,1]\ni p$ + \3 $H_n=X_1+\ldots + X_n \sim Bin(n,p)$, $X_i\sim Bernoulli(p)$ + \3 $E(H_n)=np, Var(H_n)=np(1-p), \hat{p}_n=\frac{H_n}{n}$ + \3 Zentraler Grenzwertsatz / de Moivre-Laplace: $\frac{H_n-np}{\sqrt{np(1-p)}}\in (-c,c) \longrightarrow N(0,1)(-c,c)=2(\Phi(c)-\frac{1}{?})$ + $\implies$ für große $n$ gilt näherungsweise $P(|p-\hat{p}_n|0\}$ heißt \emph{der Verwerfungsbereich}. + \2 $\beta(\theta):=E_\theta(\phi(x)) = P_\theta(X\in R)$ falls nicht randomisiert, heißt \emph{Macht} bzw. \emph{Gütefunktion} des Tests. + \2 der Test hat \emph{Signifikanzniveau $\alpha\in(0,1)$}, falls $\forall \theta\in\Theta_0: \beta(\theta)\leq \alpha$ + \begin{figure} + \centering + \includegraphics[width=0.5\linewidth]{IMG_1631.jpeg} + \end{figure} + \2 Fehler 1. Art -- verwerfen die $H_0$, obwohl sie gilt, soll um egal welche Kosten $\leq \alpha$ bleiben. + \2 Fehler 2. Art -- verwerfen die $H_0$ nicht, obwohl falsch, Wahrscheinlichkeit $1-\beta(\theta), \theta \in \Theta_1$. Die Wahrscheinlichkeit soll möglichst klein sein. + \1 Äquivalenz Hypothesentest $\iff$ Konfidenzbereich + \2 Sei $C(X)$ ein $(1-\alpha)$-Konfidenzbereich für $\theta$. Definiere $\phi(X):= 0$, falls $\theta_0 \in C(X)$ und $\phi(X)=1$, falls $\theta_0 \not\in C(X)$. + \1 Zusammenfassung: + \2 Verteilungsfunktion -- p-Werte + \2 Likelihood -- + \2 Pivot -- Hypothesentest + \2 Normalapproximation + \1 Beispiel: Gauß-Modell, $X_1,\ldots,X_n \sim N(m,v)$ + \2 $H_0: m=m_0$ + \2 $(1-\alpha)$-Konfidenzbereich : $C(X)=\{m\in\R : \left|\frac{\overline{X}_n-m}{\sqrt{V_n^* / n}}\right|m_0$ + \2 $C'(X)=\{m\in\R : T_n(m) < q_{1-\alpha}\}$ +\end{outline} + +\newpage + +\section{Likelihood} + +\begin{outline} +\0 Annahmen: entweder $S$ abzählbar, $f_\theta(x)$ Massenfunktion oder $S=\R^d$ und $f_\theta(x)$ Dichtefunktion + \1 Likelihood-Funktion $L(\theta;x)=f_\theta(x)$ Dichtefunktion von $X$ unter $\theta$; $X$ ist fest. + \1 log-Likelihood $l(\theta;x)=\log f_\theta(x)$ falls $f_\theta(x)> 0$ +\0 Beispiel: Produktmodell $X=(X_1,\ldots,X_n)$, $X$ i.i.d. mit Dichtefunktion $g_\theta$. Dann ist die Likelihood $L(\theta;x)=\prod^n_i g_\theta(x_i)$, log-Likelihood $l(\theta;x)=\sum^n_i \log g_\theta(x_i)$. +\end{outline} + +\subsection{Maximum-Likelihood-Prinzip} + +\begin{outline} +\0 Konstruiere einen Schätzer $\hat{\theta}=T(X)$ für $\theta$: wähle den Parameterwert $T(x)$, für den der Beobachtungswert $x$ am plausibelsten ist, d.h. +$$L(T(x);x)=\max_{\theta\in\Theta}L(\theta_i;x) \qquad x\in S$$ + \1 Der Schätzer $\hat{\theta}=T(X)$ heißt \emph{Maximum-Likelihood-Schätzer} (MLS) für $\theta$, falls $T(X)\in \operatorname{argmax}_{\theta\in\Theta} L(\theta;x) \forall x\in S$ + \1 \textbf{Beispiel 1}: German tank problem + \2 $L(N;x)=f_N(x)=\frac{1}{|\Omega_N|}$ für $x\in \Omega_N$ und $0$ sonst. Das ist maximal für $N=\max \{x_1,\ldots,x_n\}$. Unser MLE ist $\hat{N}=\max\{x_1,\ldots,x_n\}$. +\end{outline} + +\marginnote[0cm]{6. Vorlesung, 26.04.24} + +\begin{outline} + \1 \textbf{Beispiel 2}: $Bernoulli(p)$, $L(p;X)=P_p(X_1=x_1,\ldots,X_n=x_n)=\prod_{i=1}^n p^{x_i}(1-p)^{1-x_i}$, + \2 $l(p,x)=\log(p)\sum_i x_i + \log(1-p)\sum_i(1-x_i)$, optimiere nach $p$ (Ableitung $=0$).\\ + \1 \textbf{Beispiel 3}: Schätzen einer unbekannten WV + \2 $\Theta$ = alle WVn auf $\hat{a}\in\R^n = \{\overline{p}:\sum p_i = 1\} \in \R^n$ ein Standard-Simplex, $X_1,\ldots,X_n$ unabängig mit Verteilung $p$ unter $P_p$. \2 $L(p;x)=P(X_1=x_1,\ldots,X_n=x_n)=\prod_i p_{x_i} = \prod_{l=1}^k p_l^{h_l}$, wobei $h_l$ = Häufigkeit von $p_l$. + \2 \textbf{Behauptung:} MLE $\hat{p}$ für $p$ ist $\hat{p}_l= \frac{H_l}{n}$ = relative Häufigkeit von $a_l$ mit Stichprobe $X_1,\ldots,X_n$. \textcolor{orange}{Empirische Verteilung ist MLE für zugrundeliegende WV!} Beweis mit Lagrange. + \1 \textbf{Beispiel 4}: Gauß-Modell + \2 $\Theta = \R \times (0,\infty)$, + \2 $L(m,v;x)=-\frac{n}{2}\log(2\pi v) - \frac{1}{2v}\sum(x_i-\overline{x})^2 - \frac{n}{2v}(\overline{x}_n-m)^2$ + \2 Schätzen von $m$ bei bekannter Varianz $v$, MLE $\hat{m}=\overline{X}_n$ + \2 Schätzen von $v$ bei bekanntem Mittelwert $m$, MLE empirische Varianz + \2 Schätzen von $\theta=(m,v)$ + \3 $m=\overline{X}_n$, $v=\frac{1}{n}\sum_i(x_i-\overline{x}_n)^2$ + \3 MLE $\hat{\theta}=(\overline{X}_n,V_n)$ (nicht erwartungstreu in $v$) +\end{outline} + +\subsection{Suffiziente Statistiken} + +\begin{outline} +\0 Datenreduktion, beinhaltet alle Informationen, die für Rückschlüsse auf $\theta$ relevant sind. Idee: Wahlprognose $X_1,\ldots,X_n \sim Bernoulli(p)$. Für Rückschlüsse auf $p$ reicht es, $\sum X_i$ zu wissen. + \1 Eine Statistik $T(X)$ heißt \emph{suffizient} für $\theta$, falls $$L(\theta,x)=f_\theta(x)=g_\theta(T(x))h(x) \quad\forall \theta \in \Theta, x\in S$$ + mit messbaren Funktionen $g_\theta:\R\ra [0,\infty]$, $h:S\ra[0,\infty]$. Likelihood hängt nur durch $T(X)$ von $\theta$ ab. + \1 Gilt $h(x)>0$,dann folgt daraus für MLE: $$\operatorname{argmax}_{\theta\in\Theta} L(\theta_i;x)=\operatorname{argmax}_{\theta\in\Theta}g_\theta(T(X)).$$ + und wenn das Maximum eindeutig ist (z. B. falls $l$ strikt konkav), dann ist MLE eine Funktion von $T(x)$. + \1 \textbf{Lemma}: $T(X)$ ist suffizient, wenn $P_\theta(X=x|T(x)=t)$ nicht von $\theta$ abhängt. + \1 Als Zweistufenmodell + \2 Ziehe $T(X)$ aus Verteilung von $T(X)$ (hängt von $\theta$ ab). + \2 Ziehe $X$ aus Verteilung von $X$ gegeben $T(X)$ (hängt nicht von $\theta$ ab). +\0 Die Idee: je größer die betrachtete Klasse von Wktsverteilungen, desto mehr Informationen muss die suffziente Statistik enthalten. + \1 \textbf{Satz}: Rao-Blackwell. Ein beliebiger Schätzer $\hat{g}$ kann verbessert werden, wenn man stattdessen die bedingte Erwartung $\Tilde{g}:=\E{\hat{g}|T(X)}$ betrachtet. +\end{outline} + +\subsection{Exponentielle Familien} + +\marginnote[0cm]{7. Vorlesung, 30.04.24} +\begin{outline} + \1 Definition: $f_\theta(x)=e^{c(\theta) \cdot T(x)+d(\theta)+U(x)}1_A(x)$ + \2 in natürlicher Form, $f_\theta(x)=e^{\theta\cdot T(x)+d(\theta)+U(x)} 1_A(x)$, + \2 alternative Schreibweise, $f_\theta(x)=\frac{1}{\cZ(\theta)}e^{c(\theta)\cdot T(x)}h(x)$, wobei + \3 Normierungskonstante $\cZ(\theta):=e^{-d(\theta)}$, + \3 Referenzdichte $h(x)=e^{U(x)}1_A(x)$ + \1 Beispiele: Exponentialverteilungen, Bernoulli-, Binomial-, Poisson-Verteilungen, Normalverteilungen. + \1 In einer exponentiellen Familie ist $T(X)$ eine suffiziente Statistik. + \1 Wichtige Eigenschaft: Stabilität under Produktbildung. +\marginnote[0cm]{8. Vorlesung, 03.05.24} + \1 Berechnung von Momenten: + \2 Momenterzeugende Funktion $M(s):=\E{e^{sT(x)}}=\int e^{sT(x)}f_\theta(x)dx = e^{d(\theta)-d(s+\theta)}<\infty$ + \2 Mit Algebra $M(s)=\frac{\cZ(s+\theta)}{\cZ(\theta)}=e^{d(\theta)-d(s+\theta)}<\infty$ + \3 eine Bedingung an $M(s)$: muss in der Umgebung von $0$ endlich sein + \3 $\E{T(X)}=\E{\nabla_s e^{sT(X)}|_{s=a}}=\nabla M(0)=-\nabla d(\theta)$ + \3 $\E{T_i(X)T_j(X)}=\ldots$ + \3 $\operatorname{Cov}[T_i(X)T_j(X)]=\ldots$ + \1 \textbf{Satz}: $\hat{\theta}$ ist MLS $\iff$ $\E{T(X)}=T(X)$ + \1 Berechnung des MLS: + \2 $l(\theta,X)=\log f_\theta (X)=d(\theta)+\theta T(X)+\log h(x)$ + \2 $\nabla l(\theta)=\nabla d(\theta) + T(X)=0 \iff \nabla(\theta)=-T(X) \iff \E{T(X)}=T(X)$. Der MLE ist genau der Parameterwert $\theta$, unter dem $T(X)$ dem Erwartungswert entspricht. +\end{outline} + +\subsection{Likelihood-Quotienten-Test} + +\begin{outline} +\0 Gegeben ist $H_0: \theta \in \Theta_0$, $H_1: \theta \in \Theta_1$. + \1 Ein Hypothesentest ist eine Funktion $\phi:S\ra [0,1]$ mit Verwerfenswahrscheinlichkeit $\phi(x)$. + \1 Der Verwerfungsbereich ist $C(X)=\{x\in S : \phi(x)=1\}$. + \1 Die Gütefunktion $G(\theta)=\E{\phi(X)}$, Erwartungswert der Wkt, die Nullhypothese zu verwerfen. + \1 Der Test hat Signifikanzniveau $\alpha$, falls $G(\theta)\leq \alpha \qquad\forall \alpha \in \Theta_0$. + \1 Die Macht des Hypothesentests ist $G(\theta)$ eingeschränkt auf $\Theta_1$. Kleinere Macht $\implies$ größere Wkt, die Nullhypothese fälschlicherweise nicht zu verwerfen, Fehler 2. Art. +\0 \textbf{Einfacher Likelihood-Quotienten-Test}, feste $\theta_0$ und $\theta_1$: + \1 Entscheidungsregel: relative Dichte $$R(x)=\frac{L(\theta_1;x)}{L(\theta_0;x)}>c,$$ + \1 Entscheidungsfunktion $\phi = 1_{R(x)>c} + p\cdot 1_{R(x)=c}$ + \1 \textbf{Neyman-Pearson-Lemma}: der LQT ist der mächtigste Test zum Niveau $\alpha$.\\ +\marginnote[0cm]{9. Vorlesung, 06.05.24} +\marginnote[0cm]{$\Theta_0$ und $\Theta_1$ sind jetzt ein Bereich, keine feste Parameter} +\0 \textbf{Monotone Likelihood-Quotienten}, $\theta_0\in\Theta_0$ und $\theta_1\in\Theta_1$: + \1 nach Definition gilt: + $$R(x)=\frac{L(\theta_1;x)}{L(\theta_0;x)}=\frac{\cZ(\theta_0)}{\cZ(\theta_1)} e^{\Large(c(\theta_1)-c(\theta_0)\Large)T(x)},$$ + \1 \textbf{Satz}: für das einseitige Testproblem $H_0 : \theta \leq \theta_0$, $H_1: \theta > \theta_0$ und falls der Likelihood-Quotient streng monoton wachsend in $T(X)$ ist, dann ist LQT $\phi(X)$ der gleichmäßig \emph{mächtigste} Test, + $$\E{\psi(X)} \leq \E{\phi(X)} $$ + +\0 \textbf{Allgemeine Likelihood-Quotienten-Tests}, (ad hoc) +$$R(x)=\frac{\sup \{L(\theta;x) : \theta \in \Theta_1\}}{\sup \{L(\theta;x) : \theta \in \Theta_0\}}$$ +\end{outline} + +\subsection{Studentsche Konfidenzintervalle und $t$-Test} + +\begin{outline} + \1 Einführung: Gauß-Modell mit unbekanntem Mittelwert und Varianz, Schätzung von $m$. + \2 Empirischer Mittelwert $\overline{X_n}(\omega)$ + \2 Varianz bekannt: Pivot + \2 Varianz unbekannt: Studentscher $t$-Test + \1 $\overline{X}_n\sim N(m,\frac{v}{n})$ und $\frac{n-1}{v}V_n \sim \chi^2(n-1)$ + \1 Verwende Studentsche $t$-Statistik mit $n-1$ Freiheitsgraden, $$T_{n-1}(X)=\frac{\sqrt{n}\cdot (\overline{X}_n - m)}{\sqrt{V_n}}.$$ +\marginnote[0cm]{10. Vorlesung, 10.05.24} + \1 Lemma 2.16: $$f_{\chi^2(n)}\propto x^{\frac{n}{2}-1}e^{-\frac{x}{2}} 1_{(0,\infty)}(x)$$ + und + $$f_{t(n)}(x) \propto (1+\frac{x^2}{n})^{-\frac{n+1}{2}} (\sim e^{\frac{x^2}{2}} \text{ für } n\ra \infty)¶.$$ +\0 Fazit: wir können die Varianz mit der Stichprobenvarianz ersetzen und dabei einen nicht allzu großen Fehler machen. + +\subsection{Anwendung auf Konfidenzintervalle \& Tests} + \1 ein Test ist \textbf{unverfälscht} zum Niveau $\alpha$, wenn $P(T(X)>c) \leq \alpha$ wenn $H_0$ wahr und $P(T(X)>c) \geq \alpha$ wenn $H_1$ wahr. In anderen Worten, $\E{\phi(\theta_0)}\leq \alpha \leq \E{\phi(\theta_1)}$ + \1 Studentscher $t$-Test ist ein LQT für Gauß-Modell und ist der beste unverfälschte Test i. S. v. oben. +\end{outline} + +\newpage + +\section{Entropie und Information} + +\marginnote[0cm]{11. Vorlesung, 14.05.24} +\begin{outline} +\0 Es geht um die stetige streng konvexe Funktion +$$u(x)= +\begin{cases} + x\log x & x > 0 \\ + 0 & x=0 +\end{cases}, \qquad u'(x)=1 + \log x, \qquad u''(x)=\frac{1}{x}$$ +\0 Es gilt $u(x)\geq x-1$ und $\min u(x) = \frac{1}{e}\log(\frac{1}{e})=-\frac{1}{e}$. + +\begin{figure} + \centering + \includegraphics[width=1\linewidth]{IMG_1665.jpeg} +\end{figure} + +\subsection{Entropie} + +\0 Die \textbf{Entropie} $H(\mu)$ von \textbf{diskreter} Wktsverteilung $\mu$ ist der mittlere Informationsgewinn beim Ziehen einer Stichprobe, also +$$H(\mu)=-\sum_{x\in S, f(x)\neq 0} f(x)\log f(x)= -\sum_{x\in S, f(x)\neq 0} u(f(x))$$ + + \1 Maß für Überraschung oder Informationszuwachs beim Eintritt von Ereignissen der Wkt $p\in[0,1]$ definieren wir als $-\log f(x)$, $f(x)$ ist die Massenfunktion für $\mu$ auf $S$. + + $$H(x)=\underbrace{-\log (f(x))}_{\text{Inform-zuwachs}} \cdot \underbrace{f(x)}_{\text{Wkt. von } x}$$ + + \1 Log, weil bei $n$ unabhängigen Stichproben wird aus der Information der Probe $-\log(\prod f_i(x_i))$ ergibt sich der Informationszuwachs als Summe einzelner Beobachtungen $-\sum \log f_i (x_i)$. + + \1 Die Entropie ist immer positiv, da $f(x)\log f(x)$ immer negativ für $f(x)\in [0,1]$. Das gilt nur im abzählbaren Fall! + + \1 Die Entropie ist eine strikt konkave Abbildung auf dem Raum der Wahrscheinlichkeitsverteilungen $WV(S)$. + +\0 \textbf{Beispiele}: + + \1 Bernoulli($p$), Einsetzen ergibt $H(Bernoulli(p))=-p \log p - (1-p)\log (1-p)$, Minimum bei $p=0$ oder $p=1$, Maximum bei $p=0.5$. Sprich, die Verteilung hat minimale Entropie bei $p=\{0,1\}$ und maximale Entropie bei $p=0.5$. + + \1 \textbf{Entropieminima}: Das Dirac-Maß hat minimale Entropie, da $H(\mu) = 0 \iff f(x)\in \{0,1\}$. + + \1 \textbf{Entropiemaximum}: Die Gleichverteilung hat maximale Entropie wenn $|S|$ endlich ist. Es gilt $H(Unif(S)) = -\log(1/|S|)=\log(|S|)\geq H(\mu)$ für alle anderen $\mu$. Das heißt, Gleichverteilung ist ein ungeordneter Zustand. + + \1 Entropie kann unendlich sein, falls $S$ wie oben unendlich ist. + + \1 Entropie der Produktverteilung $H(\mu_1 \otimes \ldots \otimes \mu_n)=\sum_i H(\mu_i)$. Beweis durchs Nachrechnen. + +\0 \textbf{Was bedeutet Entropie statistisch?} + \1 Nehme $n$ unabhängige Stichproben unter $\mu$. Betrachte relative Häufigkeit $\hat{p}(x_i)=\frac{\# x_i}{n}$ und die empirische Wkt $p(x_1,\ldots,x_n)=\prod_i \hat{p}(x_i)$ als empirische Likelihood-/Dichtefunktion $L(\mu;x_1\ldots x_n)=\prod_i \hat{p}(x_i)$. Gemittelt ergibt sich der mittlere Informationszuwachs als + +$$\overline{H(X_i)}=-\frac{1}{n} \log(\prod_i \hat{p}(X_i))= - \frac{1}{n} \sum_i \log \hat{p}(X_i).$$ +Die Entropie $H(\hat{p})$ ist der mittlere Informationsgewinn bei $n$ Stichproben. Wie verhält sich diese Größe asymptotisch, wenn $n\ra\infty$? + + \1 Satz von Shannon-McMillan I: + $$-\frac{1}{n}L(\mu;X_1\ldots X_n) \overbrace{\ra}^{n\ra\infty} H(\mu) \text{ almost surely}$$ + Beweis durch GGZ, $\frac{1}{n}l(\mu;X)=\frac{1}{n}\sum_i \log(f(X_i))$, Summanden immer negativ, GGZ anwendbar, also konvergiert die Summe gegen den Erwartungswert $\int \log f d\mu = \sum f(x)\log (f(x)) = -H(\mu)$. \textbf{Entropie ist $\E{H(X)}$}!!! + +\0 In der Statistik geht es darum, zwei Wktsverteilungen voneinander zu unterscheiden. Das lässt sich durch relative Entropie quantifizieren. +\end{outline} + +\subsection{Relative Entropie} + +\begin{outline} +\0 Gegeben sind zwei Wktsverteiliungen $\mu, \nu$. Die \textbf{relative Entropie} $H(\mu|\nu)$ für absolutstetige Wahrscheinlichkeitsmaße ist nicht symmetrisch und definiert \textbf{bezüglich $\nu$}. +$$H(\mu|\nu) = \int_{\R^d}\frac{f(x)}{g(x)}\log\left(\frac{f(x)}{g(x)}\right)dx.$$ + \1 $\mu$ muss absolutstetig bzgl. $\nu$ sein, Notation $\mu \ll \nu$ + \1 dann existiert relative Dichte $\omega=\frac{d\mu}{d\nu}$ + \2 $\mu[B]=\int_B \omega d\nu \quad \forall B \in \cB$ (Lebesgue-Stieltjes?). Kurzschreibweise \enquote{$\mu = \omega d\nu$}. Das ist eindeutig bis auf $\nu$-Nullmengen (man kann eventuell das Maß auf einer Nullmenge ändern, aber ist grds. egal). Die Dichte ist größer gleich Null und strikt größer als Null $\mu$-f.ü, nicht $\nu$-f.ü. + \2 In dieser Vorlesung sind $S$ abzählbar oder $\R^d$, $\mu,\nu$ mit Massenfunktion/Dichte $f,g$ (sie existieren). +\marginnote[0cm]{$\mu$ hat Verteilung $f$, $ \nu$ hat Verteilung $g$.} +\1 wenn Nullmengen von $\nu$ in Nullmengen von $\mu$ enthalten sind, $\{g=0\}\subseteq \{f=0\}$, dann $\mu \ll \nu$ und es gilt für Dichte +$$\omega(x)=\frac{d\mu}{d\nu}(x)= +\begin{cases} + \frac{f(x)}{g(x)} = \frac{L(x,\mu)}{L(x,\nu)} & g(x)>0 \\ + \text{beliebig} & g(x)=0 \text{ (Nullmenge)} +\end{cases} +$$ + \1 Beim Entfernen von $g$ Nullmengen ändert sich $\int f(x)dx$ nach Voraussetzung nicht. Dann kann man $f(x)$ durch $\frac{g(x)}{g(x)}$ ergänzen und $\omega(x)g(x)$ bekommen. Das ist aber genau die relative Dichte $\int \omega d\nu$. + + \1 Rechenregeln: + \2 $\int h d\mu = \int h \frac{d\mu}{d\nu} \quad \forall h\geq 0$ messbar, + \2 $m \ll \nu \ll \eta$ impliziert $\mu \ll \eta$ mit $\frac{d\mu}{d\eta} = \frac{d\mu}{d\nu}\cdot \frac{d\nu}{d\eta}$ + \2 Umgekehrt, wenn $m\ll\nu$ und $\frac{d\mu}{d\nu} > 0$ $\nu$-f.ü., dann $\nu \ll \mu$ mit $\frac{d\nu}{d\mu}=\frac{1}{\frac{d\mu}{d\nu}}$. + + \1 \textbf{Relative Entropie} von $\mu$ bzgl. $\nu$ ist definiert als + $$H(\mu | \nu):=\int \log\left(\frac{d\mu}{d\nu}\right)d\mu = \int u \frac{d\mu}{d \nu} d\nu \quad \text{wenn } \mu\ll \nu$$ + und ist auch als Kullback-Leibler-Divergenz von $\mu$ bzgl $\nu$ bekannt. + + \1 \textbf{Beispiel:} Sei $\nu$ unser Modell, $\mu$ tatsächliche Verteilung. Dann ist $H(\mu|\nu)= \int \log \frac{f}{g}d\mu = \int (-\log g -(-\log f)) d\mu$ + \2 $-\log g$ ist Überraschung in unserem Modell beim Ziehen einer Stichprobe, + \2 $-\log f$ ist Überraschung beim korrekten Modell, + \2 die Differenz von beiden ist die Überraschung daraus, dass wir aus dem falschen (Alternativhypothese) Modell eine Stichprobe gezogen haben und das Integral ist ein Mittelwert darüber, + \2 hätten wir ein korrektes Modell, dann wäre die Überraschung gleich Null. + + \1 \textbf{Interpretation 1}: Ist $S$ abzählbar und $\nu$ ein Zählmaß (keine Wktsverteilung), dann gilt $H(\mu|\nu)=\sum f(x)\log(f(x))=-H(\mu)$. Relative Entropie bzgl. des Zählmaßes entspricht also Minus der Entropie. \\ + + \1 \textbf{Interpretation 2}: Ist $S$ endlich und $\mu=Unif(S)$, dann gilt $H(\mu|\nu)=\sum f(x) \cdot \log(\frac{f(x)}{1/|S|})=\sum f(x)(\log(f(x))+\log(|S|)=-H(\mu)+\log(|S|)$. Entropie der Wktsverteilung ist gleich der Entropie von der Wktsverteilung verschoben um eine Konstante. Insbesondere gilt $H(\mu |\nu)\geq 0 \implies H(\mu)\leq \log(|S|) = H(Unif(S))$. Also hat Gleichverteilung wirklich eine maximale Entropie. + +\1 Eigenschaften der relativen Entropie: + \2 $H(\mu |\nu) \geq 0$ und Null gdw $\mu=\nu$ + \3 $H(\mu|\nu)=\int u\frac{d\mu}{d\nu}d\nu$ (interpretiere als $x\log x$) $\geq \int \frac{d\mu}{d\nu}d\nu-\int 1 d \mu = 0$ nach der Ungleichung $u(x)\geq x-1$ + \3 Die Gleichheit in der Abschätzung oben oben gilt gdw $u(\frac{d\mu}{d\nu})=\frac{d\mu}{d\nu}-1$ $\nu$-f.ü. $\iff \frac{d\mu}{d\nu}=1$ $\nu$-f.ü. $\iff \mu=0$. + \2 $H(\mu_1\otimes\ldots\otimes\mu_n |\nu_1\otimes\ldots\otimes\nu_n)=\sum^n_{i=1}H(\mu_i | \nu_i)$ + \3 ohne Beweis, Übung (LOL) + +\0 \textbf{Beispiel}: $H(Bernoulli(a) | Bernoulli(b)) = a \log a/p + (1-a)\log \frac{1-a}{1-p}$ +\begin{figure} + \centering + \includegraphics[width=1\linewidth]{IMG_1666.jpeg} +\end{figure} + +\0 \textbf{Beispiel}: Normalverteilungen. + +\marginnote[0cm]{Prof: \enquote{Was wir hier sehen, ist so eine Art Abstandsbegriff für Wktsverteilungen, der nicht symmetrisch ist.}} + +\subsection{Relative Entropieminimierung unter Nebenbedingung} +\0 \textbf{Anwendung}: Wir wollen für eine Wktsverteilung $\mu_0$ (Referenz) relative Entropie minimieren und eine andere Wktsverteilung finden, gegeben einen festen Abstand $c\in \R$. Mathematisch gilt $H(\mu |\mu_0)=\min \int Td\mu \geq m$. Das ist genau der Fall, wenn die Verteilung aus der exponentiellen Familie ist.\\ + +\0 \textbf{Exponentielle Familie}: wie bereits vor zwei Wochen gemacht. Wichtig ist der Erwartungswert $m(\theta)=\int T d\mu_\theta$, auch $\mu_\theta \ll \mu_0$ mit $\frac{d\mu_\theta}{d\mu_0}(x)=\frac{Z(0)}{Z(\theta)}e^{\nu T(x)}$ +\1 Gibbssches Variationsprinzip: für $\theta\geq 0$ ist $\mu_\theta$ die eindeutige Lösung von dem Minimierungsproblem mit $m=m(\theta)$. +\marginnote[0cm]{Prof: \enquote{In der Thermodynamik ist die Aussage, dass diese ... Verteilung minimiert die relative Entropie unter den gegebenen Nebenbedingungen.}} +\end{outline} + +\marginnote[0cm]{12. Vorlesung, 17.05.24} +\begin{outline} +\0 Recap: relative Dichte wohldefiniert wenn Nenner nicht 0, relative Dichte als Quotient, relative Entropie als Integral, Bezug zu exponentiellen Familien wenn wir Entropie minimieren, global einfach die Verteilung selbst, lokal (mit bestimmten Erwartungswert) immer eine exponentielle Familie. Das möchten wir beweisen. + \1 Beweis Gibbssches Variationsprinzip. + \2 Definiere relative Entropie von $\mu$ bzgl. $\mu_0$, $F(\mu)=H(\mu|\mu_0)-\theta\int T d\mu$. + \2 $H(\mu_\theta | \mu_0)=\min \{H(\mu|\mu_0): \mu WV mit \int T d\mu = \int Td\mu_\theta\}$ + \2 $H(\mu|\mu_0)=\int \log\frac{d\mu}{d\mu_0}d\mu=\int \log \frac{d\mu}{d\mu_\theta}d\mu + \int \log \frac{d\mu_\theta}{d\mu_0}d\mu\ldots$ +\end{outline} + +\subsection{Anwendungen in der Statistik} +\begin{outline} +\0 Wir werden subexponentielle Terme ignorieren. Wenn $a_n, b_n > 0$ zwei Folgen sind, dann sind sie asymptotisch äquivalent, $a_n \simeq b_n$, wenn +$$\lim_{n\ra\infty}\left(\frac{a_n}{b_n}\right)^\frac{1}{n}=1,$$ +oder, +$$\lim_{n\ra\infty}\frac{1}{n}\log\left(\frac{a_n}{b_n}\right)=0.$$ + \1 Beispiel: $n^\alpha e^{cn}\simeq n^\beta e^{dn} \iff c=d$. +\marginnote[-1cm]{Prof: wir interessieren uns nur für Abweichungen, die groß genug sind...} + \1 Setup: $X_1,\ldots,X_n$ i.i.d., mächtigster Test für $X_i\sim \nu$ vs. $X_i\sim \mu$ ist LQT, $$\lambda_n(X_1,\ldots,X_n)=\frac{L_n(\mu,X)}{L_n(\nu,X)}=\prod_i w(X_i)$$ das Produkt der relativen Dichte der zugrundeliegenden Veteilungen. Uns interessiert das asymptotische Verhältnis des LQTs für $n\ra\infty$... + +\1 Satz von Shannon-McMillan II: +$$Z_n \simeq e^{nH(\mu|\nu)}, \quad Z_n\simeq e^{-nH(\nu|\mu)}$$ +Relative Entropie misst die asymptotische Unterscheidbarkeit von $\mu$ und $\theta$. + +\1 Konsistenz: für $n\ra\infty$ die Folge $\hat{\theta}_n := \hat{\theta}(X_1,\ldots,X_n)$ konvergiert zu $\theta$. +\1 Asymptotische Macht von LQT + \2 zu einem festen Niveau $\alpha$ gilt, dass $\lim_{n\ra\infty} \frac{1}{n}\log c_n = H(\nu | \mu)$, + \2 $\lim_{n\ra\infty} \frac{1}{n} \log \mu^n (w_n\leq c_n) \ra -H(\nu | \mu)$ +\end{outline} + +\subsection{Fisher-Information} +\begin{outline} + \1 Regularitätsannahmen: + \2 $\theta \neq \theta' \implies \mu_\theta \neq \mu_{\theta'}$ + \2 $\forall x\in S,\theta\in \Theta$: $f_\theta(x) > 0$ + \2 $f_\theta(x)\in C^3(S)$ + \2 $\int \frac{\partial}{\partial\theta}f_\theta(x)dx = + \frac{\partial}{\partial\theta} \int f_\theta(x)dx=0$ + \1 Definiere Fisher-Information des parametrischen Modells als + $$I(\theta)=\int \frac{1}{f_\theta(x)} |\frac{\partial f_\theta(x)}{\partial\theta}|^2 dx = \int l'(x)^2 f_\theta(x) dx$$ +\marginnote[0cm]{13. Vorlesung, 28.05.24} + \1 Zusammenhang mit relativer Entropie -- infinitesimale Änderung + \1 Cramer-Rao-Schranke: für den MSE jedes erwartungstreuen Schätzers gilt + $$MSE_\nu(\hat{g})=Var_\nu(\hat{g})\geq \frac{g'(\nu)^2}{I(\nu)}.$$ + \2 (Konstante Schätzer haben Varianz 0, die Erwartungstreue ist also notwendig.) + \2 Beweis: Cauchy-Schwartz für Kovarianz. +\0 \textbf{Beispiele:} Bernoulli, $\hat{p}=X$ mit Varianz $p(1-p)=\frac{1}{I(p)}, g(p)=p$. Optimal! Normalverteilung, $\hat{m}=\overline{X}, Var(\hat{m})=v=\frac{1}{I(m)}$. Optimal! Allgemein: unter welchen Bedingungen haben wir Gleichheit? Wenn die Cauchy-Schwartz-Ungleichung im Beweis scharf ist bzw. Gleichheit gilt. Das ist genau dann der Fall, wenn $l'(\theta, x)$ als affine Funktion von $T(X)$ darstellbar ist, $a(\theta) T(X)+b(\theta)$. + \1 Anwendung auf Produktmodell der Normalverteilung, der beste Schätzer im Sinne von oben hat Effizienz $\Omega(1/n)$. +\0 \textbf{Beispiele:} Wieder Normalverteilung, Gleichverteilung auf $(0,\theta)$. Wir haben vor vier Wochen einen supereffizienten Schätzer mit Varianz $O(n^{-2})$ ausgerechnet. Was läuft hier falsch? Die Dichte in diesem Fall ist nicht differenzierbar und die Regularitätsannahme ist damit nicht erfüllt. +\end{outline} + +\marginnote[0cm]{14. Vorlesung, 31.05.24} +\begin{outline} +\0 \textbf{Anwendung von der Informationsungleichung}: Lokationsmodell, $f_\theta(x)=g(x-\theta)$, $g$ ist stetig und symmetrisch. Sei $\hat{\theta}$ ein erwartungstreuer Schätzer für $\nu$, dann nach Informationsungleichung gilt +$$Var_\theta(\hat{\theta}_n) \geq \frac{1}{nI(\theta)} \forall \theta\in\Theta$$ +Es gilt auch $I(\theta)=\E{l'(\theta,X)^2}=\int \frac{g'(x-\theta)^2}{g(x-\theta)}dx=\int\frac{g'(x)^2}{g(x)}dx \forall \theta$ + \1 $I(\theta)$ groß $\iff$ hohe Unterscheidbarkeit $\iff$ kleine Varianz möglich +\0 Definiere \emph{asymptotische Effizienz} als $Var(\hat{\theta}_n)\to \frac{1}{nI(\theta)}, n\mapsto \infty$. + \1 Stichprobenmittlwert\ldots + \2 effizient bei der Normalverteilung, nicht asymptotisch effizient bei der Doppelexponentialverteilung, sehr schlecht bei heavy tails + \1 Stichprobenmedian\ldots + \2 nicht asymptotisch effizient bei der Normalverteilung, asymptotisch effizient bei der Doppelexponentialverteilung, akzeptabel bei heavy tails. Median ist sehr robust! +\0 Unterschied liegt darin, dass der MLE für NV und DEV genau der Mittlwert/Median ist. \\ +\0 \textbf{Asymptotische Normalität von MLE}: Satz von Fisher, Wilks, Wald und Beweis(-skizze). +\end{outline} + +\newpage + +\section{Empirische Verteilung} +\marginnote[0cm]{15. Vorlesung, 04.06.24} + +Nicht-parametrische Modelle. Die empirische Wahrscheinlichkeitsverteilung ist eine Zufallsvariable mit Werten in dem Raum von Wktsverteilungen $WV(S)$, da sie von der Stichprobe abhängt. + +\begin{outline} + \1 empirische Verteilung $L_n$ +\0 Die empirische Verteilung $L_n$ ist eine zufällige Wktsverteilung, d. h. $L_n$ ist eine Zufallsvariable mit Werten in $WV(S)$. Für jede disjunkte Zerlegung von $S= B_1\cup B_2 \cup \ldots \cup B_n$ gilt $(H(B_1),H(B_2),\ldots,H(B_n)) \sim Mult(n, \mu(B_1),\ldots, \mu(B_n))$.\\ +\0 Wir verwenden $\hat{\mu}_n:=L_n$ als Schätzer für $\mu$ und es gilt $$\E{\hat{\mu}_n(B)}=\mu(B)$$ und $$\Var{\hat{\mu}_n(B)} = \frac{\mu(B)(1-\mu(B))}{n}\leq \frac{1}{4n}.$$ + \1 Satz von Vardarajan: \textbf{Konsistenz} von $L_n$, \url{https://math.stackexchange.com/questions/2602960/proof-of-weak-convergence-of-empirical-measure} + \1 Dvoretzky–Kiefer–Wolfowitz Ungleichung: \url{https://en.wikipedia.org/wiki/Dvoretzky%E2%80%93Kiefer%E2%80%93Wolfowitz_inequality} +\end{outline} + +\subsection{Plug-in Schätzer} + +\begin{outline} + \1 statistisches Funktional $g:P\subseteq WV(S)\ra \R$ + \2 Funktion von $L_n$ + \1 Plug-in Schätzer $\hat{g}_n := g(L_n)$ + \2 Austausch von der unbekannten Verteilung $\mu$ in der Definition (bzw. im Integral) durch die empirische Verteilung $L_n$ und Übergang zum diskreten Fall (also Summen) +\end{outline} + +\subsection{Bootstrap} + +\begin{outline} + \1 Bootstrap-Verfahren + \1 Bootstrap-Stichprobe + \2 multinomiales Resampling + \1 Konfidenzintervall + \2 Normalapproximation + \2 empirische Quantile: $[2\hat{g}_n-\hat{q}_{1-\frac{\alpha}{2}}(\hat{g}_n^{(1)}\ldots\hat{g}_n^{(B)}), 2\hat{g}_n-\hat{q}_{\frac{\alpha}{2}}(\hat{g}_n^{(1)}\ldots\hat{g}_n^{(B)})]$ +\end{outline} + +\marginnote[0cm]{16. Vorlesung, 07.06.24} +Skipped + +\subsection{Anpassungstests} + +\marginnote[0cm]{17. Vorlesung, 11.06.24} +Skipped + +\marginnote[0cm]{18. Vorlesung, 14.06.24} + +\begin{outline} +\1 Normalapproximation der Multinomialverteilung + \2 degenerierte Normalverteilung $\implies$ Projektion auf Hyperebene +\1 Chiquadrat-Statistik +\1 Satz: Die Approximation konvergiert gegen $N(0,I_{k-1})$ für $n\to\infty$ +\1 Satz: Chiquadrat-Statistik konvergiert gegen $\chi^2(k-1)$ für $n\to\infty$ +\0 Beweise dazu... sehr lang! + + \1 Anwendung auf Anpassungstests, $H_0 : \mu = \mu_0$ + \2 $\chi^2$-Test: verwerfe, falls $T=n D_2(L_n | \mu_0) \geq c$, + \2 G-Test: verwerfe, falls $G=nH(L_n | \mu_0) \geq \frac{c}{2}$. + \2 Beide Tests erfüllen asymptotisch die Niveaubedingung für $n\to\infty$ falls $c=q_{1-\alpha, \chi^2(k-1)}$ +\marginnote[0cm]{$2G$ ist wie $T$} +\0 Ergänzung: hier testen wir, ob die Wahrscheinlichkeitsverteilung die eine Wktverteilung ist. Eigentlich möchten wir testen, ob es eine Verteilung aus gegebener endlichdimensionalen Familie ist $\implies$ der Anpassungstest für parametrische Familien, wobei $H_0 : \mu \in \{\mu_\nu : \theta \in \Theta\}$ eine $d$-dimensionale Mannigfaltigkeit. G-Test mit Parameterschätzung. Satz von Wilks: unter der Annahme konvergiert $P\circ (2G)^{-1}$ gegen $\chi^2(k-1-d)$. +\marginnote[0cm]{Wichtig: wir haben nur endlich viele Zustände.} + \1 Alternative zu Anpassungstests: Konfidenzbereich für $\mu$. + \2 für Multinomialverteilung bestimme also $k$ Konfidenzbereiche für Binomialverteilung\ldots + \2 Vorteil: Kontrolle über jeden einzelnen Parameter + \2 Nachteil: für $n=10$ müssen einzelne Konfidenzbereiche zu $\frac{\alpha}{10}$ bestimmt und geschnitten werden. Brauche mehr Stichprobenwerte, um dasselbe Niveau zu erreichen. (\enquote{Bonferroni-Korrektur}). +\end{outline} + +\marginnote[0cm]{19. Vorlesung, 18.05.24} + +\begin{outline} + \1 Satz von Glivenko-Cantelli + \1 Wie testet man auf Normalverteilung? Weitere Anpassungstests: + \2 Kolmogorov-Smirnov-Test + \2 Lilliefors-Test auf Normalverteilung + \3 $\beta$ ist skaleninvariant + \3 Probleme mit tails + \2 Anderson-Darling-Test + \2 Abweichungen in tails sind nur schwer erkennbar. Alternative: wir verwerfen, falls ein Integral größer $\varepsilon$ ist. +\0 Anmerkung: kein Anpassungstest ist perfekt. Mehrere Tests ausprobieren. +\end{outline} + +\subsection{Robuste Verfahren} + +\begin{outline} +\0 $\mu$ auf $\R$, $X_1,...,X_n \sim \mu$ i.i.d. + \1 ein fehlender Datenwert kann $\overline{X}_n$ beliebig verfälschen = nicht robust + \1 besser ist z. B. der Median $q_\frac{1}{2}$, Ordnungsstatistik = robust +\0 Wir charakterisieren Robustheit von $T_n$ bei $(x_1,\ldots,x_n)$ über: + \1 Bruchpunkt \[\varepsilon_n(X)=\frac{1}{n}\max_{k\in\{0,1,\ldots,n\}}\{\sup_{y_i\neq x_i k-mal} | T_n(y_1,\ldots,y_n)|<\infty\}\] + \1 asymptotischen Bruchpunkt $\varepsilon := \liminf_{n\to\infty} \varepsilon_n(X)$ + \1 die Sensitivitätsfunktion + \1 die Einflussfunktion +\0 Robuste Konfidenzintervalle für Quantile + \1 Schätze $q_\gamma$ mit Plugin-Schätzer $\hat{q}_\gamma = X_{(n\gamma)}$. Bestimme Konfidenzintervall + \1 Satz: die Wkt, dass das Gamma-Quantil zwischen zwei Ordnungsstatistiken liegt, beträgt die Differenz der Verteilungswerte. + \2 Verteilungsunabhängige Konfidenzintervalle! Großer Vorteil. +\0 Robuste Konfidenzintervalle für Tests + \1 Test für Median von zwei Stichproben + \2 Option 1, Mittelwert: $t$-Test. Probleme: keine Normalverteilung, Ausreißer/Messfehler, + \2 Option 2, Median: verwerfe $H_0$ falls $X_{(k)}>0$. Pearsons Vorzeichentest. Vorteil: sehr robust, unabhängig von der Verteilung. Nachteil: Größe der $X$ spielt keine Rolle. + \2 Option 3, Wilcoxon-Signed-Rank-Test: +\end{outline} + +\marginnote[0cm]{20. Vorlesung, 21.06.24} + +\section{Zusammenhang mehrerer Merkmale} + +\subsection{Binäre Merkmale: Chancenquotienten und Vierfeldertafeln} + +\marginnote[0cm]{21. Vorlesung, 25.06.24} + +\begin{outline} + \1 $Chance(A):=\frac{P(A)}{P(A^C)}=\frac{P(A)}{1-P(A)}$ + \2 nichtlineare Transformation $p \mapsto \frac{p}{(1-p)}$ + \1 Chancenquotient $\rho:=\frac{p_{11}p_{00}}{p_{10}p_{01}}=\frac{Chance(X=1 |Y=1)}{Chance(X=1 |Y=0)},$ + \2 Aus $\rho =1$ folgt $X,Y$ unabhängig und $p_{kl}=p_{k+}p_{+l}$ + \1 Schätzer für $\rho$: Plug-in Schätzer $\hat{\rho}$ + \1 Konfidenzintervall für $\rho$ + \2 Modell: $(H_{11}, H_{10}, H_{01}, H_{00}) \sim Mult(N,p_{11},p_{10},p_{01},p_{00})$ +\marginnote[0cm]{22. Vorlesung, 28.06.24} +\marginnote[0cm]{Dümbgen, 7.5} + \2 Dieselben KI wie beim \textbf{Fischers exakten Test} mit Konfidenzintervallen. Idee: gegeben $\rho$, können wir die bedingte Wkt. $p(H_{11} |H_{1+})$ und $p(H_{11} |H_{+1})$ ausrechnen.\\ + \begin{tabular}{|l|c|c|c|} + \hline + \multicolumn{1}{|c|}{\multirow{2}{*}{Haarfarbe}} & \multicolumn{3}{c|}{Augenfarbe} \\ + \cline{2-4} + & grün & nicht grün & \multicolumn{1}{c|}{} \\ + \hline + rot & 14 & 57 & 71 \\ + \hline + nicht rot & 50 & 471 $H_{00}$ & 521 \\ + \hline + & 64 & 528 & 592 N \\ + \hline + \end{tabular} + \2 Lemma: $p(H_{11} |H_{+1}=l, H_{1+}=n) = C_{n,l,N,\rho}\binom{n}{x}\binom{N-n}{l-x}\rho^x$ und die Konstante $C$ hängt nicht von $x$ ab. + \2 Wir können aus diesen Wkten die Konfidenzintervalle für $\rho$ herleiten. Bedingte Wkt => Verteilungsfunktion => Konfidenzschranken über Umkehrfunktion + \2 Bei diesem Test typisch ist $H_0 : \rho = 1$, $H_1 : \rho > 1$. +\1 \textbf{Vierfeldertafeln, modifiziertes Modell}. + \2 Im Unterschied zur oben sind $n_1, n_2$ fest vorgegeben.\\ + \begin{tabular}{|l|c|c|c|} + \hline + & Besserung & keine Besserung & \\ + \hline + Medikament & $H_{11}$ & $H_{12}$ & $n_1$ \\ + \hline + Placebo & $H_{21}$ & $H_{22}$ & $n_2$ \\ + \hline + & $H_{+1}$ & $H_{+2}$ & $N$ \\ + \hline + \end{tabular} + \2 Modell: $H_{11}\sim Bin(n_1,p_1), H_{21}\sim Bin(n_2,p_2)$ unabhängig. + \2 Wie oben. +\end{outline} + +\subsection{Test auf Unabhängigkeit/Assoziation} +\begin{outline} +\0 Gegeben $X_{1\leq k \leq n}$ und $Y_{1\leq l \leq N}$ entscheide, ob die gemeinsame Verteilung das Produkt der Randverteilungen ist, d. h. wenn $p_{kl}=p_k p_l=:\hat{p}_{kl}$ für alle $k,l$. + \1 Die Nullhypothese $H_0 : p=\hat{p}$ + \1 Methode 1, multiple Tests: Fishers exakter Test für jeden $k$ und $l$ + \1 Methode 2, Chiquadrat-Test auf Unabhängigkeit: schätze $\chi^2$-Divergenz $$\chi^2(p|\overline{p})=\sum_{k,l}\left(\frac{p_{kl}}{\overline{p_{kl}}}-1\right)^2 p_{kl}=\sum_{k,l}\frac{p_{kl}^2}{\overline{p_{kl}}}-1$$ + Die Schätzung machen wir mit dem Plug-In Schätzer (empirische Verteilung). Unter Nullhypothese ist der Wert Null. + \2 Berechnung des p-Werts: entweder exakt (bei kleinen Datensätzen) oder Bootstrap. + \2 Alternativ kann man Divergenz durch relative Entropie ersetzen. + \1 $\chi^2$-Approximation ($N$ groß) mit $(k-1)(l-1)$ Graden. + \2 Nachrechnen bestimmter Eigenschaften der $\chi^2$-Verteilung +\end{outline} + +\subsection{Permutationstests} + +\marginnote[0cm]{23. Vorlesung, 02.07.24} +\marginnote[0cm]{Dümbgen 8.1-8.3} + +\begin{outline} + \1 $(H'_0):$ \textbf{bedingte Austauschbarkeit} von $Y$ gegeben $X$, wenn für $\pi\in Sym(n)$ gilt $(X,\pi Y)\sim (X,Y)$. + \1 Lemma: Sei $\pi$ zufällige Permutation, dann gilt für alle feste $x,y$, dass Erwartungswert der Häufigkeiten unter $\pi$ dem naiven Produktmaß entspricht. Der Erwartungswert der Statistik beträgt $\frac{N}{N-1}(k-1)(l-1)$. + \1 Satz: $\ldots$ +\0 \textbf{Ziel:} Untersuchen, ob die ZV unter Permutation invariant in der Verteilung sind. Gegeben ist eine Permutation $\pi\in G$, dabei $G$ eine Untergruppe von $Sym(n) \implies$ $G$-Invarianztest. + \1 Test auf identische Verteilung von $X,Y$ + \2 $\pi(X,Y) = (\pi X, \pi Y)\sim (X,Y)$ + \1 Test auf Unabhängigkeit $X,Y$ + \2 bedingte Austauschbarkeit $\pi(X,Y)=(X,\pi Y)$ + \1 Test auf Vorzeichensymmetrie + \2 Tendenz für positive/negative Vorzeichen +\0 Konstruktion von Tests via $G$-Symmetrie. Sei $T$ eine beliebige Statistik, $(x,y)\in S^{n+m}$ Datenvektor. Definiere + \1 linksseitiger $p$-Wert: $p_l^G(x,y) = \frac{|\{\pi \in G: T(\pi(x,y))\leq T(x,y)\}|}{|G|}=P(T(\pi(x,y)) \leq T(x,y))=F_{\{T(\pi(x,y))\}} (T(x,y))$. + \1 Berechnung von $p_l^G(x,y)$. Abzählen (wenn $G$ klein), Monte-Carlo. + \1 Satz: unter $(X,Y)\sim \pi(X,y)$ gilt $p_l^G(X,Y)\leq \alpha$ kann höchstens mit Wkt. $\alpha$ gelten. +\0 Beispiel 1: Test auf identische Verteilung, $G=Sym(n+m), T(X_1,...,X_n,Y_1,...,Y_m)=|M_X-M_Y|$, dabei sind $M_X,M_Y$ Mittelwerte/Mediane/... von $X$ und $Y$.\\ +\0 Beispiel 2: Test auf Unabhängigkeit, $G=Sym(n), (X_n,Y_n)$ aus $\{0,1\}\times \R $ und $\pi(X,Y)=(X,\pi Y), T(X,Y)=\sum_i 1_{X_i=1} R_i$. Dann könnte man erkennen, ob eventuell kleine/große Ranks von $Y$ überwiegen. +\end{outline} + +\section{Regression} + +\subsection{Einfache lineare Regression} +\marginnote[0cm]{24. Vorlesung, 05.07.24} + +\subsection{Lineare Modelle} +\marginnote[0cm]{25. Vorlesung, 09.07.24} + +\begin{outline} + \1 Modell: $Y=\sum^d_k \omega_k X^{(k)}+ \varepsilon = A\omega + \varepsilon$ + \2 Beobachtung $Y:\Omega \ra \R^n$ + \2 unbekannte Parameter $\omega_1,\ldots,\omega_d \in \R$ + \2 Störgrößen $\varepsilon : \Omega\ra\R^n$ + \2 Design-Matrix $A=(X^{(1)}, \ldots, X^{(d)})$ eine $n\times d$-Matrix mit Rang $d$ + \1 Beispiele: einfache Regression, multiple lineare Regression, polynomielle Regression, Einstichproben-Lokationsmodell, $\ldots$ + \1 Beispiel Mehrstichprobenmodell: Vergleich von $p$ verschiedenen Populationen, z. B. Ertrag bei $p$ verschiedenen Düngersorten. + \marginnote[0cm]{$(i=1, \ldots, p; k=1,\ldots,n_i)$,\\ $n_i$ Anzahl Stichproben in Gruppe $i$} + \2 Response $Y_{ik}=m_i + \varepsilon_{ik}$ von Objekt $k$ in Gruppe $i$ + \2 $A=\begin{pmatrix} + 1_{n_1} & 0 & 0\\ + 0 & \ddots & 0\\ + 0 & 0 & 1_{n_p} + \end{pmatrix}$, $1_{n_i}=\begin{pmatrix} + 1 \\ + \vdots \\ + 1 + \end{pmatrix} \in \R^{n_i}$ + \2 Idee: ANOVA, vergleiche die Varianz zwischen den Gruppen mit der Varianz innerhalb der Gruppen, $H_0 : m_1 = \ldots = m_p$. + \2 Vergleiche $\hat{V}_{ZG}$ und $\hat{V}_{iG}$ + \2 Gauß-Fall: $\frac{\hat{V}_{ZG}}{\hat{V}_{iG}} \sim \frac{\frac{v}{p-1}\sum^{p-1}_{i=1} Z_i^2}{\frac{v}{n-p}\sum^{n-1}_{i=p}Z_i^2} = F_{p-1,n-p}$ und $Z_i\sim N(0,1)$ unabhängig. + \2 Die Verteilung von $F_{p-1,n-p}$ heißt Fisher-Verteilung mit $p-1$ und $n-p$ Freiheitsgraden. +\0 \textbf{Schätzer für $\omega$}: $Y=A\omega + \varepsilon$ + \1 kann nicht perfekt klappen, $\dim A < \dim Y, d{debug}{\setboolean{@tufte@debug}{true}} + +%% +% `nofonts' option -- doesn't load any fonts +% `fonts' option -- tries to load fonts +\newboolean{@tufte@loadfonts}\setboolean{@tufte@loadfonts}{true} +\DeclareOptionX[tufte]{fonts}{\setboolean{@tufte@loadfonts}{true}} +\DeclareOptionX[tufte]{nofonts}{\setboolean{@tufte@loadfonts}{false}} + +%% +% `nols' option -- doesn't configure letterspacing +% `ls' option -- configures letterspacing +\newboolean{@tufte@letterspace}\setboolean{@tufte@letterspace}{true} +\DeclareOptionX[tufte]{ls}{\setboolean{@tufte@letterspace}{true}} +\DeclareOptionX[tufte]{nols}{\setboolean{@tufte@letterspace}{false}} + +%% +% `nobib' option -- doesn't load natbib or adjust the \cite command +\newboolean{@tufte@loadnatbib}\setboolean{@tufte@loadnatbib}{true} +\DeclareOptionX[tufte]{nobib}{\setboolean{@tufte@loadnatbib}{false}} + +%% +% `titlepage' option -- creates a full title page with \maketitle + +\newboolean{@tufte@titlepage} +\DeclareOptionX[tufte]{titlepage}{\setboolean{@tufte@titlepage}{true}} +\DeclareOptionX[tufte]{notitlepage}{\setboolean{@tufte@titlepage}{false}} + +%% +% `a4paper' option + +\newboolean{@tufte@afourpaper} +\DeclareOptionX[tufte]{a4paper}{\setboolean{@tufte@afourpaper}{true}} + +%% +% `b5paper' option + +\newboolean{@tufte@bfivepaper} +\DeclareOptionX[tufte]{b5paper}{\setboolean{@tufte@bfivepaper}{true}} + +%% +% `sfsidenotes' option -- typesets sidenotes in sans serif typeface + +\newboolean{@tufte@sfsidenotes} +\DeclareOptionX[tufte]{sfsidenotes}{\setboolean{@tufte@sfsidenotes}{true}} + +%% +% `symmetric' option -- puts marginpar space to the outside edge of the page +% Note: this option forces the twoside option (see the .cls files) + +\newboolean{@tufte@symmetric} +\DeclareOptionX[tufte]{symmetric}{ + \setboolean{@tufte@symmetric}{true} + \@tufte@info@noline{The `symmetric' option implies `twoside'} + \ExecuteOptionsX[tufte]{twoside} +} + +%% +% `twoside' option -- alternates running heads + +\newboolean{@tufte@twoside} +\DeclareOptionX[tufte]{twoside}{% + \setboolean{@tufte@twoside}{true} + \@tufte@info@noline{Passing the `twoside' option to the `\@tufte@class' class} + \PassOptionsToClass{twoside}{\@tufte@class} +} + +%% +% `notoc' option -- suppresses the Tufte-style table of contents + +\newboolean{@tufte@toc} +\setboolean{@tufte@toc}{true} +\DeclareOptionX[tufte]{notoc}{\setboolean{@tufte@toc}{false}} +\DeclareOptionX[tufte]{toc}{\setboolean{@tufte@toc}{true}} + +%% +% `justified' option -- uses fully justified text (flush left and flush +% right) instead of ragged right. + +\newboolean{@tufte@justified} +\DeclareOptionX[tufte]{justified}{\setboolean{@tufte@justified}{true}} + +%% +% `bidi' option -- loads the bidi package for bi-directional text + +\newboolean{@tufte@loadbidi} +\DeclareOptionX[tufte]{bidi}{\setboolean{@tufte@loadbidi}{true}} +\DeclareOptionX[tufte]{nobidi}{\setboolean{@tufte@loadbidi}{false}} + +%% +% `nohyper' option -- suppresses loading of the hyperref package + +\newboolean{@tufte@loadhyper} +\setboolean{@tufte@loadhyper}{true} +\DeclareOptionX[tufte]{hyper}{\setboolean{@tufte@loadhyper}{true}} +\DeclareOptionX[tufte]{nohyper}{\setboolean{@tufte@loadhyper}{false}} + +%% +% `sidenote', `marginnote', `caption', `citation', `marginals' options +% Each allows one of {justified,raggedleft,raggedright,raggedouter,auto}. + +\newcommand*{\@tufte@sidenote@justification}{\@tufte@justification@autodetect} +\define@choicekey*+[tufte]{common}{sidenote}[\@tufte@kvtext\@tufte@kvnum]{justified,raggedleft,raggedright,raggedouter,auto}[auto]{% + \ifcase\@tufte@kvnum\relax + \renewcommand*{\@tufte@sidenote@justification}{\justifying}% justified + \or + \renewcommand*{\@tufte@sidenote@justification}{\RaggedLeft}% ragged left + \or + \renewcommand*{\@tufte@sidenote@justification}{\RaggedRight}% ragged right + \or + \renewcommand*{\@tufte@sidenote@justification}{\@tufte@justification@outer}% ragged outer (flush right on verso pages, flush left on recto pages) + \or + \renewcommand*{\@tufte@sidenote@justification}{\@tufte@justification@autodetect}% autodetects best justification mode based on all class options + \fi +}{% + \@tufte@warning@noline{Invalid option `#1' for sidenote key. Must be one of: justified, raggedleft, raggedright, raggedouter, auto} + \renewcommand*{\@tufte@sidenote@justification}{\@tufte@justification@autodetect}% autodetects best justification mode based on all class options +} + +\newcommand*{\@tufte@marginnote@justification}{\@tufte@justification@autodetect} +\define@choicekey*+[tufte]{common}{marginnote}[\@tufte@kvtext\@tufte@kvnum]{justified,raggedleft,raggedright,raggedouter,auto}[auto]{% + \ifcase\@tufte@kvnum\relax + \renewcommand*{\@tufte@marginnote@justification}{\justifying}% justified + \or + \renewcommand*{\@tufte@marginnote@justification}{\RaggedLeft}% ragged left + \or + \renewcommand*{\@tufte@marginnote@justification}{\RaggedRight}% ragged right + \or + \renewcommand*{\@tufte@marginnote@justification}{\@tufte@justification@outer}% ragged outer (flush right on verso pages, flush left on recto pages) + \or + \renewcommand*{\@tufte@marginnote@justification}{\@tufte@justification@autodetect}% autodetects best justification mode based on all class options + \fi +}{% + \@tufte@warning@noline{Invalid option `#1' for marginnote key. Must be one of: justified, raggedleft, raggedright, raggedouter, auto} + \renewcommand*{\@tufte@marginnote@justification}{\@tufte@justification@autodetect}% autodetects best justification mode based on all class options +} + +\newcommand*{\@tufte@caption@justification}{\@tufte@justification@autodetect} +\define@choicekey*+[tufte]{common}{caption}[\@tufte@kvtext\@tufte@kvnum]{justified,raggedleft,raggedright,raggedouter,auto}[auto]{% + \ifcase\@tufte@kvnum\relax + \renewcommand*{\@tufte@caption@justification}{\justifying}% justified + \or + \renewcommand*{\@tufte@caption@justification}{\RaggedLeft}% ragged left + \or + \renewcommand*{\@tufte@caption@justification}{\RaggedRight}% ragged right + \or + \renewcommand*{\@tufte@caption@justification}{\@tufte@justification@caption@outer}% ragged outer (flush right on verso pages, flush left on recto pages) + \or + \renewcommand*{\@tufte@caption@justification}{\@tufte@justification@autodetect}% autodetects best justification mode based on all class options + \fi +}{% + \@tufte@warning@noline{Invalid option `#1' for caption key. Must be one of: justified, raggedleft, raggedright, raggedouter, auto} + \renewcommand*{\@tufte@caption@justification}{\@tufte@justification@autodetect}% autodetects best justification mode based on all class options +} + +\newcommand*{\@tufte@citation@justification}{\@tufte@justification@autodetect} +\define@choicekey*+[tufte]{common}{citation}[\@tufte@kvtext\@tufte@kvnum]{justified,raggedleft,raggedright,raggedouter,auto}[auto]{% + \ifcase\@tufte@kvnum\relax + \renewcommand*{\@tufte@citation@justification}{\justifying}% justified + \or + \renewcommand*{\@tufte@citation@justification}{\RaggedLeft}% ragged left + \or + \renewcommand*{\@tufte@citation@justification}{\RaggedRight}% ragged right + \or + \renewcommand*{\@tufte@citation@justification}{\@tufte@justification@outer}% ragged outer (flush right on verso pages, flush left on recto pages) + \or + \renewcommand*{\@tufte@citation@justification}{\@tufte@justification@autodetect}% autodetects best justification mode based on all class options + \fi +}{% + \@tufte@warning@noline{Invalid option `#1' for citation key. Must be one of: justified, raggedleft, raggedright, raggedouter, auto} + \renewcommand*{\@tufte@citation@justification}{\@tufte@justification@autodetect}% autodetects best justification mode based on all class options +} + +% The ``marginals'' key simultaneously sets the same justification for all marginal material +\define@choicekey*+[tufte]{common}{marginals}[\@tufte@kvtext\@tufte@kvnum]{justified,raggedleft,raggedright,raggedouter,auto}[auto]{% + \ifcase\@tufte@kvnum\relax + \ExecuteOptionsX[tufte]{citation=justified,sidenote=justified,caption=justified,marginnote=justified}% justified + \or + \ExecuteOptionsX[tufte]{citation=raggedleft,sidenote=raggedleft,caption=raggedleft,marginnote=raggedleft}% ragged left + \or + \ExecuteOptionsX[tufte]{citation=raggedright,sidenote=raggedright,caption=raggedright,marginnote=raggedright}% ragged right + \or + \ExecuteOptionsX[tufte]{citation=raggedouter,sidenote=raggedouter,caption=raggedouter,marginnote=raggedouter}% ragged outer (flush right on verso pages, flush left on recto pages) + \or + \ExecuteOptionsX[tufte]{citation=auto,sidenote=auto,caption=auto,marginnote=auto}% autodetects best justification mode based on all class options + \fi +}{% + \@tufte@warning@noline{Invalid option `#1' for marginals key. Must be one of: justified, raggedleft, raggedright, raggedouter, auto} + \ExecuteOptionsX[tufte]{citation=auto,sidenote=auto,caption=auto,marginnote=auto}% autodetects best justification mode based on all class options +} + + +%% +% Unsupported options + +\newcommand{\@tufte@unsupported@option}[1]{\@tufte@warning@noline{Option `#1' is not supported -- ignoring option}\OptionNotUsed} + +\DeclareOptionX[tufte]{10pt}{\@tufte@unsupported@option{\CurrentOption}} +\DeclareOptionX[tufte]{11pt}{\@tufte@unsupported@option{\CurrentOption}} +\DeclareOptionX[tufte]{12pt}{\@tufte@unsupported@option{\CurrentOption}} +\DeclareOptionX[tufte]{a5paper}{\@tufte@unsupported@option{\CurrentOption}} +\DeclareOptionX[tufte]{executivepaper}{\@tufte@unsupported@option{\CurrentOption}} +\DeclareOptionX[tufte]{legalpaper}{\@tufte@unsupported@option{\CurrentOption}} +\DeclareOptionX[tufte]{landscape}{\@tufte@unsupported@option{\CurrentOption}} +\DeclareOptionX[tufte]{onecolumn}{\@tufte@unsupported@option{\CurrentOption}} +\DeclareOptionX[tufte]{twocolumn}{\@tufte@unsupported@option{\CurrentOption}} + +%% +% Default `book' and `handout' options + +\ifthenelse{\equal{\@tufte@pkgname}{tufte-book}} + {\ExecuteOptionsX[tufte]{titlepage}} + {\ExecuteOptionsX[tufte]{notitlepage}} + + +\DeclareOptionX*{% + \@tufte@info@noline{Passing \CurrentOption\space to the `\@tufte@class' class.}% + \PassOptionsToClass{\CurrentOption}{\@tufte@class}% +} +\ProcessOptionsX*[tufte]\relax + +%% +% Load the appropriate base class +\@tufte@info@noline{Loading the base class `\@tufte@class'} +\LoadClass{\@tufte@class} + +%% +% Detect whether we're in two-side mode or not. (Used to set up running +% heads later.) + +\ifthenelse{\boolean{@twoside}} + {\setboolean{@tufte@twoside}{true}} + {} + + + +%% +% Detect if we're using pdfLaTeX + +\newboolean{@tufte@pdf} +\IfFileExists{ifpdf.sty}{% + \RequirePackage{ifpdf} + \ifthenelse{\boolean{pdf}} + {\setboolean{@tufte@pdf}{true}} + {\setboolean{@tufte@pdf}{false}} +}{% assume we're not using pdfTex? + \setboolean{@tufte@pdf}{false} +} + +%% +% Detect if we're using XeLaTeX + +\newboolean{@tufte@xetex} +\IfFileExists{ifxetex.sty}{% + \RequirePackage{ifxetex} + \ifthenelse{\boolean{xetex}} + {\setboolean{@tufte@xetex}{true}} + {\setboolean{@tufte@xetex}{false}} +}{% not using xelatex + \setboolean{@tufte@xetex}{false} +} + +\ifthenelse{\boolean{@tufte@xetex}}{% + \RequirePackage{xltxtra}% xltxtra loads xunicode and fontspec; must be loaded before bidi +}{} + +%% +% Detect if we're using LuaTeX + +\newboolean{@tufte@luatex} +\IfFileExists{ifluatex.sty}{% + \RequirePackage{ifluatex} + \ifthenelse{\boolean{luatex}} + {\setboolean{@tufte@luatex}{true}} + {\setboolean{@tufte@luatex}{false}} +}{% not using luatex + \setboolean{@tufte@luatex}{false} +} + +\ifthenelse{\boolean{@tufte@luatex}}{% + \RequirePackage{fontspec} + \RequirePackage[osf,sc]{mathpazo} + \setmainfont[Renderer=Basic, Numbers=OldStyle, Scale = 1.0]{TeX Gyre Pagella} + \setsansfont[Renderer=Basic, Scale=0.90]{TeX Gyre Heros} + \setmonofont[Renderer=Basic]{TeX Gyre Cursor} +}{} + +%% +% Globally sets the length + +\newcommand*{\gsetlength}[2]{% + \setlength{#1}{#2}% + \global#1=#1\relax% +} + +%% +% Globally sets a boolean + +\newcommand*{\gsetboolean}[2]{% based on code from ifthen pkg + \lowercase{\def\@tempa{#2}}% + \@ifundefined{@tempswa\@tempa}% + {\PackageError{ifthen}{You can only set a boolean to `true' or `false'}\@ehc}% + {\@ifundefined{#1\@tempa}% + {\PackageError{ifthen}{Boolean #1 undefined}\@ehc}% + {\global\csname#1\@tempa\endcsname}% + }% +} + +%% +% The titlesec and titletoc packages are used to change the style of the +% section headings. These packages should be loaded before the hyperref +% package. + +\RequirePackage{titlesec,titletoc} + +%%% +%% Loads the hyperref package and sets some default options. + +\newcommand{\TufteLoadHyperref}{% + \ifthenelse{\boolean{@tufte@xetex}} + {\RequirePackage[unicode,hyperfootnotes=false,xetex]{hyperref}} + {\RequirePackage[unicode,hyperfootnotes=false]{hyperref}} + \hypersetup{% + pdfborder = {0 0 0}, + bookmarksdepth = section, + citecolor = DarkGreen, + linkcolor = DarkBlue, + urlcolor = DarkGreen, + }% +} + +%%% +%% Load the `hyperref' package. + +\ifthenelse{\boolean{@tufte@loadhyper}}{% + \TufteLoadHyperref% +}{% hyperfootnotes override our modifications to the \footnote* and \@footnote* commands. + \PassOptionsToPackage{hyperfootnotes=false}{hyperref} +} + +%% +% Set the font sizes and baselines to match Tufte's books +\renewcommand\normalsize{% + \@setfontsize\normalsize\@xpt{14}% + \abovedisplayskip 10\p@ \@plus2\p@ \@minus5\p@ + \abovedisplayshortskip \z@ \@plus3\p@ + \belowdisplayshortskip 6\p@ \@plus3\p@ \@minus3\p@ + \belowdisplayskip \abovedisplayskip + \let\@listi\@listI} +\normalbaselineskip=14pt +\normalsize +\renewcommand\small{% + \@setfontsize\small\@ixpt{12}% + \abovedisplayskip 8.5\p@ \@plus3\p@ \@minus4\p@ + \abovedisplayshortskip \z@ \@plus2\p@ + \belowdisplayshortskip 4\p@ \@plus2\p@ \@minus2\p@ + \def\@listi{\leftmargin\leftmargini + \topsep 4\p@ \@plus2\p@ \@minus2\p@ + \parsep 2\p@ \@plus\p@ \@minus\p@ + \itemsep \parsep}% + \belowdisplayskip \abovedisplayskip +} +\renewcommand\footnotesize{% + \@setfontsize\footnotesize\@viiipt{10}% + \abovedisplayskip 6\p@ \@plus2\p@ \@minus4\p@ + \abovedisplayshortskip \z@ \@plus\p@ + \belowdisplayshortskip 3\p@ \@plus\p@ \@minus2\p@ + \def\@listi{\leftmargin\leftmargini + \topsep 3\p@ \@plus\p@ \@minus\p@ + \parsep 2\p@ \@plus\p@ \@minus\p@ + \itemsep \parsep}% + \belowdisplayskip \abovedisplayskip +} +\renewcommand\scriptsize{\@setfontsize\scriptsize\@viipt\@viiipt} +\renewcommand\tiny{\@setfontsize\tiny\@vpt\@vipt} +\renewcommand\large{\@setfontsize\large\@xipt{15}} +\renewcommand\Large{\@setfontsize\Large\@xiipt{16}} +\renewcommand\LARGE{\@setfontsize\LARGE\@xivpt{18}} +\renewcommand\huge{\@setfontsize\huge\@xxpt{30}} +\renewcommand\Huge{\@setfontsize\Huge{24}{36}} + +\setlength\leftmargini {1pc} +\setlength\leftmarginii {1pc} +\setlength\leftmarginiii {1pc} +\setlength\leftmarginiv {1pc} +\setlength\leftmarginv {1pc} +\setlength\leftmarginvi {1pc} +\setlength\labelsep {.5pc} +\setlength\labelwidth {\leftmargini} +\addtolength\labelwidth{-\labelsep} + +%% +% \RaggedRight allows hyphenation + +\setlength{\parindent}{1.0pc}% +\setlength{\parskip}{0pt}% +\RequirePackage{ragged2e} +\setlength{\RaggedRightRightskip}{\z@ plus 0.08\hsize} + +% Paragraph indentation and separation for normal text +\newcommand{\@tufte@reset@par}{% + \setlength{\RaggedRightParindent}{1.0pc}% + \setlength{\JustifyingParindent}{1.0pc}% + \setlength{\parindent}{1pc}% + \setlength{\parskip}{0pt}% +} +\@tufte@reset@par + +% Paragraph indentation and separation for marginal text +\newcommand{\@tufte@margin@par}{% + \setlength{\RaggedRightParindent}{0.5pc}% + \setlength{\JustifyingParindent}{0.5pc}% + \setlength{\parindent}{0.5pc}% + \setlength{\parskip}{0pt}% +} + + +%% +% Set page layout geometry + +\RequirePackage[letterpaper,left=1in,top=1in,headsep=2\baselineskip,textwidth=27pc,marginparsep=2pc,marginparwidth=12pc,textheight=44\baselineskip,headheight=\baselineskip]{geometry} + +\ifthenelse{\boolean{@tufte@afourpaper}} + {\geometry{a4paper,left=24.8mm,top=27.4mm,headsep=2\baselineskip,textwidth=130mm,marginparsep=8.2mm,marginparwidth=49.4mm,textheight=49\baselineskip,headheight=\baselineskip}} + {} + +\ifthenelse{\boolean{@tufte@bfivepaper}} + {\geometry{paperwidth=176mm,paperheight=250mm,left=14.66mm,top=13.88mm,textwidth=130mm,marginparsep=7.33mm,marginparwidth=36.66mm,textheight=38\baselineskip,includehead}} + {} + +\ifthenelse{\boolean{@tufte@symmetric}} + {} + {\geometry{asymmetric}}% forces internal LaTeX `twoside' + + +%% +% Separation marginpars by a line's worth of space. + +\setlength\marginparpush{10pt} + +%% +% Font for margin items + +\ifthenelse{\boolean{@tufte@sfsidenotes}} + {\newcommand{\@tufte@marginfont}{\normalfont\footnotesize\sffamily}} + {\newcommand{\@tufte@marginfont}{\normalfont\footnotesize}} + +\newcommand*{\@tufte@sidenote@font}{\@tufte@marginfont} +\newcommand*{\@tufte@caption@font}{\@tufte@marginfont} +\newcommand*{\@tufte@marginnote@font}{\@tufte@marginfont} +\newcommand*{\@tufte@citation@font}{\@tufte@marginfont} + +\newcommand*{\setsidenotefont}[1]{\renewcommand*{\@tufte@sidenote@font}{#1}} +\newcommand*{\setcaptionfont}[1]{\renewcommand*{\@tufte@caption@font}{#1}} +\newcommand*{\setmarginnotefont}[1]{\renewcommand*{\@tufte@marginnote@font}{#1}} +\newcommand*{\setcitationfont}[1]{\renewcommand*{\@tufte@citation@font}{#1}} + +%% +% Set the justification based on the `justified' class option + +\newcommand{\@tufte@justification}{% + \ifthenelse{\boolean{@tufte@justified}}% + {\justifying}% + {\RaggedRight}% +} + +%% +% Turn off section numbering + +%\setcounter{secnumdepth}{-1} + +%% +% Tighten up space between displays (e.g., a figure or table) and make symmetric + +\setlength\abovedisplayskip{6pt plus 2pt minus 4pt} +\setlength\belowdisplayskip{6pt plus 2pt minus 4pt} + +%% +% To implement full-width display environments + +\newboolean{@tufte@changepage} +\IfFileExists{changepage.sty}{% + \@tufte@debug@info@noline{Found changepage.sty} + \RequirePackage[strict]{changepage} + \setboolean{@tufte@changepage}{true} +}{% + \@tufte@debug@info@noline{Found chngpage.sty} + \RequirePackage[strict]{chngpage} + \setboolean{@tufte@changepage}{false} +} + +% Write our own aliases for the \checkoddpage and \ifoddpage or \ifcpoddpage commands +\newboolean{@tufte@odd@page} +\setboolean{@tufte@odd@page}{true} +\newcommand*{\@tufte@checkoddpage}{% + \checkoddpage% + \ifthenelse{\boolean{@tufte@changepage}}{% + \ifoddpage% + \setboolean{@tufte@odd@page}{true}% + \else% + \setboolean{@tufte@odd@page}{false}% + \fi% + }{% + \ifcpoddpage% + \setboolean{@tufte@odd@page}{true}% + \else% + \setboolean{@tufte@odd@page}{false}% + \fi% + }% +} + +%% +% Compute lengths used for full-width displays + +\newlength{\@tufte@overhang}% used by the fullwidth environment and the running heads +\newlength{\@tufte@fullwidth} +\newlength{\@tufte@caption@fill} + +\newcommand{\TufteRecalculate}{% + \setlength{\@tufte@overhang}{\marginparwidth} + \addtolength{\@tufte@overhang}{\marginparsep} + + \setlength{\@tufte@fullwidth}{\textwidth} + \addtolength{\@tufte@fullwidth}{\marginparsep} + \addtolength{\@tufte@fullwidth}{\marginparwidth} + + \setlength{\@tufte@caption@fill}{\textwidth} + \addtolength{\@tufte@caption@fill}{\marginparsep} +} + +\AtBeginDocument{\TufteRecalculate} + +%% +% Modified \title, \author, and \date commands. These store the +% (footnote-less) values in \plaintitle, \plainauthor, and \thedate, respectively. + +\newcommand{\plaintitle}{}% plain-text-only title +\newcommand{\plainauthor}{}% plain-text-only author +\newcommand{\plainpublisher}{}% plain-text-only publisher + +\newcommand{\thanklesstitle}{}% full title text minus \thanks{} +\newcommand{\thanklessauthor}{}% full author text minus \thanks{} +\newcommand{\thanklesspublisher}{}% full publisher minus \thanks{} + +\newcommand{\@publisher}{}% full publisher with \thanks{} +\newcommand{\thedate}{\today} + +% TODO Fix it so that \thanks is not spaced out (with `soul') and can be +% used in \maketitle when the `sfsidenotes' option is provided. +\renewcommand{\thanks}[1]{\NoCaseChange{\footnote{#1}}} + +\renewcommand{\title}[2][]{% + \gdef\@title{#2}% + \begingroup% + % TODO store contents of \thanks command + \renewcommand{\thanks}[1]{}% swallow \thanks contents + \protected@xdef\thanklesstitle{#2}% + \endgroup% + \ifthenelse{\isempty{#1}}% + {\renewcommand{\plaintitle}{\thanklesstitle}}% use thankless title + {\renewcommand{\plaintitle}{#1}}% use provided plain-text title + \ifthenelse{\isundefined{\hypersetup}}% + {}% hyperref is not loaded; do nothing + {\hypersetup{pdftitle={\plaintitle}}}% set the PDF metadata title +} + +\let\@author\@empty% suppress default latex.ltx ``no author'' warning +\renewcommand{\author}[2][]{% + \ifthenelse{\isempty{#2}}{}{\gdef\@author{#2}}% + \begingroup% + % TODO store contents of \thanks command + \renewcommand{\thanks}[1]{}% swallow \thanks contents + \protected@xdef\thanklessauthor{#2}% + \endgroup% + \ifthenelse{\isempty{#1}}% + {\renewcommand{\plainauthor}{\thanklessauthor}}% use thankless author + {\renewcommand{\plainauthor}{#1}}% use provided plain-text author + \ifthenelse{\isundefined{\hypersetup}}% + {}% hyperref is not loaded; do nothing + {\hypersetup{pdfauthor={\plainauthor}}}% set the PDF metadata author +} + +\renewcommand{\date}[1]{% + \gdef\@date{#1}% + \begingroup% + % TODO store contents of \thanks command + \renewcommand{\thanks}[1]{}% swallow \thanks contents + \protected@xdef\thedate{#1}% + \endgroup% +} + +%% +% Provides a \publisher command to set the publisher + +\newcommand{\publisher}[2][]{% + \gdef\@publisher{#2}% + \begingroup% + \renewcommand{\thanks}[1]{}% swallow \thanks contents + \protected@xdef\thanklesspublisher{#2}% + \endgroup% + \ifthenelse{\isempty{#1}} + {\renewcommand{\plainpublisher}{\thanklesspublisher}}% use thankless publisher + {\renewcommand{\plainpublisher}{#1}}% use provided plain-text publisher +} + +% TODO: Test \hypersetup{pdfauthor,pdftitle} with DVI and XeTeX + +%% +% Require paralist package for tighter lists + +\RequirePackage{paralist} + +% Add rightmargin to compactenum + +\def\@compactenum@{% + \expandafter\list\csname label\@enumctr\endcsname{% + \usecounter{\@enumctr}% + \rightmargin=2em% added this + \parsep\plparsep + \itemsep\plitemsep + \topsep\pltopsep + \partopsep\plpartopsep + \def\makelabel##1{\hss\llap{##1}}}} + +%% +% Improved letterspacing of small caps and all-caps text. +% +% First, try to use the `microtype' package, if it's available. +% Failing that, try to use the `soul' package, if it's available. +% Failing that, well, I give up. + +\DeclareTextFontCommand{\textsmallcaps}{\scshape} + +\RequirePackage{textcase} % provides \MakeTextUppercase and \MakeTextLowercase +\def\allcapsspacing{\@tufte@warning{Proper spacing of ALL-CAPS letters has not been set up.}} +\def\smallcapsspacing{\@tufte@warning{Proper spacing of small-caps letters has not been set up.}} +\newcommand{\allcaps}[1]{\allcapsspacing{\MakeTextUppercase{#1}}} +\newcommand{\smallcaps}[1]{\smallcapsspacing{\MakeTextLowercase{#1}}} + +% If we're using pdfLaTeX v1.40+, use the letterspace package. +% If we're using pdfLaTex < v1.40, use the soul package. +% If we're using XeLaTeX, use XeLaTeX letterspacing options. +% Otherwise fall back on the soul package. + +\ifthenelse{\boolean{@tufte@pdf}} + {\@tufte@debug@info@noline{ifpdf = true}} + {\@tufte@debug@info@noline{ifpdf = false}} + +\ifthenelse{\boolean{@tufte@xetex}} + {\@tufte@debug@info@noline{ifxetex = true}} + {\@tufte@debug@info@noline{ifxetex = false}} + +% Check pdfLaTeX version +\def\@tufte@pdftexversion{0} +\ifx\normalpdftexversion\@undefined \else + \let\pdftexversion \normalpdftexversion + \let\pdftexrevision\normalpdftexrevision + \let\pdfoutput \normalpdfoutput +\fi +\ifx\pdftexversion\@undefined \else + \ifx\pdftexversion\relax \else + \def\@tufte@pdftexversion{6} + \ifnum\pdftexversion < 140 + \def\@tufte@pdftexversion{5} + \fi + \fi +\fi + +\newboolean{@tufte@letterspace@pkg@prereqs} +\setboolean{@tufte@letterspace@pkg@prereqs}{true} +\ifnum\@tufte@pdftexversion<6 + \setboolean{@tufte@letterspace@pkg@prereqs}{false} +\fi + + +\newcommand{\@tufte@letterspacing@soul}{% + \RequirePackage{soul}% + \sodef\allcapsspacing{}{0.15em}{0.65em}{0.6em}% + \sodef\smallcapsspacing{}{0.075em}{0.5em}{0.6em}% + \sodef\sotextsc{\scshape}{0.075em}{0.5em}{0.6em}% + \renewcommand{\allcaps}[1]{\allcapsspacing{\MakeTextUppercase{##1}}}% + \renewcommand{\smallcaps}[1]{\smallcapsspacing{\scshape\MakeTextLowercase{##1}}}% + \renewcommand{\textsc}[1]{\sotextsc{##1}}% +} + +\newcommand{\@tufte@letterspacing@letterspace}{% + \@tufte@debug@info@noline{Modern version of pdfTeX detected. Using `letterspace' package}% + \RequirePackage{letterspace}% + % Set up letterspacing (using microtype package) -- requires pdfTeX v1.40+ + \renewcommand{\allcapsspacing}[1]{\textls[200]{##1}}% + \renewcommand{\smallcapsspacing}[1]{\textls[50]{##1}}% + \renewcommand{\allcaps}[1]{\allcapsspacing{\MakeTextUppercase{##1}}}% + \renewcommand{\smallcaps}[1]{\smallcapsspacing{\scshape\MakeTextLowercase{##1}}}% + \renewcommand{\textsc}[1]{\smallcapsspacing{\textsmallcaps{##1}}}% +} + +\ifthenelse{\boolean{@tufte@letterspace}}{% + \ifthenelse{\boolean{@tufte@pdf}\AND\boolean{@tufte@letterspace@pkg@prereqs}\AND\NOT\boolean{@tufte@xetex}}{% + % load letterspace pkg + \IfFileExists{letterspace.sty}{% + \@tufte@letterspacing@letterspace + }{}% + }{}% + % load soul pkg + \@ifpackageloaded{letterspace}{}{% + \IfFileExists{soul.sty}{% + \@tufte@letterspacing@soul + }{% + \@tufte@warning@noline{Couldn't locate `soul' package}% + }% soul not installed... giving up. + }% +}{} + +%\ifthenelse{\boolean{@tufte@letterspace}}{% + %\ifthenelse{\boolean{pdf}}{% + %\ifthenelse{\NOT\boolean{@tufte@letterspace@pkg@prereqs}}{% + %% pdfLaTeX version is too old or not using pdfLaTeX + %\ifthenelse{\boolean{@tufte@xetex}}{% + %% TODO use xetex letterspacing + %\@tufte@debug@info@noline{XeTeX detected. Reverting to `soul' package for letterspacing}% + %\@tufte@loadsoul% + %}{% + %% use `soul' package for letterspacing + %\@tufte@debug@info@noline{Old version of pdfTeX detected. Reverting to `soul' package for letterspacing}% + %\@tufte@loadsoul% + %} + %}{% + %\IfFileExists{letterspace.sty}{% + %\@tufte@debug@info@noline{Modern version of pdfTeX detected. Using `letterspace' package} + %\RequirePackage{letterspace} + %% Set up letterspacing (using microtype package) -- requires pdfTeX v1.40+ + %\renewcommand{\allcapsspacing}[1]{\textls[200]{##1}} + %\renewcommand{\smallcapsspacing}[1]{\textls[50]{##1}} + %\renewcommand{\allcaps}[1]{\textls[200]{\MakeTextUppercase{##1}}} + %\renewcommand{\smallcaps}[1]{\smallcapsspacing{\MakeTextLowercase{##1}}} + %\renewcommand{\textsc}[1]{\smallcapsspacing{\textsmallcaps{##1}}} + %}{% microtype failed, check for soul + %\@tufte@debug@info@noline{Modern version of pdfTeX detected, but `letterspace' package not installed. Reverting to `soul' package for letterspacing} + %\@tufte@loadsoul + %}% + %}% + %}{% + %\@tufte@debug@info@noline{Plain LaTeX detected. Using `soul' package for letterspacing} + %\@tufte@loadsoul + %} +%}{% +%% we're not to load letterspacing, so do nothing +%} + + +%% +% An environment for paragraph-style section + +\providecommand\newthought[1]{% + \tuftebreak + \noindent\textsc{#1}% +} + +%% +% Redefine the display environments (quote, quotation, etc.) + +\renewenvironment{verse} + {\let\\\@centercr + \list{}{\itemsep \z@ + \itemindent -1pc% + \listparindent\itemindent + \rightmargin \leftmargin + \advance\leftmargin 1pc}% + \small% + \item\relax} + {\endlist} +\renewenvironment{quotation} + {\list{}{\listparindent 1pc% + \itemindent \listparindent + \rightmargin \leftmargin + \parsep \z@ \@plus\p@}% + \small% + \item\relax\noindent\ignorespaces} + {\endlist} +\renewenvironment{quote} + {\list{}{\rightmargin\leftmargin}% + \small% + \item\relax} + {\endlist} + +%% +% Italicize description run-in headings (instead of the default bold) + +\renewcommand*\descriptionlabel[1]{\hspace\labelsep\normalfont\em #1} + + +%% +% Used for doublespacing, and other linespacing + +\RequirePackage{setspace} + +%% +% Color +\RequirePackage[dvipsnames,svgnames]{xcolor}% load before bidi + +%% +% Load the bidi package if instructed to do so. This package must be loaded +% prior to our redefining the \footnote and \cite commands. + +\ifthenelse{\boolean{@tufte@loadbidi}}{% + \AtBeginDocument{% + \RequirePackage{bidi} + \@tufte@pkghook@post@bidi% + }% +}{} + + +%% +% A function that removes leading and trailing spaces from the supplied macro. +% Based on code written by Michael Downes (See ``Around the Bend'', #15.) +% Executing \@tufte@trim@spaces\xyzzy will result in the contents of \xyzzy +% being trimmed of leading and trailing white space. + +\catcode`\Q=3 +\def\@tufte@trim@spaces#1{% + % Use grouping to emulate a multi-token afterassignment queue + \begingroup% + % Put `\toks 0 {' into the afterassignment queue + \aftergroup\toks\aftergroup0\aftergroup{% + % Apply \trimb to the replacement text of #1, adding a leading + % \noexpand to prevent brace stripping and to serve another purpose + % later. + \expandafter\@tufte@trim@b\expandafter\noexpand#1Q Q}% + % Transfer the trimmed text back into #1. + \edef#1{\the\toks0}% +} + +% \trimb removes a trailing space if present, then calls \@tufte@trim@c to +% clean up any leftover bizarre Qs, and trim a leading space. In +% order for \trimc to work properly we need to put back a Q first. +\def\@tufte@trim@b#1 Q{\@tufte@trim@c#1Q} + +% Execute \vfuzz assignment to remove leading space; the \noexpand +% will now prevent unwanted expansion of a macro or other expandable +% token at the beginning of the trimmed text. The \endgroup will feed +% in the \aftergroup tokens after the \vfuzz assignment is completed. +\def\@tufte@trim@c#1Q#2{\afterassignment\endgroup \vfuzz\the\vfuzz#1} +\catcode`\Q=11 + +%% +% Citations should go in the margin as sidenotes + +\ifthenelse{\boolean{@tufte@loadnatbib}}{% + \RequirePackage{natbib}% + \RequirePackage{bibentry}% allows bibitems to be typeset outside thebibliography environment + % Redefine the \BR@b@bibitem command to fix a bug with bibentry+chicago style + \renewcommand\BR@b@bibitem[2][]{% + \ifthenelse{\isempty{#1}}% + {\BR@bibitem{#2}}% + {\BR@bibitem[#1]{#2}}% + \BR@c@bibitem{#2}% + }% + %\nobibliography*% pre-loads the bibliography keys + \providecommand{\doi}[1]{\textsc{doi:} #1}% pre-defining this so it may be used before the \bibliography command it issued +}{} + +%% +% Normal \cite behavior +\newcounter{@tufte@num@bibkeys}% +\newcommand{\@tufte@normal@cite}[2][0pt]{% + % Snag the last bibentry in the list for later comparison + \let\@temp@last@bibkey\@empty% + \@for\@temp@bibkey:=#2\do{\let\@temp@last@bibkey\@temp@bibkey}% + \sidenote[][#1]{% + % Loop through all the bibentries, separating them with semicolons and spaces + \normalsize\normalfont\@tufte@citation@font% + \setcounter{@tufte@num@bibkeys}{0}% + \@for\@temp@bibkeyx:=#2\do{% + \ifthenelse{\equal{\@temp@last@bibkey}{\@temp@bibkeyx}}% + {\ifthenelse{\equal{\value{@tufte@num@bibkeys}}{0}}{}{and\ }% + \@tufte@trim@spaces\@temp@bibkeyx% trim spaces around bibkey + \bibentry{\@temp@bibkeyx}}% + {\@tufte@trim@spaces\@temp@bibkeyx% trim spaces around bibkey + \bibentry{\@temp@bibkeyx};\ }% + \stepcounter{@tufte@num@bibkeys}% + }% + }% +} + + +%% +% Macros for holding the list of cite keys until after the \sidenote + +\gdef\@tufte@citations{}% list of cite keys +\newcommand\@tufte@add@citation[1]{\relax% adds a new bibkey to the list of cite keys + \ifx\@tufte@citations\@empty\else + \g@addto@macro\@tufte@citations{,}% separate by commas + \fi + \g@addto@macro\@tufte@citations{#1} +} + +\newcommand{\@tufte@print@citations}[1][0pt]{% puts the citations in a margin note + % Snag the last bibentry in the list for later comparison + \let\@temp@last@bibkey\@empty% + \@for\@temp@bibkey:=\@tufte@citations\do{\let\@temp@last@bibkey\@temp@bibkey}% + \marginpar{% + \hbox{}\vspace*{#1}% + \@tufte@citation@font% + \@tufte@citation@justification% + \@tufte@margin@par% use parindent and parskip settings for marginal text + \vspace*{-1\baselineskip}% + % Loop through all the bibentries, separating them with semicolons and spaces + \setcounter{@tufte@num@bibkeys}{0}% + \@for\@temp@bibkeyx:=\@tufte@citations\do{% + \ifthenelse{\equal{\@temp@last@bibkey}{\@temp@bibkeyx}}% + {\ifthenelse{\equal{\value{@tufte@num@bibkeys}}{0}}{}{and\ }% + \@tufte@trim@spaces\@temp@bibkeyx% trim spaces around bibkey + \bibentry{\@temp@bibkeyx}}% + {\@tufte@trim@spaces\@temp@bibkeyx% trim spaces around bibkey + \bibentry{\@temp@bibkeyx};\ }% + \stepcounter{@tufte@num@bibkeys}% + }% + }% +} + +%% +% \cite behavior when executed within a sidenote + +\newcommand{\@tufte@sidenote@citations}{}% contains list of \cites in sidenote +\newcommand{\@tufte@infootnote@cite}[1]{% + \@tufte@add@citation{#1} +} + +%% +% Set the default \cite style. This is set and reset by the \sidenote command. + +\ifthenelse{\boolean{@tufte@loadnatbib}}{% + \let\cite\@tufte@normal@cite +}{} + +%% +% Transform existing \footnotes into \sidenotes +% Sidenote: ``Where God meant footnotes to go.'' ---Tufte + +\RequirePackage{optparams}% for our new sidenote commands -- provides multiple optional arguments for commands + +\providecommand{\footnotelayout}{\@tufte@sidenote@font\@tufte@sidenote@justification} +\renewcommand{\footnotelayout}{\@tufte@sidenote@font\@tufte@sidenote@justification} + +% Override footmisc's definition to set the sidenote marks (numbers) inside the +% sidenote's text block. +\long\def\@makefntext#1{\@textsuperscript{\@tufte@sidenote@font\tiny\@thefnmark}\,\footnotelayout#1} + +% Set the in-text footnote mark in the same typeface as the body text itself. +\def\@makefnmark{\hbox{\@textsuperscript{\normalfont\footnotesize\@thefnmark}}} + +\providecommand*{\multiplefootnotemarker}{3sp} +\providecommand*{\multfootsep}{,} + +\renewcommand{\@footnotemark}{% + \leavevmode% + \ifhmode% + \edef\@x@sf{\the\spacefactor}% + \@tufte@check@multiple@sidenotes% + \nobreak% + \fi% + \@makefnmark% + \ifhmode\spacefactor\@x@sf\fi% + \relax% +} + +\newcommand{\@tufte@check@multiple@sidenotes}{% + \ifdim\lastkern=\multiplefootnotemarker\relax% + \edef\@x@sf{\the\spacefactor}% + \unkern% + \textsuperscript{\multfootsep}% + \spacefactor\@x@sf\relax% + \fi +} + +\renewcommand\@footnotetext[2][0pt]{% + \marginpar{% + \hbox{}\vspace*{#1}% + \def\baselinestretch {\setspace@singlespace}% + \reset@font\footnotesize% + \@tufte@margin@par% use parindent and parskip settings for marginal text + \vspace*{-1\baselineskip}\noindent% + \protected@edef\@currentlabel{% + \csname p@footnote\endcsname\@thefnmark% + }% + \color@begingroup% + \@makefntext{% + \ignorespaces#2% + }% + \color@endgroup% + }% +}% + +% Ensure this is run after the bidi package has been loaded +\def\@tufte@pkghook@post@bidi{}% +\g@addto@macro{\@tufte@pkghook@post@bidi}{% + \renewcommand\@footnotetext[2][0pt]{% + \marginpar{% + \hbox{}\vspace*{#1}% + \def\baselinestretch {\setspace@singlespace}% + \if@rl@footnote\@rltrue\else\@rlfalse\fi% + \reset@font\footnotesize% + \@tufte@margin@par% use parindent and parskip settings for marginal text + \vspace*{-1\baselineskip}\noindent% + \protected@edef\@currentlabel{% + \csname p@footnote\endcsname\@thefnmark% + }% + \color@begingroup% + \@makefntext{% + \ignorespaces#2% + }% + \color@endgroup% + }% + }% +}% + +% +% Define \sidenote command. Can handle \cite. + +\newlength{\@tufte@sidenote@vertical@offset} +\setlength{\@tufte@sidenote@vertical@offset}{0pt} + +% #1 = footnote num, #2 = vertical offset, #3 = footnote text +\long\def\@tufte@sidenote[#1][#2]#3{% + \ifthenelse{\boolean{@tufte@loadnatbib}}{% + \let\cite\@tufte@infootnote@cite% use the in-sidenote \cite command + }{}% + \gdef\@tufte@citations{}% clear out any old citations + \ifthenelse{\NOT\isempty{#2}}{% + \gsetlength{\@tufte@sidenote@vertical@offset}{#2}% + }{% + \gsetlength{\@tufte@sidenote@vertical@offset}{0pt}% + }% + \ifthenelse{\isempty{#1}}{% + % no specific footnote number provided + \stepcounter\@mpfn% + \protected@xdef\@thefnmark{\thempfn}% + \@footnotemark\@footnotetext[\@tufte@sidenote@vertical@offset]{#3}% + }{% + % specific footnote number provided + \begingroup% + \csname c@\@mpfn\endcsname #1\relax% + \unrestored@protected@xdef\@thefnmark{\thempfn}% + \endgroup% + \@footnotemark\@footnotetext[\@tufte@sidenote@vertical@offset]{#3}% + }% + \@tufte@print@citations% print any citations + \ifthenelse{\boolean{@tufte@loadnatbib}}{% + \let\cite\@tufte@normal@cite% go back to using normal in-text \cite command + }{}% + \unskip\ignorespaces% remove extra white space + \kern-\multiplefootnotemarker% remove \kern left behind by sidenote + \kern\multiplefootnotemarker\relax% add new \kern here to replace the one we yanked +} + +\newcommand{\sidenote}{\optparams{\@tufte@sidenote}{[][0pt]}} +\renewcommand{\footnote}{\optparams{\@tufte@sidenote}{[][0pt]}} + +%% +% Sidenote without the footnote mark + +\newcommand\marginnote[2][0pt]{% + \ifthenelse{\boolean{@tufte@loadnatbib}}{% + \let\cite\@tufte@infootnote@cite% use the in-sidenote \cite command + }{}% + \gdef\@tufte@citations{}% clear out any old citations + \marginpar{\hbox{}\vspace*{#1}\@tufte@marginnote@font\@tufte@marginnote@justification\@tufte@margin@par\vspace*{-1\baselineskip}\noindent #2}% + \@tufte@print@citations% print any citations + \ifthenelse{\boolean{@tufte@loadnatbib}}{% + \let\cite\@tufte@normal@cite% go back to using normal in-text \cite command + }{}% +} + + +%% +% The placeins package provides the \FloatBarrier command. This forces +% LaTeX to place all of the floats before proceeding. We'll use this to +% keep the float (figure and table) numbers in sequence. +\RequirePackage{placeins} + +%% +% Margin float environment + +\newsavebox{\@tufte@margin@floatbox} +\newenvironment{@tufte@margin@float}[2][-1.2ex]% + {\FloatBarrier% process all floats before this point so the figure/table numbers stay in order. + \begin{lrbox}{\@tufte@margin@floatbox}% + \begin{minipage}{\marginparwidth}% + \@tufte@caption@font% + \def\@captype{#2}% + \hbox{}\vspace*{#1}% + \@tufte@caption@justification% + \@tufte@margin@par% + \noindent% + } + {\end{minipage}% + \end{lrbox}% + \marginpar{\usebox{\@tufte@margin@floatbox}}% + } + + +%% +% Margin figure environment + +\newenvironment{marginfigure}[1][-1.2ex]% + {\begin{@tufte@margin@float}[#1]{figure}} + {\end{@tufte@margin@float}} + + +%% +% Margin table environment + +\newenvironment{margintable}[1][-1.2ex]% + {\begin{@tufte@margin@float}[#1]{table}} + {\end{@tufte@margin@float}} + + +%% +% Auto-detects the proper text alignment based on the various class options + +\newcommand*{\@tufte@justification@autodetect}{% + \ifthenelse{\boolean{@tufte@justified}}% + {\justifying}% + {\RaggedRight}% +} + +%% +% Forces the outer edge of the caption to be set ragged. +% Therefore, on verso pages it's ragged left, and on recto pages it's ragged right. + +\newcommand*{\@tufte@justification@caption@outer}{% + \ifthenelse{\boolean{@tufte@float@recto}}% + {\RaggedRight}% + {\RaggedLeft}% +} + +\newcommand*{\@tufte@justification@outer}{% + \@tufte@checkoddpage% + \ifthenelse{\boolean{@tufte@odd@page}}% + {\RaggedRight}% + {\RaggedLeft}% +} + + + +%% +% A collection of macros to be used with the new Tufte-style float environments. +% \setfloatalignment forces the caption placement to be treated as top, bottom, etc. +% \forcerectofloat forces the float to be treated as if it were appearing on a recto page. +% \forceversofloat does the same, but for verso pages. + +\newcommand{\@tufte@float@debug@info}{}% contains debug info generated as the float is processed +\newcommand{\@tufte@float@debug}[1]{% adds debug info to the queue for output + \ifthenelse{\equal{\@tufte@float@debug@info}{}}% + {\def\@tufte@float@debug@info{#1}}% + {\g@addto@macro\@tufte@float@debug@info{\MessageBreak#1}}% +} + +\newcommand{\floatalignment}{x}% holds the current float alignment (t, b, h, p) +\newcommand{\setfloatalignment}[1]{\global\def\floatalignment{#1}\@tufte@float@debug{Forcing position: [#1]}}% manually sets the float alignment +\newboolean{@tufte@float@recto} +\newcommand{\forcerectofloat}{\gsetboolean{@tufte@float@recto}{true}\@tufte@float@debug{Forcing page: [recto]}} +\newcommand{\forceversofloat}{\gsetboolean{@tufte@float@recto}{false}\@tufte@float@debug{Forcing page: [verso]}} + +% Boxes to temporarily store our float and caption +\newsavebox{\@tufte@figure@box} +\newsavebox{\@tufte@caption@box} + +% Save original LaTeX float environment +\let\@tufte@orig@float\@float +\let\@tufte@orig@endfloat\end@float + +% New length for tweaking float captions +\newlength{\@tufte@caption@vertical@offset} +\setlength{\@tufte@caption@vertical@offset}{0pt} + +% Store the caption and label contents +\newcommand{\@tufte@stored@shortcaption}{} +\newcommand{\@tufte@stored@caption}{} +\newcommand{\@tufte@stored@label}{} + +\long\def\@tufte@caption[#1][#2]#3{% + \ifthenelse{\isempty{#1}}% + {\gdef\@tufte@stored@shortcaption{#3}}% + {\gdef\@tufte@stored@shortcaption{#1}}% + \gsetlength{\@tufte@caption@vertical@offset}{-#2}% we want a positive offset to lower captions + \gdef\@tufte@stored@caption{#3}% +} + +\newcommand{\@tufte@label}[1]{% + \gdef\@tufte@stored@label{#1}% +} + +\newcommand{\@tufte@fps}{} + +\newboolean{@tufte@float@star} +\newlength{\@tufte@float@contents@width} + +%% +% Define a float environment to place the captions in the margin space + +\newenvironment{@tufte@float}[3][htbp]% + {% begin @tufte@float + % Should this float be full-width or just text-width? + \ifthenelse{\equal{#3}{star}}% + {\gsetboolean{@tufte@float@star}{true}}% + {\gsetboolean{@tufte@float@star}{false}}% + % Check page side (recto/verso) and store detected value -- can be overriden in environment contents + \@tufte@checkoddpage% + \ifthenelse{\boolean{@tufte@odd@page}}% + {\gsetboolean{@tufte@float@recto}{true}\@tufte@float@debug{Detected page: [recto/odd]}}% + {\gsetboolean{@tufte@float@recto}{false}\@tufte@float@debug{Detected page: [verso/even]}}% + % If the float placement specifier is 'b' and only 'b', then bottom-align the mini-pages, otherwise top-align them. + \renewcommand{\@tufte@fps}{#1}% + \@tufte@float@debug{Allowed positions: [#1]}% + \ifthenelse{\equal{#1}{b}\OR\equal{#1}{B}}% + {\renewcommand{\floatalignment}{b}\@tufte@float@debug{Presumed position: [bottom]}}% + {\renewcommand{\floatalignment}{t}\@tufte@float@debug{Presumed position: [top]}}% + % Capture the contents of the \caption and \label commands to use later + \global\let\@tufte@orig@caption\caption% + \global\let\@tufte@orig@label\label% + \renewcommand{\caption}{\optparams{\@tufte@caption}{[][0pt]}}% + \renewcommand{\label}[1]{\@tufte@label{##1}}% + % Handle subfigure package compatibility + \ifthenelse{\boolean{@tufte@packages@subfigure}}{% + % don't move the label while inside a \subfigure or \subtable command + \global\let\label\@tufte@orig@label% + }{}% subfigure package is not loaded + \@tufte@orig@float{#2}[#1]% + \ifthenelse{\boolean{@tufte@float@star}}% + {\setlength{\@tufte@float@contents@width}{\@tufte@fullwidth}}% + {\setlength{\@tufte@float@contents@width}{\textwidth}}% + \begin{lrbox}{\@tufte@figure@box}% + \begin{minipage}[\floatalignment]{\@tufte@float@contents@width}\hbox{}% + }{% end @tufte@float + \par\hbox{}\vspace{-\baselineskip}\ifthenelse{\prevdepth>0}{\vspace{-\prevdepth}}{}% align baselines of boxes + \end{minipage}% + \end{lrbox}% + % build the caption box + \begin{lrbox}{\@tufte@caption@box}% + \begin{minipage}[\floatalignment]{\marginparwidth}\hbox{}% + \ifthenelse{\NOT\equal{\@tufte@stored@caption}{}}{\@tufte@orig@caption[\@tufte@stored@shortcaption]{\@tufte@stored@caption}}{}% + \ifthenelse{\NOT\equal{\@tufte@stored@label}{}}{\@tufte@orig@label{\@tufte@stored@label}}{}% + \par\vspace{-\prevdepth}%% TODO: DOUBLE-CHECK FOR SAFETY + \end{minipage}% + \end{lrbox}% + % now typeset the stored boxes + \begin{fullwidth}% + \begin{minipage}[\floatalignment]{\linewidth}% + \ifthenelse{\boolean{@tufte@float@star}}% + {\@tufte@float@fullwidth[\@tufte@caption@vertical@offset]{\@tufte@figure@box}{\@tufte@caption@box}}% + {\@tufte@float@textwidth[\@tufte@caption@vertical@offset]{\@tufte@figure@box}{\@tufte@caption@box}}% + \end{minipage}% + \end{fullwidth}% + \@tufte@orig@endfloat% end original LaTeX float environment + % output debug info + \ifthenelse{\boolean{@tufte@debug}}{% + \typeout{^^J^^J----------- Tufte-LaTeX float information ----------}% + \ifthenelse{\equal{\@tufte@stored@label}{}}% + {\typeout{Warning: Float unlabeled!}}% + {\typeout{Float label: [\@tufte@stored@label]}}% + \typeout{Page number: [\thepage]}% + \def\MessageBreak{^^J}% + \typeout{\@tufte@float@debug@info}% + \ifthenelse{\boolean{@tufte@symmetric}}% + {\typeout{Symmetric: [true]}}% + {\typeout{Symmetric: [false]}}% + \typeout{----------------------------------------------------^^J^^J}% + }{}% + % reset commands and temp boxes and captions + \gdef\@tufte@float@debug@info{}% + \let\caption\@tufte@orig@caption% + \let\label\@tufte@orig@label% + \begin{lrbox}{\@tufte@figure@box}\hbox{}\end{lrbox}% + \begin{lrbox}{\@tufte@caption@box}\hbox{}\end{lrbox}% + \gdef\@tufte@stored@shortcaption{}% + \gdef\@tufte@stored@caption{}% + \gdef\@tufte@stored@label{}% + \gsetlength{\@tufte@caption@vertical@offset}{0pt}% reset caption offset + } + +\newcommand{\@tufte@float@textwidth}[3][0pt]{% + \ifthenelse{\NOT\boolean{@tufte@symmetric}\OR\boolean{@tufte@float@recto}}{% + % asymmetric or page is odd, so caption is on the right + \hbox{% + \usebox{#2}% + \hspace{\marginparsep}% + \smash{\raisebox{#1}{\usebox{#3}}}% + }% + \@tufte@float@debug{Caption position: [right]}% + }{% symmetric pages and page is even, so caption is on the left + \hbox{% + \smash{\raisebox{#1}{\usebox{#3}}}% + \hspace{\marginparsep}% + \usebox{#2}% + }% + \@tufte@float@debug{Caption position: [left]}% + }% +} + +\newcommand{\@tufte@float@fullwidth}[3][0pt]{% + \ifthenelse{\equal{\floatalignment}{b}}% + {% place caption above figure + \ifthenelse{\NOT\boolean{@tufte@symmetric}\OR\boolean{@tufte@float@recto}}% + {\hfill\smash{\raisebox{#1}{\usebox{#3}}}\par\usebox{#2}\@tufte@float@debug{Caption position: [above right]}}% caption on the right + {\smash{\raisebox{#1}{\usebox{#3}}}\hfill\par\usebox{#2}\@tufte@float@debug{Caption position: [above left]}}% caption on the left + }{% place caption below figure + \ifthenelse{\NOT\boolean{@tufte@symmetric}\OR\boolean{@tufte@float@recto}}% + {\usebox{#2}\par\hfill\smash{\raisebox{#1}{\usebox{#3}}}\@tufte@float@debug{Caption position: [below right]}}% caption on the right + {\usebox{#2}\par\smash{\raisebox{#1}{\usebox{#3}}}\hfill\@tufte@float@debug{Caption position: [below left]}}% caption on the left + }% +} + + +%% +% Redefine the figure environment to place the captions in the margin space + +\renewenvironment{figure}[1][htbp]% + {\ifvmode\else\unskip\fi\begin{@tufte@float}[#1]{figure}{}} + {\end{@tufte@float}} + + +%% +% Redefine the table environment to place the captions in the margin space + +\renewenvironment{table}[1][htbp] + {\ifvmode\else\unskip\fi\begin{@tufte@float}[#1]{table}{}} + {\end{@tufte@float}} + + +%% +% Full-width figure + +\renewenvironment{figure*}[1][htbp]% + {\ifvmode\else\unskip\fi\begin{@tufte@float}[#1]{figure}{star}} + {\end{@tufte@float}} + + +%% +% Full-width table + +\renewenvironment{table*}[1][htbp]% + {\ifvmode\else\unskip\fi\begin{@tufte@float}[#1]{table}{star}} + {\end{@tufte@float}} + + +%% +% Full-page-width area + +\newenvironment{fullwidth} + {\ifthenelse{\boolean{@tufte@symmetric}}% + {\ifthenelse{\boolean{@tufte@changepage}}{\begin{adjustwidth*}{}{-\@tufte@overhang}}{\begin{adjustwidth}[]{}{-\@tufte@overhang}}}% + {\begin{adjustwidth}{}{-\@tufte@overhang}}% + }% + {\ifthenelse{\boolean{@tufte@symmetric}}% + {\ifthenelse{\boolean{@tufte@changepage}}{\end{adjustwidth*}}{\end{adjustwidth}}}% + {\end{adjustwidth}}% + } + +%% +% Format the captions in a style similar to the sidenotes + +\long\def\@caption#1[#2]#3{% + \par% + \addcontentsline{\csname ext@#1\endcsname}{#1}% + {\protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}}% + \begingroup% + \@parboxrestore% + \if@minipage% + \@setminipage% + \fi% + \@tufte@caption@font\@tufte@caption@justification% + \noindent\csname fnum@#1\endcsname: \ignorespaces#3\par% + %\@makecaption{\csname fnum@#1\endcsname}{\ignorespaces #3}\par + \endgroup} + +%% +% If we're NOT using XeLaTeX and the `nofonts' class option was NOT provided, +% we should load the Palatino, Helvetica, and Bera Mono fonts (if they are +% installed.) + +\ifthenelse{\boolean{@tufte@loadfonts}\AND\NOT\boolean{@tufte@xetex}\AND\NOT\boolean{@tufte@luatex}}{% + \IfFileExists{mathpazo.sty}{\RequirePackage[osf,sc]{mathpazo}}{} + \IfFileExists{helvet.sty}{\RequirePackage[scaled=0.90]{helvet}}{} + \IfFileExists{beramono.sty}{\RequirePackage[scaled=0.85]{beramono}}{} + \RequirePackage[T1]{fontenc} + \RequirePackage{textcomp} +}{} + + +%% +% Turns newlines into spaces. Based on code from the `titlesec' package. + +\DeclareRobustCommand{\@tufte@newlinetospace}{% + \@ifstar{\@tufte@newlinetospace@i}{\@tufte@newlinetospace@i}% +} + +\def\@tufte@newlinetospace@i{% + \ifdim\lastskip>\z@\else\space\fi + \ignorespaces% +} + +\DeclareRobustCommand{\newlinetospace}[1]{% + \let\@tufte@orig@cr\\% save the original meaning of \\ + \def\\{\@tufte@newlinetospace}% turn \\ and \\* into \space + \let\newline\\% turn \newline into \space + #1% + \let\\\@tufte@orig@cr% revert to original meaning of \\ +} + + +%% +% Sets up the running heads and folios. + +\RequirePackage{fancyhdr} + +% Set the default page style to 'fancy' +\pagestyle{fancy} + +% Set the header/footer width to be the body text block plus the margin +% note area. +\AtBeginDocument{% + \ifthenelse{\boolean{@tufte@symmetric}} + {\fancyhfoffset[LE,RO]{\@tufte@overhang}} + {\fancyhfoffset[RE,RO]{\@tufte@overhang}} +} + +% The running heads/feet don't have rules +\renewcommand{\headrulewidth}{0pt} +\renewcommand{\footrulewidth}{0pt} + +% The 'fancy' page style is the default style for all pages. +\fancyhf{} % clear header and footer fields +\ifthenelse{\boolean{@tufte@twoside}} + {\fancyhead[LE]{\thepage\quad\smallcaps{\newlinetospace{\plainauthor}}}% + \fancyhead[RO]{\smallcaps{\newlinetospace{\plaintitle}}\quad\thepage}} + {\fancyhead[RE,RO]{\smallcaps{\newlinetospace{\plaintitle}}\quad\thepage}} + + +% The `plain' page style is used on chapter opening pages. +% In Tufte's /Beautiful Evidence/ he never puts page numbers at the +% bottom of pages -- the folios are unexpressed. +\fancypagestyle{plain}{ + \fancyhf{} % clear header and footer fields + % Uncomment the following five lines of code if you want the opening page + % of the chapter to express the folio in the lower outside corner. + %\ifthenelse{\boolean{@tufte@twoside}} + % {\fancyfoot[LE,RO]{\thepage}} + % {\fancyfoot[RE,RO]{\thepage}} +} + +% The `empty' page style suppresses all headers and footers. +% It's used on title pages and `intentionally blank' pages. +\fancypagestyle{empty}{ + \fancyhf{} % clear header and footer fields +} + + +%% +% Set raggedright and paragraph indentation for document + +\AtBeginDocument{\@tufte@justification} + + +%% +% Prints the list of class options and their states. + +\newcommand{\typeoutbool}[2]{% + \ifthenelse{\boolean{#2}} + {\typeout{\space\space#1: true}} + {\typeout{\space\space#1: false}} +} + +\newcommand{\typeoutstr}[2]{% + \typeout{\space\space#1: #2} +} + +\newcommand{\PrintTufteSettings}{% + \typeout{-------------------- Tufte-LaTeX settings ----------} + \typeout{Class: \@tufte@pkgname} + \typeout{} + \typeout{Class options:} + \typeoutbool{a4paper}{@tufte@afourpaper} + \typeoutbool{b5paper}{@tufte@bfivepaper} + \typeoutbool{load fonts}{@tufte@loadfonts} + \typeoutbool{fully-justified}{@tufte@justified} + \typeoutbool{letterspacing}{@tufte@letterspace} + \typeoutbool{sans-serif sidenotes}{@tufte@sfsidenotes} + \typeoutbool{symmetric margins}{@tufte@symmetric} + \typeoutbool{titlepage}{@tufte@titlepage} + \typeoutbool{twoside}{@tufte@twoside} + \typeoutbool{debug}{@tufte@debug} + \typeout{} + \typeout{Internal variables:} + \typeoutbool{[twoside]}{@twoside} + \typeoutbool{pdflatex}{@tufte@pdf} + \typeoutbool{xelatex}{@tufte@xetex} + \typeout{----------------------------------------------------} +} + +%% +% Amount of space to skip before \newthought or after title block + +\newskip\tufteskipamount +\tufteskipamount=1.0\baselineskip plus 0.5ex minus 0.2ex + +\newcommand{\tuftebreak}{\par\ifdim\lastskip<\tufteskipamount + \removelastskip\penalty-100\tufteskip\fi} + +\newcommand{\tufteskip}{\vspace\tufteskipamount} + + +%% +% Produces a full title page + +\newcommand{\maketitlepage}[0]{% + \cleardoublepage% + {% + \sffamily% + \begin{fullwidth}% + \fontsize{18}{20}\selectfont\par\noindent\textcolor{darkgray}{\allcaps{\thanklessauthor}}% + \vspace{11.5pc}% + \fontsize{36}{40}\selectfont\par\noindent\textcolor{darkgray}{\allcaps{\thanklesstitle}}% + \vfill% + \fontsize{14}{16}\selectfont\par\noindent\allcaps{\thanklesspublisher}% + \end{fullwidth}% + } + \thispagestyle{empty}% + \clearpage% +} + +%% +% Title block + +\renewcommand{\maketitle}{% + \newpage + \global\@topnum\z@% prevent floats from being placed at the top of the page + \begingroup + \setlength{\parindent}{0pt}% + \setlength{\parskip}{4pt}% + \let\@@title\@empty + \let\@@author\@empty + \let\@@date\@empty + \ifthenelse{\boolean{@tufte@sfsidenotes}}{% + \gdef\@@title{\sffamily\LARGE\allcaps{\@title}\par}% + \gdef\@@author{\sffamily\Large\allcaps{\@author}\par}% + \gdef\@@date{\sffamily\Large\allcaps{\@date}\par}% + }{% + \gdef\@@title{\LARGE\itshape\@title\par}% + \gdef\@@author{\Large\itshape\@author\par}% + \gdef\@@date{\Large\itshape\@date\par}% + }% + \@@title + \@@author + \@@date + \endgroup + \thispagestyle{plain}% suppress the running head + \tuftebreak% add some space before the text begins + \@afterindentfalse\@afterheading% suppress indentation of the next paragraph +} + + +%% +% Title page (if the `titlepage' option was passed to the tufte-handout +% class.) + +\ifthenelse{\boolean{@tufte@titlepage}} + {\renewcommand{\maketitle}{\maketitlepage}} + {} + +%% +% When \cleardoublepage is called, produce a blank (empty) page -- i.e., +% without headers and footers +\def\cleardoublepage{\clearpage\if@twoside\ifodd\c@page\else + \hbox{} + %\vspace*{\fill} + %\begin{center} + % This page intentionally contains only this sentence. + %\end{center} + %\vspace{\fill} + \thispagestyle{empty} + \newpage + \if@twocolumn\hbox{}\newpage\fi\fi\fi} + +%% +% Make Tuftian-style section headings and TOC formatting + +\titleformat{\chapter}% + [display]% shape + {\relax\ifthenelse{\NOT\boolean{@tufte@symmetric}}{\begin{fullwidth}}{}}% format applied to label+text + {\itshape\huge\thechapter}% label + {0pt}% horizontal separation between label and title body + {\huge\rmfamily\itshape}% before the title body + [\ifthenelse{\NOT\boolean{@tufte@symmetric}}{\end{fullwidth}}{}]% after the title body + +\titleformat{\section}% + [hang]% shape + {\normalfont\Large\itshape}% format applied to label+text + {\thesection}% label + {1em}% horizontal separation between label and title body + {}% before the title body + []% after the title body + +\titleformat{\subsection}% + [hang]% shape + {\normalfont\large\itshape}% format applied to label+text + {\thesubsection}% label + {1em}% horizontal separation between label and title body + {}% before the title body + []% after the title body + +\titleformat{\paragraph}% + [runin]% shape + {\normalfont\itshape}% format applied to label+text + {\theparagraph}% label + {1em}% horizontal separation between label and title body + {}% before the title body + []% after the title body + +\titlespacing*{\chapter}{0pt}{50pt}{40pt} +\titlespacing*{\section}{0pt}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex} +\titlespacing*{\subsection}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus.2ex} + +% Subsubsection and following section headings shouldn't be used. +% See Bringhurst's _The Elements of Typography_, section 4.2.2. +\renewcommand\subsubsection{% + \@tufte@error{\string\subsubsection is undefined by this class. + See Robert Bringhurst's _The Elements of + Typographic Style_, section 4.2.2. + \string\subsubsection was used} + {From Bringhurst's _The Elements of Typographic Style_, section 4.2.2: Use as + many levels of headings as you need, no more and no fewer. Also see the many + related threads on Ask E.T. at http://www.edwardtufte.com/.} +} + +\renewcommand\subparagraph{% + \@tufte@error{\string\subparagraph is undefined by this class.% + See Robert Bringhurst's _The Elements of + Typographic Style_, section 4.2.2. + \string\subparagraph was used} + {From Bringhurst's _The Elements of Typographic Style_, section 4.2.2: Use as + many levels of headings as you need, no more and no fewer. Also see the many + related threads on Ask E.T. at http://www.edwardtufte.com/.} +} + + +% Formatting for main TOC (printed in front matter) +% {section} [left] {above} {before w/label} {before w/o label} {filler + page} [after] +\ifthenelse{\boolean{@tufte@toc}}{% + \titlecontents{part}% FIXME + [0em] % distance from left margin + {\vspace{1.5\baselineskip}\begin{fullwidth}\LARGE\rmfamily\itshape} % above (global formatting of entry) + {\contentslabel{2em}} % before w/label (label = ``II'') + {} % before w/o label + {\rmfamily\upshape\qquad\thecontentspage} % filler + page (leaders and page num) + [\end{fullwidth}] % after + \titlecontents{chapter}% + [0em] % distance from left margin + {\vspace{1.5\baselineskip}\begin{fullwidth}\LARGE\rmfamily\itshape} % above (global formatting of entry) + {\hspace*{0em}\contentslabel{2em}} % before w/label (label = ``2'') + {\hspace*{0em}} % before w/o label + {\rmfamily\upshape\qquad\thecontentspage} % filler + page (leaders and page num) + [\end{fullwidth}] % after + \titlecontents{section}% FIXME + [0em] % distance from left margin + {\vspace{0\baselineskip}\begin{fullwidth}\Large\rmfamily\itshape} % above (global formatting of entry) + {\hspace*{2em}\contentslabel{2em}} % before w/label (label = ``2.6'') + {\hspace*{2em}} % before w/o label + {\rmfamily\upshape\qquad\thecontentspage} % filler + page (leaders and page num) + [\end{fullwidth}] % after + \titlecontents{subsection}% FIXME + [0em] % distance from left margin + {\vspace{0\baselineskip}\begin{fullwidth}\large\rmfamily\itshape} % above (global formatting of entry) + {\hspace*{4em}\contentslabel{4em}} % before w/label (label = ``2.6.1'') + {\hspace*{4em}} % before w/o label + {\rmfamily\upshape\qquad\thecontentspage} % filler + page (leaders and page num) + [\end{fullwidth}] % after + \titlecontents{paragraph}% FIXME + [0em] % distance from left margin + {\vspace{0\baselineskip}\begin{fullwidth}\normalsize\rmfamily\itshape} % above (global formatting of entry) + {\hspace*{6em}\contentslabel{2em}} % before w/label (label = ``2.6.0.0.1'') + {\hspace*{6em}} % before w/o label + {\rmfamily\upshape\qquad\thecontentspage} % filler + page (leaders and page num) + [\end{fullwidth}] % after +}{} + +%% +% Format lists of figures/tables + +\renewcommand\listoffigures{% + \ifthenelse{\equal{\@tufte@class}{book}}% + {\chapter*{\listfigurename}}% + {\section*{\listfigurename}}% +% \begin{fullwidth}% + \@starttoc{lof}% +% \end{fullwidth}% +} + +\renewcommand\listoftables{% + \ifthenelse{\equal{\@tufte@class}{book}}% + {\chapter*{\listtablename}}% + {\section*{\listtablename}}% +% \begin{fullwidth}% + \@starttoc{lot}% +% \end{fullwidth}% +} + +\newcommand{\@tufte@lof@line}[2]{% + % #1 is the figure/table number and its caption text + % #2 is the page number on which the figure/table appears + \leftskip 0.0em + \rightskip 0em + \parfillskip 0em plus 1fil + \parindent 0.0em + \@afterindenttrue + \interlinepenalty\@M + \leavevmode + \@tempdima 2.0em + \advance\leftskip\@tempdima + \null\nobreak\hskip -\leftskip + {#1}\nobreak\qquad\nobreak#2% + \par% +} + +\renewcommand*\l@figure{\@tufte@lof@line} +\let\l@table\l@figure + + +%% +% A handy command to disable hyphenation for short bits of text. +% Borrowed from Peter Wilson's `hyphenat' package. + +\AtBeginDocument{% + \@ifpackageloaded{hyphenat}{}{% + \newlanguage\langwohyphens% define a language without hyphenation rules + \providecommand{\nohyphens}[1]{{\language\langwohyphens #1}}% used for short bits of text + \providecommand{\nohyphenation}{\language\langwohyphens}% can be used inside environments for longer text + }% +} + +%% +% Redefine \bibsection to not mark the running heads. +% (Code modified from natbib.sty.) + +\ifthenelse{\boolean{@tufte@loadnatbib}}{% + \@ifundefined{chapter}{% + \renewcommand\bibsection{\section*{\refname}}% + }{% + \@ifundefined{NAT@sectionbib}{% + \renewcommand\bibsection{\chapter{\bibname}}% + }{% + \renewcommand\bibsection{\section*{\bibname}}% + }% + }% +} + +%% +% An index environment to mimic Tufte's indexes + +\RequirePackage{multicol} +\renewenvironment{theindex}{% + \ifthenelse{\equal{\@tufte@class}{book}}% + {\chapter{\indexname}}% + {\section*{\indexname}}% + \begin{fullwidth}% + \small% + \parskip0pt% + \parindent0pt% + \let\item\@idxitem% + \begin{multicols}{3}% +}{% + \end{multicols}% + \end{fullwidth}% +} +\renewcommand\@idxitem{\par\hangindent 2em} +\renewcommand\subitem{\par\hangindent 3em\hspace*{1em}} +\renewcommand\subsubitem{\par\hangindent 4em\hspace*{2em}} +\renewcommand\indexspace{\par\addvspace{1.0\baselineskip plus 0.5ex minus 0.2ex}\relax}% +\newcommand{\lettergroup}[1]{}% swallow the letter heading in the index + + +%% +% A couple commands to increase the number of floats you can use at a time. + +\def\morefloats{% provides a total of 52 floats + \ifthenelse{\isundefined{\bx@S}}{% + \@tufte@debug@info@noline{Adding 34 more float slots.} + \newinsert\bx@S + \newinsert\bx@T + \newinsert\bx@U + \newinsert\bx@V + \newinsert\bx@W + \newinsert\bx@X + \newinsert\bx@Y + \newinsert\bx@Z + \newinsert\bx@a + \newinsert\bx@b + \newinsert\bx@c + \newinsert\bx@d + \newinsert\bx@e + \newinsert\bx@f + \newinsert\bx@g + \newinsert\bx@h + \newinsert\bx@i + \newinsert\bx@j + \newinsert\bx@k + \newinsert\bx@l + \newinsert\bx@m + \newinsert\bx@n + \newinsert\bx@o + \newinsert\bx@p + \newinsert\bx@q + \newinsert\bx@r + \newinsert\bx@s + \newinsert\bx@t + \newinsert\bx@u + \newinsert\bx@v + \newinsert\bx@w + \newinsert\bx@x + \newinsert\bx@y + \newinsert\bx@z + \gdef\@freelist{\@elt\bx@A\@elt\bx@B\@elt\bx@C\@elt\bx@D\@elt\bx@E + \@elt\bx@F\@elt\bx@G\@elt\bx@H\@elt\bx@I\@elt\bx@J + \@elt\bx@K\@elt\bx@L\@elt\bx@M\@elt\bx@N + \@elt\bx@O\@elt\bx@P\@elt\bx@Q\@elt\bx@R + \@elt\bx@S\@elt\bx@T\@elt\bx@U\@elt\bx@V + \@elt\bx@W\@elt\bx@X\@elt\bx@Y\@elt\bx@Z + \@elt\bx@a\@elt\bx@b\@elt\bx@c\@elt\bx@d\@elt\bx@e + \@elt\bx@f\@elt\bx@g\@elt\bx@h\@elt\bx@i\@elt\bx@j + \@elt\bx@k\@elt\bx@l\@elt\bx@m\@elt\bx@n + \@elt\bx@o\@elt\bx@p\@elt\bx@q\@elt\bx@r + \@elt\bx@s\@elt\bx@t\@elt\bx@u\@elt\bx@v + \@elt\bx@w\@elt\bx@x\@elt\bx@y\@elt\bx@z}% + }{% we've already added another 34 floats, so we'll add 26 more, but that's it! + \ifthenelse{\isundefined{\bx@AA}}{% + \@tufte@debug@info@noline{Adding 26 more float slots.} + \newinsert\bx@AA + \newinsert\bx@BB + \newinsert\bx@CC + \newinsert\bx@DD + \newinsert\bx@EE + \newinsert\bx@FF + \newinsert\bx@GG + \newinsert\bx@HH + \newinsert\bx@II + \newinsert\bx@JJ + \newinsert\bx@KK + \newinsert\bx@LL + \newinsert\bx@MM + \newinsert\bx@NN + \newinsert\bx@OO + \newinsert\bx@PP + \newinsert\bx@QQ + \newinsert\bx@RR + \newinsert\bx@SS + \newinsert\bx@TT + \newinsert\bx@UU + \newinsert\bx@VV + \newinsert\bx@WW + \newinsert\bx@XX + \newinsert\bx@YY + \newinsert\bx@ZZ + \gdef\@freelist{\@elt\bx@A\@elt\bx@B\@elt\bx@C\@elt\bx@D\@elt\bx@E + \@elt\bx@F\@elt\bx@G\@elt\bx@H\@elt\bx@I\@elt\bx@J + \@elt\bx@K\@elt\bx@L\@elt\bx@M\@elt\bx@N + \@elt\bx@O\@elt\bx@P\@elt\bx@Q\@elt\bx@R + \@elt\bx@S\@elt\bx@T\@elt\bx@U\@elt\bx@V + \@elt\bx@W\@elt\bx@X\@elt\bx@Y\@elt\bx@Z + \@elt\bx@a\@elt\bx@b\@elt\bx@c\@elt\bx@d\@elt\bx@e + \@elt\bx@f\@elt\bx@g\@elt\bx@h\@elt\bx@i\@elt\bx@j + \@elt\bx@k\@elt\bx@l\@elt\bx@m\@elt\bx@n + \@elt\bx@o\@elt\bx@p\@elt\bx@q\@elt\bx@r + \@elt\bx@s\@elt\bx@t\@elt\bx@u\@elt\bx@v + \@elt\bx@w\@elt\bx@x\@elt\bx@y\@elt\bx@z + \@elt\bx@AA\@elt\bx@BB\@elt\bx@CC\@elt\bx@DD\@elt\bx@EE + \@elt\bx@FF\@elt\bx@GG\@elt\bx@HH\@elt\bx@II\@elt\bx@JJ + \@elt\bx@KK\@elt\bx@LL\@elt\bx@MM\@elt\bx@NN + \@elt\bx@OO\@elt\bx@PP\@elt\bx@QQ\@elt\bx@RR + \@elt\bx@SS\@elt\bx@TT\@elt\bx@UU\@elt\bx@VV + \@elt\bx@WW\@elt\bx@XX\@elt\bx@YY\@elt\bx@ZZ}% + }{% + \@tufte@error{You may only call \string\morefloats\space twice. See the Tufte-LaTeX documentation for other workarounds} + {There are already 78 float slots allocated. Try using \string\FloatBarrier\space or \string\clearpage\space to place some floats before creating more.} + }% + }% +} + + +%% +% Detect if the subfigure package has been loaded + +\newboolean{@tufte@packages@subfigure} +\setboolean{@tufte@packages@subfigure}{false} +\AtBeginDocument{% + \@ifpackageloaded{subfigure} + {\gsetboolean{@tufte@packages@subfigure}{true}} + {\gsetboolean{@tufte@packages@subfigure}{false}}% +} + + +%% +% Detect of the float package has been loaded + +\AtBeginDocument{% + \@ifpackageloaded{float}{% + % Save the redefined float environment (instead of the LaTeX float environment) + \let\@tufte@orig@float\@float + \let\@tufte@orig@endfloat\end@float + + % Define Tuftian float styles (with the caption in the margin) + \newcommand{\floatc@tufteplain}[2]{% + \begin{lrbox}{\@tufte@caption@box}% + \begin{minipage}[\floatalignment]{\marginparwidth}\hbox{}% + \@tufte@caption@font{\@fs@cfont #1:} #2\par% + \end{minipage}% + \end{lrbox}% + \smash{\hspace{\@tufte@caption@fill}\usebox{\@tufte@caption@box}}% + } + \newcommand{\fs@tufteplain}{% + \def\@fs@cfont{\@tufte@caption@font}% + \let\@fs@capt\floatc@tufteplain% + \def\@fs@pre{}% + \def\@fs@post{}% + \def\@fs@mid{}% + \let\@fs@iftopcapt\iftrue% + } + \let\fs@tufteplaintop=\fs@tufteplain + \let\floatc@tufteplaintop=\floatc@tufteplain + \newcommand\floatc@tufteruled[2]{% + {\@fs@cfont #1} #2\par% + } + \newcommand\fs@tufteruled{% + \def\@fs@cfont{\@tufte@caption@font}% + \let\@fs@capt\floatc@tufteplain% + \def\@fs@pre{\hrule height.8pt depth0pt width\textwidth \kern2pt}% + \def\@fs@post{\kern2pt\hrule width\textwidth\relax}% + \def\@fs@mid{}% + \let\@fs@iftopcapt\iftrue% + } + \newcommand\fs@tufteboxed{% + \def\@fs@cfont{}% + \let\@fs@capt\floatc@tufteplain% + \def\@fs@pre{% + \setbox\@currbox\vbox{\hbadness10000 + \moveleft3.4pt\vbox{\advance\hsize by6.8pt + \hrule \hbox to\hsize{\vrule\kern3pt + \vbox{\kern3pt\box\@currbox\kern3pt}\kern3pt\vrule}\hrule}} + }% + \def\@fs@mid{\kern2pt}% + \def\@fs@post{}% + \let\@fs@iftopcapt\iftrue% + } + }{% + % Nothing to do + } +} + +\AtBeginDocument{% + \@ifpackageloaded{algorithm}{% + % Set the float style to the Tuftian version + \ifthenelse{\equal{\ALG@floatstyle}{plain}\OR\equal{\ALG@floatstyle}{ruled}\OR\equal{\ALG@floatstyle}{boxed}}{% + \@tufte@info@noline{Switching algorithm float style from \ALG@floatstyle\space to tufte\ALG@floatstyle}% + \floatstyle{tufte\ALG@floatstyle}% + \restylefloat{algorithm}% + }{}% + }{% + % Nothing to do + } +} + + +%% +% For compatibility with the subfig package, we'll set captions=false so that +% it doesn't load the caption package (which modifies our own caption +% formatting). + +\PassOptionsToPackage{caption=false}{subfig} + + +%% +% If debugging is enabled, print the Tufte-LaTeX options and the list of +% files. + +\ifthenelse{\boolean{@tufte@debug}} + {\PrintTufteSettings\listfiles} + {} + + +%% +% If there is a `tufte-common-local.tex' file, load it up. + +\IfFileExists{tufte-common-local.tex} + {\input{tufte-common-local.tex}% + \@tufte@info@noline{Loading tufte-common-local.tex}} + {} + + +%% +% End of file +\endinput diff --git a/tufte-handout.cls b/tufte-handout.cls new file mode 100644 index 0000000..73625ee --- /dev/null +++ b/tufte-handout.cls @@ -0,0 +1,39 @@ +\NeedsTeXFormat{LaTeX2e}[1994/06/01] + +\ProvidesClass{tufte-handout}[2015/06/21 v3.5.2 Tufte-handout class] + +%% +% Declare we're tufte-handout +\newcommand{\@tufte@class}{article}% the base LaTeX class (defaults to the article/handout style) +\newcommand{\@tufte@pkgname}{tufte-handout}% the name of the package (defaults to tufte-handout) + +%% +% Load the common style elements +\input{tufte-common.def} + + +%% +% Set up any handout-specific stuff now + +%% +% Abstract + +% TODO The abstract should be printed on its own page of the `titlepage' +% option was specified. +\renewenvironment{abstract} + {\begin{quotation}\if@tufte@sfsidenotes\begin{sffamily}\fi} + {\if@tufte@sfsidenotes\end{sffamily}\fi\end{quotation}} + + +%% +% If there is a `tufte-handout-local.tex' file, load it. + +\IfFileExists{tufte-handout-local.tex}{% + \input{tufte-handout-local}% + \@tufte@info@noline{Loading tufte-handout-local.tex}% +}{} + + +%% +% End of file +\endinput \ No newline at end of file