Per title I want to project a regression line but use the previous data point NOT included in the dataset for calculating the regression line as an anchor such that the regression line starts at that previous data point. NOTE: If the previous data point needs to be included that is also acceptable.
The following code calculates the regression line slope.
One thought was to have the last point be the YIntercept, but
not sure how -- or -- if the formula for the slope needs to be modified to have the previous point be the YIntercept?
Given the formula Y = mx + b one would think that
setting b = YIntercept = last data point, this would give the correct result.
Any other solutions appreciated.
The following code calculates the regression line slope.
One thought was to have the last point be the YIntercept, but
not sure how -- or -- if the formula for the slope needs to be modified to have the previous point be the YIntercept?
Given the formula Y = mx + b one would think that
setting b = YIntercept = last data point, this would give the correct result.
Any other solutions appreciated.
Code:
Private Function fLFit()
'IN PROCESS -- 20180319
'Linear Regression
Dim i As Integer
Dim n As Integer '# Data Pts.
Dim SX As Double 'Sum X
Dim SY As Double 'Sum Y
Dim SX2 As Double 'Sum X Squared
Dim SXY As Double 'Sum X * Y
Dim SY As Double 'Sum Y
Dim Num As Double 'Numerator of Fraction
Dim Dem As Double 'Denominator of Fraction
n = CInt(msngInput1)
SX = 0
SY = 0
For i = 1 To n
SX = SX + X(i)
SX2 = SX2 + X(i) ^ 2
SY = SY + Y(i)
SY2 = SY2 + Y(i) ^ 2
SXY = SXY + X(i) * Y(i)
Next i
'Calculate Slope
Num = (n * SXY) - (SX * SY)
Dem = (n * SX2) - (SX * SX)
Slope = Num / Dem
End Function