Skip to content

Commit

Permalink
Indices: ice_differential: Refactor ($n_infreq - 1)
Browse files Browse the repository at this point in the history
This is re-used many times in the calculations
  • Loading branch information
shawnlaffan committed Feb 19, 2024
1 parent 8e77c16 commit 0f84deb
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions lib/Biodiverse/Indices/RichnessEstimation.pm
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,7 @@ sub _get_ice_differential {
my $t_1 = $t - 1; # used many times below

if ($CV_infreq_h != 0) {
my $n_infreq_1 = $n_infreq - 1;
if ($q == 1) {
$dc_infreq =
-1 * (
Expand All @@ -783,17 +784,17 @@ sub _get_ice_differential {
$d = ($C_infreq - $D_infreq * $dc_infreq) / $C_infreq ** 2
+ $t / $t_1
* ($C_infreq**2*$n_infreq*($n_infreq - 1)
* ($C_infreq**2*$n_infreq*$n_infreq_1
* ($D_infreq * $si + $Q1 * $si)
- $Q1 * $D_infreq * $si *
(2 * $C_infreq * $dc_infreq
* $n_infreq * ($n_infreq - 1)
* $n_infreq * $n_infreq_1
+ $C_infreq ** 2
* ($n_infreq - 1)
* $n_infreq_1
+ $C_infreq ** 2
* $n_infreq
)
) / $C_infreq ** 4 / $n_infreq ** 2 / ($n_infreq - 1) ** 2
) / $C_infreq ** 4 / $n_infreq ** 2 / $n_infreq_1 ** 2
- ($C_infreq - $Q1 * $dc_infreq) / $C_infreq**2;
}
elsif ($q == 2){
Expand All @@ -807,10 +808,10 @@ sub _get_ice_differential {
$d = ($C_infreq - $D_infreq * $dc_infreq)
/ $C_infreq**2
+ $t / $t_1
* ($C_infreq**2 * $n_infreq * ($n_infreq - 1) * $Q1 * ($si + 2 * $D_infreq) - $Q1 * $D_infreq * $si *
(2 * $C_infreq * $dc_infreq * $n_infreq * ($n_infreq - 1) + $C_infreq**2 * 2 * ($n_infreq - 1) + $C_infreq**2 * $n_infreq * 2)
* ($C_infreq**2 * $n_infreq * $n_infreq_1 * $Q1 * ($si + 2 * $D_infreq) - $Q1 * $D_infreq * $si *
(2 * $C_infreq * $dc_infreq * $n_infreq * $n_infreq_1 + $C_infreq**2 * 2 * $n_infreq_1 + $C_infreq**2 * $n_infreq * 2)
)
/ $C_infreq**4 / $n_infreq**2 / ($n_infreq - 1)**2
/ $C_infreq**4 / $n_infreq**2 / $n_infreq_1**2
- ( -$Q1 * $dc_infreq) / $C_infreq**2;
}
else {
Expand All @@ -820,13 +821,13 @@ sub _get_ice_differential {
$d = ($C_infreq - $D_infreq * $dc_infreq) / $C_infreq**2
+ $t/$t_1
* ($C_infreq**2 * $n_infreq * ($n_infreq - 1) * $Q1 * ($si + $q * ($q - 1) * $D_infreq) - $Q1 * $D_infreq * $si
* (2 * $C_infreq * $dc_infreq * $n_infreq * ($n_infreq - 1)
+ $C_infreq**2 * $q * ($n_infreq - 1)
* ($C_infreq**2 * $n_infreq * $n_infreq_1 * $Q1 * ($si + $q * ($q - 1) * $D_infreq) - $Q1 * $D_infreq * $si
* (2 * $C_infreq * $dc_infreq * $n_infreq * $n_infreq_1
+ $C_infreq**2 * $q * $n_infreq_1
+ $C_infreq**2 * $n_infreq * $q
)
)
/ $C_infreq**4 / $n_infreq**2 / ($n_infreq - 1)**2
/ $C_infreq**4 / $n_infreq**2 / $n_infreq_1**2
- ( - $Q1 * $dc_infreq) / $C_infreq**2;
}
}
Expand Down

0 comments on commit 0f84deb

Please sign in to comment.