Docsity

Regression Analysis in Excel: Understanding Simple Linear Regression, Study notes of Statistics

Toggle sidebar
bg1
LECTURE 5
Regression analysis in Excel - The basics
In statistical modeling, regression analysis is used to estimate the relationships between two or
more variables:
Dependent variable (aka criterion variable) is the main factor you are trying to understand and
predict.
Independent variables (aka explanatory variables, or predictors) are the factors that might
influence the dependent variable.
Regression analysis helps you understand how the dependent variable changes when one of the
independent variables varies and allows to mathematically determine which of those variables
really has an impact.
Technically, a regression analysis model is based on the sum of squares, which is a
mathematical way to find the dispersion of data points. The goal of a model is to get the smallest
possible sum of squares and draw a line that comes closest to the data.
In statistics, they differentiate between a simple and multiple linear regression. Simple linear
regression models the relationship between a dependent variable and one independent variables
using a linear function. If you use two or more explanatory variables to predict the dependent
variable, you deal with multiple linear regression. If the dependent variable is modeled as a
non-linear function because the data relationships do not follow a straight line, use nonlinear
regression instead. The focus of this tutorial will be on a simple linear regression.
As an example, let's take sales numbers for umbrellas for the last 24 months and find out the
average monthly rainfall for the same period. Plot this information on a chart, and the regression
line will demonstrate the relationship between the independent variable (rainfall) and dependent
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Regression Analysis in Excel: Understanding Simple Linear Regression and more Study notes Statistics in PDF only on Docsity!

LECTURE 5

Regression analysis in Excel - The basics

In statistical modeling, regression analysis is used to estimate the relationships between two or more variables: Dependent variable (aka criterion variable) is the main factor you are trying to understand and predict. Independent variables (aka explanatory variables, or predictors ) are the factors that might influence the dependent variable. Regression analysis helps you understand how the dependent variable changes when one of the independent variables varies and allows to mathematically determine which of those variables really has an impact. Technically, a regression analysis model is based on the sum of squares , which is a mathematical way to find the dispersion of data points. The goal of a model is to get the smallest possible sum of squares and draw a line that comes closest to the data. In statistics, they differentiate between a simple and multiple linear regression. Simple linear regression models the relationship between a dependent variable and one independent variables using a linear function. If you use two or more explanatory variables to predict the dependent variable, you deal with multiple linear regression. If the dependent variable is modeled as a non-linear function because the data relationships do not follow a straight line, use nonlinear regression instead. The focus of this tutorial will be on a simple linear regression. As an example, let's take sales numbers for umbrellas for the last 24 months and find out the average monthly rainfall for the same period. Plot this information on a chart, and the regression line will demonstrate the relationship between the independent variable (rainfall) and dependent

variable (umbrella sales):

Linear regression equation

Mathematically, a linear regression is defined by this equation: y = bx + a + ε Where: ļ‚· x is an independent variable. ļ‚· y is a dependent variable. ļ‚· a is the Y-intercept , which is the expected mean value of y when all x variables are equal to 0. On a regression graph, it's the point where the line crosses the Y axis. ļ‚· b is the slope of a regression line, which is the rate of change for y as x changes. ļ‚· ε is the random error term, which is the difference between the actual value of a dependent variable and its predicted value. The linear regression equation always has an error term because, in real life, predictors are never perfectly precise. However, some programs, including Excel, do the error term calculation behind the scenes. So, in Excel, you do linear regression using the least squares method and seek coefficients a and b such that: y = bx + a For our example, the linear regression equation takes the following shape: Umbrellas sold = b * rainfall + a

  1. In the Excel Options dialog box, select Add-ins on the left sidebar, make sure Excel Add-ins is selected in the Manage box, and click Go.
  1. In the Add-ins dialog box, tick off Analysis Toolpak , and click OK : This will add the Data Analysis tools to the Data tab of your Excel ribbon.

Run regression analysis

In this example, we are going to do a simple linear regression in Excel. What we have is a list of average monthly rainfall for the last 24 months in column B, which is our independent variable (predictor), and the number of umbrellas sold in column C, which is the dependent variable. Of course, there are many other factors that can affect sales, but for now we focus only on these two variables:

o Optionally, select the Residuals checkbox to get the difference between the predicted and actual values.

  1. Click OK and observe the regression analysis output created by Excel.

Interpret regression analysis output

As you have just seen, running regression in Excel is easy because all calculations are preformed automatically. The interpretation of the results is a bit trickier because you need to know what is behind each number. Below you will find a breakdown of 4 major parts of the regression analysis output. Regression analysis output: Summary Output

