Created
February 6, 2018 14:09
-
-
Save cszang/fd144ae329ba6cc206ce80eb7687943d to your computer and use it in GitHub Desktop.
Simple bivariate "Gershunov-test"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(zoo) | |
g_test <- function(x, y, w = 20, l = 1000) { | |
cor_fun <- function(x) cor(x[,1], x[,2]) | |
## benchmark | |
d0 <- data.frame(x, y) | |
c0 <- rollapply(d0, width = w, cor_fun, by.column = FALSE) | |
## l simulations | |
di <- lapply(1:l, function(f) { | |
data.frame(x, rnorm(length(x), mean = mean(y), sd = sd(y))) | |
}) | |
ci <- lapply(sim, function(x) rollapply(x, width = w, cor_fun, | |
by.column = FALSE)) | |
## get sds and compare | |
s0 <- sd(c0) | |
si <- sapply(ci, sd) | |
ecdf(si)(s0) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment