blib/lib/App/RecordStream/Aggregator/LinearRegression.pm

filter: Statementstmt 97.0% 33 / 34 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 88.8% 8 / 9 Podpod 0.0% 0 / 3 totaltotal 89.1% 41 / 46 CC 1 SCAR 1.1
CC
1
Cov
97%
long_usage
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« blib/lib/App/RecordStream/Aggregator/Covariance.pm ↑ Summary blib/lib/App/RecordStream/Aggregator/Count.pm »
1 package App::RecordStream::Aggregator::LinearRegression;
2  
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 7 ▶use App::RecordStream::Aggregator::Ord2Bivariate;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 7 ▶use App::RecordStream::Aggregator;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 ▶use App::RecordStream::DomainLanguage::Registry;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 7 ▶use base 'App::RecordStream::Aggregator::Ord2Bivariate';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 #sub new -- passed through
13  
14 #sub new_from_valuation -- passed through
15  
16 sub squish
17 {
18 1 ▶ my ($this, $cookie) = @_;
Subroutine squish: called CC=1 SCAR=0.0
Pod undocumented
19  
20 1 my ($sum1, $sumx, $sumy, $sumxy, $sumx2, $sumy2) = @$cookie;
21  
22 1 my $beta = ($sumxy * $sum1 - $sumx * $sumy) / ($sumx2 * $sum1 - $sumx ** 2);
23 1 my $alpha = ($sumy - $beta * $sumx) / $sum1;
24  
25 1 my $sbeta_numerator = ($sumy2 + $alpha ** 2 * $sum1 + $beta ** 2 * $sumx2 - 2 * $alpha * $sumy + 2 * $alpha * $beta * $sumx - 2 * $beta * $sumxy) / ($sum1 - 2);
26 1 my $sbeta_denominator = $sumx2 - $sumx * $sumx / $sum1;
27 1 my $sbeta = sqrt($sbeta_numerator / $sbeta_denominator);
28 1 my $salpha = $sbeta * sqrt($sumx2 / $sum1);
29  
30 return
31 {
32 1 'alpha' => $alpha,
33 'beta' => $beta,
34 'beta_se' => $sbeta,
35 'alpha_se' => $salpha,
36 };
37 }
38  
39 sub long_usage
40 {
41 0 ▶ return <<EOF;
Subroutine long_usage: not called CC=1 SCAR=6.9
Pod undocumented
42 Usage: linreg,<x field>,<y field>
43 Dump various status from a linear regression of y against x.
44 EOF
45 }
46  
47 sub short_usage
48 {
49 1 ▶ return "perform a linear regression of provided fields, dumping various statistics";
Subroutine short_usage: called CC=1 SCAR=0.0
Pod undocumented
50 }
51  
52 7 App::RecordStream::Aggregator->register_implementation('linreg', __PACKAGE__);
53 7 App::RecordStream::Aggregator->register_implementation('linearregression', __PACKAGE__);
54  
55 7 App::RecordStream::DomainLanguage::Registry::register_vfn(__PACKAGE__, 'new_from_valuation', 'linreg', 'VALUATION', 'VALUATION');
56 7 App::RecordStream::DomainLanguage::Registry::register_vfn(__PACKAGE__, 'new_from_valuation', 'linearregression', 'VALUATION', 'VALUATION');
57  
58 7 1;
« blib/lib/App/RecordStream/Aggregator/Covariance.pm ↑ Summary blib/lib/App/RecordStream/Aggregator/Count.pm »