calc_AUC: Calculate the trapezoidal area under the curve for a...

View source: R/calc_AUC.R

calc_AUCR Documentation

Calculate the trapezoidal area under the curve for a stimulated C-peptide assay

Description

This function calculates the area under the curve for a mixed-meal tolerance test (MMTT), oral glucose tolerance test (OGTT), or similar, using the trapezoidal rule. As input, it takes a data frame of C-peptide or insulin values for each timepoint, with an identifier column. This can be a long data frame with timepoint indicated in a separete column, or a wide data frame with separate columns for each timepoint. Options include 2-hour vs. 4-hour AUC, dropping visits with missing timepoints vs. using the average of the two surrounding timepoints, and whether to use the 0 timepoint or the average of the pre-0 and 0 timepoints as the initial value.

Usage

calc_AUC(
  input_data, input_format = "wide",
  pep_colname = "pep", timepoint_colname = "timepoint", 
  initial_timepoint = "zero", treat_missing = "drop",
  auc_timeframe = "2-hour")

Arguments

input_data

data frame containing the C-peptide data from MMTTs or stimulated insulin data from OGTTs. Should contain a unique visit/test identifer and the C-peptide level at each timepoint. If there are issues with values below the detection threshold, those must be resolved before running this function (i.e. values such as "<0.01" are not allowed)

input_format

character, the format of the C-peptide data. Defaults to "wide", which has each timepoint in a separate column, with a single row for each visit. Set to "long" if the data frame has a separate row for each timepoint.

pep_colname

character or numeric. Usage depends on the value of input_format. If input_format is set to "wide", this should be the prefix of the column identifiers for the timepoint. E.g. if the different timepoints are in columns named "pep0", "pep15", "pep30", then this argument should be set to "pep". If input_format is set to "long", this argument should be the name or number of the column containing the C-peptide information. Defaults to "pep".

timepoint_colname

character or numeric, the column containing the timepoint values. Used only if input_format is set to "long".

initial_timepoint

character, how to handle the initial timepoint. Defaults to "zero", which uses the 0-minute timepoint. Alternative option is "average", which uses the average of the pre-0 timepoint and the 0 timepoint.

treat_missing

character, how to handle visits with missing timepoints. Defaults to "drop", which causes any visits missing a timepoint in the AUC window to be dropped. Alternative option is "weighted_average", which causes the AUC to be calculated as if that timepoint were not taken (i.e. the curve is drawn with a straight line between the preceding and following timepoints); this works only for non-consecutive missing timepoints that are not the first or last in the AUC calculation!

auc_timeframe

character, either "2-hour" or "4-hour". Determines whether the AUC is calculated over 2 hours or 4. If "4-hour" is selected, any 2-hour MMTTs will be dropped. Defaults to "2-hour".

Value

a vector containing the AUC values, with NA where it could not be calculated


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