2022-09-18

Linar Regression on height and weight of women

This is a study of linear regression of the height and weight of 15 women

The Data for height and weight of 15 women

##    height weight
## 1      58    115
## 2      59    117
## 3      60    120
## 4      61    123
## 5      62    126
## 6      63    129
## 7      64    132
## 8      65    135
## 9      66    139
## 10     67    142
## 11     68    146
## 12     69    150
## 13     70    154
## 14     71    159
## 15     72    164

Linear regression formulas

model: \(Height = \beta_0 + \beta_1\cdot Weight + \varepsilon\), where \(\varepsilon \sim \mathcal{N}(\mu=0; \,\,\sigma^2)\)

Fitted: \(Height = \hat\beta_0 + \hat\beta_1\cdot Weight\)

plotting the data with plotly

R code to plot the linear regression

y = women$weight; x = women$height
mod = lm(y~x, data = women)

xax <- list(
  title = "Height",
  titlefont = list(family="Modern Computer Roman")
)
yax <- list(
  title = "Weight",
  titlefont = list(family="Modern Computer Roman")
)

plot_ly(x=x, y=y, type="scatter", mode="markers", name="data") %>%
   add_lines(x = x, y = fitted(mod), name="fitted") %>%
   layout(xaxis = xax, yaxis = yax)

plotting the data using ggplot2

## `geom_smooth()` using formula 'y ~ x'

Calculating residuals

Residual = actual y value - predicted y value

\(r_i = y_i - \hat{y_i}\)

\(r_i = y_i - (m \cdot x + b)\)

plotting residuals using ggplot2