You are on page 1of 19

Regression

This example teaches you how to run a linear regression analysis in Excel and how to interpret the
Summary Output.
Below you can find our data. The big question is: is there a relation between Quantity Sold
(Output) and Price and Advertising (Input). In other words: can we predict Quantity Sold if we
know Price and Advertising?

1. On the Data tab, in the Analysis group, click Data Analysis.

Note: can't find the Data Analysis button? Click here to load the Analysis ToolPak add-in.
2. Select Regression and click OK.

3. Select the Y Range (A1:A8). This is the predictor variable (also called dependent variable).
4. Select the X Range(B1:C8). These are the explanatory variables (also called independent
variables). These columns must be adjacent to each other.
5. Check Labels.
6. Click in the Output Range box and select cell A11.

7. Check Residuals.

8. Click OK.

Excel produces the following Summary Output (rounded to 3 decimal places).

R Square
R Square equals 0.962, which is a very good fit. 96% of the variation in Quantity Sold is explained
by the independent variables Price and Advertising. The closer to 1, the better the regression line
(read on) fits the data.

Significance F and P-values


To check if your results are reliable (statistically significant), look at Significance F (0.001). If this
value is less than 0.05, you're OK. If Significance F is greater than 0.05, it's probably better to stop
using this set of independent variables. Delete a variable with a high P-value (greater than 0.05)
and rerun the regression until Significance F drops below 0.05.

Most or all P-values should be below below 0.05. In our example this is the case.
(0.000, 0.001 and 0.005).

Coefficients y=mx+c
The regression line is: y = Quantity Sold = 8536.214 -835.722 * Price + 0.592 * Advertising. In
other words, for each unit increase in price, Quantity Sold decreases with 835.722 units. For each
unit increase in Advertising, Quantity Sold increases with 0.592 units. This is valuable information.

You can also use these coefficients to do a forecast. For example, if price equals $4 and
Advertising equals $3000, you might be able to achieve a Quantity Sold of 8536.214 -835.722 * 4
+ 0.592 * 3000 = 6970.

Residuals
The residuals show you how far away the actual data points are fom the predicted data points
(using the equation). For example, the first data point equals 8500. Using the equation, the
predicted data point equals 8536.214 -835.722 * 2 + 0.592 * 2800 = 8523.009, giving a residual of
8500 - 8523.009 = -23.009.
You can also create a scatter plot of these residuals.

Pivot Tables
Pivot tables are one of Excel's most powerful features. A pivot table allows you to extract the
significance from a large, detailed data set.
Our data set consists of 213 records and 6 fields. Order ID, Product, Category, Amount, Date and
Country.

Insert a Pivot Table


To insert a pivot table, execute the following steps.
1. Click any single cell inside the data set.

2. On the Insert tab, in the Tables group, click PivotTable.


The following dialog box appears. Excel automatically selects the data for you. The default
location for a new pivot table is New Worksheet.

3. Click OK.

Drag fields
The PivotTable Fields pane appears. To get the total amount exported of each product, drag the
following fields to the different areas.
1. Product field to the Rows area.

2. Amount field to the Values area.

3. Country field to the Filters area.


Below you can find the pivot table. Bananas are our main export product. That's how easy pivot
tables can be!

Sort
To get Banana at the top of the list, sort the pivot table.

1. Click any cell inside the Sum of Amount column.


2. Right click and click on Sort, Sort Largest to Smallest.

Result.

Filter
Because we added the Country field to the Filters area, we can filter this pivot table by Country.
For example, which products do we export the most to France?

1. Click the filter drop-down and select France.

Result. Apples are our main export product to France.


Note: you can use the standard filter (triangle next to Row Labels) to only show the amounts of
specific products.

Change Summary Calculation


By default, Excel summarizes your data by either summing or counting the items. To change the
type of calculation that you want to use, execute the following steps.

1. Click any cell inside the Sum of Amount column.

2. Right click and click on Value Field Settings.

3. Choose the type of calculation you want to use. For example, click Count.
4. Click OK.

Result. 16 out of the 28 orders to France were 'Apple' orders.

Two-dimensional Pivot Table


If you drag a field to the Rows area and Columns area, you can create a two-dimensional pivot
table. First, insert a pivot table. Next, to get the total amount exported to each country, of each
product, drag the following fields to the different areas.
1. Country field to the Rows area.

2. Product field to the Columns area.

3. Amount field to the Values area.

4. Category field to the Filters area.


Below you can find the two-dimensional pivot table.

To easily compare these numbers, create a pivot chart and apply a filter. Maybe this is one step
too far for you at this stage, but it shows you one of the many other powerful pivot table features
Excel has to offer.
Vlookup
 The VLOOKUP function is one of the most popular functions in Excel. This page contains many
