Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: standard deviation accuracy question

by 5mi11er (Deacon)
on Jul 22, 2005 at 16:13 UTC ( [id://477275]=note: print w/replies, xml ) Need Help??


in reply to Re: standard deviation accuracy question
in thread standard deviation accuracy question

And furthering the work of esteemed monk tlm above, the difference is explained completely by whether or not your final step divides by (N-1) or by N.

   Data Set    Div(N-1)   Div N
 ------------ ---------- -------
  condition1    50.73     49.56
  condition2    44.34     43.32
  condition3    52.05     50.85
  condition4    56.39     55.10
use strict; use warnings; use List::Util 'sum'; sub sample_sd { die unless @_ and ref $_[ 0 ] eq 'ARRAY' and @{ $_[ 0 ] } > 1; my $data = shift; my $sum = sum @$data; my $n = @$data; my $mean = $sum/$n; my $sq_dev = sum map $_*$_, map $_ - $mean, @$data; return sqrt( ( $sq_dev )/( $n - 1 ) ); } sub sample_sd2 { die unless @_ and ref $_[ 0 ] eq 'ARRAY' and @{ $_[ 0 ] } > 1; my $data = shift; my $sum = sum @$data; my $n = @$data; my $mean = $sum/$n; my $sq_dev = sum map $_*$_, map $_ - $mean, @$data; return sqrt( ( $sq_dev )/( $n ) ); } while ( <DATA> ) { my @data = split; my $label = shift @data; my $sd = sample_sd( \@data ); my $sd2 = sample_sd2( \@data ); printf "$label %.2f %.2f\n", $sd, $sd2; } __DATA__ condition1 397 322 350 346 338 324 461 477 432 373 386 412 475 360.5 3 +84 324 424 319 454.5 412 387 370 condition2 360.5 318.5 356 316.5 330 296.5 444 474 416.5 355 320 401.5 + 363.5 332 363 324 388 312 344 372 347.5 338 condition3 372 354 358 311 336.5 297 485 461 407.5 365 342 428 494 343 +.5 372 324 379.5 345 389 384 363 346 condition4 324 305.5 364 320 327.5 288.5 432.5 434 447 369 315 397.5 5 +15 339 405 330 396 319 345 381.5 340 317
Update: Which is exactly what the following posts (at least) had attempted to tell you: Re^2: standard deviation accuracy question Re: standard deviation accuracy question and Re^2: standard deviation accuracy question

-Scott

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://477275]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2025-05-23 20:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.