[R] Calculation of Age heaping

Richard O'Keefe r@oknz @end|ng |rom gm@||@com
Mon Aug 9 13:40:01 CEST 2021


According to Wikipedia, this is the definition of Whipple's index:

"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)."

Let ages be a vector of integers representing ages.
whipple <- function (ages) {
    mids <- ages[ages >= 23 & ages <= 62] * 2
    5 * mean( mids %% 10 == 0)
}

If you want any other digit(s), you could try
whipple <- function (ages, digits = c(0,5)) {
    mids <- ages[ages >= 23 & ages <= 62] %% 10
    (10/leng(digits)) * mean(mids %in% digits)
}

So it is not clear to me why you want any package to do this.
The Whipple index does not come with any statistical measure of strength,
although https://en.wikipedia.org/wiki/Whipple%27s_index
mentions a UN table of values to compare with.

That Wikipedia page also warns about limits to applicability.
I note that with the exception of using an upper inclusive bound of
62 (as in the Wikipedia page) this definition of the Whipple index
agrees perfectly with that in A'Hearn et al's papers (which use 72)
but NOT with DemoTools.  So you need to be very clear to yourself
and others where your definition of the Whipple index comes from,
what it is, and whether the code you use computes what you think
it does.  (UNTESTED CODE ABOVE!)

