SOLVED

R-Squared for Nonlinear Trendlines in Graphs

%3CLINGO-SUB%20id%3D%22lingo-sub-2798612%22%20slang%3D%22en-US%22%3ER-Squared%20for%20Nonlinear%20Trendlines%20in%20Graphs%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2798612%22%20slang%3D%22en-US%22%3E%3CP%3EThe%20r-squared%20calculation%20in%20Excel%20for%20nonlinear%20trendlines%20previously%20displayed%20the%20quantity%20developed%20using%20the%20linear%20regression%20model%20of%20the%20transformed%20data.%20Can%20anyone%20point%20me%20to%20the%20updated%20equation%20used%20to%20define%20r-squared%20in%20a%20nonlinear%20trendline%3F%20Below%20is%20a%20example%20of%20an%20exponential%20trend%20where%20the%20r-squared%20displayed%20on%20the%20log-linear%20graph%20matches%20the%20calculated%20value%20in%20cell%20L7%2C%20however%2C%20is%20not%20consistent%20with%20the%20r-squared%20in%20the%20linear-linear%20trend%20despite%20equivalence%20of%20the%20regression%20coefficients.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22jmt188_0-1632996703571.png%22%20style%3D%22width%3A%20702px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F313916iD98CF4C3782C8004%2Fimage-dimensions%2F702x401%3Fv%3Dv2%22%20width%3D%22702%22%20height%3D%22401%22%20role%3D%22button%22%20title%3D%22jmt188_0-1632996703571.png%22%20alt%3D%22jmt188_0-1632996703571.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2798612%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2800734%22%20slang%3D%22en-US%22%3ERe%3A%20R-Squared%20for%20Nonlinear%20Trendlines%20in%20Graphs%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2800734%22%20slang%3D%22en-US%22%3EI%20can%20probably%20help%20you.%20But%20I%20am%20too%20lazy%20to%20retype%20your%20data%20and%20reverse-engineer%20your%20formulas.%3CBR%20%2F%3E%3CBR%20%2F%3EPlease%20attach%20an%20Excel%20file%20(not%20an%20image)%20that%20demonstrates%20the%20problem.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2800750%22%20slang%3D%22en-US%22%3ERe%3A%20R-Squared%20for%20Nonlinear%20Trendlines%20in%20Graphs%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2800750%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F146717%22%20target%3D%22_blank%22%3E%40Joe%20User%3C%2FA%3E%26nbsp%3BPlease%20see%20the%20attached%20file.%20The%20y-values%20include%20random%20noise%20in%20an%20effort%20to%20ensure%20r-squared%20values%20less%20than%20unity.%20That%20said%2C%20all%20equations%20should%20update%20each%20time%20the%20worksheet%20is%20modified.%20Thanks%20for%20the%20help.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2802110%22%20slang%3D%22en-US%22%3ERe%3A%20R-Squared%20for%20Nonlinear%20Trendlines%20in%20Graphs%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2802110%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1170633%22%20target%3D%22_blank%22%3E%40jmt188%3C%2FA%3E%26nbsp%3B%20wrote%3A%20%60%60Please%20see%20the%20attached%20file.%20The%20y-values%20include%20random%20noise%60%60%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20the%20file.%26nbsp%3B%20And%20I'm%20happy%20to%20find%20someone%20(else)%20who%20knows%20how%20to%20create%20credible%20examples%20with%20%22random%20noise%22.%26nbsp%3B%20That%20is%20my%20modus%20operandi.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMay%20I%20suggest%20an%20improvement%3F%26nbsp%3B%20See%20the%20highlighted%20changes%20that%20I%20made%20in%20the%20%22orig%22%20worksheet%20in%20the%20attached%20file.%26nbsp%3B%20%3CFONT%20color%3D%22%23FF0000%22%3ENote%3A%20I%20%22protected%22%20the%20worksheet%20so%20that%20I%20don't%20modify%20it%20accidentally.%26nbsp%3B%20But%20the%20password%20is%20empty.%26nbsp%3B%20So%20just%20right-click%20the%20tab%20and%20click%20Unprotect%2C%20if%20you%20wish.%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20a%20nutshell%2C%20the%20random%20data%20is%20created%20%22on%20the%20side%22%20(column%20N)%2C%20and%20initially%2C%20the%20actual%20data%20(column%20B)%20references%20column%20N%20with%20formulas%20of%20the%20form%20%3DN2.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20advantage%20is%3A%20when%20we%20find%20the%20example%20that%20we%20want%20to%20discuss%2C%20copy-and-paste-value%20column%20N%20into%20column%20O%2C%20and%20change%20column%20B%20to%20reference%20column%20O%20with%20formulas%20of%20the%20form%20%3DO2.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThat%20ensures%20that%20we%20all%20see%20the%20same%20example.%26nbsp%3B%20And%20it%20makes%20it%20easy%20to%20switch%20between%20new%20random%20data%20and%20one%20or%20more%20snapshots.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E-----%3C%2FP%3E%3CP%3EBack%20to%20your%20question....%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EUnfortunately%2C%20I%20do%20not%20understand%20what%20you%20are%20trying%20to%20do%20in%20columns%20F%3AL.%26nbsp%3B%20So%20I%20have%20taken%20the%20liberty%20of%20redesigning%20the%20worksheet.%26nbsp%3B%20%3CFONT%20color%3D%22%23FF0000%22%3EThe%20following%20refers%20to%20my%20%22new%22%20worksheet.%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E(If%20I%20have%20missed%20an%20important%20point%2C%20and%20you%20want%20assistance%2C%20feel%20free%20to%20explain%20the%20intent%20of%20columns%20F%3AL.%26nbsp%3B%20And%20I%20apologize%20in%20advance%20for%20my%20denseness.)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20will%20try%20to%20be%20brief%2C%20because%20there%20is%20a%20lot%20that%20I%20could%20explain%2C%20but%20I%20want%20to%20%22rush%20ahead%22%20to%20answer%20your%20question.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ELMK%20if%20you%20need%20more%20clarification.%26nbsp%3B%20I%20am%20happy%20to%20explain%20in%20more%20detail.%26nbsp%3B%20But%20I%20get%20the%20sense%20that%20you%20are%20very%20capable%20of%20filling%20in%20the%20details%20yourself.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E-----%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1170633%22%20target%3D%22_blank%22%3E%40jmt188%3C%2FA%3E%26nbsp%3B%20wrote%20originally%3A%20%60%60Can%20anyone%20point%20me%20to%20the%20updated%20equation%20used%20to%20define%20r-squared%20in%20a%20nonlinear%20trendline%3F%60%60%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThere%20has%20indeed%20been%20a%20change%20in%20how%20the%20trendline%20R%5E2%20is%20calculated%20in%20Office%20365%20Excel%20and%20other%20recent%20versions%20of%20Excel%20vs.%20older%20versions%20Excel%20like%202010%2C%20which%20I%20use.%26nbsp%3B%20I%20could%20explain%20that%20in%20more%20detail.%26nbsp%3B%20But%20I%20do%20not%20believe%20that%20is%20germane%20to%20your%20question.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%20color%3D%22%23FF0000%22%3ENevertheless%2C%20please%20LMK%20what%20version(s)%20of%20Excel%20you%20use%2C%20in%20case%20it%20is%20needed%20for%20any%20follow-up%20discussion.%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20difference%20that%20you%20see%20can%20be%20explained%20by%20the%20difference%20highlighted%20in%20E4%3AE5%20and%20compared%20with%20M4%3AM5.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20the%20%22log-linear%22%20chart%20on%20the%20right%20(chart%20%232)%2C%20the%20trendline%20R%5E2%20is%20the%20correlation%20coefficent%20(really%20the%20coefficient%20of%20determination)%20between%20the%20actual%20data%20for%20%22y2%22%20in%20column%20J%20and%20the%20estimated%20data%20in%20column%20K.%26nbsp%3B%20That%20can%20be%20calculated%20with%20the%20RSQ%20function%2C%20as%20demonstrated%20in%20M5.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20estimated%20data%20for%20y2%20is%20based%20on%20the%20formula%20of%20the%20form%20y%20%3D%20a*x%20%2B%20ln(b).%26nbsp%3B%20The%20LINEST%20coefficients%20are%20calculated%20in%20M3%3AM4.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20the%20%22linear-linear%22%20chart%20on%20the%20left%20(chart%20%231)%2C%20the%20trendline%20R%5E2%20is%20the%20correlation%20coefficient%20(again%2C%20really%20the%20coefficient%20of%20determination)%20between%20the%20actual%20data%20for%20%22y1%22%20in%20column%20B%20and%20the%20estimated%20data%20in%20column%20C.%26nbsp%3B%20That%20can%20be%20calculated%20with%20the%20RSQ%20function%2C%20as%20demonstrated%20in%20E5.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20estimated%20data%20for%20y1%20is%20based%20on%20the%20%3CU%3E%3CEM%3Enonlinear%3C%2FEM%3E%3C%2FU%3E%20formula%20of%20the%20form%20y%20%3D%20b*exp(a*x).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBut%20note%20that%26nbsp%3Bthe%20coefficient%20of%20determination%20for%20y1%20that%20LINEST%20returns%20in%20E4%20is%20the%20trendline%20R%5E2%20for%20%3CU%3E%3CEM%3Echart%20%232%3C%2FEM%3E%3C%2FU%3E%20and%20the%20LINEST%20CoD%20and%20RSQ%20in%20M4%3AM5%20%3CU%3E%3CEM%3Efor%20y2%3C%2FEM%3E%3C%2FU%3E.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThat%20is%20because%20the%20coefficients%20for%20estimated%20y1%20are%20derived%20from%20the%20same%20%3CU%3E%3CEM%3Elinear%3C%2FEM%3E%3C%2FU%3E%20formula%20for%20estimated%20y2.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThat%20is%2C%20the%20%3CU%3E%3CEM%3Elinear%3C%2FEM%3E%3C%2FU%3E%20equation%20for%20deriving%20%22a%22%20and%20%22b%22%20for%20estimated%20y1%20is%20of%20the%20form%20ln(y)%20%3D%20a*x%20%2B%20ln(b)%2C%20and%20estimated%20ln(y1)%20equals%20estimated%20y2%20because%20the%20original%20data%20y2%20%3D%20ln(y1).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20estimated%20y1%2C%20the%20coefficent%20b%20is%20EXP(F3)%2C%20where%20F3%20is%20ln(b).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20hope%20that%20is%20helpful.%26nbsp%3B%20I%20rushed%20through%20it%20very%20quickly%2C%20I%20know.%26nbsp%3B%20Again%2C%20LMK%20if%20you%20want%20more%20detail%20and%20a%20slower%20presentation.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2803039%22%20slang%3D%22en-US%22%3ERe%3A%20R-Squared%20for%20Nonlinear%20Trendlines%20in%20Graphs%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2803039%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1170633%22%20target%3D%22_blank%22%3E%40jmt188%3C%2FA%3E....%20Note%20that%20I%20just%20made%20some%20significant%20edits%20to%20my%20previous%20response%20in%20order%20to%20improve(%3F)%20the%20explanation.%26nbsp%3B%20If%20you%20had%20trouble%20following%20the%20explanation%20previously%2C%20you%20might%20want%20to%20reread%20the%20edited%20response.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2804294%22%20slang%3D%22en-US%22%3ERe%3A%20R-Squared%20for%20Nonlinear%20Trendlines%20in%20Graphs%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2804294%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F146717%22%20target%3D%22_blank%22%3E%40Joe%20User%3C%2FA%3E%26nbsp%3BThank%20you%20for%20identifying%20the%20cause%20of%20the%20observed%20discrepancy%20between%20my%20calculation%20and%20the%20values%20presented%20in%20the%20graph.%20I%20was%20not%20aware%20that%20Excel%20had%20modified%20the%20r-squared%20value%20associated%20with%20nonlinear%20trendlines%20to%20the%20Pearson%20Coefficient%20as%20calculated%20in%20linear-linear%20space.%20As%20noted%20in%20your%20reply%2C%20the%20Pearson%20Coefficient%20and%20Coefficient%20of%20Determination%20are%20equivalent%20in%20the%20absence%20of%20a%20data%20transformation.%20This%20equivalence%2C%20coupled%20with%20the%20modified%20definition%20in%20Excel%20resulted%20in%20differences%20when%20reopening%20older%20worksheets.%20Thank%20you%20again%20for%20clarifying%20the%20issue%20as%20well%20as%20providing%20some%20useful%20recommendations%20going%20forward.%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

