[R] Theil decomposition

Dennis Murphy djmuser at gmail.com
Wed Nov 16 09:57:22 CET 2011


Looking at the help pages in the ineq package, the Theil() function
simply returns the value of the index. You can look at the source code
of the relevant functions to see what they actually compute:

library('ineq')
ineq     # the main function
Theil    # for the Theil index

Neither function is long - ineq() is a wrapper for the index of
choice. The code for Theil is very straightforward.

It appears that if you want to decompose the index, you'll have to
roll your own function to do so. If you know how to compute it
componentwise, you could write a function to get the necessary
information in each group, and then use that information to compute
the overall index.

Here's a reproducible example using the chickwts data that computes
means and sample sizes by feed type, then uses the result to compute a
weighted mean:

library('plyr')
(v <- ddply(chickwts, .(feed), summarise,
                  m = mean(weight), n = length(weight)))
with(v, weighted.mean(m, n))
# [1] 261.3099

This is a template of how you might produce the components you need
for the Theil index and them pull them together into a weighted sum or
product, if that's what you need to do.

HTH,
Dennis

On Tue, Nov 15, 2011 at 10:35 PM, Kitty Lee <lee.kitty at yahoo.com> wrote:
> I came across the package 'ineq' that computes a variety of inequality measures (e.g. gini, theil etc). I want to compute the Theil index (racial segregation) and decompose the total into sub-components (by geog levels). I think the package doesn't report the decomposition (correct me if I'm wrong). Just wonder is that available elsewhere?
>
>
>
> K.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list