I have time series data from several samples (wildtype (WT) vs. knockout (KO)) for calcium concentrations. In particular, I get 2 peaks for each sample and use the 2nd peak to calibrate the first peak, for this I need the AUC of both peaks. My goal is to apply a spline function to my time series data and to calculate the AUCs.
So far I used the MESS
package and the auc()
function and set type=spline
Time is measured in ms from 0 to 1801204 ms
df <- data
df
# A tibble: 551 x 7
Time KO_1 WT1 KO_2 WT2 KO_3 WT3
1 29800 87 80 94 99 102 99
2 30000 77 91 89 89 80 104
3 31487 264 334 261 147 330 257
4 31687 352 294 349 176 242 356
5 31887 341 333 359 260 303 353
6 32087 349 436 346 250 280 334
7 32287 328 373 383 321 287 443
8 32487 382 484 376 323 270 416
9 32687 437 495 295 317 300 458
10 32887 351 542 387 378 312 422
# ... with 541 more rows
library(MESS)
auc(df$Time, df$WT1, from=min(df$Time, na.rm = TRUE),
to = max(df$Time, na.rm = TRUE) ,type = 'spline')
My expected result is that I get a value for AUC for WT1. But I always receive the error message:
Error in integrate(myfunction, lower = from, upper = to) : maximum number of subdivisions reached
The error message comes from function integrate
that is used within MESS::auc
.
More precisely, it comes from the argument subdivisions
(maximum number of subintervals), which is set to 100 by default. However, in your case, a higher value would probably make more sense.
An quick and easy fix (but not a very sustainable one!), is, to copy+paste the auc function into an R script, adapt it to your needs (see below) and then source it before you use it.
Here is how that works:
mess_auc_adapted.R
auc
(auc <- function...
).res <- integrate(myfunction, lower = from, upper = to)$value
becomes
res <- integrate(myfunction, lower = from, upper = to, ...)$value
auc
the following way: source("mess_auc_adapted.R")
auc(x = df$Time, y = df$WT1, from=min(df$Time, na.rm = TRUE),
to = max(df$Time, na.rm = TRUE) ,type = 'spline', subdivisions = WHATEVER_NUMBER_THAT_MAKES_SENSE)
A better solution is to contact the maintainer, tell them your problem and a possible solution to it. Just open an issue here: https://github.com/ekstroem/MESS/issues. This way the problem can be addressed directly.