The r-squared calculation in Excel for nonlinear trendlines previously displayed the quantity developed using the linear regression model of the transformed data. Can anyone point me to the updated equation used to define r-squared in a nonlinear trendline? Below is a example of an exponential trend where the r-squared displayed on the log-linear graph matches the calculated value in cell L7, however, is not consistent with the r-squared in the linear-linear trend despite equivalence of the regression coefficients.

 

jmt188_0-1632996703571.png

6 Replies
I can probably help you. But I am too lazy to retype your data and reverse-engineer your formulas.

Please attach an Excel file (not an image) that demonstrates the problem.

@Joe User Please see the attached file. The y-values include random noise in an effort to ensure r-squared values less than unity. That said, all equations should update each time the worksheet is modified. Thanks for the help.

@jmt188  wrote: ``Please see the attached file. The y-values include random noise``

 

Thanks for the file.  And I'm happy to find someone (else) who knows how to create credible examples with "random noise".  That is my modus operandi.

 

May I suggest an improvement?  See the highlighted changes that I made in the "orig" worksheet in the attached file.  Note: I "protected" the worksheet so that I don't modify it accidentally.  But the password is empty.  So just right-click the tab and click Unprotect, if you wish.

 

In a nutshell, the random data is created "on the side" (column N), and initially, the actual data (column B) references column N with formulas of the form =N2.

 

