2
# ********************************************************************
4
# * Copyright (c) 2006, International Business Machines Corporation and
5
# * others. All Rights Reserved.
6
# ********************************************************************
9
use Statistics::Descriptive;
10
use Statistics::Distributions;
13
# Create a new Dataset with the given data.
26
my $stats = Statistics::Descriptive::Full->new();
27
$stats->add_data(@{$self->{_data}});
28
$self->{_mean} = $stats->mean();
31
# Use a t distribution rather than Gaussian because (a) we
32
# assume an underlying normal dist, (b) we do not know the
33
# standard deviation -- we estimate it from the data, and (c)
34
# we MAY have a small sample size (also works for large n).
35
my $t = Statistics::Distributions::tdistr($n-1, 0.005);
36
$self->{_error} = $t * $stats->standard_deviation();
43
# Set a scaling factor for all data; 1.0 means no scaling.
46
my ($self, $scale) = @_;
47
$self->{_scale} = $scale;
50
# Multiply the scaling factor by a value.
53
$self->{_scale} *= $a;
59
return $self->{_mean} * $self->{_scale};
62
# Return a 99% error based on the t distribution. The dataset
63
# is desribed as getMean() +/- getError().
66
return $self->{_error} * $self->{_scale};
69
# Divide two Datasets and return a new one, maintaining the
70
# mean+/-error. The new Dataset has no data points.
75
my $minratio = ($self->{_mean} - $self->{_error}) /
76
($rhs->{_mean} + $rhs->{_error});
77
my $maxratio = ($self->{_mean} + $self->{_error}) /
78
($rhs->{_mean} - $rhs->{_error});
80
my $result = Dataset->new();
81
$result->{_mean} = ($minratio + $maxratio) / 2;
82
$result->{_error} = $result->{_mean} - $minratio;
83
$result->{_scale} = $self->{_scale} / $rhs->{_scale};
87
# subtracts two Datasets and return a new one, maintaining the
88
# mean+/-error. The new Dataset has no data points.
93
my $result = Dataset->new();
94
$result->{_mean} = $self->{_mean} - $rhs->{_mean};
95
$result->{_error} = $self->{_error} + $rhs->{_error};
96
$result->{_scale} = $self->{_scale};
100
# adds two Datasets and return a new one, maintaining the
101
# mean+/-error. The new Dataset has no data points.
106
my $result = Dataset->new();
107
$result->{_mean} = $self->{_mean} + $rhs->{_mean};
108
$result->{_error} = $self->{_error} + $rhs->{_error};
109
$result->{_scale} = $self->{_scale};
113
# Divides a dataset by a scalar.
114
# The new Dataset has no data points.
119
my $result = Dataset->new();
120
$result->{_mean} = $self->{_mean}/$s;
121
$result->{_error} = $self->{_error}/$s;
122
$result->{_scale} = $self->{_scale};
126
# Divides a dataset by a scalar.
127
# The new Dataset has no data points.
128
sub multiplyByScalar {
132
my $result = Dataset->new();
133
$result->{_mean} = $self->{_mean}*$s;
134
$result->{_error} = $self->{_error}*$s;
135
$result->{_scale} = $self->{_scale};