calc_rate: Calculate rate of change in oxygen over time

View source: R/calc_rate.R

calc_rateR Documentation

Calculate rate of change in oxygen over time

Description

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.

Usage

calc_rate(x, from = NULL, to = NULL, by = "time", plot = TRUE, ...)

Arguments

x

object of class inspect or data.frame. This is the timeseries of paired values of oxygen against time from which to calculate rates.

from

numeric value or vector. Defaults to NULL. The start of the region(s) over which you want to calculate the rate in the units specified in by. If a vector, each value must have a paired value in to.

to

numeric value or vector. Defaults to NULL. The end of the region(s) over which you want to calculate the rate in the units specified in by. If a vector, each value must have a paired value in from.

by

string. "time", "row", or "oxygen". Defaults to "time". This is the method used to subset the data region between from and to.

plot

logical. Defaults to TRUE. Plot the results.

...

Allows additional plotting controls to be passed, such as pos, panel, and quiet = TRUE.

Details

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/

Value

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.

Examples

# 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)

januarharianto/respR documentation built on March 29, 2024, 6:51 p.m.