The advantage is: when we find the example that we want to discuss, copy-and-paste-value column N into column O, and change column B to reference column O with formulas of the form =O2.

 

That ensures that we all see the same example.  And it makes it easy to switch between new random data and one or more snapshots.

 

-----

Back to your question....

 

Unfortunately, I do not understand what you are trying to do in columns F:L.  So I have taken the liberty of redesigning the worksheet.  The following refers to my "new" worksheet.

 

(If I have missed an important point, and you want assistance, feel free to explain the intent of columns F:L.  And I apologize in advance for my denseness.)

 

I will try to be brief, because there is a lot that I could explain, but I want to "rush ahead" to answer your question.

 

LMK if you need more clarification.  I am happy to explain in more detail.  But I get the sense that you are very capable of filling in the details yourself.

 

-----

@jmt188  wrote originally: ``Can anyone point me to the updated equation used to define r-squared in a nonlinear trendline?``

 

There has indeed been a change in how the trendline R^2 is calculated in Office 365 Excel and other recent versions of Excel vs. older versions Excel like 2010, which I use.  I could explain that in more detail.  But I do not believe that is germane to your question.

 

Nevertheless, please LMK what version(s) of Excel you use, in case it is needed for any follow-up discussion.

 

The difference that you see can be explained by the difference highlighted in E4:E5 and compared with M4:M5.

 

