File Coverage

blib/lib/App/RecordStream/Aggregator/LinearRegression.pm
Criterion Covered Total %
statement 27 29 93.1
branch n/a
condition n/a
subroutine 7 9 77.7
pod 0 3 0.0
total 34 41 82.9


line stmt bran cond sub pod time code
1             package App::RecordStream::Aggregator::LinearRegression;
2              
3 6     6   72568 use strict;
  6         22  
  6         153  
4 6     6   24 use warnings;
  6         12  
  6         133  
5              
6 6     6   475 use App::RecordStream::Aggregator::Ord2Bivariate;
  6         11  
  6         103  
7 6     6   25 use App::RecordStream::Aggregator;
  6         11  
  6         119  
8 6     6   407 use App::RecordStream::DomainLanguage::Registry;
  6         12  
  6         149  
9              
10 6     6   35 use base 'App::RecordStream::Aggregator::Ord2Bivariate';
  6         16  
  6         1733  
11              
12             #sub new -- passed through
13              
14             #sub new_from_valuation -- passed through
15              
16             sub squish
17             {
18 1     1 0 9 my ($this, $cookie) = @_;
19              
20 1         4 my ($sum1, $sumx, $sumy, $sumxy, $sumx2, $sumy2) = @$cookie;
21              
22 1         5 my $beta = ($sumxy * $sum1 - $sumx * $sumy) / ($sumx2 * $sum1 - $sumx ** 2);
23 1         4 my $alpha = ($sumy - $beta * $sumx) / $sum1;
24              
25 1         10 my $sbeta_numerator = ($sumy2 + $alpha ** 2 * $sum1 + $beta ** 2 * $sumx2 - 2 * $alpha * $sumy + 2 * $alpha * $beta * $sumx - 2 * $beta * $sumxy) / ($sum1 - 2);
26 1         3 my $sbeta_denominator = $sumx2 - $sumx * $sumx / $sum1;
27 1         2 my $sbeta = sqrt($sbeta_numerator / $sbeta_denominator);
28 1         3 my $salpha = $sbeta * sqrt($sumx2 / $sum1);
29              
30             return
31             {
32 1         7 'alpha' => $alpha,
33             'beta' => $beta,
34             'beta_se' => $sbeta,
35             'alpha_se' => $salpha,
36             };
37             }
38              
39             sub long_usage
40             {
41 0     0 0   return <
42             Usage: linreg,,
43             Dump various status from a linear regression of y against x.
44             EOF
45             }
46              
47             sub short_usage
48             {
49 0     0 0   return "perform a linear regression of provided fields, dumping various statistics";
50             }
51              
52             App::RecordStream::Aggregator->register_implementation('linreg', __PACKAGE__);
53             App::RecordStream::Aggregator->register_implementation('linearregression', __PACKAGE__);
54              
55             App::RecordStream::DomainLanguage::Registry::register_vfn(__PACKAGE__, 'new_from_valuation', 'linreg', 'VALUATION', 'VALUATION');
56             App::RecordStream::DomainLanguage::Registry::register_vfn(__PACKAGE__, 'new_from_valuation', 'linearregression', 'VALUATION', 'VALUATION');
57              
58             1;