I am having an issue where the logarithmic function is behaving differently depending on the type of graph I use with the same data. When I generate the equation by hand, it returns the scatterplot linear trendline, but the slope function and linear graph produce a different trendline.
Linear vs Scatter
The equation for the scatter plot logarithmic line is:
y = -0.079ln(x) + 0.424
The equation for the linear plot trenline is:
y = -0.052ln(x) + 0.3138
I can generate the linear plot trenline slope using this equation:
=SLOPE(B2:B64,LN(A2:A64)) = -0.052
But using the general slope equation, I get the scatter plot trendline (using SQL):
SELECT SUM(multipliedresiduals) / SUM(xresidsquared)
FROM (
SELECT *
,log(x.x) - l.avgx xresiduals
,x.y - l.avgy yresiduals
,power(log(x.x) - l.avgx, 2) xresidsquared
,((log(x.x) - l.avgx) * (x.y - l.avgy)) multipliedresiduals
FROM ##logtest x
CROSS JOIN (
SELECT avg(log(x)) avgx
,avg(y) avgy
FROM ##logtest l
) l
) z = -0.0789746757495071 (Scatter Plot Slope)
What's going on? I'm mainly interested in replicating the linear plot trenline equation in SQL
Here is the data:
https://docs.google.com/spreadsheets/d/1sOlyXaHnUcCuD9J28cKHnrhhcr2hvYSU1iCNWXcTqEA/edit?usp=sharing
Here is the Excel File:
https://www.dropbox.com/s/6hpd4bzvmbxe5pu/ScatterLinearTest.xlsx?dl=0