| blk.changeFromBaseline | R Documentation |
These functions compute change from baseline in a block-format data set.
blk.changeFromBaseline(x, id, baseline = blk.singleValue(x, id, ind = bl.ind, select = bl.select),
bl.ind = NULL, bl.select = "first", diff.op = percentChange, ...)
blk.relativeTime(time, id, baseline = blk.singleValue(time, id, ind=bl.ind, select=bl.select),
bl.ind = NULL, bl.select = "first", diff.op = difftime.default, ...)
x, time |
A vector in |
id |
A valid |
baseline |
A vector of basline values or times, one for each level of |
bl.ind |
A logical vector that indicates elements of |
bl.select |
How to select a single baseline from a vector of possibilities. |
diff.op |
A function that computes differences in |
... |
Further arguments passed to |
A unique baseline value for each level of id is required. The
baseline values can be specified in two ways: directly as a vector of
length nlevels{id}, or indirectly by the arguments bl.ind and
bl.select which are passed to blk.singleValue.
Relative time refers to change from baseline in a time
variable, so there are two functions which are essentially identical,
except for the default value of diff.op. By default,
blk.changeFromBaseline computes the percent change from baseline.
When applied to date/time objects (class lind{POSIXt}), the default
diff.op for blk.relativeTime computes relative time in hours.
A vector in block-format with respect to id containing
the change from baseline (or relative time) for x (or time).
Benjamin Rich <mail@benjaminrich.net>
block-format
blk.singleValue
difftime.default
require(nlme)
data(Phenobarb)
dat <- Phenobarb[1:56,] # First 4 subjects
cbind(dat, PCT.CHG=blk.changeFromBaseline(dat$conc, asID(dat$Subject), bl.ind=(!is.na(dat$conc))))
# Relative time from calendar date and clock time
# -----------------------------------------------
# This data already has relative time, so for this example we will
# re-create a calendar date and clock time from made-up baseline times.
baseline <- strptime(c("2005-04-13 8:05:00", "2005-04-16 7:59:00", "2005-03-31 9:00:00", "2005-04-19 8:35:00"), format="%F %T")
# Back-calcuate the calendar date and clock time
dat$time2 <- blk.repeatValue(baseline, id2=asID(dat$Subject)) + as.difftime(dat$time, units="hours")
# Now, recalcuate the relative time assuming that only time2 was specified
cbind(dat, REL.TIME=blk.relativeTime(dat$time2, asID(dat$Subject), bl.ind=(!is.na(dat$dose))))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.