6. Functions : Stat Library Functions : LSQ Function
 
Share this page                  
LSQ Function
The LSQ function is based on the linear equation y = mx + c, performs a linear regression analysis for data contained in the xdata and ydata lists, and returns the slope of the line, the intercept of the line, and the correlation coefficient for the line.
Note:  Slope, intercept, and correlation must all be passed by reference (byref).
This function has the following syntax:
LSQ(xdata, ydata, byref(slope), byref (intercept), byref(correlation))
Arguments
Data Type
Description
xdata
Array of Object
X-axis data points
Default: null
ydata
Array of Object
Y-axis data points
slope
Float
Slope of linear equation
Default: null
intercept
Float
Y-axis intercept of the line
Default: null
correlation
Float
Correlation coefficient
Default: null
The Array of Object can be an Array of FloatObject, IntegerObject, or MoneyObject. If xdata is not included, then the x-axis data points (0, 1, 2, 3 ...) up to the number of y-axis data points are used. A correlation coefficient of 1 is interpreted as being the best case and a 0 is the worst case, with -1 indicating complete reverse correlation.
This function returns:
ER_OK—No error encountered
Null—On error
It also returns the following, through optional arguments passed by reference:
Slope—The slope of the line (m)
Intercept—The y-axis intercept of the line (c)
Correlation—A correlation coefficient