2026-10-13

Explaining the Statistical Idea

For this assignment I have decided to work on the Statistical Idea on Simple Linear Regression.

A simple linear regression requires 2 variables. One of these variables normally represented as X is called an independent variable as this variable is used to predict the dependent variable. The other variable represented as Y is called a dependent variable as it’s result is predicted from an equation using the independent variable.

A simple linear regression is used to analyze the relationship between the 2 variables. From this analysis, we can observe the trends in the data. Some examples of possible trends could be that as the value of the independent variable increases, the dependent variable also increases. This shows a positive relationship. While if the dependent variable decreases, given the independent variable increases then this is an example of a negative relationship.

An Example of Simple Linear Regression

We can use the in built cars dataset of R in order to analyze the simple linear regression between two of dataset’s variable

For this assignment, we use the speed of car and stopping distance as the two variables required for the simple linear regression analysis.

We can choose the independent Variable (X) to be the speed of the car and the dependent variable (Y) to be the distance travelled to stop the car.

From these variables, we can answer the relationship on the speed of car and stopping distance using simple linear regression.

Mathematics on Simple Linear Regression

A Simple Linear Regression is in the given format: \(Y=B_0+B_1X\)

Out of all of these variables: Y is the dependent Variable \(B_0\) is y-intercept of the Simple Linear Regression \(B_1\) is the slope of the Simple Linear Regression X is the independent variable

In our dataset, X is set to be the speed of the car while Y is set to be the stopping distance

Further Explanation on Mathematics of the Simple Linear Regression

When we will perform analysis of this dataset in future steps we will be able to calculate the value for \(B_0\) and \(B_1\). \(B_0\) is the value in the simple linear regression if the independent variable(speed of car) was set to 0.

The value of \(B_1\) decides whether the Simple Linear Regression shows a positive or negative relationship between the 2 variables. If the value of \(B_1\) is more than 0 then this show a positive relationship between the independent and dependent variables. While if the value of \(B_1\) is less than 0 then this shows the negative relationship between the independent and dependent variables. If \(B_1\) = 0 then the dependent variable will always be a constant value equal to \(B_0\) which normally do not bring any interesting relationship between these 2 variables.

Loading dataset in model

To be able to find the exact columns used in the dataset, we perform the head operation on the cars dataset.

data(cars)
head(cars)
##   speed dist
## 1     4    2
## 2     4   10
## 3     7    4
## 4     7   22
## 5     8   16
## 6     9   10

We also load the dataset by performing operation data(cars) to be able to use its columns in later steps in the R code calculations.

Using the columns names which includes dataset’s content to build a regression model

From this we know that the column names used are dist and speed. Using these names, we will be able to build a Simple regression model

Simple_Regression_Model = lm(dist ~ speed, data=cars)
coef(Simple_Regression_Model)
## (Intercept)       speed 
##  -17.579095    3.932409

Observations seen after building the model

From using R operations we find \(B_0\) is approximately -17.579 and \(B_1\) is 3.932, leading for this equation to be y = -17.579 + 3.932x, where y is stopping distance and x is speed of car. This means an increase in 1 mph in car speed leads to 3.932 ft increase in distance required to stop the car

Histogram for the distance required by the car to stop

Interpretation of the histogram (1st ggplot)

By looking at this histogram we see that this distribution is right-skewed. From this we see that most of the observations are see in distances <= 40 ft, and the number of observations on an average reduces as the distance increases.

Scatterplot of Car’s speed and its distance including the regression line

Interpretation of the scatterplot (2nd ggplot)

Looking at the regression line, we see a clear positive relationship between Car’s speed and the Stopping distance. This means when then car’s speed increase then on an average the stopping distance of the car also increases.

Interactive plotly visualization

Interpretation of the plotly visualization

In this interactive plot, we can hover on each point to see its exact x and y co-ordinates which are the car’s speed (mph) and dist before car stops (ft) respectively. We also these co-ordinates when we hover on the blue regression line which was predicted by the model.

Conclusion

In summary, we looked into the statistical idea of simple linear regression by working on an example using the cars dataset. A simple linear regression uses a linear equation having one independent variable which is speed of car in the example and dependent variable which is the stopping distance in the example.

To find the slope and y-intercept this equation, we build a single linear regression model and find out that the y-intercept is -17.579 and slope is 3.932. Using this we are able to develop an equation y = -17.579 + 3.932x, where y is stopping distance and x is speed of car.

We then use this regression line in the scatter plot and the interactive plotly regression and see a clear positive relationship in the data.