
1. Re: Regression Line Calculation
Robin Kennedy Jun 27, 2013 11:16 AM (in response to Dwight Taylor)Hi Dwight,
You need to replicate the linear regression formula that tableau uses to plot the trend line. The equation to use is as on wiki: https://en.wikipedia.org/wiki/Simple_linear_regression
In Tableau, that translates to creating a calculated field for beta as
Beta =
(WINDOW_AVG(sum([X Axis])*sum([Y Axis]))(WINDOW_AVG(sum([X Axis]))*WINDOW_AVG(sum([Y Axis]))))
/ (WINDOW_AVG(sum([X Axis])^2)(WINDOW_AVG(sum([X Axis]))^2))
and alpha as
Alpha =
window_avg(sum([Y Axis])) 
[Beta]*window_avg(sum([X Axis]))
You can then combine them to create a linear regression line, which in turn can be used in another calculated field to determine whether the points on the chart are above or below this line
Linear Regression = [Alpha] + [Beta] * sum([X Axis])
Performance =
if sum([Y Axis]) > [Linear regression] then 'Above'
else 'Below'
end
You need to pay special attention to how the table calculations are partitioned and addressed
Hope that helps (and special thanks to Joe Mako on this forum post here: http://community.tableau.com/thread/121346)
See the attached workbook for a working version.

Linear Regression Help.twbx.zip 947.9 KB


2. Re: Regression Line Calculation
Karthik Ravikumar Mar 26, 2015 9:16 PM (in response to Robin Kennedy)Hi Robin
This is great. I have 2 questions for you.
 Lets say I want to force the Yintercept to 0. Then what would be the tweaked formula to calculate Beta?
 Also do you know if there is a way I can display the equation on the trend line always
Regards
