2.4.5 fitLR


Brief Information

Simple linear regression

Additional Information

Minimum Origin Version Required for documented features: Origin 9.0

Command Line Usage

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)

X-Function Execution Options

Please refer to the page for additional option switches when accessing the x-function from script

Variables

Display
Name
Variable
Name
I/O
and
Type
Default
Value
Description
Input iy

Input

XYRange

<active>

This variable specifies the input data range.

Fit Begin/End Points N

Input

int

0

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

0

Check this to fix (1) the intercept in linear regression. Default (0) does not fix intercept.

Fix Intercept At intercept

Input

double

0

Specify the value of fixed intercept. This value is ignored if fixint = 0.

Fix Slope fixslope

Input

int

0

Check this to fix (1) the slope in linear regression. Default (0) does not fix slope.

Fix Slope At slope

Input

double

1

Specify the value of fixed slope. This value is ignored if fixslope = 0.

Intercept a

Output

double

<unassigned>

The fitted intercept.

Slope b

Output

double

<unassigned>

The fitted slope.

Intercept Error aerr

Output

double

<unassigned>

If defined, this variable will contain the intercept error.

Slope Error berr

Output

double

<unassigned>

If defined, this variable will contain the slope error.

R value r

Output

double

<unassigned>

If defined, this variable will contain the Adjusted residual sum of squares.

Number of Actual Points Used pts

Output

int

<unassigned>

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

<optional>

This variable specifies the output range for creating the fit line datasets.

Description

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

Examples

  • Code Sample
//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=;

Algorithm

The slope of the linear regression is given by the:

FitLR help English files image004.gif where FitLR help English files image006.gif and FitLR help English files image008.gif

And the intercept:

FitLR help English files image010.gif

Related X-Functions


Keywords:curve fitting