if (FALSE) {
# The following code need to download additional demo data
# Please see https://rave.wiki/ for more details
library(raveio)
repo <- prepare_subject_raw_voltage_with_epoch(
subject = "demo/DemoSubject",
time_windows = c(-1, 3),
electrodes = c(14, 15))
##### Direct baseline on repository
voltage_baseline(
x = repo, method = "zscore",
baseline_windows = list(c(-1, 0), c(2, 3))
)
voltage_mean <- repo$raw_voltage$baselined$collapse(
keep = c(1,3), method = "mean")
matplot(voltage_mean, type = "l", lty = 1,
x = repo$raw_voltage$dimnames$Time,
xlab = "Time (s)", ylab = "Voltage (z-scored)",
main = "Mean coltage over trial (Baseline: -1~0 & 2~3)")
abline(v = 0, lty = 2, col = 'darkgreen')
text(x = 0, y = -0.5, "Aud-Onset ", col = "darkgreen", cex = 0.6, adj = c(1,1))
##### Alternatively, baseline on each electrode channel
voltage_mean2 <- sapply(repo$raw_voltage$data_list, function(inst) {
re <- voltage_baseline(
x = inst, method = "zscore",
baseline_windows = list(c(-1, 0), c(2, 3)))
rowMeans(re[])
})
# Same with floating difference
max(abs(voltage_mean - voltage_mean2)) < 1e-8
}
Run the code above in your browser using DataLab