Exercise

# Fitting a linear model "by hand"

Recall the simple linear regression model: $$ Y = b_0 + b_1 \cdot X $$

Two facts enable you to compute the slope \(b_1\) and intercept \(b_0\) of a simple linear regression model from some basic summary statistics.

First, the slope can be defined as:

$$ b_1 = r_{X,Y} \cdot \frac{s_Y}{s_X} $$

where \(r_{X,Y}\) represents the correlation (`cor()`

) of \(X\) and \(Y\) and \(s_X\) and \(s_Y\) represent the standard deviation (`sd()`

) of \(X\) and \(Y\), respectively.

Second, the point \((\bar{x}, \bar{y})\) is *always* on the least squares regression line, where \(\bar{x}\) and \(\bar{y}\) denote the average of \(x\) and \(y\), respectively.

The `bdims_summary`

data frame contains all of the information you need to compute the slope and intercept of the least squares regression line for body weight (\(Y\)) as a function of height (\(X\)). You might need to do some algebra to solve for \(b_0\)!

Instructions

**100 XP**

- Print the
`bdims_summary`

data frame. - Use
`mutate()`

to add the`slope`

and`intercept`

to the`bdims_summary`

data frame.