# [R] Calculation of Age heaping

Jim Lemon drj|m|emon @end|ng |rom gm@||@com
Tue Aug 10 06:21:48 CEST 2021

```Here is my hasty attempt last night checked in the light of morning.
It seems to return the correct extreme values and contains an example.

Jim

On Mon, Aug 9, 2021 at 10:50 PM Md. Moyazzem Hossain
<hossainmm using juniv.edu> wrote:
>
> Dear Jim,
>
> Thank you very much for your kind help.
>
> Take care.
>
> Md
>
> On Mon, Aug 9, 2021 at 1:17 PM Jim Lemon <drjimlemon using gmail.com> wrote:
>>
>> And if you really don't like programming:
>>
>> whipple_index<-function(x,td=c(0,5)) {
>>  wi<-rep(NA,11)
>>  names(wi)<-c(paste0("wi",0:9),"O/all")
>>  for(i in 0:9) {
>>   ttd<-which((x %% 10) %in% i)
>>   wi[i+1]<-length(ttd) * 100/length(x)
>>  }
>>  ttd<-which((x %% 10) %in% td)
>>  wi[11]<-length(ttd) * 100/(length(x)/length(td))
>>  return(wi)
>> }
>>
>> I haven't tested this extensively, but it may be helpful. You can
>> specify the final digits for the overall test. Select your ages before
>> passing them to whipple_index.
>>
>> Jim
>>
>> On Mon, Aug 9, 2021 at 9:05 PM Greg Minshall <minshall using umich.edu> wrote:
>> >
>> > Md,
>> >
>> > if this is what you are looking for:
>> > ----
>> > https://en.wikipedia.org/wiki/Whipple%27s_index
>> > ----
>> >
>> > then, the article says the algorithm is
>> > ----
>> > The index score is obtained by summing the number of persons in the age
>> > range 23 and 62 inclusive, who report ages ending in 0 and 5, dividing
>> > that sum by the total population between ages 23 and 62 years inclusive,
>> > and multiplying the result by 5. Restated as a percentage, index scores
>> > range between 100 (no preference for ages ending in 0 and 5) and 500
>> > (all people reporting ages ending in 0 and 5).
>> > ----
>> >
>> > that seems fairly straight forward.  if you are trying to learn R,
>> > and/or learn programming, i might suggest you *not* use a package, and
>> > rather work on coding up the calculation yourself.  that would probably
>> > be a good, but not too hard, exercise, of some interest.  enjoy!
>> >
>> > cheers, Greg
>> >
>> > ______________________________________________
>> > R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > and provide commented, minimal, self-contained, reproducible code.
>
>
>
> --
> Best Regards,
> Md. Moyazzem Hossain
> Associate Professor
> Department of Statistics
> Jahangirnagar University
> Savar, Dhaka-1342