The result of Gini index on QIIME2 is puzzling!
I've used the following to calculate Gini index on QIIME2, for example:
qiime diversity alpha \
--i-table table1_1m2-featuretable.qza \
--p-metric gini_index \
--o-alpha-diversity table1_1m2-featuretable-gini_index.qza
qiime metadata tabulate \
--m-input-file table1_1m2-featuretable-gini_index.qza \
qiime tools view table1_1m2-featuretable-all.qzv
I've checked skbio.diversity.alpha.gini_index — scikit-bio 0.6.2 documentation these days, and I have visted its related code website scikit-bio/skbio/diversity/alpha/_gini.py at 0.6.2 · scikit-bio/scikit-bio · GitHub, it seems simple, but I can't understand, could it be written in R script format?
I've tried to calculate it (Gini index) in R, and the following are four methods I've run in R, however their results are in variant, and none of them can match the result calculated by QIIME2 (name of the data is called D1):
# Using two packages
library("ineq");
library("DescTools")
# Method 1:
Gini_D <- matrix(nrow = 1, ncol = nrow(D1))
for (i in c(1:nrow(D1))) {
Gini_D[i] <- ineq::Gini(factor(as.numeric(D1[i,])))
rownames(Gini_D)<-"Gini_D"
}
Gini_D
# Method 2:
Gini_D <- matrix(nrow = 1, ncol = nrow(D1))
for (i in c(1:nrow(D1))) {
Gini_D[i] <- DescTools::Gini(as.numeric(D1[i,]))
rownames(Gini_D)<-"Gini_D"
}
Gini_D
# Method 3:
Gini_D <- matrix(nrow = 1, ncol = nrow(D1))
for (i in c(1:nrow(D1))) {
Gini_D[i] <- DescTools::GiniSimpson(factor(as.numeric(D1[i,])))
rownames(Gini_D)<-"Gini_D"
}
Gini_D
# Method 4:
Gini_D <- matrix(nrow = 1, ncol = nrow(D1))
for (i in c(1:nrow(D1))) {
Gini_D[i] <- DescTools::GiniDeltas(factor(as.numeric(D1[i,])))
rownames(Gini_D)<-"Gini_D"
}
Gini_D