diff --git a/content/chapters/part1/1.tex b/content/chapters/part1/1.tex index a83f2c5..ceb60eb 100644 --- a/content/chapters/part1/1.tex +++ b/content/chapters/part1/1.tex @@ -135,4 +135,11 @@ If $H$ is the projection matrix of the subspace generated by $\X$, $X\Y$ is the \includestandalone{figures/schemes/orthogonal_projection} \caption{Orthogonal projection of $\Y$ on plan generated by the base described by $\X$. $\color{blue}a$ corresponds to $\norm{\X\hat{\beta} - \bar{\Y}}^2$ and $\color{blue}b$ corresponds to $\norm{\Y - \hat{\beta}\X}^2$} \label{fig:scheme-orthogonal-projection} -\end{figure} \ No newline at end of file +\end{figure} + +\begin{figure} + \centering + \includestandalone{figures/schemes/ordinary_least_squares} + \caption{Ordinary least squares and regression line with simulated data.} + \label{fig:ordinary-least-squares} +\end{figure} diff --git a/content/chapters/part1/2.tex b/content/chapters/part1/2.tex index f614b6a..0c78cd7 100644 --- a/content/chapters/part1/2.tex +++ b/content/chapters/part1/2.tex @@ -69,7 +69,7 @@ Let $u = \begin{pmatrix} \begin{figure} \centering \includestandalone{figures/schemes/vector_orthogonality} - \caption{Illustration for the scalar product of two orthogonal vectors.} + \caption{Scalar product of two orthogonal vectors.} \label{fig:scheme-orthogonal-scalar-product} \end{figure} diff --git a/figures/schemes/ordinary_least_squares.tex b/figures/schemes/ordinary_least_squares.tex new file mode 100644 index 0000000..39190b2 --- /dev/null +++ b/figures/schemes/ordinary_least_squares.tex @@ -0,0 +1,45 @@ +\documentclass[margin=0.5cm]{standalone} +\usepackage{tikz} +\usepackage{luacode} + + +\begin{document} + +\begin{tikzpicture} + % Draw axes + \draw[->] (0,0) -- (5,0); + \draw[->] (0,0) -- (0,5); + + \directlua{ + function runif(min, max) + return min + (max - min) * math.random() + end + math.randomseed(42) + x_min = 0 + x_max = 5 + error_min = -1 + error_max = 1 + beta0 = 2 + beta1 = 1/5 + x_values = {} + y_values = {} + for i=1,42 do + x = runif(x_min, x_max) + epsilon = runif(error_min, error_max) + y_hat = beta0 + beta1 * x + y = y_hat + epsilon + tex.print("\\draw[-,very thin, lightgray] ("..x..","..y_hat..") -- ("..x..","..y..") ;") + x_values[i] = x + y_values[i] = y + end + for i=1,42 do + x = x_values[i] + y = y_values[i] + tex.print("\\node[black] at ("..x..","..y..") {.};") + end + } + % Draw least square line + \draw[-,blue,thick] (0,2) -- (5,\directlua{tex.print(5*beta1+beta0)}); + % Draw square norm +\end{tikzpicture} +\end{document} \ No newline at end of file diff --git a/main.pdf b/main.pdf index a0ebaac..f922198 100644 Binary files a/main.pdf and b/main.pdf differ