## calculating variance in perl programming

 perl, programming, shell scripts calculating variance in perl programming
# 1 calculating variance in perl programming

#!/usr/bin/perl -w
use strict;

open(FH,"\$ARGV") or die;
my @temp=<FH>;
close FH;
my \$mean = Mean(\@temp);
my \$var = variance(\@temp);
print "\$var\n";
sub estimate_variance {
my (\$arrayref) = @_;
my (\$mean,\$result) = (mean(\$arrayref),0);
foreach (@\$arrayref) { \$result += (\$_ - \$mean)**2 }
return \$result / \$#{\$arrayref};
}
error shown:
Undefined subroutine &main::variance called at variance_try1.pl line 9.

wht can be possible solution??

Last edited by cdfd123; 01-12-2008 at 10:47 AM.. Reason: correcting string
 cdfd123 View Public Profile for cdfd123 Find all posts by cdfd123
# 2
variance () is not a Perl function. You will need to write your own or find a module that can do it.
 frank_rizzo View Public Profile for frank_rizzo Find all posts by frank_rizzo
# 3
I though you were trying to do this in C shamrock View Public Profile for shamrock Find all posts by shamrock
# 4
It might be easier if you used a standard proven statistics module of which there are a number on CPAN.

For example, I have modified your code to work with the CPAN Module Statistics/Descriptive

 fpmurphy View Public Profile for fpmurphy Find all posts by fpmurphy
# 5
Quote:
Originally Posted by shamrock
I though you were trying to do this in C Dear Shamrock
I have tried both using c and perl ..
So got results both in C and perl..
Thanks for curiosity
 cdfd123 View Public Profile for cdfd123 Find all posts by cdfd123

## Compare sum of two columns if variance is zero do nothing else send an email

11☺Hi, I have to data sets: One is in .txt format and other is in .csv format, please refer below two outputs from two files. File1.txt SOURCE PAYDATE TOTAL_DOLLARS RECORD_COUNT ASSET 05/25/2018 247643.94 ASSET 06/20/2018 ...

## AWK sample variance

I would like to calculate 1/n In awk, I wrote the following line for the sigma summation: { summ+=(\$1-average)^2 } Full code: BEGIN { Print "This script calculate error estimates"; sum=0 } { sum+=\$1; n++ } END { average = sum/n } BEGIN { summ=0 } { summ+=(\$1-average)^2 } END { print...

## Calculating Running Variance Using Awk

Hi all, I am attempting to calculate a running variance for a file containing a column of numbers. I am using the formula variance=sum((x-mean(x))^2)/(n-1), where x is the value on the current row, and mean(x) is the average of all of the values up until that row. n represents the total number...

## Calculating the epoch time from standard time using awk and calculating the duration

Hi All, I have the following time stamp data in 2 columns Date TimeStamp(also with milliseconds) 05/23/2012 08:30:11.250 05/23/2012 08:30:15.500 05/23/2012 08:31.15.500 . . etc From this data I need the following output. 0.00( row1-row1 in seconds) 04.25( row2-row1 in...

## perl programming

how to link the linux files in perl on the local webpage ???? suppose we have some results and want to get them published on the local webpage of our internal site. how this can be done using HTML and perl together , so that the results are published directly on the webpage. thanks kullu

## Help me with perl programming

Hi, i am very beginer to perl, I am reading one xml file and i am creating hash table for that file. i written code like this #!/usr/bin/perl use warnings; use strict; use XML::LibXML::Reader; #Reading XML with a pull parser my \$file; open( \$file, 'formal.xml'); my \$reader =...

## Programming help - Perl !

I am having a text file with Vivek 50 Ram 34 Hulk 45 Vivek 23 Ram 23 Vivek 55 Now I need a perl script to display the fields of 1st column & the 2nd column with summation (& avoid the duplicates). Vivek 128 Ram 57 hulk 45 Plz help me...

## Awk total and variance

File1 0358 Not Visible ***:* NA:NA RDF1+TDEV Grp'd (M) RW 102413 0359 Not Visible ***:* NA:NA RDF1+TDEV N/Grp'd (m) RW - 035A Not Visible ***:* NA:NA RDF1+TDEV N/Grp'd (m) RW - 035B Not Visible ***:* NA:NA ...

## C language to calculate mean,variance

Here I want to calculate mean,variance and sum from a file 1.1*2*4*22*211*22*12*22*22*11 2.2*2*22*12*22*11*11*122*33*22 3.9*7*22*88*87*98*67*66*56*66*11 As this is a large file and i am trying to write in c where formulae of MEAN = 1/N (X1...+..Xn) Variance = square root of 1/N-1...

## PERL - DB programming

Hi friends, What are the possible ways to connect to DB2 database from Perl (on unix). I need to connect to DB2 and get records for further processing. Can you please suggest the best possible way. I heard about DBI/DBD, if you have some sample scripts please post them too. Thanks in advance.