| blk.AUC.by.trapezoid | R Documentation |
Compute area under a curve (AUC) by the trapezoid rule within
each block of a block-format data set.
blk.AUC.by.trapezoid(x, y, id, id2 = id, ind = NULL, fill = NA, diff.op = "-", ...)
x,y |
A vector in |
id |
A valid |
id2 |
A valid |
ind |
A logical vector that designates a subset of points. By default all points are included. |
fill |
A value to use when no other value is appropriate. |
diff.op |
A function that computes differences in |
... |
Further arguments passed to |
This function operates on data sets in block-format.
Within each block,
the points on a curve are determined by x and y. A
subset of points to include can be specified with ind.
Then, within each block, AUC is computed by the trapezoid rule.
The parameter id2 determines the return value.
If id2 is NULL, the returned vector contains one
element for each level of id, with fill used for
blocks of size zero.
If id2 is NULL,
a vector containing one value for
each level of id. Otherwise,
a vectors in block-format with respect to id2.
Benjamin Rich <mail@benjaminrich.net>
block-format
data(pkstudy.PC)
df <- with(pkstudy.PC, data.frame(
id = asID(subjid),
datetime = strptime(pcdtc, "%Y-%m-%dT%H:%M", tz="UTC"),
reltime = NA,
conc = ifelse(grepl("^BQL", pcstresc), 0, pcstresn)))
# Simulate missing values
df$conc[c(3, 25)] <- NA
df$reltime <- with(df, blk.relativeTime(datetime, id))
# EXAMPLE 1 - id2=NULL
with(df, blk.AUC.by.trapezoid(x=reltime, y=conc, id=id, id2=NULL, ind=!is.na(conc)))
# EXAMPLE 2 - id2=id (default)
df$auc <- with(df, blk.AUC.by.trapezoid(x=reltime, y=conc, id=id, ind=!is.na(conc)))
# EXAMPLE 3 - use datetime directly and speficy diff.op
df$auc2 <- with(df, blk.AUC.by.trapezoid(x=datetime, y=conc, id=id, ind=!is.na(conc), diff.op=difftime.hours))
# See results:
head(df, 30)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.