AndriSignorell / DescTools

Tools for Descriptive Statistics and Exploratory Data Analysis
http://andrisignorell.github.io/DescTools/
82 stars 18 forks source link

DescTools::HunterGaston does not calculate Hunter-Gaston index #120

Open bernasco opened 1 year ago

bernasco commented 1 year ago

Thanks for developing and maintaining this package.

I stumbled on an issue with the HunterGaston function in DescTools version 0.99.48.

The HunterGaston function does not seem to do what it promises. It does not calculate the Hunter-Gaston index (Hunter & Gaston, 1988, DOI:10.1128/jcm.26.11.2465-2466.1988). Instead it seems to calculate the adjusted Gini index with small-sample correction proposed by Deltas (2003, DOI:10.1162/rest.2003.85.1.226).

To make HunterGaston live up to its promise, the two lines

p <- prop.table(table(x))
sum(p * (1 - p)) * length(p)/(length(p) - 1)

should be replaced by this line:

sum(table(x) * (table(x) - 1)) / (sum(table(x)) * (sum(table(x)) - 1))

or by (better readable) these five lines:

freqtab <- table(x)
numerator <- sum(freqtab * (freqtab - 1))
freqsum <- sum(freqtab)
denominator <- freqsum * (freqsum - 1)
numerator / denominator

I suggest to rename the original function to "DeltasGini".

AndriSignorell commented 1 year ago

Thanks for spotting this! This function apparently did not have my full attention and care. I review the facts of the case.

bernasco commented 1 year ago

Thanks, I will keep an eye on your GitHub.

FYI: I found out that the Hunter-Gaston index is also available in the vegan package, under the name simpson.unb (i.e. unbiased version of the Simpson index).

Best

Wim

--

Prof. dr  Wim Bernasco | Netherlands Institute for the Study of Crime and Law Enforcement (NSCR) | NSCR Blog | @.***  Phone: + 31 6 2958 6451

Van: Andri Signorell @.***> Verzonden: zondag 11 juni 2023 10:48 Aan: AndriSignorell/DescTools CC: Wim Bernasco; Author Onderwerp: Re: [AndriSignorell/DescTools] DescTools::HunterGaston does not calculate Hunter-Gaston index (Issue #120)  

CAUTION: This email originated from outside your organization. Exercise caution when opening attachments or on clicking links from unknown senders.

Thanks for spotting this! This function apparently did not have my full attention and care. I review the facts of the case. — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

AndriSignorell commented 8 months ago

This has been fixed in DescTools 0.99.50.4

AndriSignorell commented 7 months ago

Hmm, I fear we're not yet done here. Do you have a good testing example?