Simple linear regression
Minimum Origin Version Required for documented features: Origin 9.0
1. fitLR (1,2); // Fit using column 1 as X and 2 as Y 2. fitLR iy:=(1,2) N:=5; 3. fitLR (1,2) N:=-10; 4. fitLR iy:=(1,2) N:=-5 oy:=<new>; 5. fitLR iy:=(1,2) fixint:=1 intercept:=0; // Force fit through 0,0 (beginning with 9.0) 6. fitLR iy:=(1,2) fixslope:=1 slope:=0.667; // Force fit to slope of 0.667 (beginning with 9.0)
Please refer to the page for additional option switches when accessing the x-function from script
Display Name |
Variable Name |
I/O and Type |
Default Value |
Description |
---|---|---|---|---|
Input | iy |
Input XYRange |
|
This variable specifies the input data range. |
Fit Begin/End Points | N |
Input int |
|
This variable specifies the number of points to use in the linear regression. When this value is zero, all points in the range are used. When the number is a positive integer, the first N points are used. When the number is a negative integer, the last N points are used. |
Fix Intercept | fixint |
Input int |
Check this to fix (1) the intercept in linear regression. Default (0) does not fix intercept. | |
Fix Intercept At | intercept |
Input double |
|
Specify the value of fixed intercept. This value is ignored if fixint = 0. |
Fix Slope | fixslope |
Input int |
|
Check this to fix (1) the slope in linear regression. Default (0) does not fix slope. |
Fix Slope At | slope |
Input double |
|
Specify the value of fixed slope. This value is ignored if fixslope = 0. |
Intercept | a |
Output double |
The fitted intercept. | |
Slope | b |
Output double |
|
The fitted slope. |
Intercept Error | aerr |
Output double |
|
If defined, this variable will contain the intercept error. |
Slope Error | berr |
Output double |
|
If defined, this variable will contain the slope error. |
R value | r |
Output double |
|
If defined, this variable will contain the Adjusted residual sum of squares. |
Number of Actual Points Used | pts |
Output int |
|
If defined, this variable will contain the number of points in the fit. This will be the number of points in the range when N = 0 is used to fit all points. |
Output | oy |
Output XYRange |
|
This variable specifies the output range for creating the fit line datasets. |
This X-Function calculates the slope and intercept of the linear regression line. Regardless of the settings for optional outputs, the function creates a Tree object named fitlr which contains these property values:
fitlr.iy$
fitlr.N
fitlr.fixint
fitlr.intercept
fitlr.fixslope
fitlr.slope
fitlr.a
fitlr.b
fitlr.aerr
fitlr.berr
fitlr.r
fitlr.pts
//Shows how to use fitLR on various ranges from provided sample data and dump the results //Create a new workbook and import the sample file string ResultBook$; newbook name:="Linear Regression Sample" sheet:=1 result:=ResultBook$; impfile fname:=system.path.program$+"Samples\Curve Fitting\Multiple Gaussians.dat"; type "The fit result of the first 25 points of curve B:"; range aa = [ResultBook$]1!2; fitLR iy:=aa n:=25; fitLR.b=; fitLR.a=; type; type "The fit result of the last 25 points of curve C:"; range bb = [ResultBook$]1!3; fitLR iy:=bb n:=-25; fitLR.b=; fitLR.a=; type; type "The fit result of the middle portion of the curve D:"; range cc = [ResultBook$]1!(1, 4)[12:26]; fitLR iy:=cc fixint:=1 intercept:=0; // Force fit through 0,0 fitLR.b=; fitLR.a=; type; type "The fit result of the last 25 points of curve E:"; range ee = [ResultBook$]1!(1,5)[25:50]; fitLR iy:=ee fixslope:=1 slope:=0.667; // Force fit to slope of 0.667 fitLR.b=; fitLR.a=;
The slope of the linear regression is given by the:
And the intercept:
Keywords:curve fitting