[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: linear regression calculations in Visual Basic



PureBytes Links

Trading Reference Links

This is what I get after looking at p. 104 of _Data Reduction and Error
Analysis for the Physical Sciences_ by Bevington...

Slope = (N*B - C*D) / (N*E - C^2)

and

Y_intercept = (E*D - C*B) / (N*E - C^2)

wher N is the number of data points, 200 in your example.

Also, be careful about putting parenthesis around your entire denominator.
x / E - C^2 is different from x / (E - C^2).


Let me know what works,
Aaron Schindler
Schindler Trading



----- Original Message -----
From: "Craig" <craigbud@xxxxxxxxxxx>
To: <omega-list@xxxxxxxxxx>
Sent: Monday, April 08, 2002 8:15 PM
Subject: OT: linear regression calculations in Visual Basic


> I'm trying to move away from Excel VBA into VB and found that Visual Basic
> lacks statistics functions.  Therefore, I need to calculate the values
from
> scratch, but I'm not having any success.
>
> Here's a snippet calculating the slope and y-intercept for the best fit
> line in a scatter x-y plot:
>
>
> For counter = 0 to 199
>      x = xArray(counter)
>      y = yArray(counter)
>      A = x * y 'x*y
>      B = B + A               'sum of x*y
>      C = C + x             'sum of x
>      D = D+ y             'sum of y
>      E = E + x ^ 2 'sum of x squared
> Next counter
>
> Slope = (B* C* D) / E- C^2
>
> Y_intercept = (D*E - C*B) / E - C^2
>
> The slope and Y_intercept are wrong.  Would somebody help me?
>
> Thanks,
>
> Craig
>
>