Skip to content

Commit e3eeb39

Browse files
authored
Merge pull request #108 from dajmcdon/km-test-correlation
Km test correlation
2 parents 054895d + 82338db commit e3eeb39

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/testthat/test-correlation.R

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
library(tibble)
2+
3+
test_that("epi_cor throws an error for a non-epi_df for its first argument",{
4+
expect_error(epi_cor(1:10,1,1))
5+
expect_error(epi_cor(data.frame(x=1:10),1,1))
6+
})
7+
8+
test_that("epi_cor requires two var arguments, var1 and var2",{
9+
expect_error(epi_cor(archive_cases_dv_subset$DT,var2=1))
10+
expect_error(epi_cor(archive_cases_dv_subset$DT,var1=1))
11+
})
12+
13+
test_that("epi_cor functions as intended",{
14+
expect_equal(epi_cor(x = jhu_csse_daily_subset,
15+
var1 = case_rate_7d_av,
16+
var2 = death_rate_7d_av,
17+
cor_by = geo_value,
18+
dt1 = -2)[1],
19+
tibble(geo_value = unique(jhu_csse_daily_subset$geo_value))
20+
)
21+
22+
edf <- as_epi_df(data.frame(geo_value=rep("asdf",20),
23+
time_value=as.Date("2020-01-01") + 1:20,
24+
pos=1:20,
25+
neg=-(1:20)))
26+
expect_equal(epi_cor(edf, pos, pos)[[2]],1)
27+
expect_equal(epi_cor(edf, pos, neg)[[2]],-1)
28+
})
29+
30+
test_that("shift works as intended",{
31+
expect_identical(epiprocess:::shift(1:100,1),dplyr::lead(1:100))
32+
expect_identical(epiprocess:::shift(1:100,0),1:100)
33+
expect_identical(epiprocess:::shift(1:100,-1),dplyr::lag(1:100))
34+
})

0 commit comments

Comments
 (0)