View source: R/baseline_correction.R
| baseline_correction | R Documentation |
Function for computing amplitude corrected to the selected baseline.
baseline_correction(data, baseline_range, type = "absolute")
data |
A data frame, tibble or a database table with input data, required columns: subject, sensor, time, signal, epoch. |
baseline_range |
A numeric vector of time points used as the baseline (e.g., |
type |
A character indicating the type of baseline correction. Only the value |
If the values from baseline_range vector are out of the range of the time column, the baseline calculation proceeds as follows:
If a part of the baseline_range vector is in the time column and part is outside its range, the baseline correction is computed only from the part inside a time range.
If the whole baseline_range vector is out of the time range, the baseline and also the signal_base values of the output are NA's.
In both cases the function returns a warning message along with the output data frame or tibble.
Note: If there are NA values in the signal column, matching rows are ignored in the baseline calculation (which may bias the results) and the function prints a warning message.
A data frame/tibble with added columns:
signal_base |
Signal corrected by subtracting the baseline for each epoch. |
baseline |
A baseline value used for correction. |
# Computing baseline correction on first 10 points, sensor "E1"
# a) Prepare data and compute
data01 <- epochdata |> dplyr::filter(.data$subject == 1 & .data$sensor == "E1")
basedata <- baseline_correction(data01, baseline_range = 1:10, type = "absolute")
# b) Plot raw (black line) and corrected (red line) signal for epoch 1
epoch1 <- basedata |> dplyr::filter(.data$epoch == 1)
plot(epoch1$signal, type = "l", ylim = c(-20, 30), main = "Raw (black) vs Corrected (red) Signal",
xlab = "time point", ylab = "amplitude")
lines(epoch1$signal_base, col = "red")
# Set baseline_range outside of time range
# results in NA's in baseline and signal_base columns
# also returns a warning message
basedata <- baseline_correction(data01, baseline_range = 70:80, type = "absolute")
head(basedata)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.