This part tells you how well the calculated linear regression equation fits your source data. Here's what each piece of information means: Multiple R. It is the C orrelation Coefficient that measures the strength of a linear relationship between two variables. The correlation coefficient can be any value between - 1 and 1, and its absolute value indicates the relationship strength. The larger the absolute value, the stronger the relationship: ļ‚· 1 means a strong positive relationship ļ‚· - 1 means a strong negative relationship ļ‚· 0 means no relationship at all R Square. It is the Coefficient of Determination , which is used as an indicator of the goodness of fit. It shows how many points fall on the regression line. The R^2 value is calculated from the total sum of squares, more precisely, it is the sum of the squared deviations of the original data from the mean. In our example, R^2 is 0.91 (rounded to 2 digits), which is fairy good. It means that 91% of our values fit the regression analysis model. In other words, 91% of the dependent variables (y- values) are explained by the independent variables (x-values). Generally, R Squared of 95% or more is considered a good fit. Adjusted R Square. It is the R square adjusted for the number of independent variable in the model. You will want to use this value instead of R square for multiple regression analysis. Standard Error. It is another goodness-of-fit measure that shows the precision of your regression analysis - the smaller the number, the more certain you can be about your regression equation. While R^2 represents the percentage of the dependent variables variance that is explained by the model, Standard Error is an absolute measure that shows the average distance that the data points fall from the regression line. Observations. It is simply the number of observations in your model. Regression analysis output: ANOVA The second part of the output is Analysis of Variance (ANOVA):

0.45*82-19.074=17. In a similar manner, you can find out how many umbrellas are going to be sold with any other monthly rainfall (x variable) you specify. Regression analysis output: residuals If you compare the estimated and actual number of sold umbrellas corresponding to the monthly rainfall of 82 mm, you will see that these numbers are slightly different: ļ‚· Estimated: 17.8 (calculated above) ļ‚· Actual: 15 (row 2 of the source data) Why's the difference? Because independent variables are never perfect predictors of the dependent variables. And the residuals can help you understand how far away the actual values are from the predicted values: For the first data point (rainfall of 82 mm), the residual is approximately - 2.8. So, we add this number to the predicted value, and get the actual value: 17.8 - 2.8 = 15. How to make a linear regression graph in Excel If you need to quickly visualize the relationship between the two variables, draw a linear regression chart. That's very easy! Here's how:

  1. Select the two columns with your data, including headers.
  1. On the Inset tab, in the Chats group, click the Scatter chart icon, and select the Scatter thumbnail (the first one): This will insert a scatter plot in your worksheet, which will resemble this one:
  1. On the right pane, select the Linear trendline shape and, optionally, check Display Equation on Chart to get your regression formula: As you may notice, the regression equation Excel has created for us is the same as the linear regression formula we built based on the Coefficients output.
  2. Switch to the Fill & Line tab and customize the line to your liking. For example, you can choose a different line color and use a solid line instead of a dashed line (select Solid line

in the Dash type box):

Important note! In the regression graph, the independent variable should always be on the X axis and the dependent variable on the Y axis. If your graph is plotted in the reverse order, swap the columns in your worksheet, and then draw the chart anew. If you are not allowed to rearrange the source data, then you can switch the X and Y axes directly in a chart. How to do regression in Excel using formulas Microsoft Excel has a few statistical functions that can help you to do linear regression analysis such as LINEST, SLOPE, INTERCPET, and CORREL. The LINEST function uses the least squares regression method to calculate a straight line that best explains the relationship between your variables and returns an array describing that line. You can find the detailed explanation of the function's syntax in this tutorial. For now, let's just make a formula for our sample dataset: =LINEST(C2:C25, B2:B25) Because the LINEST function returns an array of values, you must enter it as an array formula. Select two adjacent cells in the same row, E2:F2 in our case, type the formula, and press Ctrl + Shift + Enter to complete it. The formula returns the b coefficient (E1) and the a constant (F1) for the already familiar linear regression equation: y = bx + a If you avoid using array formulas in your worksheets, you can calculate a and b individually with regular formulas: Get the Y-intercept (a): =INTERCEPT(C2:C25, B2:B25)

Get the slope (b): =SLOPE(C2:C25, B2:B25) Additionally, you can find the correlation coefficient ( Multiple R in the regression analysis summary output) that indicates how strongly the two variables are related to each other: =CORREL(B2:B25,C2:C25) The following screenshot shows all these Excel regression formulas in action: Tip. If you'd like to get additional statistics for your regression analysis, use the LINEST function with the s tats parameter set to TRUE as shown in this example. That's how you do linear regression in Excel. That said, please keep in mind that Microsoft Excel is not a statistical program. If you need to perform regression analysis at the professional level, you may want to use targeted software such as XLSTAT, RegressIt, etc.