For the "log-linear" chart on the right (chart #2), the trendline R^2 is the correlation coefficent (really the coefficient of determination) between the actual data for "y2" in column J and the estimated data in column K.  That can be calculated with the RSQ function, as demonstrated in M5.

 

The estimated data for y2 is based on the formula of the form y = a*x + ln(b).  The LINEST coefficients are calculated in M3:M4.

 

For the "linear-linear" chart on the left (chart #1), the trendline R^2 is the correlation coefficient (again, really the coefficient of determination) between the actual data for "y1" in column B and the estimated data in column C.  That can be calculated with the RSQ function, as demonstrated in E5.

 

The estimated data for y1 is based on the nonlinear formula of the form y = b*exp(a*x).

 

But note that the coefficient of determination for y1 that LINEST returns in E4 is the trendline R^2 for chart #2 and the LINEST CoD and RSQ in M4:M5 for y2.

 

That is because the coefficients for estimated y1 are derived from the same linear formula for estimated y2.

 

That is, the linear equation for deriving "a" and "b" for estimated y1 is of the form ln(y) = a*x + ln(b), and estimated ln(y1) equals estimated y2 because the original data y2 = ln(y1).

 

For estimated y1, the coefficent b is EXP(F3), where F3 is ln(b).

 

I hope that is helpful.  I rushed through it very quickly, I know.  Again, LMK if you want more detail and a slower presentation.

 

best response confirmed by jmt188 (New Contributor)
Solution

@jmt188.... Note that I just made some significant edits to my previous response in order to improve(?) the explanation.  If you had trouble following the explanation previously, you might want to reread the edited response.

@Joe User Thank you for identifying the cause of the observed discrepancy between my calculation and the values presented in the graph. I was not aware that Excel had modified the r-squared value associated with nonlinear trendlines to the Pearson Coefficient as calculated in linear-linear space. As noted in your reply, the Pearson Coefficient and Coefficient of Determination are equivalent in the absence of a data transformation. This equivalence, coupled with the modified definition in Excel resulted in differences when reopening older worksheets. Thank you again for clarifying the issue as well as providing some useful recommendations going forward.

@jmt188  wrote: ``I was not aware that Excel had modified the r-squared value associated with nonlinear trendlines to the Pearson Coefficient as calculated in linear-linear space. As noted in your reply, the Pearson Coefficient and Coefficient of Determination are equivalent in the absence of a data transformation.``

 

Just to clarify, I am not saying that the trendline R^2 calculates the square of the Pearson correlation coefficient per se, instead of the CoD.

 

My use of RSQ was a simplification, relying on the equivalence that you mention, which applies to your examples.

 

We know that LINEST R^2 calculates the CoD.  See the help page.

 

And according to my comments in another discussion (click here), I had concluded that the trendline R^2 also calculates the CoD.

 

I believe there have been two changes ("corrections") to the trendline R^2 calculation in Office 365 Excel and more recent versions.

 

1. The trendline R^2 has adopted the different CoD calculation that LINEST uses when a zero intercept is specified. Again, see the LINEST help page.

 

Thus, the trendline R^2 and LINEST R^2 will agree when a zero intercept is specified.

 

2. The trendline R^2 calculation is based on the correlation between the original y and the estimated y generated by the trendline formula, which might not be linear.

 

In contrast, using your chart #1 trendline for example, the Excel 2010 trendline R^2 is based on the correlation between the original y and the estimated ln(y) = a*x + ln(b) instead of the estimated y = b*exp(a*x).

 

(As does the LINEST R^2 (CoD), since it cannot know that the linear relationship between Y and X is derived from a nonlinear relationship.)

 

It is #2 that is relevant to the difference that you observed in the two charts, not the use of RSQ instead of CoD.