57

I have the following information:

  Height    Weight

    170     65
    167     55
    189     85
    175     70
    166     55
    174     55
    169     69
    170     58
    184     84
    161     56
    170     75
    182     68
    167     51
    187     85
    178     62
    173     60
    172     68
    178     55
    175     65
    176     70

I want to construct quadratic and cubic regression analysis in Excel. I know how to do it by linear regression in Excel, but what about quadratic and cubic? I have searched a lot of resources, but could not find anything helpful.

3
  • 3
    my 1st google result for "excel polynomial regression" is people.stfx.ca/bliengme/ExcelTips/Polynomial.htm - what's wrong with that?!?
    – Aprillion
    Commented Jun 1, 2012 at 22:28
  • @deathApril I suggest you add this as the answer
    – brettdj
    Commented Jun 2, 2012 at 10:42
  • @deathApril i've been googling for a how to perform polynomial regressions in Excel. i already found the link you mention; but i don't think it includes anything to do with quadratic or 4th order regressions. i could be wrong: it's horribly written.
    – Ian Boyd
    Commented Sep 2, 2012 at 20:19

3 Answers 3

198

You need to use an undocumented trick with Excel's LINEST function:

=LINEST(known_y's, [known_x's], [const], [stats])

Background

A regular linear regression is calculated (with your data) as:

=LINEST(B2:B21,A2:A21)

which returns a single value, the linear slope (m) according to the formula:

enter image description here

which for your data:

enter image description here

is:

enter image description here

Undocumented trick Number 1

You can also use Excel to calculate a regression with a formula that uses an exponent for x different from 1, e.g. x1.2:

enter image description here

using the formula:

=LINEST(B2:B21, A2:A21^1.2)

which for you data:

enter image description here

is:

enter image description here

You're not limited to one exponent

Excel's LINEST function can also calculate multiple regressions, with different exponents on x at the same time, e.g.:

=LINEST(B2:B21,A2:A21^{1,2})

Note: if locale is set to European (decimal symbol ","), then comma should be replaced by semicolon and backslash, i.e. =LINEST(B2:B21;A2:A21^{1\2})

Now Excel will calculate regressions using both x1 and x2 at the same time:

enter image description here

How to actually do it

The impossibly tricky part there's no obvious way to see the other regression values. In order to do that you need to:

  • select the cell that contains your formula:

    enter image description here

  • extend the selection the left 2 spaces (you need the select to be at least 3 cells wide):

    enter image description here

  • press F2

  • press Ctrl+Shift+Enter

    enter image description here

You will now see your 3 regression constants:

  y = -0.01777539x^2 + 6.864151123x + -591.3531443

Bonus Chatter

I had a function that I wanted to perform a regression using some exponent:

y = m×xk + b

But I didn't know the exponent. So I changed the LINEST function to use a cell reference instead:

=LINEST(B2:B21,A2:A21^F3, true, true)

With Excel then outputting full stats (the 4th paramter to LINEST):

enter image description here

I tell the Solver to maximize R2:

enter image description here

And it can figure out the best exponent. Which for you data:

enter image description here

is:

enter image description here

11
  • 1
    Thanks! Note: if you are using Excel for Mac, you do the array formula with CONTROL+U and then ⌘+Z+RETURN
    – Bani
    Commented Apr 16, 2013 at 14:34
  • 2
    @Jesse Alright, I upvoted for you. Edit: Hmm, I get #VALUE! when I insert this formula into my Excel 2010... Nevermind, I have to use ; instead of , for element separator. (Hope this helps someone.)
    – Alex
    Commented Sep 30, 2014 at 0:00
  • 2
    @Alex: If your computer is set up to a European to locale, i.e.. to use decimal comma (not decimal points), then "{1,2}" must be changed to "{1\2}". (And in addition, commas must be changed to semicolons of course.) Commented Jun 2, 2015 at 12:17
  • 4
    This is not completely undocumented. What's actually happening is that you are creating multiple x vectors in the linest function by using the formula known_x's^{array of powers}, and then regressing against them. And an important note: if your x values are in rows, then you have to use semicolons instead of commas to separate the list of powers (this makes your array of powers into a column instead of a row). Commented Apr 28, 2016 at 8:15
  • 2
    I could realize in French with that formula: =LINEST(B2:B21;A2:A21^{1.2}) with a point between each exponent degrees.
    – jbaptperez
    Commented May 4, 2018 at 8:59
14

I know that this question is a little old, but I thought that I would provide an alternative which, in my opinion, might be a little easier. If you're willing to add "temporary" columns to a data set, you can use Excel's Analysis ToolPak→Data Analysis→Regression. The secret to doing a quadratic or a cubic regression analysis is defining the Input X Range:.

If you're doing a simple linear regression, all you need are 2 columns, X & Y. If you're doing a quadratic, you'll need X_1, X_2, & Y where X_1 is the x variable and X_2 is x^2; likewise, if you're doing a cubic, you'll need X_1, X_2, X_3, & Y where X_1 is the x variable, X_2 is x^2 and X_3 is x^3. Notice how the Input X Range is from A1 to B22, spanning 2 columns.

Input for Quadratic Regression Analysis in Excel

The following image the output of the regression analysis. I've highlighted the common outputs, including the R-Squared values and all the coefficients.

Coefficients of Quadratic Regression Analysis in Excel

1
  • Thank you for your answer, I know this is a bit old, but I have a question here. When doing regression with excel, the inputs should not be independent ? if yes, how can we choose the two columns to be X and X^2 ?
    – Nizar
    Commented Feb 15, 2018 at 14:01
6

The LINEST function described in a previous answer is the way to go, but an easier way to show the 3 coefficients of the output is to additionally use the INDEX function. In one cell, type: =INDEX(LINEST(B2:B21,A2:A21^{1,2},TRUE,FALSE),1) (by the way, the B2:B21 and A2:A21 I used are just the same values the first poster who answered this used... of course you'd change these ranges appropriately to match your data). This gives the X^2 coefficient. In an adjacent cell, type the same formula again but change the final 1 to a 2... this gives the X^1 coefficient. Lastly, in the next cell over, again type the same formula but change the last number to a 3... this gives the constant. I did notice that the three coefficients are very close but not quite identical to those derived by using the graphical trendline feature under the charts tab. Also, I discovered that LINEST only seems to work if the X and Y data are in columns (not rows), with no empty cells within the range, so be aware of that if you get a #VALUE error.

2
  • 2
    If you your computer is set up to use decimal comma instead of decimal points (i.e., European locales; e.g. "3,14" instead of "3.14") then "{1,2}" must be changed to "{1\2}". Yes, a backslash! And as usual commas must be changed to semicolons. So the formula becomes =INDEX(LINEST(B2:B21;A2:A21^{1\2};TRUE;FALSE);1) Commented Jun 2, 2015 at 8:29
  • @Spanky You can use LINEST in rows too. Just add TRANSPOSE. Like: =LINEST(TRANSPOSE(D9:M9);TRANSPOSE(D6:M6)^{1\2})
    – user882670
    Commented Sep 4, 2015 at 16:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.