Measures of association or relationship: Linear Regression

00Comment iconComment iconComment iconComment icon

Today we will describe in the form of a linear function the connection between two variables

Writer image

Translated byEditorial

Writer image

Revised byEditorial

Edit Article

Introduction

For any two data sets you may find, there are two viable data collection alternatives that can be used to describe the interaction between the two sets.

The first is to describe how strongly the variables are associated. For this, the correlation already taught is used, where the size of the correlation coefficient indicates how strongly they are associated.

The second is to try to establish a relationship between the two variables, where it is possible to say how much one variable changes if we decrease or increase the second.

Functional Relationship

As we know, the perimeter and the side of a square are related. The relationship that connects them is perfectly defined and can be expressed through a mathematical statement:

\[ 2p = 4l \]

Where 2p is the perimeter and l is the side.

Then, by assigning any value to R, it is possible to determine exactly the value of 2p.

Now let us consider the relationship that exists between the weight and height of a group of people. It is evident that this relationship is not of the same type as the previous one; it is much less precise. Thus, it may happen that different heights correspond to equal weights or that equal heights correspond to different weights. However, on average, the greater the height, the greater the weight.

Relationships of the perimeter-side type are known as functional relationships, and those of the weight-height type as statistical relationships. Statistical relationships can be represented by a function, also called simple linear regression.

Objectives of Simple Linear Regression

- Predict values of a dependent variable (Y) as a function of an independent variable (X).

- Understand how much variations in X can affect Y.

Simple Linear Regression

Simple linear regression is used to examine the relationship between a dependent variable and an independent variable. After performing an analysis, regression statistics can be used to predict the dependent variable when the independent variable is known. Regression goes beyond correlation by adding prediction capabilities.

People use regression at an intuitive level every day. In business, a well-dressed man is considered a financial success. A mother knows that more sugar in her children’s diet results in higher energy levels. The ease of waking up in the morning often depends on how late you went to bed the night before. Quantitative regression adds precision by developing a mathematical formula that can be used for predictive purposes.

For example, a medical researcher may want to use body weight (independent variable) to predict the most appropriate dose for a new medication (dependent variable). The purpose of running regression is to find a formula that fits the relationship between the two variables. You can then use this formula to predict values for the dependent variable when only the independent variable is known. A doctor can prescribe the appropriate dose based on a person’s body weight.

The regression line (known as the least squares line) is a graph of the expected value of the dependent variable for all values of the independent variable. Technically, it is the line that “minimizes the squared residuals.” The regression line is the one that best fits the data in a scatter plot.

Using the regression equation, the dependent variable can be predicted from the independent variable. The slope of the regression line (b) is defined as the rise divided by the run. The y-intercept (a) is the point on the y-axis where the regression line would intercept the y-axis. The slope and the y-intercept are incorporated into the regression equation. The intercept is generally called the constant or linear coefficient, and the slope is called the angular coefficient. Since the regression model is generally not a perfect predictor, there is also an error term in the equation.

In the regression equation, y is always the dependent variable and x is always the independent variable. Here are three equivalent ways to mathematically describe a linear regression model:

\[ y = (\text{angle} x) + \text{intercept} + \text{error} \]

\[ y = (\text{angular coefficient} · x) + \text{linear coefficient} + \text{error} \]

\[ y = a*x + b + e \]

We call simple linear regression the line that minimizes the error, calculating A and B so that the expected value of the error is zero.

Calculating Constants A and B

The constants are calculated starting with A. Similar to correlation, the angular coefficient is also calculated from covariance. Its formula is as follows:

\[ a = \frac{\sigma_{x,y}}{\sigma_{x}^2} \]

The angle is the covariance divided by the variance of the independent variable. In this case, it can be seen that, unlike the angular coefficient, only one variable remains in the divisor, while still keeping the variance of the dependent variable in the model.

Knowing A, B is calculated:

\[ y = a · x + b + e \]

\[E[y] = E[a · x + b + e] \]

\[ E[y] = E[a · x] + E[b] + E[e] \]

\[ \bar{y} = a · \bar{x} + b + 0 \]

\[ b = \bar{y} - a · \bar{x} \]

Some books write the direct formula:

\[ a = \frac{N · (\sum{X · Y}) - (\sum{X}) · (\sum{Y})}{N · (\sum{X^{2}}) - (\sum{X})^{2}} \]

\[ b = \frac{(\sum{Y}) - a · (\sum{X})}{N} \]

