Learn R Programming

APCtools

Routines for Descriptive and Model-Based APC Analysis

Aim of this Package

Age-Period-Cohort (APC) analysis aims to determine relevant drivers for long-term developments and is used in many fields of science. The main focus is on disentangling the interconnected effects of age, period, and cohort. Long-term developments of some characteristic can either be associated with changes in a person’s life cycle (age), macro-level developments over the years that simultaneously affect all age groups (period), or the generational membership of an individual, shaped by similar socialization processes and historical experiences (cohort). The critical challenge in APC analysis is the linear dependency of the components age, period, and cohort (cohort = period - age). Accordingly, flexible methods and visualization techniques are needed to properly disentangle observed temporal association structures.

In contrast to other software packages, APCtools builds on a flexible and robust semiparametric regression approach to circumvent this identification problem. The package includes modern visualization techniques and general routines to facilitate the interpretability of the estimated temporal structures and simplify the workflow of an APC analysis.

Main Functionality

Sophisticated functions are available both for descriptive and regression model-based analyses. For the former, we use density (or ridgeline) matrices, classical heatmaps and hexamaps (hexagonally binned heatmaps) as innovative visualization techniques building on the concept of Lexis diagrams. Model-based analyses build on the separation of the temporal dimensions based on generalized additive models, where a tensor product interaction surface (usually between age and period) is utilized to represent the third dimension (usually cohort) on its diagonal. Such tensor product surfaces can also be estimated while accounting for further covariates in the regression model.

Documentation and Useful Materials

Installation

The most current version from GitHub can be installed via

devtools::install_github("bauer-alex/APCtools")

How to Contribute

If you encounter problems with the package, find bugs or have suggestions for additional functionalities please open a GitHub issue. Alternatively, feel free to contact us directly via email.

Contributions (via pull requests or otherwise) are welcome. Before you open a pull request or share your updates with us, please make sure that all unit tests pass without errors or warning messages. You can run the unit tests by calling

devtools::test()

References

Bauer, A., Weigert, M., and Jalal, H. (2022). APCtools: Descriptive and Model-based Age-Period-Cohort Analysis. Journal of Open Source Software, 7(73), 4056, https://doi.org/10.21105/joss.04056.

Weigert, M., Bauer, A., Gernert, J., Karl, M., Nalmpatian, A., Küchenhoff, H., and Schmude, J. (2021). Semiparametric APC analysis of destination choice patterns: Using generalized additive models to quantify the impact of age, period, and cohort on travel distances. Tourism Economics. https://doi.org/10.1177/1354816620987198.

Jalal, H., Burke, D. (2020). Hexamaps for Age–Period–Cohort Data Visualization and Implementation in R. Epidemiology, 31 (6), e47-e49. doi: https://doi.org/10.1097/EDE.0000000000001236.

Copy Link

Version

Install

install.packages('APCtools')

Monthly Downloads

382

Version

1.0.4

License

MIT + file LICENSE

Maintainer

Alexander Bauer

Last Published

January 13th, 2023

Functions in APCtools (1.0.4)

plot_1Dsmooth

get_plotGAMobject

Extract returned values of plot.gam() while suppressing creation of the plot
plot_densityMatrix

Create a matrix of density plots
plot_density

Plot the density of one metric or categorical variable
plot_APCheatmap

Heatmap of an APC surface
ensure_segmentsInPlotRange

Internal helper for gg_addReferenceLines to keep diagonal lines in the plot range
extract_summary_linearEffects

Internal helper to extract summary of linear effects in a gam model
gg_highlightDiagonals

Internal helper to add the diagonal highlighting to a ggplot
gg_addReferenceLines

Internal helper to add reference lines in an APC heatmap
plot_APChexamap

Hexamap of an APC surface
plot_marginalAPCeffects

Plot of marginal APC effects based on an estimated GAM model
plot_density_categorical

Internal helper to plot a categorical density
plot_jointMarginalAPCeffects

Joint plot to compare the marginal APC effects of multiple models
plot_partialAPCeffects

Partial APC plots based on an estimated GAM model
plot_linearEffects

Plot linear effects of a gam in an effect plot
travel

Data from the German Reiseanalyse survey
plot_variable

Distribution plot of one variable against one APC dimension
plot_density_metric

Internal helper to plot a metric density
create_groupVariable

Internal helper to create a group variable as base for a density matrix
drug_deaths

Drug deaths of white men in the United States
compute_yCoordinate

Internal helper to tilt the x-axis for the hexamap plot
calc_density

Internal helper to calculate the (group-specific) density of a variable
capitalize_firstLetter

Internal function to capitalize the first letter of a character
create_modelSummary

Create model summary tables for multiple estimated GAM models
create_highlightDiagonalData

Internal helper to create a dataset for ggplot2 to highlight diagonals
compute_xCoordinate

Internal helper to tilt the x-axis for the hexamap plot
create_APCsummary

Create a summary table for multiple estimated GAM models
create_oneAPCsummaryTable

Internal helper to create a summary table for one estimated GAM model