Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
bernasco opened this issue Jun 1, 2023 · 4 comments
Open

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

bernasco opened this issue Jun 1, 2023 · 4 comments

Comments

@bernasco
Copy link

bernasco commented Jun 1, 2023

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
Copy link
Owner

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

@bernasco
Copy link
Author

bernasco commented Jun 15, 2023 via email

@AndriSignorell
Copy link
Owner

This has been fixed in DescTools 0.99.50.4

@AndriSignorell
Copy link
Owner

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

clrpackages pushed a commit to clearlinux-pkgs/R-DescTools that referenced this issue Nov 21, 2023
…sion 0.99.51

DescTools 0.99.51 (2023-11-02)
------------------------------

NEW FUNCTIONS ADDED:
  * Labels() is a vectorized function for Label().
  * SDN() and VarN() return the uncorrected (biased) estimators for
    standard deviation and variance (sometimes needed for
	  didactical reasons).
	* EX() and VarX() return the expected value and the variance for
	  the distribution of a discrete random variable.
	* Mgsub() is a vectorized version for gsub, allowing to replace
	  multiple patterns at the same time.
	* New function GiniDeltas() returns the Gini variant from Deltas.
	  (Credits to Wim Bernasco,  AndriSignorell/DescTools#120)

(NEWS truncated at 15 lines)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants