mirror of
https://github.com/msberends/AMR.git
synced 2025-07-08 20:41:58 +02:00
age and age_groups
This commit is contained in:
22
man/age.Rd
Normal file
22
man/age.Rd
Normal file
@ -0,0 +1,22 @@
|
||||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/age.R
|
||||
\name{age}
|
||||
\alias{age}
|
||||
\title{Age in years of individuals}
|
||||
\usage{
|
||||
age(x, y = Sys.Date())
|
||||
}
|
||||
\arguments{
|
||||
\item{x}{date(s) - will be coerced with \code{\link{as.POSIXlt}}}
|
||||
|
||||
\item{y}{reference date(s) - defaults to \code{\link{Sys.Date}} - will be coerced with \code{\link{as.POSIXlt}}}
|
||||
}
|
||||
\value{
|
||||
Integer (no decimals)
|
||||
}
|
||||
\description{
|
||||
Calculates age in years based on a reference date, which is the sytem time at default.
|
||||
}
|
||||
\seealso{
|
||||
age_groups
|
||||
}
|
66
man/age_groups.Rd
Normal file
66
man/age_groups.Rd
Normal file
@ -0,0 +1,66 @@
|
||||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/age.R
|
||||
\name{age_groups}
|
||||
\alias{age_groups}
|
||||
\title{Split ages in age groups}
|
||||
\usage{
|
||||
age_groups(x, split_at = c(12, 25, 55, 75))
|
||||
}
|
||||
\arguments{
|
||||
\item{x}{age, e.g. calculated with \code{\link{age}}}
|
||||
|
||||
\item{split_at}{values to split \code{x}, defaults to 0-11, 12-24, 26-54, 55-74 and 75+. See Details.}
|
||||
}
|
||||
\value{
|
||||
Ordered \code{\link{factor}}
|
||||
}
|
||||
\description{
|
||||
Splits ages into groups defined by the \code{split} parameter.
|
||||
}
|
||||
\details{
|
||||
To split ages, the input can be:
|
||||
\itemize{
|
||||
\item{A numeric vector. A vector of \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 (26-54), middle-aged adults (55-74) and elderly (75+).}
|
||||
\item{A character:}
|
||||
\itemize{
|
||||
\item{\code{"children"}, 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, 95)}. This will split on 0-64, 65-74, 75-84, 85-94 and 95+.}
|
||||
\item{\code{"fives"}, equivalent: of \code{1:20 * 5}. This will split on 0-4, 5-9, 10-14, 15-19 and so forth.}
|
||||
\item{\code{"tens"}, equivalent: of \code{1:10 * 10}. This will split on 0-9, 10-19, 20-29 and so forth.}
|
||||
}
|
||||
}
|
||||
}
|
||||
\examples{
|
||||
ages <- c(3, 8, 16, 54, 31, 76, 101, 43, 21)
|
||||
|
||||
# split on 0-49 and 50+
|
||||
age_groups(ages, 50)
|
||||
|
||||
# split on 0-20, 21-49 and 50+
|
||||
age_groups(ages, c(21, 50))
|
||||
|
||||
# split on every ten years
|
||||
age_groups(ages, 1:10 * 10)
|
||||
age_groups(ages, "tens")
|
||||
|
||||
# split on every five years
|
||||
age_groups(ages, 1:20 * 5)
|
||||
age_groups(ages, "fives")
|
||||
|
||||
# split on children
|
||||
age_groups(ages, "children")
|
||||
|
||||
# resistance of ciprofloxacine per age group
|
||||
septic_patients \%>\%
|
||||
mutate(first_isolate = first_isolate(.)) \%>\%
|
||||
filter(first_isolate == TRUE,
|
||||
mo == as.mo("E. coli")) \%>\%
|
||||
group_by(age_group = age_groups(age)) \%>\%
|
||||
select(age_group,
|
||||
cipr) \%>\%
|
||||
ggplot_rsi(x = "age_group")
|
||||
}
|
||||
\seealso{
|
||||
age
|
||||
}
|
@ -114,6 +114,17 @@ septic_patients \%>\%
|
||||
size = 1,
|
||||
linetype = 2,
|
||||
alpha = 0.25)
|
||||
|
||||
# resistance of ciprofloxacine per age group
|
||||
septic_patients \%>\%
|
||||
mutate(first_isolate = first_isolate(.)) \%>\%
|
||||
filter(first_isolate == TRUE,
|
||||
mo == as.mo("E. coli")) \%>\%
|
||||
# `age_group` is also a function of this package:
|
||||
group_by(age_group = age_groups(age)) \%>\%
|
||||
select(age_group,
|
||||
cipr) \%>\%
|
||||
ggplot_rsi(x = "age_group")
|
||||
\donttest{
|
||||
|
||||
# for colourblind mode, use divergent colours from the viridis package:
|
||||
|
Reference in New Issue
Block a user