| 1 | #!/usr/bin/env perl | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 18 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 18 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 18 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | package Medical::Growth::NHANES_2000::Base; | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 18 | our ($VERSION) = '1.00'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 18 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 18 | ▶ | use Exporter; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 18 | ▶ | use Moo::Lax; # Vanilla Moo considered harmful | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 18 | ▶ | use Statistics::Standard_Normal qw(z_to_pct pct_to_z); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 18 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 18 | extends 'Medical::Growth::Base'; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | # Ugly hack here to accommodate the fact that MooX::ClassAttribute | ||||||||||||||||||||||||||||
| 21 | # doesn't handle inheriting/overriding class attrs. | ||||||||||||||||||||||||||||
| 22 | # If you're writing your own, and can afford to use Moose, | ||||||||||||||||||||||||||||
| 23 | # MooseX::ClassAttribute is cleaner. | ||||||||||||||||||||||||||||
| 24 | 33 | ▶ | sub _declare_params_LMS { | ||||||||||||||||||||||||||
|
Subroutine
_declare_params_LMS: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 33 | my $class = shift; | |||||||||||||||||||||||||||
| 26 | 18 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 33 | ▶ | *{ $class . '::_params_LMS' } = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 32539 | state $lms_values = shift->_build_params_LMS; | |||||||||||||||||||||||||||
| 29 | 32539 | $lms_values; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | 33 | } | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 17 | ▶ | sub _build_params_LMS { | ||||||||||||||||||||||||||
|
Subroutine
_build_params_LMS: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 34 | 17 | my $class = shift; | |||||||||||||||||||||||||||
| 35 | 17 | my (@data); | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 17 | foreach my $r ( @{ $class->read_data } ) { | |||||||||||||||||||||||||||
| 38 | 1751 | push @data, | |||||||||||||||||||||||||||
| 39 | { | ||||||||||||||||||||||||||||
| 40 | index => $r->[0], | ||||||||||||||||||||||||||||
| 41 | L => $r->[1], | ||||||||||||||||||||||||||||
| 42 | M => $r->[2], | ||||||||||||||||||||||||||||
| 43 | S => $r->[3] | ||||||||||||||||||||||||||||
| 44 | }; | ||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | 17 | @data = sort { $a->{index} <=> $b->{index} } @data; | |||||||||||||||||||||||||||
| 47 | 17 | \@data; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 32539 | ▶ | sub lookup_LMS { | ||||||||||||||||||||||||||
|
Subroutine
lookup_LMS: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||
| 51 | 32539 | my ( $self, $index ) = @_; | |||||||||||||||||||||||||||
| 52 | 32539 | ▶ | return unless defined $index; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 32538 | my $list = $self->_params_LMS; | |||||||||||||||||||||||||||
| 54 | 32538 | my $i = 0; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 32538 | ▶ | return if $index < $list->[0]->{index} or $index > $list->[-1]->{index}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$index < $list->[0]{"index"} or $index > $list->[-1]{"index"}
MC/DC100%2/2
$index < $list->[0]{"index"} or $index > $list->[-1]{"index"}
$index < $list->[0]{"index"}
$index > $list->[-1]{"index"}
Truth table100%3/3
A or B
A= $index < $list->[0]{"index"}B= $index > $list->[-1]{"index"}
| |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 32532 | ▶ | $i++ while $list->[$i]->{index} < $index; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 32532 | ▶ | $i-- if $i and $index != $list->[$i]->{index}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$i and $index != $list->[$i]{"index"}
MC/DC100%2/2
$i and $index != $list->[$i]{"index"}
$i
$index != $list->[$i]{"index"}
Truth table100%3/3
A and B
A= $iB= $index != $list->[$i]{"index"}
| |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | # Exact match, just return current values | ||||||||||||||||||||||||||||
| 62 | 32532 | ▶ | return @{ $list->[$i] }{qw/L M S/} if $index == $list->[$i]->{index}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | # Between two indices; return interpolated values | ||||||||||||||||||||||||||||
| 65 | 1 | my ( $lo_i, $lo_l, $lo_m, $lo_s ) = @{ $list->[$i] }{qw/index L M S/}; | |||||||||||||||||||||||||||
| 66 | 1 | my ( $hi_i, $hi_l, $hi_m, $hi_s ) = @{ $list->[ $i + 1 ] }{qw/index L M S/}; | |||||||||||||||||||||||||||
| 67 | 1 | my $frac = ( $index - $lo_i ) / ( $hi_i - $lo_i ); | |||||||||||||||||||||||||||
| 68 | return ( | ||||||||||||||||||||||||||||
| 69 | 1 | $lo_l + $frac * ( $hi_l - $lo_l ), | |||||||||||||||||||||||||||
| 70 | $lo_m + $frac * ( $hi_m - $lo_m ), | ||||||||||||||||||||||||||||
| 71 | $lo_s + $frac * ( $hi_s - $lo_s ) | ||||||||||||||||||||||||||||
| 72 | ); | ||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 16267 | ▶ | sub z_for_value { | ||||||||||||||||||||||||||
|
Subroutine
z_for_value: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 76 | 16267 | my ( $self, $value, $index ) = @_; | |||||||||||||||||||||||||||
| 77 | 16267 | my ( $l, $m, $s ) = $self->lookup_LMS($index); | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 16267 | ▶ | return unless $m; # Off end of range | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 16265 | ▶ | if ($l) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 16264 | return ( ( $value / $m )**$l - 1 ) / ( $l * $s ); | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | else { | ||||||||||||||||||||||||||||
| 85 | 1 | return log( $value / $m ) / $s; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 16264 | ▶ | sub pct_for_value { | ||||||||||||||||||||||||||
|
Subroutine
pct_for_value: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 90 | 16264 | my ( $self, $value, $index ) = @_; | |||||||||||||||||||||||||||
| 91 | 16264 | return z_to_pct( $self->z_for_value( $value, $index ) ); | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 16267 | ▶ | sub value_for_z { | ||||||||||||||||||||||||||
|
Subroutine
value_for_z: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 95 | 16267 | my ( $self, $z_score, $index ) = @_; | |||||||||||||||||||||||||||
| 96 | 16267 | my ( $l, $m, $s ) = $self->lookup_LMS($index); | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 16267 | ▶ | return unless $m; # Off end of range | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 16265 | ▶ | if ($l) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 16263 | return $m * ( 1 + $l * $s * $z_score )**( 1 / $l ); | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | else { | ||||||||||||||||||||||||||||
| 104 | 2 | return $m * exp( $s * $z_score ); | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 16264 | ▶ | sub value_for_pct { | ||||||||||||||||||||||||||
|
Subroutine
value_for_pct: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 109 | 16264 | my ( $self, $pct, $index ) = @_; | |||||||||||||||||||||||||||
| 110 | 16264 | $self->value_for_z( pct_to_z($pct), $index ); | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 18 | 1; | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | __END__ | ||||||||||||||||||||||||||||