"This page shows an example of how to combine theory, quizes and code on one page. With headings and boxes, the interactive parts can be indicated (for now only if part of one cell)\n",
"\n",
"Remark: at this moment, the use of a jupyter-quiz combined with interactive code does not work.\n",
"Remark: \n",
" - The coding is not interactive when the {fa}`rocket` --> {guilabel}`Live Code` is not clicked, you have to make that clear to the reader. You can make sure all relevant cells are executed upon starting the interactive mode by adding `thebe-init` or `thebe-remove-input-init` as a cell tag.\n",
" - at this moment, the use of a jupyter-quiz combined with interactive code does not work.\n",
"\n",
"## Weighted least-squares estimation\n",
"In ordinary least-squares estimation, we assume that all observations are equally important. In many cases this is not realistic, as observations may be obtained by different measurement systems, or under different circumstances. We want our methodology for least-squares estimation to be able to take this into account.\n",
...
...
@@ -95,6 +97,8 @@
"source": [
"## Exercise\n",
"\n",
"For this exercise, active the live coding by clicking {fa}`rocket` --> {guilabel}`Live Code` on the top of this page. As soon as this is loaded, you can start coding yourself.\n",
"\n",
":::{card}\n",
"\n",
"You have a time series of 8 measurements and fit a model assuming a linear trend (constant velocity).\n",
...
...
%% Cell type:markdown id: tags:
# Example theory-quiz-code page
This page shows an example of how to combine theory, quizes and code on one page. With headings and boxes, the interactive parts can be indicated (for now only if part of one cell)
Remark: at this moment, the use of a jupyter-quiz combined with interactive code does not work.
Remark:
- The coding is not interactive when the {fa}`rocket` --> {guilabel}`Live Code` is not clicked, you have to make that clear to the reader. You can make sure all relevant cells are executed upon starting the interactive mode by adding `thebe-init` or `thebe-remove-input-init` as a cell tag.
- at this moment, the use of a jupyter-quiz combined with interactive code does not work.
## Weighted least-squares estimation
In ordinary least-squares estimation, we assume that all observations are equally important. In many cases this is not realistic, as observations may be obtained by different measurement systems, or under different circumstances. We want our methodology for least-squares estimation to be able to take this into account.
We achieve this goal by introducing a weight matrix in the minimization problem:
In the unweighted least-squares approach, we arrive at the normal equation by pre-multiplying both sides of $\mathrm{y=Ax}$ with the transpose of the design matrix $\mathrm{A^T}$:
$$
\mathrm{y=Ax} \;\rightarrow \;\mathrm{A^T\; y = A^T\; A x }
$$
In the weighted least-squares approach, we now need to add weight matrix $W$ to this pre-multiplication factor, i.e., $ \mathrm{A^T W}$, to obtain the normal equation:
$$
\mathrm{y=Ax} \;\rightarrow \;\mathrm{A^T W \; y = A^TW \; A x}
$$
The normal matrix is now defined as $\mathrm{N=A^T W A}$. From this, assuming that the normal matrix $N$ is invertible (non-singular) we find the weighted least-squares estimate $ \mathrm{\hat{x}} $,
$$
\begin{align*}
\mathrm{\hat{x}} &= \mathrm{(A^T W A)^{-1} A^T W y} \\
The weight matrix $\mathrm{W}$ expresses the (relative) weights between the observations. It is always a square matrix. The size of the weight matrix depends on the number of observations, $m$. The size of the weight matrix is $m\times m$.
If it is a unit matrix ($\mathrm{W=I}$), this implies that all observations have equal weight. Note that in this case the equations are equal to the ordinary least-squares solution.
If it is a diagonal matrix, with different values on the diagonal, this implies that entries with a higher value correspond to the observations which are considered to be of more importance. If the weight matrix has non-zero elements on the off-diagonal positions, this implies that (some) observations are correlated.
## Weighted least-squares estimator: properties
Until now, we have looked at the weighted least-squares solution of a single *realization* of the observations, where generally we assume that it is a realization of the *random* observable vector $Y$, since measurements are affected by random errors. As such it follows the the weighted least-squares *estimator* is given by:
$$
\hat{X} = \mathrm{(A^T W A )^{-1} A^T W} Y
$$
This estimator has two important properties: it is *linear* and *unbiased*.
The linearity property is due to the fact that $\hat{X}$ is a linear function of the observables $Y$.
The unbiased property means that the expectation of $\hat{X}$ is equal to the true (but unknown) $\mathrm{x}$. This can be shown as follows:
$$
\mathbb{E}(\hat{X}) = \mathrm{(A^T W A )^{-1} A^T W} \mathbb{E}(Y) = \mathrm{(A^T W A )^{-1} A^T W Ax = x}
$$
This a very desirable property. It applies that if we would repeat the measurements many times to obtain a new estimate, the *average of the estimated* values would be equal to the truy values.
%% Cell type:markdown id: tags:
## Exercise
For this exercise, active the live coding by clicking {fa}`rocket` --> {guilabel}`Live Code` on the top of this page. As soon as this is loaded, you can start coding yourself.
:::{card}
You have a time series of 8 measurements and fit a model assuming a linear trend (constant velocity).
Times of observations, observed values and number of observations are given.
Remark: It would be nice if the box in which this exercise is given extends to all cells below.