knitr::opts_chunk$set(echo = FALSE)
# rmdhelp::show_knit_hook_call()
knitr::knit_hooks$set(hook_convert_odg = rmdhelp::hook_convert_odg)

Goal

Assessment of relationship between

Example

tbl_reg <- tibble::tibble(Animal = c(1:10),
                          `Breast Circumference` = c(176, 177, 178, 179, 179, 180, 181, 182,183, 184),
                          `Body Weight` = c(471, 463, 481, 470, 496, 491, 518, 511, 510, 541))
n_nr_obs <- nrow(tbl_reg)
knitr::kable(tbl_reg,
             booktabs = TRUE,
             longtable = TRUE,
             escape = FALSE)

Diagram

library(ggplot2)
ggplot(tbl_reg, aes(x = `Breast Circumference`, y = `Body Weight`)) +
  geom_point(color = "blue") 

Observations

Regression Model

#rmdhelp::use_odg_graphic(ps_path = "odg/measure-band.odg")
knitr::include_graphics(path = "odg/measure-band.png")

Model Building

\begin{equation} E(y) = b_0 + b_1 * x \notag \end{equation}

Parameter Estimation

Least Squares

#rmdhelp::use_odg_graphic(ps_path = "odg/lsq-plot.odg")
knitr::include_graphics(path = "odg/lsq-plot.png")

Estimators

Find values $\hat{b}_0$ and $\hat{b}_1$ such that

\begin{equation} \mathbf{e}^T\mathbf{e} = \sum_{i=1}^N e_i^2 = \sum_{i=1}^N \left[ y_i - E(e_i) \right]^2 = \sum_{i=1}^N \left[ y_i - b_0 - b_1*x_i \right]^2 \notag \end{equation}

is minimal

Minimization

\begin{align} \frac{\partial\mathbf{e}^T\mathbf{e}}{\partial b_0} &= -2 \sum_{i=1}^N \left[y_i - b_0 - b_1x_i\right] \notag \ &= -2\left[\sum_{i=1}^N y_i - Nb_0 - b_1\sum_{i=1}^N x_i\right] \notag \end{align}

\begin{align} \frac{\partial\mathbf{e}^T\mathbf{e}}{\partial b_1} &= -2 \sum_{i=1}^N x_i\left[y_i - b_0 - b_1x_i\right] \notag \ &= -2 \left[\sum_{i=1}^N x_iy_i - b_0 \sum_{i=1}^N x_i - b_1 \sum_{i=1}^N x_i^2 \right]\notag \end{align}

Notation

$$x. = \sum_{i=1}^N x_i$$ $$y. = \sum_{i=1}^N y_i$$ $$(x^2). = \sum_{i=1}^N x_i^2 $$ $$(xy). = \sum_{i=1}^N x_iy_i$$ $$\bar{x}. = {x. \over N}$$ $$\bar{y}. = {y. \over N}$$

Solutions

\begin{equation} \hat{b}_0 = \bar{y}. - \hat{b}_1\bar{x}. \notag \end{equation}

and

\begin{equation} \hat{b}_1 = \frac{(xy). - N\bar{x}.\bar{y}.}{(x^2). - N\bar{x}.^2} \notag \end{equation}



charlotte-ngs/asmss2022 documentation built on June 7, 2022, 1:33 p.m.