Tuesday, February 24, 2009

Whipple's index in R

The index measures the degree of age heaping in demographic data. Joerg Baten have been applying it to appraise the numeracy of historical populations. Surely there is neater way to do it, but here is the code in R that I've just written:
tmp1<-data[data>=23 & data<=62]
tmp2<-tmp1%%5
whipple<-(length(tmp2[tmp2==0])/length(tmp1))*500
whipple

1 comment:

Unknown said...

Hi Leonardo

Just to say thank you for this - it was just what I wanted.

I turned it into a function like this:

whipple<-function(data){length(data[data%%5==0])/length(data)*500}

That way you can quickly run it on different subsets, e.g.

whipple(data[data>20])

n.b. I am not an expert at R so don't assume that this works as intended!