On Mon, 9 Aug 2021 at 22:28, Md. Moyazzem Hossain <hossainmm using juniv.edu> wrote:
>
> Dear Avi Gross,
>
> Thank you very much for your email. Actually, I have a little knowledge of
> R programming.
>
> I have a dataset of ages ranging from 10 to 90. Now, I want to find out the
> Whipple’s index for age heaping among individuals for each digit like
> 0,1,...,9.
>
> I have searched in google I got the following functions. That's why I use
> the package and the following code.
>
> *check_heaping_whipple(Value, Age, ageMin = 25, ageMax = 65, digit = c(0,
> 5)) *     [link:
> https://rdrr.io/github/timriffe/DemoTools/man/check_heaping_whipple.html]
>
> Thanks in advance.
>
> Md
>
>
>
> On Sun, Aug 8, 2021 at 10:48 PM Avi Gross via R-help <r-help using r-project.org>
> wrote:
>
> > It is not too clear to me what you want to do and why that package is the
> > way to do it. Is the package a required part of your assignment? If so,
> > maybe someone else can help you find how to properly install it on your
> > machine, assuming you have permissions to replace the other package it
> > seems to require. You may need to create your own environment. If you are
> > open to other ways, see below.
> >
> > Are you trying to do something as simple as counting how many people in
> > your data are in various buckets such as each age truncated or rounded to
> > an integer from 0 to 99? If so, you might miss some of my cousins alive at
> > 100 or that died at 103 and 105 recently 😉
> >
> > Or do you want ages in groups of 10 or so meaning the first of two digits
> > is 0 through 9?
> >
> > Many such things can be done quite easily without the package if you wish.
> >
> > As far as I can tell, your code reads in a data.frame from your local file
> > with any number of columns that you do not specify. If it is one, the
> > solution becomes much easier. You then for some reason feel the need to
> > convert it to a matrix. You then do whatever your Whipple does several ways.
> >
> > Here is an outline of ways you can do this yourself.
> >
> > First, combine all your data into one or more vectors. You already have
> > that in your data.frame but if all columns are numeric, you can of course
> > do something with a matrix.
> >
> > Then make sure you remove anything objectionable, such as negative numbers
> > or numbers too large or NA or whatever your logic requires.
> >
> > If you have a variable ready with N entries to hold the buckets, such as
> > length(0:100) or for even buckets of 5, perhaps length(0:99)/5 you
> > initialize that to all zeroes.
> >
> > Now take your data, and perhaps transform it into a copy where every age
> > is truncated to an integer or divided by 5 first or whatever you need so it
> > contains a pure integer like 6 or 12. What I mean is if your buckets are 5
> > wide, and you want 5:9 to map into one bucket, your transform might be
> > as.integer(original/5.0) or one of many variants like that.
> >
> > You can now simply use one of many methods in R to loop through your
> > values that result and assuming you have a zeroed vector called counter and
> > the current value being looked at is N, you simply increment counter[N] or
> > of N-1 or whatever your logic requires.
> >
> > Alternately R has many built-in methods (or in other packages) like cut()
> > that might do something similar without as much work.
> >
> > And just for the heck of it, I tried your download instructions. Unlike
> > your three choices, I was offered 13 choices and as I had no clue what YOU
> > were supposed to download, I aborted.
> >
> >  1: All
> > 2: CRAN packages only
> > 3: None
> > 4: colorspace (2.0-1 -> 2.0-2) [CRAN]
> > 5: isoband    (0.2.4 -> 0.2.5) [CRAN]
> > 6: utf8       (1.2.1 -> 1.2.2) [CRAN]
> > 7: cli        (3.0.0 -> 3.0.1) [CRAN]
> > 8: ggplot2    (3.3.3 -> 3.3.5) [CRAN]
> > 9: pillar     (1.6.1 -> 1.6.2) [CRAN]
> > 10: tibble     (3.1.2 -> 3.1.3) [CRAN]
> > 11: dplyr      (1.0.6 -> 1.0.7) [CRAN]
> > 12: Rcpp       (1.0.6 -> 1.0.7) [CRAN]
> > 13: curl       (4.3.1 -> 4.3.2) [CRAN]
> > 14: cpp11      (0.2.7 -> 0.3.1) [CRAN]
> >
> > In your case, if you selected All, what exactly did you expect?
> >
> >
> > -----Original Message-----
> > From: R-help <r-help-bounces using r-project.org> On Behalf Of Md. Moyazzem
> > Hossain
> > Sent: Sunday, August 8, 2021 5:25 PM
> > To: r-help using r-project.org
> > Subject: [R] Calculation of Age heaping
> >
> > Dear R-expert,
> >
> > I hope that you are doing well.
> >
> > I am interested to calculate the age heaping for each digit (0,1,...,9)
> > based on my data set. However, when I run the R code, I got the following
> > errors. Please help me in this regard.
> >
> > ##########################################
> > library(remotes)
> > install_github("timriffe/DemoTools")
> >
> > ###
> > Downloading GitHub repo timriffe/DemoTools using HEAD These packages have more
> > recent versions available.
> > It is recommended to update all of them.
> > Which would you like to update?
> >
> >  1: All
> >  2: CRAN packages only
> >  3: None
> >
> > Enter one or more numbers, or an empty line to skip updates: 1
> >
> > *After installing some packages, I got the following error message*
> >
> > package ‘backports’ successfully unpacked and MD5 sums checked
> > Error: Failed to install 'DemoTools' from GitHub:
> >   (converted from warning) cannot remove prior installation of package
> > ‘backports’
> >
> > I am attaching the R-code and data file along with this email.
> >
> > Please help me in this regard.
> >
> > Thanks in advance.
> > --
> > Best Regards,
> > Md. Moyazzem Hossain
> > Associate Professor
> > Department of Statistics
> > Jahangirnagar University
> > Savar, Dhaka-1342
> > Bangladesh
> > Website: http://www.juniv.edu/teachers/hossainmm
> > Research: *Google Scholar
> > <https://scholar.google.com/citations?user=-U03XCgAAAAJ&hl=en&oi=ao>*;
> > *ResearchGate
> > <https://www.researchgate.net/profile/Md_Hossain107>*; *ORCID iD
> > <https://orcid.org/0000-0003-3593-6936>*
> >
> > ______________________________________________
> > R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > 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.
> >
>
>
> --
> Best Regards,
> Md. Moyazzem Hossain
> Associate Professor
> Department of Statistics
> Jahangirnagar University
> Savar, Dhaka-1342
> Bangladesh
> Website: http://www.juniv.edu/teachers/hossainmm
> Research: *Google Scholar
> <https://scholar.google.com/citations?user=-U03XCgAAAAJ&hl=en&oi=ao>*;
> *ResearchGate
> <https://www.researchgate.net/profile/Md_Hossain107>*; *ORCID iD
> <https://orcid.org/0000-0003-3593-6936>*
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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