% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/model_jp.R
\name{model_jp}
\alias{model_jp}
\title{Joinpoint Regression Models by Groups}
\usage{
model_jp(data, value, time, group, k = 2, step = TRUE, test = TRUE)
}
\arguments{
\item{data}{Data frame containing age-standardized rates.}

\item{value}{Name of the response variable (character).}

\item{time}{Name of the time variable (character).}

\item{group}{Name of one or more grouping variables (character vector).}

\item{k}{Maximum number of joinpoints to be estimated (integer).}

\item{step}{Use stepwise procedure to select the number of joinpoints (logical).}

\item{test}{whether to test for differences in slope t-values during the stepwise selection
procedure. Only used when \code{step = TRUE}.}
}
\value{
A list of models by group.
}
\description{
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
\code{segmented::selgmented()} or \code{segmented::segmented()} and applies
a log transformation to the response variable.
}
\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, step = TRUE, test = TRUE)

# Show the output of the first model
mods$cyl_6
summary(mods$cyl_6)
}
\author{
Tamara Ricardo
}
