Type: Package
Title: Tidy Tools for Joinpoint Regression Models
Version: 0.5.0
Description: Provides tools to fit joinpoint regression models with a log-linear specification by levels of a categorical variable. The package acts as a wrapper around the 'segmented' package, facilitating model fitting, selection, and interpretation. It includes functions to estimate the Annual Percent Change (APC) and the Average Annual Percent Change (AAPC), along with their 95% confidence intervals, and to generate formatted summary tables and plots of results.
License: MIT + file LICENSE
Encoding: UTF-8
Imports: dplyr, purrr, tidyr, tibble, ggplot2, segmented, scales, flextable, rlang, stringr, stats, officer
RoxygenNote: 7.3.3
URL: https://github.com/datos-ine/joinpointR
BugReports: https://github.com/datos-ine/joinpointR/issues
Suggests: testthat (≥ 3.0.0)
Config/testthat/edition: 3
NeedsCompilation: no
Packaged: 2026-04-29 14:58:19 UTC; user
Author: Tamara Ricardo ORCID iD [aut, cre]
Maintainer: Tamara Ricardo <tamararicardo83@gmail.com>
Depends: R (≥ 4.1.0)
Repository: CRAN
Date/Publication: 2026-05-02 09:50:02 UTC

Average Annual Percent Change (AAPC)

Description

Estimates the Average Annual Percent Change (AAPC) and its 95% confidence interval. Optionally displays statistical significance using significance stars.

Usage

get_aapc(mod, digits = 1, show_ci = TRUE, dec = ".")

Arguments

mod

Joinpoint regression model (segmented object) or linear regression model (lm object).

digits

Number of decimal places to display (integer).

show_ci

Logical; if TRUE, displays the 95% confidence interval. If FALSE, displays significance stars.

dec

Character. Decimal separator to use (e.g., "." or ",").

Value

A character string with the AAPC and either its 95% confidence interval or significance stars.

Author(s)

Tamara Ricardo

Examples

# Load example data
data("plant", package = "segmented")

names(plant)

# Fit the joinpoint models
mods <- model_jp(data = plant, value = "y", time = "time", group = "group", k = 2, test = TRUE)

# AAPC of the first model
get_aapc(mods$RKW, digits = 1, show_ci = TRUE, dec = ".")

Annual Percent Change by Segment (APC)

Description

Calculates the Annual Percent Change (APC) for each segment and its 95% confidence interval.

Usage

get_apc(mod, digits = 1, time = "time", dec = ".")

Arguments

mod

Joinpoint regression model (segmented object).

digits

Number of decimal places to display (integer).

time

Time variable used in the model (character).

dec

Character. Decimal separator to use (e.g., "." or ",").

Value

A character vector with APC and 95% CI for each segment.

Author(s)

Tamara Ricardo

Examples

# Load example data
data("plant", package = "segmented")

names(plant)

# Fit the joinpoint models
mods <- model_jp(data = plant, value = "y", time = "time", group = "group", k = 2, test = TRUE)

# Obtain APC (95% CI)
get_apc(mods$RKW, digits = 1, time = "time", dec = ".")

Plot Joinpoint Regression Models

Description

Creates a ggplot showing observed values, fitted joinpoint regression lines, and optional joinpoints.

Usage

gg_jpoint(mods, obs = TRUE, jp = TRUE, facets = FALSE)

Arguments

mods

List of joinpoint regression models (output of model_jp()).

obs

Logical. If TRUE, displays observed data points.

jp

Logical. If TRUE, displays joinpoints as vertical dashed lines.

facets

Logical. If TRUE, displays one panel per group using facets.

Value

A ggplot object.

Examples

library(dplyr)
# Load example data
data("plant", package = "segmented")

names(plant)

# Fit the joinpoint models
mods <- model_jp(data = plant, value = "y", time = "time", group = "group", k = 2, test = TRUE)

# Plot results
gg_jpoint(mods, obs = TRUE, jp = TRUE, facets = FALSE)

# Facets by group
gg_jpoint(mods, obs = TRUE, jp = TRUE, facets = TRUE)

Joinpoint Regression Models by Groups

Description

Fits segmented linear regression models by groups for age-standardized rates, using a stepwise procedure based on the Bayesian Information Criterion (BIC). Internally calls segmented::selgmented() and applies a log transformation to the response variable.

Usage

model_jp(data, value, time, group, k = 2, test = TRUE)

Arguments

data

Data frame containing age-standardized rates.

value

Response variable (character).

time

Time variable (character).

group

Grouping variable (character).

k

Maximum number of joinpoints (integer).

test

Test for differences in the t-values of the slope (logical).

Value

A list of models by group.

Author(s)

Tamara Ricardo

Examples

# Generate example data
library(dplyr)
df <- mtcars |>
mutate(
  year = seq(2000, length.out = n(), by = 1),
  group = factor(paste("cyl", cyl, sep = "_")),
  rate = mpg
) |>
select(year, group, rate)

# Check group levels
levels(df$group)

# Fit models
mods <- model_jp(data = df, value = "rate", time = "year", group = "group", k = 2, test = TRUE)

# Show the output of the first model
mods$cyl_6
summary(mods$cyl_6)

Summary Table For Joinpoint Regression Models

Description

Generates a table displaying the number of joinpoints, time breaks, APC and its 95% confidence interval, and AAPC and its statistical significance from a list of joinpoint models.

Usage

summary_jp(
  mods,
  digits = 1,
  var1 = "group",
  var2 = "subgroup",
  ft = FALSE,
  lan = c("en", "es")
)

Arguments

mods

List of joinpoint regression models (model_jp() output).

digits

Number of decimal places to display (integer).

var1

Character. Name of the grouping variable.

var2

Character. Name of the subgrouping variable (optional).

ft

Logical. If TRUE returns a flextable object, if FALSE returns a tibble.

lan

Language of output: "en" (English) or "es" (Spanish).

Value

A tibble or a flextable object.

Author(s)

Tamara Ricardo

Examples

library(dplyr)
# Load example data
data("plant", package = "segmented")

names(plant)

# Fit the joinpoint models
mods <- model_jp(data = plant, value = "y", time = "time", group = "group", k = 2, test = TRUE)

summary_jp(mods, digits = 1, var1 = "group", ft = FALSE, lan = "en")