feat: Add ordinary least square figure
This commit is contained in:
parent
ae51323390
commit
180409edc3
|
@ -136,3 +136,10 @@ If $H$ is the projection matrix of the subspace generated by $\X$, $X\Y$ is the
|
|||
\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}
|
||||
|
||||
\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}
|
||||
|
|
|
@ -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}
|
||||
|
||||
|
|
|
@ -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}
|
Loading…
Reference in New Issue