Learn R Programming

respirometry (version 1.2.1)

calc_MO2: Calculate metabolic rate

Description

Calculates metabolic rate (MO2) given O2 measurements over time. Oxygen measurements are split into bins and MO2s are calculated from each bin (unless bin_width is set to 0). The bin_width parameter defines the width of the bins in timed intervals (e.g. 15 minutes). Linear regressions are fit through each bin and the calculated MO2 is returned as the slope of the change in O2 over time.

Usage

calc_MO2(
  duration,
  o2,
  o2_unit = "percent_a.s.",
  bin_width,
  vol,
  temp = 25,
  sal = 35,
  atm_pres = 1013.25,
  time,
  pH,
  good_data = TRUE
)

Arguments

duration

numeric vector of the timepoint for each observation (minutes).

o2

numeric vector of O2 observations.

o2_unit

a string describing the unit used to measure o2. Default is "percent_a.s." Options are from conv_o2.

bin_width

numeric or data frame. OPTION 1: A single number defining how long of a period should be binned for each MO2 determination (minutes). If MO2 is to be calculated from one observation to the next (rather than binned observations), set bin_width to 0. To calculate a single MO2 value from all observations, set bin_width to Inf. OPTION 2: A data frame with two numeric columns: "o2" and "width" generated by make_bins. Useful for Pcrit calculations or another application where bins of different widths are desired at different PO2s. For each row, set the "width" value to the bin duration (minutes) desired for observations <= the value in the "o2" column.

vol

volume of the respirometer (liter).

temp

temperature (<U+00B0>C). Default is 25 <U+00B0>C.

sal

salinity (psu). Default is 35 psu.

atm_pres

atmospheric pressure (mbar). Default is 1013.25 mbar.

time

(optional). Numeric vector of timestamp observations.

pH

(optional). Numeric vector of pH observations.

good_data

logical vector of whether O2 observations are "good" measurements and should be included in analysis. Linear regressions will not be fit over bins that include "bad" data. Bins will be split at bad data points. Default is that all observations are TRUE.

Value

A data frame is returned:

DUR_MEAN

Mean duration of the bin (minutes).

DUR_RANGE

Range of duration timepoints in the bin.

TIME_MEAN

Exists only if the parameter time has values. Mean timestamp of the bin.

TIME_RANGE

Exists only if the parameter time has values. Range of timestamps in the bin.

PH_MEAN

Exists only if the parameter pH has values. Mean pH of the bin. Averaged using mean_pH().

O2_MEAN

Mean O2 value of the bin in the unit chosen by o2_unit).

O2_RANGE

Range of O2 values in the bin.

MO2

Metabolic rate (umol O2 / hour).

R2

Coefficient of determination for the linear regression fit to calculate MO2.

N

Number of observations in the bin.

See Also

make_bins, calc_b, closed, scale_MO2, conv_resp_unit

Examples

Run this code
# NOT RUN {
# get O2 data
file <- system.file('extdata', 'witrox_file.txt', package = 'respirometry')
o2_data <- na.omit(import_witrox(file, split_channels = TRUE)$CH_4)

# calculate MO2
(mo2_5_min <- calc_MO2(duration = o2_data$DURATION, o2 = o2_data$O2,
bin_width = 5, vol = 10, temp = o2_data$TEMP, sal = o2_data$SAL))

# what if measurements from the 10 to 12 minute marks can't be trusted?
bad_data = o2_data$DURATION >= 10 & o2_data$DURATION <= 12
(mo2_5_min <- calc_MO2(duration = o2_data$DURATION, o2 = o2_data$O2,
bin_width = 5, vol = 10, temp = o2_data$TEMP, sal = o2_data$SAL, good_data = !bad_data))

# easily make a Pcrit plot
plot(mo2_5_min$O2_MEAN, mo2_5_min$MO2)

# I want to express MO2 in mg per min instead.
(mo2_5_min$MO2 <- conv_resp_unit(value = mo2_5_min$MO2, from = 'umol_O2 / hr', to = 'mg_O2 / min'))

# just endpoint measurement:
calc_MO2(duration = o2_data$DURATION, o2 = o2_data$O2,
bin_width = Inf, vol = 10, temp = o2_data$TEMP, sal = o2_data$SAL)

# In my trial, observations above 77% air saturation were really noisy, but much less noisy at
# lower O2 values. I want to adjust my bin width based on the PO2 to obtain the best balance of
# resolution and precision throughout the whole trial. Below 77% a.s., use 4 minute bins. Above
# 77% a.s. use 10 minute bins.
bins = data.frame(o2 = c(77, 100), width = c(4, 10))
calc_MO2(duration = o2_data$DURATION, o2 = o2_data$O2,
bin_width = bins, vol = 10, temp = o2_data$TEMP, sal = o2_data$SAL)

# }

Run the code above in your browser using DataLab