auc_wide: Calculate AUC from a wide-format dataframe

Description Usage Arguments Value See Also Examples

Description

This function calculates the trapezoidal method AUC for data in WIDE format dataframe, with each row encoding an individial subject. The function uses the sfsmisc::integrate.xy() function, which can handle unordered time input. Variables used must follow the naming convention "xxxmeasure_123"

Usage

1
2
auc_wide(dfWide, measure, sep = "_", varname = measure,
  use.spline = FALSE, ...)

Arguments

dfWide

a dataframe with repeated measures in "wide" format

measure

Defines the measure to assess, and must be encoded in variable name. Must be quoted. Also defines the outcome variable name, unless 'varname' is defined as something else

sep

Defines the separator between the measure and time. Defaults to "_". Time must be encoded as a number AT THE END of the variable name: ( e.g., "measure_000, measure_001, measure_002...")

varname

Defines the output variable name, to be appended to the prefix "auc_".

use.spline

Whether to use linear trapezoid (use.spline=FALSE), or to integrate under cubic spline (use.spline=TRUE). defaults to FALSE.

...

Passes to the 'integrate.xy' function. Options include "a, b, digits, and xtol"

Value

Modified dataframe appended with a new variable (column) for AUC. The new variable will have named attributes "method", "sourceVars", and "times" which capture the methods used for the calculation

See Also

integrate.xy

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# A very clean dataframe
dfWide1 <- data.frame(
  glucose_0  =c(120, 120, 140, 140, 150),
  glucose_30 =c(250, 250, 270, 325, 400),
  glucose_60 =c(150, 210, 300, 350, 275))
auc_wide(dfWide1, "glucose")

# A messier dataframe: glucose from different study type, time unordered
dfWide5 <- data.frame(
  glucose_ogtt_030=c(250, 250, 270, 325, 400),
  XXXglucose_ogtt_000=c(120, 120, 140, 140, 150),
  glucose_ogtt_060 =c(150, 210, 300, 350, 275),
  glucose_hg_060 =c(150, 210, 300, 350, 275))

auc_wide(dfWide5, "glucose", sep="_ogtt_")  # works

JMLuther/metabolicR documentation built on May 7, 2019, 10:12 a.m.