easy to follow VLOOKUP examples.

Exact Match
Most of the time you are looking for an exact match when you use the VLOOKUP function in
Excel. Let's take a look at the arguments of the VLOOKUP function.

1. The VLOOKUP function below looks up the value 53 (first argument) in the leftmost column of
the red table (second argument).

2. The value 4 (third argument) tells the VLOOKUP function to return the value in the same row
from the fourth column of the red table.
Note: the Boolean FALSE (fourth argument) tells the VLOOKUP function to return an exact match.
If the VLOOKUP function cannot find the value 53 in the first column, it will return a #N/A error.
3. Here's another example. Instead of returning the salary, the VLOOKUP function below returns
the last name (third argument is set to 3) of ID 79.

Approximate Match
Let's take a look at an example of the VLOOKUP function in approximate match mode (fourth
argument set to TRUE).

1. The VLOOKUP function below looks up the value 85 (first argument) in the leftmost column of
the red table (second argument). There's just one problem. There's no value 85 in the first
column.
2. Fortunately, the Boolean TRUE (fourth argument) tells the VLOOKUP function to return an
approximate match. If the VLOOKUP function cannot find the value 85 in the first column, it will
return the largest value smaller than 85. In this example, this will be the value 80.

3. The value 2 (third argument) tells the VLOOKUP function to return the value in the same row
from the second column of the red table.

Note: always sort the leftmost column of the red table in ascending order if you use the
VLOOKUP function in approximate match mode (fourth argument set to TRUE).
Vlookup Looks Right
The VLOOKUP function always looks up a value in the leftmost column of a table and returns the
corresponding value from a column to the right.
1. For example, the VLOOKUP function below looks up the first name and returns the last name.

2. If you change the column index number (third argument) to 3, the VLOOKUP function looks up
the first name and returns the salary.

Note: in this example, the VLOOKUP function cannot lookup the first name and return the ID. The
VLOOKUP function only looks to the right. No worries, you can use INDEX and MATCH in Excel to
perform a left lookup.

First Match
If the leftmost column of the table contains duplicates, the VLOOKUP function matches the first
instance. For example, take a look at the VLOOKUP function below.
Explanation: the VLOOKUP function returns the salary of Mia Clark, not Mia Reed.

Vlookup is Case-insensitive
The VLOOKUP function in Excel performs a case-insensitive lookup. For example, the VLOOKUP
function below looks up MIA (cell G2) in the leftmost column of the table.

Explanation: the VLOOKUP function is case-insensitive so it looks up MIA or Mia or mia or miA,
etc. As a result, the VLOOKUP function returns the salary of Mia Clark (first instance). Use INDEX,
MATCH and EXACT in Excel to perform a case-sensitive lookup.

Multiple Criteria
Do you want to look up a value based on multiple criteria? Use INDEX and MATCH in Excel to
perform a two-column lookup.
Note: the array formula above looks up the salary of James Clark, not James Smith, not James
Anderson.

#N/A error
If the VLOOKUP function cannot find a match, it returns a #N/A error.

1. For example, the VLOOKUP function below cannot find the value 28 in the leftmost column.

2. If you like, you can use the IFNA function to replace the #N/A error with a friendly message.
Note: the IFNA function was introduced in Excel 2013. If you're using Excel 2010 or Excel 2007,
simply replace IFNA with IFERROR. Remember, the IFERROR function catches other errors as well.
For example, the #NAME? error if you accidentally misspell the word VLOOKUP.

Multiple Lookup Tables


When using the VLOOKUP function in Excel, you can have multiple lookup tables. You can use
the IF function to check whether a condition is met, and return one lookup table if TRUE and
another lookup table if FALSE.
1. Create two named ranges: Table1 and Table2.

2. Select cell E4 and enter the VLOOKUP function shown below.


Explanation: the bonus depends on the market (UK or USA) and the sales amount. The second
argument of the VLOOKUP function does the trick. If UK, the VLOOKUP function uses Table1, if
USA, the VLOOKUP function uses Table2. Set the fourth argument of the VLOOKUP function to
TRUE to return an approximate match.

3. Press Enter.

4. Select cell E4, click on the lower right corner of cell E4 and drag it down to cell E10.

Note: for example, Walker receives a bonus of $1,500. Because we're using named ranges, we can
easily copy this VLOOKUP function to the other cells without worrying about cell references.

Index and Match


Instead of using VLOOKUP, use INDEX and MATCH. To perform advanced lookups, you'll need
INDEX and MATCH. Maybe this is one step too far for you at this stage, but it shows you one of
the many other powerful formulas Excel has to offer.

Xlookup
If you have Excel 365, use XLOOKUP instead of VLOOKUP. The XLOOKUP function is easier to use
and has some additional advantages.

You might also like