vka725 has asked for the wisdom of the Perl Monks concerning the following question:
I'm currently working on writing a little script to be able to calculate the average energy and the standard deviation of that energy of these molecular simulations I ran. There's about 600 snapshots for each molecule and I have to find the average and standard deviation in the energy of the snap shots for each molecule.
I am not only a super Perl newb, i'm new to coding as well. My PI helped me out for the first part (using it to find averages) and it worked. The second part was adding to it to be able to calculate the standard deviation.
So I was able to obtain some kind of standard deviation for 3 snapshots but they did not match the standard deviation i used in excel (i used STDEV.P since we have the entire population, N, not N-1).
I can't seem to get it right and I want to see if anyone can help me out here before I go and ask my PI. I want to understand the logic behind this as well, rather than have him just type something out for me.
Thank you!#!/usr/bin/env perl $conf = $ARGV[0]; $n1 = $ARGV[1]; $n2 = $ARGV[2]; $esum0 = 0; $esum1 = 0; for($i=$n1;$i<=$n2;$i++){ $i = sprintf("%0.3d",$i); system("analyze $conf.$i E | grep \"ACE\" -A 1 > log "); open(IN,"log"); @temp = split(" ",<IN>); $e0 = $temp[2]; @temp = split(" ",<IN>); $e1 = $temp[1]; close IN; print "$i $e0 $e1 "; #---average-calculation--- $esum0 = $esum0 + $e0; $esum1 = $esum1 + $e1; } { $esum0=$esum0/$n2; $esum1=$esum1/$n2; $esum0= sprintf("%0.4f",$esum0); $esum1= sprintf("%0.4f",$esum1); } #averages my@coolbeans = ('averages', " $esum0", "$esum1"); print " @coolbeans\n"; #---standard-deviation--- for($i=$n1;$i<=$n2;$i++){ $estd0=($esum0-$e0) ** 2; $estd0=($estd0/$n2) **0.5; $estd0= sprintf ("%0.4f", $estd0); $estd1=($esum1-$e1) ** 2; $estd1=($estd1/$n2) **0.5; $estd1= sprintf ("%0.4f", $estd1); } #stdev my@arroba = ('stdev', "$estd0", "$estd1"); print " @arroba\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: standard deviation help
by GotToBTru (Prior) on Jul 07, 2015 at 19:56 UTC | |
by vka725 (Initiate) on Jul 07, 2015 at 20:00 UTC | |
|
Re: standard deviation help
by Laurent_R (Canon) on Jul 07, 2015 at 21:02 UTC | |
|
Re: standard deviation help
by hippo (Archbishop) on Jul 07, 2015 at 21:39 UTC | |
by vka725 (Initiate) on Jul 08, 2015 at 00:40 UTC | |
|
Re: standard deviation help
by poj (Abbot) on Jul 08, 2015 at 10:53 UTC |