| Title: | Tidy Tools for Joinpoint Regression Models |
|---|---|
| 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. |
| Authors: | Tamara Ricardo [aut, cre] (ORCID: <https://orcid.org/0000-0002-0921-2611>) |
| Maintainer: | Tamara Ricardo <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.6.2 |
| Built: | 2026-06-02 18:55:19 UTC |
| Source: | https://github.com/datos-ine/joinpointr |
Estimates the Average Annual Percent Change (AAPC) and its 95% confidence interval. Optionally displays statistical significance using significance stars.
get_aapc(mod, digits = 1, show_ci = TRUE, dec = ".")get_aapc(mod, digits = 1, show_ci = TRUE, dec = ".")
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 ","). |
A character string with the AAPC and either its 95% confidence interval or significance stars.
Tamara Ricardo
# 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 = ".")# 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 = ".")
Calculates the Annual Percent Change (APC) for each segment and its 95% confidence interval.
get_apc(mod, digits = 1, time = "time", dec = ".")get_apc(mod, digits = 1, time = "time", dec = ".")
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 ","). |
A character vector with APC and 95% CI for each segment.
Tamara Ricardo
# 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 = ".")# 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 = ".")
Creates a ggplot showing observed values, fitted joinpoint regression lines, and optional joinpoints.
gg_jpoint(mods, obs = TRUE, jp = TRUE, facets = FALSE)gg_jpoint(mods, obs = TRUE, jp = TRUE, facets = FALSE)
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. |
A ggplot object.
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)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)
Fits segmented linear regression models by groups for age-standardized rates
using joinpoint regression. Models can be fitted using either a stepwise
selection procedure based on the Bayesian Information Criterion (BIC) or a
fixed number of joinpoints. Internally calls
segmented::selgmented() or segmented::segmented() and applies
a log transformation to the response variable.
model_jp(data, value, time, group, k = 2, step = TRUE, test = TRUE)model_jp(data, value, time, group, k = 2, step = TRUE, test = TRUE)
data |
Data frame containing age-standardized rates. |
value |
Name of the response variable (character). |
time |
Name of the time variable (character). |
group |
Name of one or more grouping variables (character vector). |
k |
Maximum number of joinpoints to be estimated (integer). |
step |
Use stepwise procedure to select the number of joinpoints (logical). |
test |
whether to test for differences in slope t-values during the stepwise selection
procedure. Only used when |
A list of models by group.
Tamara Ricardo
# 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, step = TRUE, test = TRUE) # Show the output of the first model mods$cyl_6 summary(mods$cyl_6)# 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, step = TRUE, test = TRUE) # Show the output of the first model mods$cyl_6 summary(mods$cyl_6)
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.
summary_jp( mods, digits = 1, var1 = "group", var2 = "subgroup", ft = FALSE, lan = c("en", "es") )summary_jp( mods, digits = 1, var1 = "group", var2 = "subgroup", ft = FALSE, lan = c("en", "es") )
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). |
A tibble or a flextable object.
Tamara Ricardo
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")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")