Skip to content

Commit 5b5a899

Browse files
committed
Additional correlation/lag tests
1 parent 2cb2542 commit 5b5a899

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

R-packages/covidcast/tests/testthat/test-cor.R

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,57 @@ test_that("simple correlations", {
2929
by = "geo_value"),
3030
expected)
3131
})
32+
33+
test_that("basic lagged correlations", {
34+
foo <- data.frame(
35+
time_value = as.Date(c("2020-01-01", "2020-01-02",
36+
"2020-01-03", "2020-01-04")),
37+
geo_value = "pa",
38+
issue = 1,
39+
value = c(1, 2, 1, 2)
40+
)
41+
42+
bar <- data.frame(
43+
time_value = as.Date(c("2020-01-01", "2020-01-02",
44+
"2020-01-03", "2020-01-04")),
45+
geo_value = "pa",
46+
issue = 1,
47+
value = c(2, 1, 2, 1)
48+
)
49+
50+
expected <- tibble(
51+
geo_value = "pa",
52+
value = 1
53+
)
54+
expect_equal(covidcast_cor(foo, bar, dt_x = 1),
55+
expected)
56+
expect_equal(covidcast_cor(foo, bar, dt_y = 1),
57+
expected)
58+
})
59+
60+
test_that("lags are in correct direction", {
61+
foo <- data.frame(
62+
time_value = seq.Date(as.Date("2020-01-01"), as.Date("2020-01-10"),
63+
"day"),
64+
geo_value = "pa",
65+
issue = 1,
66+
value = 1:10
67+
)
68+
69+
bar <- data.frame(
70+
time_value = seq.Date(as.Date("2020-01-01"), as.Date("2020-01-10"),
71+
"day"),
72+
geo_value = "pa",
73+
issue = 1,
74+
value = c(rep(0, 5), 1:5)
75+
)
76+
77+
expected <- tibble(
78+
geo_value = "pa",
79+
value = 1
80+
)
81+
expect_equal(covidcast_cor(foo, bar, dt_x = -4),
82+
expected)
83+
expect_equal(covidcast_cor(foo, bar, dt_y = 4),
84+
expected)
85+
})

0 commit comments

Comments
 (0)