Learn R Programming

This is the repository containing the source code, documentation and metadata for the R package $\texttt{MAPCtools}$, a package for analyzing age-period-cohort data. The package provides functions for estimating Bayesian APC models using INLA.

The package was developed during my Master's thesis in the 30 credit course TMA4900 - Industrial Mathematics, Master's Thesis.

Copy Link

Version

Install

install.packages('MAPCtools')

Version

0.1.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Lars Vatten

Last Published

June 25th, 2025

Functions in MAPCtools (0.1.0)

check_cols_exist

Check if a set of columns is missing from a data frame. For use in aggregate_df.
plot_lincombs

Plot Linear Combinations of Age-Period-Cohort Effects by Strata
plot_mean_response_1D

Plot mean of a response variable across a single variable, optionally stratified
plot_model_selection_criteria

Make a plot of model fit scores
plot_time_effect

Plot time effects with uncertainty ribbons
resolve_column

Helper for evaluating column names, strings, or self-contained vectors
toy_data

Synthetic Age-Period-Cohort Dataset
model_selection_criteria_table

Make a table of model fit scores
multinomial_aggregator

Aggregate multinomial data (No changes needed here)
number_of_strata

Count number of groups across a set of variables in a data frame
dynamic_pretty_breaks

Compute dynamic pretty breaks for continuous x-axis
validate_lincombs_against_formula

Validate lincomb terms against an INLA formula
plot_mean_response_2D

Plot mean of a response variable across two dimensions, optionally stratified
plot_counts_with_mean

Plot heatmap of observation counts with mean overlay, optionally stratified
plot_missing_data

Plot Missing Group Combinations
plot_counts_2D

Plot counts of observations across two dimensions, optionally stratified
number_of_groups

Count number of groups across a set of variables in a data frame
clamp

Clamp a numeric value within bounds
aggregate_grouped_df

Aggregate grouped data using aggregate_df
amultinomial

Aggregate multinomial data. Used in aggregate_df.
as.APC.df

Add 1-indexed APC columns to data frame, handling numeric or categorical age/period
abinomial

Aggregate binomial data
aggregate_df

Aggregate data across an entire data frame using sufficient statistics
as.APC.NA.df

Create NA structure across age, period and cohort groups based on strata
generate_MAPC_formula

Generate MAPC formula for INLA
add_APC_by_match

Add 1-indexed age, period and cohort indices via match()
add_cohort_index

Add cohort column to data frame
dynamic_pretty_discrete_breaks

Compute dynamic pretty breaks for discrete x-axis
agaussian

Aggregate Gaussian data
binomial_aggregator

Aggregate binomial data
fit_all_MAPC

Fit all configurations of MAPC models using INLA
fit_MAPC

Fit a multivariable age-period-cohort model
gaussian_aggregator

Aggregate Gaussian data
generate_apc_lincombs

Generate Age-Period-Cohort Linear Combinations for INLA
add_cohort_column

Add cohort column to data frame
expected_groups

Find expected groups based on distinct values across a set of variables
plot_binned_counts

Plot counts of observations across bins of a numeric variable, optionally stratified
plot_counts_1D

Plot counts of observations across a single variable, optionally stratified
longest_run

Function for finding longest consecutive run of non-missing indices