How do I get an exponential regression that minimizes R^2?

%3CLINGO-SUB%20id%3D%22lingo-sub-1937718%22%20slang%3D%22en-US%22%3EHow%20do%20I%20get%20an%20exponential%20regression%20that%20minimizes%20R%5E2%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1937718%22%20slang%3D%22en-US%22%3E%3CP%3EHow%20do%20I%20get%20an%20exponential%20regression%20that%20minimizes%20R%5E2%3F%26nbsp%3B%20(The%20exponential%20regression%20trendline%20fails%20to%20minimize%20R%5E2%2C%20and%20instead%20seems%20to%20minimize%20the%20R%5E2%20of%20the%20linear%20regression%20on%20the%20log%20of%20the%20y-axis.)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EConsider%20the%20following%20data%2C%20generated%20by%20the%20Python%20script%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-python%22%3E%3CCODE%3Eimport%20math%2C%20random%3B%20print(%22%5Cn%22.join(f%22%7Bn%3A%26lt%3B2%7D%20%7Bmath.exp(n)%2Bint(random.uniform(0%2C100))%3A%26lt%3B15%7D%22%20for%20n%20in%20range(1%2C%2012)))%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CTABLE%20border%3D%220%22%20width%3D%22127px%22%20cellspacing%3D%220%22%20cellpadding%3D%220%22%3E%3CTBODY%3E%3CTR%3E%3CTD%20width%3D%2252px%22%20height%3D%2221%22%3En%3C%2FTD%3E%3CTD%20width%3D%2275px%22%3Eeapprox%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%2252px%22%20height%3D%2221%22%3E1%3C%2FTD%3E%3CTD%20width%3D%2275px%22%3E97.71828%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%2252px%22%20height%3D%2221%22%3E2%3C%2FTD%3E%3CTD%20width%3D%2275px%22%3E101.3891%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%2252px%22%20height%3D%2221%22%3E3%3C%2FTD%3E%3CTD%20width%3D%2275px%22%3E87.08554%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%2252px%22%20height%3D%2221%22%3E4%3C%2FTD%3E%3CTD%20width%3D%2275px%22%3E92.59815%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%2252px%22%20height%3D%2221%22%3E5%3C%2FTD%3E%3CTD%20width%3D%2275px%22%3E194.4132%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%2252px%22%20height%3D%2221%22%3E6%3C%2FTD%3E%3CTD%20width%3D%2275px%22%3E410.4288%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%2252px%22%20height%3D%2221%22%3E7%3C%2FTD%3E%3CTD%20width%3D%2275px%22%3E1174.633%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%2252px%22%20height%3D%2221%22%3E8%3C%2FTD%3E%3CTD%20width%3D%2275px%22%3E3032.958%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%2252px%22%20height%3D%2221%22%3E9%3C%2FTD%3E%3CTD%20width%3D%2275px%22%3E8198.084%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%2252px%22%20height%3D%2221%22%3E10%3C%2FTD%3E%3CTD%20width%3D%2275px%22%3E22124.47%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%2252px%22%20height%3D%2221%22%3E11%3C%2FTD%3E%3CTD%20width%3D%2275px%22%3E59973.14%3C%2FTD%3E%3C%2FTR%3E%3C%2FTBODY%3E%3C%2FTABLE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPlotting%20this%20on%20a%20log-y%20scale%20in%20Excel%202019%20with%20an%20exponential%20trendline%20gives%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22JasonGross_0-1606578741240.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F236455i20099DE92AD08F9F%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22JasonGross_0-1606578741240.png%22%20alt%3D%22JasonGross_0-1606578741240.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CDIV%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%3CP%3EDoing%20the%20same%20computation%20in%20Google%20sheets%20gives%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22eapprox%20vs.%20n.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F236454iB64C2BFD3FF43055%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22eapprox%20vs.%20n.png%22%20alt%3D%22eapprox%20vs.%20n.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EClearly%20the%20Excel%20trendline%20fails%20to%20minimize%26nbsp%3BR%5E2%2C%20presumably%20because%20Excel%20is%20assuming%20that%20a%20linear%20regression%20with%20unit%20weights%20on%20x%2C%20log(y)%20is%20the%20same%20as%20an%20exponential%20regression%20with%20unit%20weights%20on%20x%2C%20y%20(it's%20not%3B%20you%20need%20to%20log-scale%20the%20weights%2Ferrors%20as%20well).%26nbsp%3B%20How%20do%20I%20correct%20this%20issue%2C%20and%20get%20Excel%20to%20give%20me%20the%20actually%20correct%20trendline%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1937718%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1937965%22%20slang%3D%22en-US%22%3ERe%3A%20How%20do%20I%20get%20an%20exponential%20regression%20that%20minimizes%20R%5E2%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1937965%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F884301%22%20target%3D%22_blank%22%3E%40JasonGross%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EPlease%20try%20with%20this%20setting%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22image.png%22%20style%3D%22width%3A%20655px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F236463i6E48025D356B43A8%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22image.png%22%20alt%3D%22image.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1941069%22%20slang%3D%22en-US%22%3ERe%3A%20How%20do%20I%20get%20an%20exponential%20regression%20that%20minimizes%20R%5E2%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1941069%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F884301%22%20target%3D%22_blank%22%3E%40JasonGross%3C%2FA%3E%26nbsp%3B%26nbsp%3B%20Re%3A%20%60%60How%20do%20I%20get%20an%20exponential%20regression%20that%20minimizes%20R%5E2%3F%20%5B....%5D%20Doing%20the%20same%20computation%20in%20Google%20sheets%20gives%20%5Bin%20image%2C%20effectively%5D%20y%20%3D%202.07e%5E(0.931x)%60%60%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20must%20be%20brief.%20I%20might%20add%20an%20image%20and%20attach%20an%20Excel%20file%20later.%26nbsp%3B%20And%20I%20might%20add%20a%20more-explanatory%20response%20later.%26nbsp%3B%20But%20in%20a%20nutshell....%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EObviously%2C%20we%20want%20to%20%3CU%3E%3CEM%3Emaximize%3C%2FEM%3E%3C%2FU%3E%2C%20not%20minimize%20R%5E2.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnd%20there%20appears%20to%20be%20a%20typo(!)%20in%20your%20image.%26nbsp%3B%20Given%20the%20form%20of%20the%20exponentional%20trendline%20equation%20as%20y%20%3D%20b*EXP(m*x)%2C%20for%20m%3D0.931%20(rounded)%2C%20b%20must%20be%202.%3CSTRONG%3E%3CFONT%20color%3D%22%23FF0000%22%3E207%3C%2FFONT%3E%3C%2FSTRONG%3E%20(rounded)%2C%20not%202.%3CSTRONG%3E%3CFONT%20color%3D%22%23FF0000%22%3E07%3C%2FFONT%3E%3C%2FSTRONG%3E%20%3CEM%3E%5Bsic%5D%3C%2FEM%3E.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%20color%3D%22%23FF0000%22%3ESo%20you%20can%20mimic%20the%20Google%20chart%20by%20entering%20an%20intercept%20value%20(b)%20that%20rounds%20to%202.207.%3CFONT%20color%3D%22%23000000%22%3E%3CBR%20%2F%3E%3C%2FFONT%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%20color%3D%22%23000000%22%3EIgnore%20the%20R%5E2%20that%20appears%20in%20the%20chart.%26nbsp%3B%20It%20is%20%22wrong%22%20(misleading)%20for%20exponentional%20trendlines.%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EEmpirically%2C%20I%20have%20determined%20that%20the%20intercept%20can%20be%20a%20value%20%3CFONT%20color%3D%22%23FF0000%22%3Ebetween%202.206561%20and%202.207499%3C%2FFONT%3E%2C%20rounded%20to%206%20decimal%20places%2C%20in%20order%20for%20it%20to%20be%20displayed%20as%202.207.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThen%20the%20slope%20(m)%20is%20between%200.931499%20and%200.931444%2C%20truncated%20to%206%20decimal%20places%2C%20which%20rounds%20to%26nbsp%3B%200.931.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E(In%20contract%2C%20if%20the%20intercept%20(b)%20were%20between%202.065000%20and%202.07499%2C%20which%20rounds%20to%202.07%20%3CEM%3E%5Bsic%5D%3C%2FEM%3E%2C%20the%20slope%20(m)%20would%20round%20to%200.940%2C%20not%200.931%20%3CEM%3E%5Bsic%5D%3C%2FEM%3E.)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECaveat%3A%26nbsp%3B%20You%20might%20get%20slightly%20different%20results%20when%20you%20use%20the%20exact%20given%20y-values.%26nbsp%3B%20I%20must%20use%20the%20y-values%20as%20you%20posted%20them%2C%20which%20might%20be%20rounded%20due%20to%20the%20cell%20format.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20Excel%2C%20the%20slope%20(m)%20can%20be%20calculated%20with%20the%20following%20%3CU%3E%3CEM%3Enormally-entered%3C%2FEM%3E%3C%2FU%3E%20formula%20(press%20Enter%20as%20usual)%20in%20I11%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%20color%3D%22%23FF0000%22%3E%3DLINEST(LN(B2%3AB12)-LN(N10)%2C%20A2%3AA12%2C%20FALSE)%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ewhere%20N10%20is%20the%20intercept%20value%20(b)%20that%20you%20choose%2C%20A2%3AA12%20are%20the%20x-values%20(1%20to%2011)%2C%20and%20B2%3AB12%20are%20the%20given%20y-values%20(97.71828%20to%2059973.14%2C%20as%20you%20posted%20them).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20correct%20R%5E2%20can%20be%20calculated%20with%20the%20following%20%3CU%3E%3CEM%3Enormally-entered%3C%2FEM%3E%3C%2FU%3E%20formula%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%20color%3D%22%23FF0000%22%3E%3DRSQ(N10*EXP(I11*A2%3AA12)%2C%20B2%3AB12)%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ewhere%20I11%20contains%20the%20LINEST%20formula%20above.%26nbsp%3B%20That%20displays%200.999%20(rounded)%2C%20like%20Google.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBut%20IMHO%2C%20that%20is%20not%20the%20best%20%22trend%22%20formula%20to%20use.%26nbsp%3B%20Again%2C%20perhaps%20I'll%20post%20more%20later.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EGotta%20run!%26nbsp%3B%20Well%2C%20bike.%20(smile)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Visitor

How do I get an exponential regression that minimizes R^2?  (The exponential regression trendline fails to minimize R^2, and instead seems to minimize the R^2 of the linear regression on the log of the y-axis.)

 

Consider the following data, generated by the Python script

 

import math, random; print("\n".join(f"{n:<2} {math.exp(n)+int(random.uniform(0,100)):<15}" for n in range(1, 12)))

 

neapprox
197.71828
2101.3891
387.08554
492.59815
5194.4132
6410.4288
71174.633
83032.958
98198.084
1022124.47
1159973.14

 

Plotting this on a log-y scale in Excel 2019 with an exponential trendline gives

JasonGross_0-1606578741240.png

 
 

Doing the same computation in Google sheets gives

eapprox vs. n.png

Clearly the Excel trendline fails to minimize R^2, presumably because Excel is assuming that a linear regression with unit weights on x, log(y) is the same as an exponential regression with unit weights on x, y (it's not; you need to log-scale the weights/errors as well).  How do I correct this issue, and get Excel to give me the actually correct trendline?

 

2 Replies

@JasonGross 

Please try with this setting

image.png

@JasonGross   Re: ``How do I get an exponential regression that minimizes R^2? [....] Doing the same computation in Google sheets gives [in image, effectively] y = 2.07e^(0.931x)``

 

I must be brief. I might add an image and attach an Excel file later.  And I might add a more-explanatory response later.  But in a nutshell....

 

Obviously, we want to maximize, not minimize R^2.

 

And there appears to be a typo(!) in your image.  Given the form of the exponentional trendline equation as y = b*EXP(m*x), for m=0.931 (rounded), b must be 2.207 (rounded), not 2.07 [sic].

 

So you can mimic the Google chart by entering an intercept value (b) that rounds to 2.207.

 

Ignore the R^2 that appears in the chart.  It is calculated differently than either LINEST or RSQ below, which seems to be how it is calculated for the Google image.

 

Empirically, I have determined that the intercept can be a value between 2.206561 and 2.207499, rounded to 6 decimal places, in order for it to be displayed as 2.207.

 

Then the slope (m) is between 0.931499 and 0.931444, truncated to 6 decimal places, which rounds to  0.931.

 

(In contrast, if the intercept (b) were between 2.065000 and 2.07499, which rounds to 2.07 [sic], the slope (m) would round to 0.940, not 0.931 [sic].)

 

Caveat:  You might get slightly different results when you use the exact given y-values.  I must use the y-values as you posted them, which might be rounded due to the cell format.

 

In Excel, the slope (m) can be calculated with the following normally-entered formula (press Enter as usual) in I11:

 

=LINEST(LN(B2:B12)-LN(N10), A2:A12, FALSE)

 

where N10 is the intercept value (b) that you choose, A2:A12 are the x-values (1 to 11), and B2:B12 are the given y-values (97.71828 to 59973.14, as you posted them).

 

R^2 can be calculated with the following normally-entered formula:

 

=RSQ(N10*EXP(I11*A2:A12), B2:B12)

 

where I11 contains the LINEST formula above.  That displays 0.999 (rounded), like Google.

 

But IMHO, that is not the best "trend" formula to use.  Again, perhaps I'll post more later.

 

Gotta run!  Well, bike. (smile)