3.3.2.38 LR

This command performs a linear regression on dataset and its dependent X dataset.

Please see the fitlr X-Function.

Syntax:

lr  [option] dataset [range]

If the data is plotted in an active graph window, lr adds the data plot of the fitted curve to the graph window. If the Data Selector tool was used to set the range, then the fit is performed over the selected range and the resulting curve displayed for the full range.


Note on LR Object Properties

The fitting results are stored in lr object properties. To read the value of these properties, use the following syntax:

lr.property =

The value of the property is returned in the Script window. The properties return a null value until the lr command has been executed. The lr object has the following properties:

lr.b -- Slope.
lr.a -- Intercept.
lr.sdB -- Standard deviation of slope.
lr.sdA -- Standard deviation of intercept.
lr.sd-- Standard deviation of the fit.
lr.r -- Correlation coefficient.
lr.n -- Number of points used in the fitting.
lr.chkLinearr -- Sets the amount of tolerance in the automatic determination of linear segments from the data. (See the -b and -e options.)
lr.maxLRange -- Specifies the percentage of the entire data range to be examined by the find linear segment routine. (See the -b and -e options.)

Options:

no option; Perform a linear regression on dataset

Syntax: lr message

Perform a linear regression on dataset.

-b, -e; Perform a linear regression on the beginning or ending linear region of dataset

Syntax: lr -b dataset,-e dataset

Perform a linear regression on the beginning or ending linear region of dataset.

Note:

When you use the lr -b dataset or lr -e dataset commands to perform a linear regression on the beginning (b) or ending (e) linear region of dataset, the dataset is automatically searched for linearity, as determined by the following parameters that can be modified in the ORGSYS.CNF file:

lr.maxLRange: The percentage of the entire data range to perform a linear regression on. For example, when lr.maxLRange = 40 (default) and dataset has 20 points, lr -b dataset performs a linear regression on the first 8 points in dataset, if these points meet the requirements of the lr.chkLinearR parameter. Thus, if the fourth point is outside the tolerance set by lr.chkLinearR, then the lr -b dataset command would only perform a linear regression on the first three points in dataset.

lr.chkLinearR: Sets the amount of tolerance in the automatic determination of linear segments.

-n; Perform a linear regression on dataset but do not create a data plot

Syntax: lr -n dataset [range]

Perform a linear regression on dataset but do not create a data plot of the fit line.

-s; Use the axis scale function to transform the data before performing the linear regression

Syntax: lr -s dataset [range]

Use the axis scale function to transform the data before performing the linear regression.This allows you to do an apparent linear fit on data that is plotted against a nonlinear scale, for example, a Log 10 scale.

-x; Using the dataset xdataset as X values to perform a linear regression

Syntax: lr -x dataset [range]

Perform a linear regression on dataset, using the dataset xdataset to supply the X values (independent variables).

Examples:

The following script performs a linear fit of dataset Data1_B beginning at the first data point and continuing until the end of the linear region. It types the resulting slope and intercept to the Script window.

lr col(1);
type "Slope is $(lr.b)";
type "Intercept is $(lr.a)";