Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Your program would be much simpler if you reversed the order of your subscripts. Each column of your data is a set of data. It is convenient to have each set stored as its own array.
use strict; use warnings; use List::Util qw(sum); my @raw; my $n; while (my $line = <DATA>) { my @cols = split / /, $line; foreach my $j (0..$#cols) { push @{$raw[$j]}, $cols[$j]; } } { local $, = ' '; print process_column($_), "\n" foreach @raw; } sub process_column { my @x = @{$_[0]}; my $n = @x; my $x_tot = sum( @x ); my @x_jack = map { ($x_tot - $_) / ($n - 1) } @x; my $g_jack_av; my $g_jack_err; #foreach my $dg (@x) { foreach my $dg (@x_jack) { #UPDATE $g_jack_av += $dg; $g_jack_err += $dg**2; } $g_jack_av /= $n; $g_jack_err /= $n; $g_jack_err = sqrt(($n-1)*abs($g_jack_err-$g_jack_av**2)); return ($g_jack_av, $g_jack_err); } __DATA__ 1.1 2.1 3.1 4.1 1.2 2.2 3.2 4.2 1.3 2.3 3.3 4.3 1.4 2.4 3.4 4.4

OUTPUT

1.25 0.193649167310372 2.25 0.193649167310365 3.25 0.193649167310338 4.25 0.193649167310365

OUTPUT (with correction)

1.25 0.064549722436785 2.25 0.0645497224367747 3.25 0.0645497224367334 4.25 0.064549722436816

UPDATE: Corrected error reported by AnomalousMonk in Re^2: Calculate jackknife error from of each column of a multi-column file

Bill

In reply to Re: Calculate jackknife error from of each column of a multi-column file by BillKSmith
in thread Calculate jackknife error from of each column of a multi-column file by pyari_billi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2024-03-19 11:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found