calc_Cpeptide_rates: Estimate rate of C-peptide change over time, by subject (with...

View source: R/calc_Cpeptide_rates.R

calc_Cpeptide_ratesR Documentation

Estimate rate of C-peptide change over time, by subject (with options!)

Description

This function uses linear models to estimate the rate of C-peptide AUC change over time. There are three options for how to fit models, set using the model_type argument: "independent" fits a separate, independent intercept and slope for each value of identifier_column; "random_effect" fits an individual-level random effect for both the intercept and the slope; "grouped_random_effect" fits an individual-level random effect for the intercept, a group-level fixed effect for each unique value of group_column, and an individual-level random effect around the group means.

Usage

calc_Cpeptide_rates(
  cpeptide_auc_data,
  model_type = c("independent", "random_effect"),
  identifier_column = "subject",
  time_column = "cpeptide_study_day",
  auc_column = "auc",
  group_column
)

Arguments

cpeptide_auc_data

data frame containing the C-peptide data. Should contain a unique subject identifer, a numeric column for the timing of visits, and C-peptide AUC values. Any non-NA values included in this data frame will be used, so filtering should be done before passing the data to this function.

model_type

character, the type(s) of model to fit. Options are "independent", "random_effect", and "grouped_random_effect". "independent" uses a simple fixed-effects model with slopes and intercepts for each subject. "random_effect" uses a mixed-effects model with subject-level random intercepts and slopes. "grouped_random_effect" uses a mixed-effects model like "random_effect", but with group-level fixed effects for the slopes.

identifier_column

character or numeric, the column containing the subject identifiers. Defaults to "subject". If the contents of the specified column are numeric, they are coerced to character class, with a warning.

time_column

character or numeric, the column with the time variable. Should be numeric and based on a baseline visit, as intercept values only make sense if they are based on a common scale. Default is "cpeptide_study_day".

auc_column

character or numeric, the column containing the C-peptide AUC values. Data should be transformed to whatever form the model is to be fit to (typically log-transformed). Defaults to "auc".

group_column

character or numeric, the column containing the subject grouping. Used only if model_type is set to "grouped_random_effect"

Value

a list containing, for each value of model_type, an element with the model fit(s) (as $model) and and a data frame with the extracted slopes and intercepts for each subject (as $rates). Slopes are given in the units of auc_column / unit of time_column.


mjdufort/CpeptideTools documentation built on March 5, 2025, 6:58 p.m.