2 # *******************************************************************************
3 # * Copyright (C) 2002-2004, International Business Machines Corporation and *
4 # * others. All Rights Reserved. *
5 # *******************************************************************************
8 use Statistics::Descriptive;
9 use Statistics::Distributions;
12 # Create a new Dataset with the given data.
25 my $stats = Statistics::Descriptive::Full->new();
26 $stats->add_data(@{$self->{_data}});
27 $self->{_mean} = $stats->mean();
30 # Use a t distribution rather than Gaussian because (a) we
31 # assume an underlying normal dist, (b) we do not know the
32 # standard deviation -- we estimate it from the data, and (c)
33 # we MAY have a small sample size (also works for large n).
34 my $t = Statistics::Distributions::tdistr($n-1, 0.005);
35 $self->{_error} = $t * $stats->standard_deviation();
42 # Set a scaling factor for all data; 1.0 means no scaling.
45 my ($self, $scale) = @_;
46 $self->{_scale} = $scale;
49 # Multiply the scaling factor by a value.
52 $self->{_scale} *= $a;
58 return $self->{_mean} * $self->{_scale};
61 # Return a 99% error based on the t distribution. The dataset
62 # is desribed as getMean() +/- getError().
65 return $self->{_error} * $self->{_scale};
68 # Divide two Datasets and return a new one, maintaining the
69 # mean+/-error. The new Dataset has no data points.
74 my $minratio = ($self->{_mean} - $self->{_error}) /
75 ($rhs->{_mean} + $rhs->{_error});
76 my $maxratio = ($self->{_mean} + $self->{_error}) /
77 ($rhs->{_mean} - $rhs->{_error});
79 my $result = Dataset->new();
80 $result->{_mean} = ($minratio + $maxratio) / 2;
81 $result->{_error} = $result->{_mean} - $minratio;
82 $result->{_scale} = $self->{_scale} / $rhs->{_scale};