2024-02-13

What is Simple Linear Regression?

  • Simple Linear Regression is used to establish the relationship between two different variables.

  • This Regression line can be used to estimate new values and predicts trends with data.

  • If the Slope of the Regression Line is positive or negative, it means that both variables are interlinked and that the independent variable is directly or inversely proportional to the dependent variable.

  • If there is no slope to the simple linear regression, then it means that the two variables are not dependent on each other and that there is not correlation present.

Examples of Simple Linear Regression in Real World Environments

  • Linear Regressions are used daily worldwide to make predictions about topics such as weather, business practices, hospitals, etc.

  • Many Business use it to determine if the money being spent is having a positive correlation with the revenue generated as well.

  • Stores use it plot price vs the sales which can be used to set the price of a product.

  • Employers can use it to determine if the pay is having a positive or negative correlation with the productivity level at work.

  • Like this, there are multiple situation world wide in which linear regressions are used to determine the relationships between two variables.

Interactive Plotly Plot that Shows the Distribution of Time Spent of Social Media by Various Age Groups

GGPlot Number 1 with Graphing the Relation between Age and Time Spent

Plot with Simple Linear Regression to Show Relationship of Age vs. Social Media Usage

Math Text in Latex Part 1:

-Formula for Simple Linear Regression: \[\hat{y} = \beta_0 + \beta_1 \cdot x\] - This formula shows the predicted value of y given all of the data points that were given and provided from the original data set. This formula is used to make predictions about what values could be in various situations in the real world. Beta 1 is the slope of the function which essentially determines the correlation coefficient, R value. Beta 0 is the y-intercept of the graph which determines where the graph would start out without any x input.

Math Text in Latex Part 2:

\[\hat{y}:\] - the predicted y-value, for any value x, given the data and best line of fit graph \[\beta_0:\] - y intercept \[\beta_1:\] - slope of the function

R Code to Graph Plots:

library(plotly)
data <- read.csv("/Users/ananthnarne/Downloads/dummy_data.csv")  
plot <- plot_ly(data, x = ~age, y = ~time_spent, type = 'scatter', mode = 'markers',
                marker = list(size = 10, color = 'rgba(255, 182, 193, .9)', line = list(color = 'rgba(152, 0, 0, .8)', width = 2)))
plot
library(ggplot2)
data <- read.csv("/Users/ananthnarne/Downloads/dummy_data.csv")  
ggplot(data, aes(x = age, y = time_spent)) +
  geom_point() + # Add the points
  geom_smooth(method = "lm", se = FALSE, color = "blue") + 
  labs(title = "Age vs Time Spent", x = "Age", y = "Time Spent on R Programming") +
  theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'