knitr::opts_chunk$set(echo = FALSE)
options(repos = c(CRAN = "https://cran.rstudio.com/"))

Introduction and Presentation Goal

Welcome to the presentation on Multivariate Linear Regression using the Iris dataset. Goal: To understand and apply multivariate linear regression on the Iris dataset to predict Sepal.Length based on Sepal.Width and Petal.Length.

Simple Linear Regression

Simple Linear Regression models the relationship between two variables using a linear equation.

\[ y = \beta_0 + \beta_1x + \epsilon \]

Where:

  • \(y\) is the dependent variable.
  • \(x\) is the independent variable.
  • \(\beta_0\) is the intercept.
  • \(\beta_1\) is the slope.
  • \(\epsilon\) is the error term.

Multivariate Linear Regression

Multivariate Linear Regression extends Simple Linear Regression to multiple predictors. \[ y = \beta_0 + \beta_1x_1 + \beta_2x_2 + \cdots + \beta_nx_n + \epsilon \] Where:

  • \(y\) is the dependent variable.
  • \(x_1, x_2, \ldots, x_n\) are the independent variables.
  • \(\beta_0\) is the intercept.
  • \(\beta_1, \beta_2, \ldots, \beta_n\) are the slopes.
  • \(\epsilon\) is the error term.

Installing packages

First, let’s install necessary packages and load the dataset:

## 
## The downloaded binary packages are in
##  /var/folders/6c/yl6fx9f13fvbbjhrwvpts6540000gn/T//RtmplaQE8X/downloaded_packages
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
## Registered S3 method overwritten by 'GGally':
##   method from   
##   +.gg   ggplot2
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union

Introduction to Iris Dataset

The Iris dataset contains measurements of sepals and petals for three species of iris flowers: Setosa, Versicolor, and Virginica.

##   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 1          5.1         3.5          1.4         0.2  setosa
## 2          4.9         3.0          1.4         0.2  setosa
## 3          4.7         3.2          1.3         0.2  setosa
## 4          4.6         3.1          1.5         0.2  setosa
## 5          5.0         3.6          1.4         0.2  setosa
## 6          5.4         3.9          1.7         0.4  setosa

EDA and Prep of Sepal.Width

Exploratory Data Analysis for Sepal.Width

EDA and Prep of Petal.Length

Exploratory Data Analysis for Petal.Length

EDA and Prep of Sepal.Length

Exploratory Data Analysis for Sepal.Length

Multivariate Linear Regression Code

Code for fitting the multivariate linear regression model:

##               Estimate Std. Error   t value     Pr(>|t|)
## (Intercept)  2.2491402 0.24796963  9.070224 7.038510e-16
## Sepal.Width  0.5955247 0.06932816  8.589940 1.163254e-14
## Petal.Length 0.4719200 0.01711768 27.569160 5.847914e-60

3D-plot of regression output

Finally, let us visualise the regression output: