95% confidence intervals in Perl

We assume that we have a txt file with one value per line. We want to generate the 95% confidence intervals of the set of these values.

Example in Perl

You need first to compile and install the following perl libraries:



use Statistics::PointEstimation;
use strict;

my @r = ();
my $stats;

open (MYFILE, 'data.txt'); # name of the text file is data.txt
while (<MYFILE>) { # read line by line and store the values in @r
     push (@r, $_);

$stats = new Statistics::PointEstimation;
$stats->set_significance(95); # set the desired confidence level
$stats->add_data(@r); # add the set of values

print "$stats->mean()\t $stats->lower_clm()\t $stats->upper_clm()\n";

close (MYFILE);

Running this program will print to STDOUT the mean, the lower 95% bound and the upper 95% bound.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License