| 1 | package Statistics::PointEstimation; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use vars qw($VERSION @ISA $AUTOLOAD); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Statistics::Distributions qw(chisqrdistr tdistr fdistr udistr uprob chisqrprob tprob fprob); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Statistics::Descriptive; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use POSIX; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | @ISA= qw (Statistics::Descriptive::Full); | |||||||||||||||||||||||||||
| 11 | 1 | $VERSION = '1.1'; | |||||||||||||||||||||||||||
| 12 | 1 | my %confidence_interval= #data related to confidence interval | |||||||||||||||||||||||||||
| 13 | ( | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | "significance" => undef, | ||||||||||||||||||||||||||||
| 16 | "alpha" => undef, | ||||||||||||||||||||||||||||
| 17 | "df" =>undef, | ||||||||||||||||||||||||||||
| 18 | "standard_error" => undef, | ||||||||||||||||||||||||||||
| 19 | "t_value" =>undef, | ||||||||||||||||||||||||||||
| 20 | "t_statistic" =>undef, | ||||||||||||||||||||||||||||
| 21 | "t_prob" =>undef, | ||||||||||||||||||||||||||||
| 22 | "delta" =>undef, | ||||||||||||||||||||||||||||
| 23 | "upper_clm" => undef, | ||||||||||||||||||||||||||||
| 24 | "lower_clm" =>undef, | ||||||||||||||||||||||||||||
| 25 | "valid" =>undef | ||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 500 | ▶ | sub new{ | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 31 | 500 | my $proto = shift; | |||||||||||||||||||||||||||
| 32 | 500 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||
| 33 | 500 | my $self = $class->SUPER::new(); | |||||||||||||||||||||||||||
| 34 | 500 | my %confidence=%confidence_interval; | |||||||||||||||||||||||||||
| 35 | 500 | $self->{confidence}=\%confidence; | |||||||||||||||||||||||||||
| 36 | 500 | bless ($self, $class); | |||||||||||||||||||||||||||
| 37 | 500 | return $self; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 500 | ▶ | sub compute_confidence_interval{ | ||||||||||||||||||||||||||
|
Subroutine
compute_confidence_interval: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 41 | 500 | my $self=shift; | |||||||||||||||||||||||||||
| 42 | 500 | ▶ | croak "sample size must be >1 to compute the confidence interval \n" if($self->count()<=1); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 500 | ▶ | $self->{'significance'}=95 if (!defined($self->{'significance'})); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 500 | $self->{df}=$self->count()-1; | |||||||||||||||||||||||||||
| 45 | 500 | $self->{alpha}=(100-$self->{significance})/2; | |||||||||||||||||||||||||||
| 46 | 500 | $self->{alpha}/=100; | |||||||||||||||||||||||||||
| 47 | 500 | $self->{standard_error}=$self->standard_deviation()/sqrt($self->count()); | |||||||||||||||||||||||||||
| 48 | 500 | $self->{t_value}=abs tdistr($self->{df},$self->{alpha}); | |||||||||||||||||||||||||||
| 49 | 500 | $self->{delta}=$self->{t_value}*$self->{standard_error}; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 500 | $self->{upper_clm}=$self->mean() +$self->{delta}; | |||||||||||||||||||||||||||
| 52 | 500 | $self->{lower_clm}=$self->mean() -$self->{delta}; | |||||||||||||||||||||||||||
| 53 | $self->{t_statistic}=$self->{standard_error} | ||||||||||||||||||||||||||||
| 54 | 500 | ▶ | ?($self->mean()/$self->{standard_error}):0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 500 | $self->{t_prob}=1- abs (tprob($self->{df},-1*$self->{t_statistic})-tprob($self->{df},$self->{t_statistic})) ; | |||||||||||||||||||||||||||
| 56 | 500 | $self->{valid}=1; | |||||||||||||||||||||||||||
| 57 | 500 | return 1; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | 500 | ▶ | sub add_data{ | ||||||||||||||||||||||||||
|
Subroutine
add_data: called CC=5 SCAR=17.6
Pod
documented
| |||||||||||||||||||||||||||||
| 61 | 500 | my $self = shift; | |||||||||||||||||||||||||||
| 62 | 500 | my $aref; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 500 | ▶ | if (ref $_[0] eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 0 | $aref = $_[0]; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | else { | ||||||||||||||||||||||||||||
| 68 | 500 | $aref = \@_; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | 500 | ▶ | my $significance=$self->{'significance'} if (defined($self->{'significance'})); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 500 | $self->SUPER::add_data($aref); | |||||||||||||||||||||||||||
| 72 | 500 | $self->{'significance'}=$significance; | |||||||||||||||||||||||||||
| 73 | 500 | ▶ | $self->compute_confidence_interval() if ((defined($self->{count}))&&($self->{count}>1)) ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->{"count"} and $self->{"count"} > 1
MC/DC0%0/2
defined $self->{"count"} and $self->{"count"} > 1
defined $self->{"count"}
$self->{"count"} > 1
Truth table33%1/3
A and B
A= defined $self->{"count"}B= $self->{"count"} > 1
| |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 500 | return 1; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | 500 | ▶ | sub set_significance{ # set the significance level. usually 90, 95 or 99 | ||||||||||||||||||||||||||
|
Subroutine
set_significance: called CC=5 SCAR=18.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 79 | 500 | my $self=shift; | |||||||||||||||||||||||||||
| 80 | 500 | my $significance=shift; | |||||||||||||||||||||||||||
| 81 | 500 | ▶ | $self->{'significance'}=$significance if (($significance>0)&&($significance<100)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$significance > 0 and $significance < 100
MC/DC0%0/2
$significance > 0 and $significance < 100
$significance > 0
$significance < 100
Truth table33%1/3
A and B
A= $significance > 0B= $significance < 100
| |||||||||||||||||||||||||||||
| 82 | 500 | ▶ | $self->compute_confidence_interval() if((defined($self->{count}))&&($self->{count}>1)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->{"count"} and $self->{"count"} > 1
MC/DC0%0/2
defined $self->{"count"} and $self->{"count"} > 1
defined $self->{"count"}
$self->{"count"} > 1
Truth table33%1/3
A and B
A= defined $self->{"count"}B= $self->{"count"} > 1
| |||||||||||||||||||||||||||||
| 83 | 500 | return 1; | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 1 | ▶ | sub print_confidence_interval{ | ||||||||||||||||||||||||||
|
Subroutine
print_confidence_interval: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 88 | 1 | my $self=shift; | |||||||||||||||||||||||||||
| 89 | 1 | print "mean:",$self->mean(),"\n"; | |||||||||||||||||||||||||||
| 90 | 1 | print "variance:",$self->variance(),"\n"; | |||||||||||||||||||||||||||
| 91 | 1 | my $confidence=\%confidence_interval; | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 1 | foreach my $k ( keys %$confidence) | |||||||||||||||||||||||||||
| 94 | { | ||||||||||||||||||||||||||||
| 95 | 11 | print "$k:", $self->{$k}," \n"; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | 1 | return 1; | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 1 | ▶ | sub output_confidence_interval{ | ||||||||||||||||||||||||||
|
Subroutine
output_confidence_interval: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 102 | 1 | my $self=shift; | |||||||||||||||||||||||||||
| 103 | 1 | ▶ | croak "sample size must be >1 to compute the confidence interval\n" if($self->{valid}!=1); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 1 | my $title=shift; | |||||||||||||||||||||||||||
| 105 | 1 | print "Summary from the observed values of the sample $title:\n"; | |||||||||||||||||||||||||||
| 106 | 1 | print "\tsample size= ", $self->count()," , degree of freedom=", $self->df(), "\n"; | |||||||||||||||||||||||||||
| 107 | 1 | print "\tmean=", $self->mean()," , variance=", $self->variance(),"\n"; | |||||||||||||||||||||||||||
| 108 | 1 | print "\tstandard deviation=", $self->standard_deviation()," , standard error=", $self->standard_error(),"\n"; | |||||||||||||||||||||||||||
| 109 | 1 | print "\t the estimate of the mean is ", $self->mean()," +/- ",$self->delta(),"\n\t", | |||||||||||||||||||||||||||
| 110 | " or (",$self->lower_clm()," to ",$self->upper_clm," ) with ",$self->significance," % of confidence\n"; | ||||||||||||||||||||||||||||
| 111 | 1 | print "\t t-statistic=T=",$self->t_statistic()," , Prob >|T|=",$self->t_prob(),"\n"; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 1493 | ▶ | sub AUTOLOAD{ | ||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=5 SCAR=17.1
| |||||||||||||||||||||||||||||
| 115 | 1493 | my $self = shift; | |||||||||||||||||||||||||||
| 116 | 1493 | ▶ | my $type = ref($self) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | or croak "$self is not an object"; | ||||||||||||||||||||||||||||
| 118 | 1493 | my $name = $AUTOLOAD; | |||||||||||||||||||||||||||
| 119 | 1493 | $self->{_confidence}=\%confidence_interval; | |||||||||||||||||||||||||||
| 120 | 1493 | $name =~ s/.*://; | |||||||||||||||||||||||||||
| 121 | 1493 | ▶ | return if $name eq "DESTROY"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | 993 | ▶ | if (exists $self->{_permitted}->{$name} ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 123 | 0 | return $self->{$name}; | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | elsif(exists $self->{'_confidence'}->{$name}) | ||||||||||||||||||||||||||||
| 126 | { | ||||||||||||||||||||||||||||
| 127 | 993 | return $self->{$name}; | |||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | else | ||||||||||||||||||||||||||||
| 130 | { | ||||||||||||||||||||||||||||
| 131 | 0 | croak "Can't access `$name' field in class $type"; | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | 1 | 1; | |||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | package Statistics::PointEstimation::Sufficient; | ||||||||||||||||||||||||||||
| 137 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 138 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 139 | 1 | ▶ | use vars qw($VERSION $AUTOLOAD @ISA); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 140 | 1 | ▶ | use POSIX; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 141 | 1 | @ISA=qw (Statistics::PointEstimation); | |||||||||||||||||||||||||||
| 142 | 1 | $VERSION='1.1'; | |||||||||||||||||||||||||||
| 143 | 1 | my %fields= #data related to confidence interval | |||||||||||||||||||||||||||
| 144 | ( | ||||||||||||||||||||||||||||
| 145 | "count"=>undef, | ||||||||||||||||||||||||||||
| 146 | "mean" =>undef, | ||||||||||||||||||||||||||||
| 147 | "variance" => undef, | ||||||||||||||||||||||||||||
| 148 | "standard_deviation" =>undef, | ||||||||||||||||||||||||||||
| 149 | "significance" => undef, | ||||||||||||||||||||||||||||
| 150 | "alpha" => undef, | ||||||||||||||||||||||||||||
| 151 | "df" =>undef, | ||||||||||||||||||||||||||||
| 152 | "standard_error" => undef, | ||||||||||||||||||||||||||||
| 153 | "t_value" =>undef, | ||||||||||||||||||||||||||||
| 154 | "t_statistic" =>undef, | ||||||||||||||||||||||||||||
| 155 | "t_prob" =>undef, | ||||||||||||||||||||||||||||
| 156 | "delta" =>undef, | ||||||||||||||||||||||||||||
| 157 | "upper_clm" => undef, | ||||||||||||||||||||||||||||
| 158 | "lower_clm" =>undef, | ||||||||||||||||||||||||||||
| 159 | "valid" =>undef | ||||||||||||||||||||||||||||
| 160 | ); | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 0 | ▶ | sub new{ | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 163 | 0 | my $proto = shift; | |||||||||||||||||||||||||||
| 164 | 0 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||||||||||
|
Condition0%0/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||
| 165 | 0 | my $self = {%fields}; | |||||||||||||||||||||||||||
| 166 | 0 | bless ($self, $class); | |||||||||||||||||||||||||||
| 167 | 0 | return $self; | |||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | 0 | ▶ | sub add_data{ | ||||||||||||||||||||||||||
|
Subroutine
add_data: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 0 | croak "the add_data() method is not supported in Statistics::PointEstimation::Sufficient\n"; | |||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | 0 | ▶ | sub load_data{ | ||||||||||||||||||||||||||
|
Subroutine
load_data: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 175 | 0 | my $self=shift; | |||||||||||||||||||||||||||
| 176 | 0 | my ($count,$mean,$variance)=@_; | |||||||||||||||||||||||||||
| 177 | 0 | $self->{count}=$count; | |||||||||||||||||||||||||||
| 178 | 0 | $self->{mean}=$mean; | |||||||||||||||||||||||||||
| 179 | 0 | $self->{variance}=$variance; | |||||||||||||||||||||||||||
| 180 | 0 | $self->{standard_deviation}=sqrt($variance); | |||||||||||||||||||||||||||
| 181 | 0 | ▶ | $self->compute_confidence_interval() if ($self->count()>1) ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 182 | 0 | return; | |||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 0 | ▶ | sub AUTOLOAD{ | ||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 187 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 188 | 0 | ▶ | my $type = ref($self) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 189 | or croak "$self is not an object"; | ||||||||||||||||||||||||||||
| 190 | 0 | $self->{_confidence}=\%fields; | |||||||||||||||||||||||||||
| 191 | 0 | my $name = $AUTOLOAD; | |||||||||||||||||||||||||||
| 192 | 0 | $name =~ s/.*://; | |||||||||||||||||||||||||||
| 193 | 0 | ▶ | return if $name eq "DESTROY"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | 0 | ▶ | if(exists $self->{_confidence}->{$name}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 196 | { | ||||||||||||||||||||||||||||
| 197 | 0 | return $self->{$name}; | |||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | else | ||||||||||||||||||||||||||||
| 200 | { | ||||||||||||||||||||||||||||
| 201 | 0 | croak "Can't access `$name' field in class $type"; | |||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||
| 204 | 1 | 1; | |||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | __END__ | ||||||||||||||||||||||||||||