Linear regression model

Practicing Statistics Interview Questions in R

Zuzanna Chmielewska

Actuary

Linear regression model

fruits

Practicing Statistics Interview Questions in R

Linear regression model

a price of a house

Practicing Statistics Interview Questions in R

data points with some positive linear correlation

Practicing Statistics Interview Questions in R

data points with some positive linear correlation

Practicing Statistics Interview Questions in R

Linear regression model

$$ y_i = \beta_0 + \beta_1 \cdot x_{i1} + ... + \beta_p \cdot x_{ip} + e_{i}$$ where:

  • $y_i$ - dependent variable,
  • $x_{ij}$ - independent variables,
  • $\beta_{j}$ - parameters,
  • $e_i$ - error.
Practicing Statistics Interview Questions in R

Linear predictor function

$$ \hat{y_i} = \beta_0 + \beta_1 \cdot x_{i1} + ... + \beta_p \cdot x_{ip}$$

Practicing Statistics Interview Questions in R

simple linear model $$ \hat{y_i} = \beta_0 + \beta_1 \cdot x_{i} $$

Practicing Statistics Interview Questions in R

simple linear model $$ \hat{y_i} = \beta_0 + \beta_1 \cdot x_{i} $$

Practicing Statistics Interview Questions in R

simple linear model $$ \hat{y_i} = \beta_0 + \beta_1 \cdot x_{i} $$

Practicing Statistics Interview Questions in R

simple linear model $$ \hat{y_i} = \beta_0 + \beta_1 \cdot x_{i} $$

Practicing Statistics Interview Questions in R

Log-transformation

Examples: $$ \hat{y_i} = \beta_0 + \beta_1 \cdot ln(x_{i1}) + ... + \beta_p \cdot x_{ip}$$

$$ ln(\hat{y_i}) = \beta_0 + \beta_1 \cdot x_{i1} + ... + \beta_p \cdot x_{ip}$$

Practicing Statistics Interview Questions in R

Assumptions

  • Linear relationship
  • Normally distributed errors
  • Homoscedastic errors
  • Independent observations
Practicing Statistics Interview Questions in R

Linear model in R

model <- lm(dist ~ speed, data = cars)

print(model)
Call:
lm(formula = dist ~ speed, data = cars)

Coefficients:
(Intercept)        speed  
    -17.579        3.932
Practicing Statistics Interview Questions in R

Linear model in R

model <- lm(dist ~ speed, data = cars)
new_car <- data.frame(speed = 17.5)

predict(model, newdata = new_car)
       1 
51.23806
Practicing Statistics Interview Questions in R

Diagnostic plots

model <- lm(dist ~ speed, data = cars)
plot(model)

linear model diagnostic plots

Practicing Statistics Interview Questions in R

linear model diagnostic plot

Practicing Statistics Interview Questions in R

linear model diagnostic plot

Practicing Statistics Interview Questions in R

linear model diagnostic plot

Practicing Statistics Interview Questions in R

linear model diagnostic plot

Practicing Statistics Interview Questions in R

Summary

  • linear regression model
  • linear predictor function
  • lm() in R
  • diagnostic plots
Practicing Statistics Interview Questions in R

Let's practice!

Practicing Statistics Interview Questions in R

Preparing Video For Download...