The DHS Program User Forum - RDF feed https://userforum.dhsprogram.com/index.php SII, RII, CI, and Gini https://userforum.dhsprogram.com/index.phpindex.php?t=rview&goto=26072&th=12424#msg_26072
I am using the Bangladesh data (BDHS-2017-2018) specifically the KR data file. I want to calculate the "Relative index of inequality." "Slope index of inequality," "Concentration index and concentration curve," and "Gini coefficient and Lorenze curve" in consideration of the wealth index (v190), maternal education (v149), and full vaccination coverage (ch_allvac_either). I'd like to compute each indicator by division (v101). I am using R. I want to make certain that I am on the correct truck. The following is my R code:

############################################################ ############################################################ ###############################
#Rcode
## Calculate ridit score
KRvac\$ridit_score_wealth <- rank(KRvac\$v190, ties.method = "average") / nrow(KRvac)

# Loop to create a data frame with division and its corresponding SII, RII, and CI
divisions <- unique(KRvac\$v101)
sii_wealth_vec <- numeric(length(divisions))
rii_wealth_vec <- numeric(length(divisions))
ci_wealth_vec <- numeric(length(divisions))
gini_vec <- numeric(length(divisions))

for (i in 1:length(divisions)) {
KRvac_subset <- KRvac %>% filter(v101 == divisions[i])

model_wealth <- glm(ch_allvac_either ~ ridit_score_wealth, family = binomial(link = "logit"), data = KRvac_subset)

pred_wealth_top <- predict(model_wealth, newdata = data.frame(ridit_score_wealth = max(KRvac_subset\$ridit_score_wealth)), se.fit = TRUE)
pred_wealth_bottom <- predict(model_wealth, newdata = data.frame(ridit_score_wealth = min(KRvac_subset\$ridit_score_wealth)), se.fit = TRUE)

pred_wealth_top<-as.numeric(pred_wealth_top)
pred_wealth_bottom<-as.numeric(pred_wealth_bottom)

sii_wealth_vec[i] <- pred_wealth_top - pred_wealth_bottom
rii_wealth_vec[i] <- pred_wealth_top / pred_wealth_bottom

ci_wealth_vec[i] <- sii_wealth_vec[i]/(2*sqrt(rii_wealth_vec[i]))

n <- nrow(KRvac_subset)
y_values <- sort(KRvac_subset\$ch_allvac_either)
x_values <- sort(KRvac_subset\$ridit_score_wealth)
numerator <- sum((2 * (1:n) - n - 1) * y_values * x_values)
denominator <- n * sum(y_values) * sum(x_values)
gini_vec[i] <- numerator / denominator
}

results_df <- data.frame(division = divisions, sii = sii_wealth_vec, rii = rii_wealth_vec, ci = ci_wealth_vec, gini = gini_vec)

############################################################ ############################################################ ###############################

Here the plot code (Concentration Curve and Lorenze Curve) is not included. It would be greatly appreciated if anyone could assist me in ensuring that I am doing the right thing; if not, please correct my code; and I also require assistance with the plot code. I am a little bit confused about that.

Your early response will be appreciated

Thank you]]>
Kazi_Salahin 2023-02-04T08:19:19-00:00
Re: SII, RII, CI, and Gini https://userforum.dhsprogram.com/index.phpindex.php?t=rview&goto=26102&th=12424#msg_26102
We (DHS staff) cannot help with questions that are not specifically about DHS data and indicators. Perhaps other forum users can review your R code.]]>
Janet-DHS 2023-02-08T14:44:52-00:00