Tuesday, July 1, 2008

Regression-based inequality decomposition in R

In a previous blog I posted the R functions to decompose Gini coefficients based on a weighted average of pseudo-Gini (Fei et al 1978Shorrocks 1982). Another way to decompose inequality is a regression-based approach proposed by Morduch and Sicular (2002) following the logic of Shorrock's theorem in his classic 1982 paper. 


1. The R function I created


decomp <- function(M) {

    n <- length(M$coefficients)

cov <- cov(M$model[,1],M$model)

var <- cov[1]

cof <- M$coefficients

share <- cov[2:n]*cof[2:n]/cov[1]

decomp <- rbind(cov[2:n],cof[2:n],var,share)

rownames(decomp) <- c("covariance","coefficient",

                      "variance","contribution")

decomp

}


2. An example in R results:


> M <- lm(PCEP2~PCGDP2 + POPDEN + PRIMERT, data=data)
> decomp(M)
                  PCGDP2       POPDEN      PRIMERT
covariance   209.4603179  -0.23886994  -0.69024676
coefficient    0.2973024 -32.81779552 -17.33004045
variance     423.0538678 423.05386785 423.05386785
contribution   0.1471989   0.01852999   0.02827537
> #. A test: The sum of contribution equals to the R square.
> sum(decomp(M)[4,]);summary(M)$r.squared
[1] 0.1940043
[1] 0.1940043

No comments: