2023-09-09

Simple Linear Regression

Simple Linear Regression is a statistical method used to model the relationship between two variables: a dependent variable and an independent variable. The goal is to find the line of best fit that represents the relationship between the two variables. This guide will cover the basics of simple linear regression and how it can be used in data analysis.

Interpretation of Simple Linear Regression

The slope of the line of best fit can be interpreted as the rate of change of the dependent variable for every one unit change in the independent variable. The y-intercept represents the predicted value of the dependent variable when the independent variable is . The coefficient of determination (R-squared) measures the proportion of variance in the dependent variable that is explained by the independent variable.

Equation for Simple Linear Regression

The equation for simple linear regression is: \[ y = mx + b \] Where ‘y’ is the dependent variable, ‘m’ is the slope of the line and ‘b’ is the y-intercept.

Interpreting the coefficients of Simple Linear Regression

The slope, ‘m’, tells us how much the dependent variable changes for every one unit change in the independent variable. \[ \dfrac{dy}{dx} = m \] The y-intercept, ‘b’, tells us the value of the dependent variable when the independent variable is 0. \[ y(0) = b \]

Plotly Plot Data

## Loading required package: ggplot2
## 
## 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
## 
## Call:
## lm(formula = Exam_Score ~ Hours_Studied, data = data)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -24.6443  -4.8623  -0.2705   4.9405  20.2559 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)    53.2301     7.2184   7.374 1.97e-09 ***
## Hours_Studied   2.9298     0.2821  10.385 7.25e-14 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 9.142 on 48 degrees of freedom
## Multiple R-squared:  0.692,  Adjusted R-squared:  0.6856 
## F-statistic: 107.8 on 1 and 48 DF,  p-value: 7.25e-14

Plotly Plot scatter plot with Simple Linear Regression

Ggplot 1 with Simple Linear Regression Analysis

Ggplot 2 with Simple Linear Regression Analysis

R code for Simple Linear Regression

R Markdown

This is an R Markdown presentation. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document.

Slide with Bullets

  • Bullet 1
  • Bullet 2
  • Bullet 3

Slide with R Output

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Slide with Plot