I am writing a function to calculate the standard error of the estimate of a linear regression (I understand excel already has this), but I am doing it so that I can give it the linear equation that I want to be considered, rather than the function calculating it itself as the STEYX built-in function does. I cannot seem to get VBA to calculate my y-predicted values though. The For loop I have written just populates my array with the same value, which is my y-predicted at my first x-value, and then it writes this to every slot in my array. Can someone please tell me what is wrong with my code? If I can't get beyond this I won't be able to calculate the rest of what I need to for the statistic.
Code:
Function CustomSyx(yvalues As Range, xvalues As Range, slope As Variant, intercept As Variant)
'Define variables
Dim n As Integer
Dim i As Integer
Dim Syx As Variant
Dim ypred() As Variant
Dim resid() As Variant
Dim m As Variant
Dim b As Variant
Dim residsum
'Set Values
x = xvalues.Value
y = yvalues.Value
n = WorksheetFunction.Count(x)
m = slope
b = intercept
ReDim ypred(1 To n)
ReDim resid(1 To n)
For i = 1 To n
ypred(i) = m * x(i, 1) + b
Next i
CustomSyx = x
End Function