VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



linear regression

by Ralf Kriegel (1 Submission)
Category: Math/Dates
Compatability: Visual Basic 3.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (5 Votes)

Calculation of a linear regression
(straight line) using a X,Y data array

Inputs
X,Y data array
Assumes
requires a minimum of two data points
Code Returns
Slope and Y-intersection
Side Effects
nothing
API Declarations
nothing

Rate linear regression

Public Sub LinRegsngArr(ByRef sng_XArray!(), ByRef sng_YArray!(), _
  ByVal lowLimInd&, ByVal uppLimInd&, ByRef Slope!, ByRef YSection!)
'this Code calculates a linear regression
'using the points of two Arrays (X,Y) 
'and gives back slope and Y-intersection 
'of the straight line
Dim sng_XSum!, sng_YSum!, sng_XQuad!, sng_YQuad!, sng_XYProd!, sng_Fract!
Dim lng_Index&, ValuesCounts&, sng_Zaehler!
 ValuesCounts = uppLimInd - lowLimInd + 1
  For lng_Index = lowLimInd To uppLimInd
   sng_XSum = sng_XSum + sng_XArray(lng_Index)
   sng_YSum = sng_YSum + sng_YArray(lng_Index)
   sng_XQuad = sng_XQuad + sng_XArray(lng_Index) ^ 2
   sng_YQuad = sng_YQuad + sng_YArray(lng_Index) ^ 2
   sng_XYProd = sng_XYProd + sng_YArray(lng_Index) * sng_XArray(lng_Index)
  Next
 sng_Fract = ValuesCounts * sng_XQuad - sng_XSum ^ 2
 Slope = (ValuesCounts * sng_XYProd - sng_XSum * sng_YSum) / sng_Fract
 YSection = (sng_YSum * sng_XQuad - sng_XSum * sng_XYProd) / sng_Fract
 
End Sub

Download this snippet    Add to My Saved Code

linear regression Comments

No comments have been posted about linear regression. Why not be the first to post a comment about linear regression.

Post your comment

Subject:
Message:
0/1000 characters