The function calculates rates by fitting a linear model of oxygen against
time, with the slope of this regression being the rate. There are no units
involved in calc_rate
. This is a deliberate decision. The units of oxygen
concentration and time will be specified later in convert_rate()
when
rates are converted to specific output units.
For continuous data recordings, it is recommended a data.frame
containing
the data be prepared via inspect()
, and entered as the x
input. For
data not prepared like this, x
can be a 2-column data.frame
containing
numeric values of time (col 1) and oxygen (col 2). If multiple columns are
found in either an inspect
or data frame input, only the first two columns
are used.
Specifying regions
For calculating rates over specific regions of the data, the from
and to
inputs in the by
units of "time"
(the default), "oxygen
", or "row"
.
The from
and to
inputs do not need to be precise; the function will use
the closest values found.
Multiple regions can be examined within the same dataset by entering from
and to
as vectors of paired values to specify different regions. In this
case, $rate
in the output will be a vector of multiple rates with each
result corresponding to the position of the paired from
and to
inputs. If
from
and to
are NULL
(the default), the rate is determined over the
entire dataset.
Plot
A plot is produced (provided plot = TRUE
) showing the original data
timeseries of oxygen against time (bottom blue axis) and row index (top red
axis), with the region specified via the from
and to
inputs highlighted.
Second panel is a close-up of the rate region with linear model coefficients.
Third and fourth panels are summary plots of fit and residuals.
Additional plotting options
If multiple rates have been calculated, by default the first (pos = 1
) is
plotted. Others can be plotted by changing the pos
input either in the main
function call, or by plotting the output, e.g. plot(object, pos = 2)
. In
addition, each sub-panel can be examined individually by using the panel
input, e.g. plot(object, panel = 2)
.
Console output messages can be suppressed using quiet = TRUE
. If axis
labels (particularly y-axis) are difficult to read, las = 2
can be passed
to make axis labels horizontal, and oma
(outer margins, default oma = c(0.4, 1, 1.5, 0.4)
), and mai
(inner margins, default mai = c(0.3, 0.15, 0.35, 0.15)
) used to adjust plot margins.
S3 Generic Functions
Saved output objects can be used in the generic S3 functions print()
,
summary()
, and mean()
.
print()
: prints a single result, by default the first rate. Others can be
printed by passing the pos
input. e.g. print(x, pos = 2)
summary()
: prints summary table of all results and metadata, or those
specified by the pos
input. e.g. summary(x, pos = 1:5)
. The summary can
be exported as a separate dataframe by passing export = TRUE
.
mean()
: calculates the mean of all rates, or those specified by the pos
input. e.g. mean(x, pos = 1:5)
The mean can be exported as a separate value
by passing export = TRUE
.
More
For additional help, documentation, vignettes, and more visit the respR
website at https://januarharianto.github.io/respR/