Skip to content

Commit

Permalink
simplify some calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Jan 26, 2025
1 parent 788a71d commit 826ec94
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/PDL/Stats/Basic.pd
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pp_def('stdv',
a2 += $a() * $a();
%}
if (N < 1) { $SETBAD(b()); continue; }
$b() = sqrt( a2 / N - (sa/N)*(sa/N) );
$b() = sqrt( (a2 - sa*sa/N) / N );
',
Doc => 'Sample standard deviation.',
);
Expand All @@ -79,7 +79,7 @@ pp_def('stdv_unbiased',
a2 += $a() * $a();
%}
if (N < 2) { $SETBAD(b()); continue; }
$b() = pow( a2/(N-1) - sa*sa/(N*(N-1)), .5 );
$b() = pow( (a2 - sa*sa/N) / (N-1), .5 );
',
Doc => 'Unbiased estimate of population standard deviation.',
);
Expand All @@ -97,7 +97,7 @@ pp_def('var',
a2 += $a() * $a();
%}
if (N < 1) { $SETBAD(b()); continue; }
$b() = a2 / N - sa*sa/(N*N);
$b() = (a2 - sa*sa/N) / N;
',
Doc => 'Sample variance.',
);
Expand Down Expand Up @@ -277,7 +277,7 @@ pp_def('cov',
sb += $b();
%}
if (N < 1) { $SETBAD(c()); continue; }
$c() = ab / N - (sa/N) * (sb/N);
$c() = (ab - sa*sb/N) / N;
',
Doc => 'Sample covariance. see B<corr> for ways to call',
);
Expand Down

0 comments on commit 826ec94

Please sign in to comment.