AMR/man/age_groups.Rd

85 lines
3.7 KiB
Plaintext
Raw Normal View History

2018-12-15 22:40:07 +01:00
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/age.R
\name{age_groups}
\alias{age_groups}
\title{Split ages into age groups}
2018-12-15 22:40:07 +01:00
\usage{
age_groups(x, split_at = c(12, 25, 55, 75), na.rm = FALSE)
2018-12-15 22:40:07 +01:00
}
\arguments{
\item{x}{age, e.g. calculated with \code{\link[=age]{age()}}}
2018-12-15 22:40:07 +01:00
2019-05-10 16:44:59 +02:00
\item{split_at}{values to split \code{x} at, defaults to age groups 0-11, 12-24, 25-54, 55-74 and 75+. See Details.}
2020-03-07 21:48:21 +01:00
\item{na.rm}{a \link{logical} to indicate whether missing values should be removed}
2018-12-15 22:40:07 +01:00
}
\value{
2020-03-07 21:48:21 +01:00
Ordered \link{factor}
2018-12-15 22:40:07 +01:00
}
\description{
2018-12-22 22:39:34 +01:00
Split ages into age groups defined by the \code{split} parameter. This allows for easier demographic (antimicrobial resistance) analysis.
2018-12-15 22:40:07 +01:00
}
\details{
2020-03-07 21:48:21 +01:00
To split ages, the input for the \code{split_at} parameter can be:
2018-12-15 22:40:07 +01:00
\itemize{
\item A numeric vector. A vector of e.g. \code{c(10, 20)} will split on 0-9, 10-19 and 20+. A value of only \code{50} will split on 0-49 and 50+.
The default is to split on young children (0-11), youth (12-24), young adults (25-54), middle-aged adults (55-74) and elderly (75+).
\item A character:
\itemize{
\item \code{"children"} or \code{"kids"}, equivalent of: \code{c(0, 1, 2, 4, 6, 13, 18)}. This will split on 0, 1, 2-3, 4-5, 6-12, 13-17 and 18+.
\item \code{"elderly"} or \code{"seniors"}, equivalent of: \code{c(65, 75, 85)}. This will split on 0-64, 65-74, 75-84, 85+.
\item \code{"fives"}, equivalent of: \code{1:20 * 5}. This will split on 0-4, 5-9, 10-14, ..., 90-94, 95-99, 100+.
2020-03-07 21:48:21 +01:00
\item \code{"tens"}, equivalent of: \code{1:10 * 10}. This will split on 0-9, 10-19, 20-29, ..., 80-89, 90-99, 100+.
}
2018-12-15 22:40:07 +01:00
}
}
\section{Stable lifecycle}{
\if{html}{\figure{lifecycle_stable.svg}{options: style=margin-bottom:5px} \cr}
2020-07-08 14:48:06 +02:00
The \link[=lifecycle]{lifecycle} of this function is \strong{stable}. In a stable function, major changes are unlikely. This means that the unlying code will generally evolve by adding new arguments; removing arguments or changing the meaning of existing arguments will be avoided.
If the unlying code needs breaking changes, they will occur gradually. For example, a parameter will be deprecated and first continue to work, but will emit an message informing you of the change. Next, typically after at least one newly released version on CRAN, the message will be transformed to an error.
}
2019-01-02 23:24:07 +01:00
\section{Read more on our website!}{
2020-07-28 18:39:57 +02:00
On our website \url{https://msberends.github.io/AMR} you can find \href{https://msberends.github.io/AMR/articles/AMR.html}{a comprehensive tutorial} about how to conduct AMR analysis, the \href{https://msberends.github.io/AMR/reference}{complete documentation of all functions} (which reads a lot easier than here in R) and \href{https://msberends.github.io/AMR/articles/WHONET.html}{an example analysis using WHONET data}. As we would like to better understand the backgrounds and needs of our users, please \href{https://msberends.github.io/AMR/survey.html}{participate in our survey}!
2019-01-02 23:24:07 +01:00
}
2018-12-15 22:40:07 +01:00
\examples{
ages <- c(3, 8, 16, 54, 31, 76, 101, 43, 21)
# split into 0-49 and 50+
2018-12-15 22:40:07 +01:00
age_groups(ages, 50)
# split into 0-19, 20-49 and 50+
age_groups(ages, c(20, 50))
2018-12-15 22:40:07 +01:00
# split into groups of ten years
2019-04-09 10:34:40 +02:00
age_groups(ages, 1:10 * 10)
age_groups(ages, split_at = "tens")
2018-12-15 22:40:07 +01:00
# split into groups of five years
2019-04-09 10:34:40 +02:00
age_groups(ages, 1:20 * 5)
age_groups(ages, split_at = "fives")
2018-12-15 22:40:07 +01:00
# split specifically for children
2018-12-15 22:40:07 +01:00
age_groups(ages, "children")
# same:
age_groups(ages, c(1, 2, 4, 6, 13, 17))
2018-12-15 22:40:07 +01:00
2019-11-03 22:41:29 +01:00
\dontrun{
2018-12-15 22:40:07 +01:00
# resistance of ciprofloxacine per age group
2018-12-16 11:40:54 +01:00
library(dplyr)
example_isolates \%>\%
2019-05-30 08:51:38 +02:00
filter_first_isolate() \%>\%
2019-05-29 00:36:48 +02:00
filter(mo == as.mo("E. coli")) \%>\%
2018-12-15 22:40:07 +01:00
group_by(age_group = age_groups(age)) \%>\%
2019-05-29 00:36:48 +02:00
select(age_group, CIP) \%>\%
2018-12-15 22:40:07 +01:00
ggplot_rsi(x = "age_group")
}
2019-11-03 22:41:29 +01:00
}
2018-12-15 22:40:07 +01:00
\seealso{
To determine ages, based on one or more reference dates, use the \code{\link[=age]{age()}} function.
2018-12-15 22:40:07 +01:00
}