“The goal of this presentation is to inform what simple linear regression is in relation to statistics and how it might be applied.I will be using a built in dataframe ,in R studio, called Tree to demonstrate.”
2024-02-15
“The goal of this presentation is to inform what simple linear regression is in relation to statistics and how it might be applied.I will be using a built in dataframe ,in R studio, called Tree to demonstrate.”
“A simple Linear Regression models the relationship between a single independent variable (X) and a dependent variable (Y).”The relationship is modeled by the equation:
\[ Y = \\beta_0 + \\beta_1 X + \\epsilon \] let the following be true: Y= dependent variable
X= independent variable
\(\\beta_0\) = intercept
\(\\beta_1\) = slope
\(\\epsilon\) = error term”
“For multiple the equation is:
\[ Y = \\beta_0 + \\beta_1 X_1 + \\beta_2 X_2 +... + \\beta_n X_n + \\epsilon \] Y= dependent variable
X_!,X_2…X_n = Independent variable
\(\\beta_0\) = intercept
\(\\beta_1\) = slope
\(\\epsilon\) = error term”
“When using linear regression we assume these cases:
Linearity: There should be a linear relationship between the independent and dependent variables.
Independence:The residuals (errors) should be independent of each other. There should be no pattern in the residuals over time or across observations.
Homoscedasticity:The variance of the residuals should be constant across all levels of the independent variables. In other words, the spread of the residuals should be the same at all values of the independent variable.
Normality:The residuals should follow a normal distribution. This assumption is important for hypothesis testing and confidence intervals. ”
“Why do we need linear regression? The models that make up Linear Regression are actually the basis for machine learning itself. Lets look at a simple graph
“Using previous data we can approximate a rate of change through the data with a line. Giving a better understanding of the datas trend over a dependent variable.
## `geom_smooth()` using formula = 'y ~ x'
“Another example would be this data set collected from 30 random clerical employees.All from a financial company on a questionnaires of favorable responses to 7 questions.
"For those who wish to go into R studio and test linear regression models
on diffrent data sets the code is listed bellow:
knitr::opts_chunk$set(echo = FALSE)
library(tidyverse)]
library(ggplot2)
library(plotly)
ex_tree <- ggplot(data = trees, aes(x = Girth, y = Volume)) + geom_point()
ex_tree <- geom_smooth(method = "lm")
model <- lm(complaints ~ rating, data = attitude)
predicted <- predict(model)
plot <- plot_ly(data = attitude, x = ~rating, y = ~complaints,
type = "scatter", mode = "markers", name = "Data")
plot <- add_trace(plot, x = attitude$rating, y = predicted,
mode = "lines", name = "Regression Line")
plot <- layout(plot, title = "Linear Regression Model",
xaxis = list(title = "Rating"),
yaxis = list(title = "Complaints"))
print(plot)
"Linear regression is an efficient and important part of statistics.While the examples were limited to graphs ,for coding purposes, Linear regression is used constantly in day to day activities. Unknowingly your brain makes predictions based off expected values vs known values."