lag-times of profiles and cor() [🇷 for BE/BA]
❝ It all relates to SaToWIB and the functions that compare two concentration vectors…
t <- seq(0, 24, 0.5)
lag <- 2
c1 <- exp(-log(2) / 4 * t) - exp(-log(2) / 1 * t) # no lag-time
c2 <- exp(-log(2) / 4 * (t - lag)) - exp(-log(2) / 1 * (t - lag)) # lag-time
c2[c2 < 0] <- NA
plot(t, c1, type = "l", ylab = "c", las = 1)
lines(t, c2)
data <- data.frame(t = t, c1 = c1, c2 = c2)
m1 <- lm(c2 ~ c1, data = data)
m2 <- lm(c2 ~ c1 * t, data = data)
res <- data.frame(model = c("Pearson", "simple", "nested"),
r.sq = c(cor(data$c2, data$c1, use = "complete.obs"),
summary(m1)$r.squared,
summary(m2)$r.squared),
r.sq.adj = c(NA,
summary(m1)$adj.r.squared,
summary(m2)$adj.r.squared))
# shift c2 by the estimated lag-time
c3 <- c2[tail(which(c2 == 0), 1):length(c2)]
c3 <- c(c3, rep(NA, length(c1) - length(c3)))
ski <- paste("correlation of shifted profiles =",
cor(c3, c1, use = "complete.obs"), "\n")
print(res, row.names = FALSE); cat(ski)
model r.sq r.sq.adj
Pearson 0.8059089 NA
simple 0.6494891 0.6413377
nested 0.9711260 0.9690133
correlation of shifted profiles = 1
If you are courageous, estimate the lag-time and shift the profile(s). Of course, this works only with equally spaced intervals, which we never have. Hence, I would opt for the nested model.
# visualize why the simple model is crap
plot(c1, c2, ylab = "c2, c3", las = 1, col = "blue")
abline(coef(m1), col = "blue")
# out of competition
points(c1, c3, col = "red")
abline(lm(c3 ~ c1), col = "red")
Dif-tor heh smusma 🖖🏼 Довге життя Україна!
Helmut Schütz
The quality of responses received is directly proportional to the quality of the question asked. 🚮
Science Quotes
Complete thread:
- The order function ElMaestro 2024-03-24 17:07 [🇷 for BE/BA]
- The order function ElMaestro 2024-03-24 20:31
- The order function Helmut 2024-03-24 21:12
- The order function d_labes 2024-03-26 19:58
- The order function ElMaestro 2024-03-27 08:43
- The sort function Helmut 2024-04-02 10:51
- The sort function ElMaestro 2024-04-02 22:44
- lag-times of profiles and cor()Helmut 2024-04-04 09:39
- Roaster VII/VIII, Bandana Castor, and Effiou ElMaestro 2024-04-04 12:30
- Nomen est omen Helmut 2024-04-04 13:04
- Nomen est omen ElMaestro 2024-04-04 13:50
- Nomen est omen Ohlbe 2024-04-04 14:52
- Nomen est omen ElMaestro 2024-04-04 16:16
- Nomen est omen nobody 2024-04-10 09:21
- Nomen est omen Ohlbe 2024-04-10 09:34
- Nomen est omen nobody 2024-04-10 10:21
- Nomen est omen Ohlbe 2024-04-10 09:34
- Nomen est omen nobody 2024-04-10 09:21
- Nomen est omen ElMaestro 2024-04-04 16:16
- Nomen est omen Ohlbe 2024-04-04 14:52
- Nomen est omen ElMaestro 2024-04-04 13:50
- Nomen est omen Helmut 2024-04-04 13:04
- Roaster VII/VIII, Bandana Castor, and Effiou ElMaestro 2024-04-04 12:30
- lag-times of profiles and cor()Helmut 2024-04-04 09:39
- The sort function ElMaestro 2024-04-02 22:44
- The sort function Helmut 2024-04-02 10:51
- The order function ElMaestro 2024-03-27 08:43
- The order function ElMaestro 2024-03-24 20:31