| Statistics-LSNoHistory documentation | view source | Contained in the Statistics-LSNoHistory distribution. |
Statistics::LSNoHistory - Least-Squares linear regression package without data history
# construct from points
$reg = Statistics::LSNoHistory->new(points => [
1.0 => 1.0,
2.1 => 1.9,
2.8 => 3.2,
4.0 => 4.1,
5.2 => 4.9
]);
# other equivalent constructions
$reg = Statistics::LSNoHistory->new(
xvalues => [1.0, 2.1, 2.8, 4.0, 5.2],
yvalues => [1.0, 1.9, 3.2, 4.1, 4.9]
);
# or
$reg = Statistics::LSNoHistory->new;
$reg->append_arrays(
[1.0, 2.1, 2.8, 4.0, 5.2],
[1.0, 1.9, 3.2, 4.1, 4.9]
);
# or
$reg = Statistics::LSNoHistory->new;
$reg->append_points(
1.0 => 1.0, 2.1 => 1.9, 2.8 => 3.2, 4.0 => 4.1, 5.2 => 4.9
);
# You may also construct from the preliminary statistics of a
# previous regression:
$reg = Statistics::LSNoHistory->new(
num => 5,
sumx => 15.1,
sumy => 15.1,
sumxx => 56.29,
sumyy => 55.67,
sumxy => 55.83,
minx => 1.0,
maxx => 5.2,
miny => 1.0,
maxy => 4.9
);
# thus a branch may be instantiated as follows
$branch = Statistics::LSNoHistory->new(%{$reg->dump_stats});
$reg->append_point(6.1, 5.9);
$branch->append_point(5.8, 6.0);
# calculate regression values, print some
printf("Slope: %.2f\n", $reg->slope);
printf("Intercept %.2f\n", $reg->intercept);
printf("Correlation Coefficient: %.2f\n", $reg->pearson_r);
...
This package provides standard least squares linear regression functionality without the need for storing the complete data history. Like any other, it finds best m,k (in least squares sense) so that y = m*x + k fits data points (x_1,y_1),...,(x_n,y_n).
In many applications involving linear regression, it is desirable to compute a regression based on the intermediate statistics of a previous regression along with any new data points. Thus there is no need to store a complete data history, but rather only a minimal set of intermediate statistics, the number of which, thanks to Gauss, is 6.
The user interface provides a way to instantiate a regression object with either raw data or previous intermediate statistics.
The constructor (or class method new) takes several possible arguments. The initialization scenario depends on the kinds of arguments passed and falls into one of the following categories:
=> Number of points.
=> Sum of x values.
=> Sum of y values.
=> Sum of x values squared.
=> Sum of y values squared.
=> Sum of x*y products.
=> Minimum x value.
=> Maximum x value.
=> Minimum y value.
=> Maximum y value.
{ num => <val>,
sumx => <val>,
sumy => <val>,
sumxx => <val>,
sumyy => <val>,
sumxy => <val>,
minx => <val>,
maxx => <val>,
miny => <val>,
maxy => <val> }
COPYING for complete information.
| Statistics-LSNoHistory documentation | view source | Contained in the Statistics-LSNoHistory distribution. |