Home » Topics » Child Health » SII, RII, CI, and Gini (Calculation of relative index of inequality, slope index of inequality, Concentration Curve and Index, Lorenz Curve and Gini Coefficient)
SII, RII, CI, and Gini [message #26072] |
Sat, 04 February 2023 03:19 |
Kazi_Salahin
Messages: 9 Registered: February 2023
|
Member |
|
|
Dear Concern
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
|
|
|
|
|
|
Goto Forum:
Current Time: Fri Nov 8 21:23:06 Coordinated Universal Time 2024
|