calc_rate | R Documentation |
Calculates rate of oxygen uptake or production from respirometry data. A rate
can be determined over the whole dataset, or on subsets of the data using the
from
and to
inputs to specify data regions in terms of oxygen
or time
units or row
numbers of the input data. Multiple rates can be extracted
from the same dataset by using these inputs to enter vectors of paired values
in the appropriate metric. See Examples.
calc_rate(x, from = NULL, to = NULL, by = "time", plot = TRUE, ...)
x |
object of class |
from |
numeric value or vector. Defaults to |
to |
numeric value or vector. Defaults to |
by |
string. |
plot |
logical. Defaults to |
... |
Allows additional plotting controls to be passed, such as |
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.
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.
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.
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.
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
.
For additional help, documentation, vignettes, and more visit the respR
website at https://januarharianto.github.io/respR/
Output is a list
object of class calc_rate
containing input
parameters and data, various summary data, metadata, linear models, and the
primary output of interest $rate
, which can be background adjusted in
adjust_rate
or converted to units in convert_rate
.
# Subset by 'time' (the default)
inspect(sardine.rd, time = 1, oxygen = 2, plot = FALSE) %>%
calc_rate(from = 200, to = 1800)
# Subset by oxygen
inspect(sardine.rd, time = 1, oxygen = 2, plot = FALSE) %>%
calc_rate(94, 91, by = "oxygen")
# Subset by row
inspect(sardine.rd, time = 1, oxygen = 2, plot = FALSE) %>%
calc_rate(1000, 2000, by = "row")
# Use a data frame input, and calculate rate from multiple regions by
# using a vector in the 'from' and 'to' inputs
x <- calc_rate(intermittent.rd,
from = c(200,2300,4100),
to = c(1800,3200,4600),
by = 'time',
plot = FALSE)
# Print and summary of results
print(x)
summary(x)
# Plot the third of these results
plot(x, pos = 3)
# Plot only the timeseries plot and hide the legend
plot(x, pos = 3, panel = 1, legend = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.