I want to calculate Gini coefficients using Gini()
from DescTools
(because it offers an easy way to calculate "unbiased" Gini coefficients with weights, confidence intervals, etc.), but I get some errors when I use this function with "big" samples. Here is a simple example that produces the error on my side:
library("DescTools")
x1 <- sample(c(1:100000), 50) #Here I create a sample of 50 cases varying from 1 to 100,000
Gini(x1) #Here I use the Gini function without any parameters, and it returns the Gini coefficient as expected:
[1] 0.3153713
x2 <- sample(c(1:100000), 500) #Now, I create a sample of 500 cases varying from 1 to 100,000
Gini(x2) #And if I compute the Gini coefficient with the same parameters, I get the following error:
[1] NA
Warning messages: 1: In sum(x * 1:n) : integer overflow - use sum(as.numeric(.)) 2: In n * sum(x) : NAs produced by integer overflow
I can't figure what is the problem, any idea?
I'm using R version 3.3.1 (2016-06-21) -- "Bug in Your Hair" with RStudio Version 0.99.903 and ‘DescTools’ version 0.99.17.
Edit: Oh well, converting my numbers from integer to numeric seems to do the job (but I still don't get it, anyway...):
x2 <- as.numeric(x2) #Now, Gini() will work...