How to do auto-populating multivariable regression in Excel

In Excel, you can do regression with the Data Analysis toolpak, but there are 2 major limitations to this. The main limitation is that you have to re-run the Data Analysis tool each time you want updated results. This gets old very quickly if you want to see how various changes are affecting your final results. The other limitation is that you can only have 16 independent variables. What I will show below is how to program the regression yourself so you don't have to use the toolpak. This allows you to use as many variables as you need, and it automatically updates as you enter data.

I won't go into the details of how all the math behind the regression works, as that is beyond the scope of this article, but I will show how to do it. You can always use the Data Analysis toolpak to verify if you have done it correctly.

1. First, set up the information in your spreadsheet. In my example, I will be approximating the cost of a house based on 4 independent variables. Here, column A is my dependent variable, and columns C through F are my independent variables. You will need to make a column for the intercept as well, which will be filled in with all 1s.



2. In a separate sheet, use the formula shown below (adjusting the references to fit with your own data, of course) and copy it to match size of your data set. Mine is 5x5 because I have 5 variables (1 intercept and 4 independent variables).

First Step


3. Make another formula that is the same height as the last, but only 1 column wide. Put the formula below in (again adjusting references), then copy it down.

Second Step



4. Make yet another formula that is the same length as the first matrix, but only 1 row tall. Put the formula below in (again adjusting references). This will have to be put in as an array formula. That means that you will have to select the entire length, then put in the formula, and simultaneously press Ctrl-Shift-Enter when you are done. These numbers represent your intercept and independent variables.

Third Step


5. Back in the original sheet, this formula below (once more adjusting references) will apply the intercept and dependent variables to your data and give you a final regressed value.

Get Regressed Values



Back to Resources page.