With the angular and linear coefficients, we can finally form a line that best explains the relationship between two variables:

Image content of the Website

In a linear relationship, the line will be the one that best explains this relationship because the average of the errors is zero!

Why divide covariance by the variance of \( X \)?

We want \( \beta_1 \) to represent "how much \( Y \) changes, on average, when \( X \) increases by 1 unit".

But covariance alone does not give us this directly, because:

- If \( X \) has a very large variance (values that are very spread out), the covariance can be large even if the relationship between \( X \) and \( Y \) is weak.

- If \( X \) has a very small variance (values that are very concentrated), the covariance can be small even if the relationship is strong.

Solution: We divide the covariance by the variance of \( X \) to normalize the effect of the scale of \( X \). This gives us a standardized measure of the relationship between \( X \) and \( Y \).

Think of it this way:

- Covariance = "How much do \( X \) and \( Y \) change together?"

- Variance of \( X \) = "How much does \( X \) vary on its own?"

By dividing the covariance by the variance of \( X \), we are calculating:

\[ \beta_1 = \frac{\text{How much } X \text{ and } Y \text{ vary together}}{\text{How much } X \text{ varies on its own}} \]

This answers the question: "For each unit that \( X \) varies, how much does \( Y \) vary, on average?"

Correlation vs. Linear Regression

There are real differences between correlation and linear regression, but fortunately, they usually do not matter. Correlation and linear regression provide exactly the same association value (r²), and for most biological experiments, this is the only truly important result.

The main difference is that correlation implies an association between two variables, but not direct interference between them, while linear regression assumes that an increase in the independent variable causes an effect on the dependent variable.

Many people usually see linear regression as an item to be done after analyzing correlation, where it is even possible to visually analyze the relationship between two variables. In any case, it is interesting to calculate both because they give different results: correlation says how much of the variance is explained by the relationship between the two variables (29% correlation implies that only 29% is explained); while linear regression calculates a direct relationship (if we increase x by 1, how much will y increase), but this relationship may be flawed since not all variation is explained by the relationship between the two variables.

Will the data always be a straight line?

A great way to check whether the line is a good fit for your data is through the coefficient of determination: r². In the end, r² is just the squared correlation; for this reason, checking linear regression is considered very similar to checking the correlation between the data.

Although the correlation coefficient gives the same result as the coefficient of determination in a simple linear regression, they are calculated in different ways. The coefficient of determination is the variation of the observed data in relation to the line divided by the variation of the data:

\[ r² = \frac{\text{Variation of the observed data in relation to the line}}{\text{Total variation}} \]

For this reason, linear regression is also known as least squares regression because it minimizes the square of the observed errors as much as possible.

Exercises

1) What is the difference between correlation and linear regression?

2) Make the scatter plot and the line that best fits the data below:

Month (X)Demand (Y)
12400
22100
32550
42700
52750
62800
73000

3) In the previous exercise, it was found that the covariance of the two data sets is 485.71 and the variance of the independent variable (month) is 4. What are the slope and intercept coefficients of the linear regression line?

4) A store wrote down how many swimming trunks it sold on 4 days of the year. Calculate the equation of the line that best fits the following points:

Temperature (X)Swimming trunks sold (Y)
2010
2525
3030
3540

5) In the previous exercise, how many swimming trunks are expected to be sold at 40 degrees?

6) It is known that the more you study, the higher your grade. A student, doubting this, decides to check the study time and grade of each student in his class. He noticed that the average study time was 4 hours and the average grade was 7. He also noticed that the covariance of the two data sets was 8 and the variance of study time was 5. Based on a linear regression, what is the line that best explains the relationship between studying and the final grade?

7) In the previous exercise, Zezinho got a grade of 5.4. How long did he study according to the regression? If he needed a grade of 8.6 to pass, how long would he have needed to study according to the regression?

Answer Key

3) Y = 2128.5713 + 121.4286 · X

4) Y = 1.9 · X - 26

5) 50 swimming trunks

6) Y = 1.6 · X + 0.6

7) He studied 3 hours. He needed to have studied 5 hours.

Bibliographic References

http://www.biostathandbook.com/linearregression.html

https://www.statpac.com/statistics-calculator/correlation-regression.htm

http://www.kean.edu/~fosborne/bstat/09rc.html

https://edisciplinas.usp.br/pluginfile.php/1479289/mod_resource/content/0/regr_lin.pdf