Commit 50ffc6c3 authored by Chris Jewell's avatar Chris Jewell
Browse files

Added test for mismatched data.

parent 8ab72778
# Test time/location data structure
test_that("Test time/location data structures", {
testdata = function()
{
# Test priors
priors <-
list(
......@@ -14,7 +15,6 @@ test_that("Test time/location data structures", {
ss = group_by(sim_SA_data, Time, Location) %>%
slice(1:10) %>% ungroup %>% as.data.frame
src = reshape2::melt(
ss[ss$Location == 'A', c(1, 2:9)],
id.vars = c('Type', 'Time'),
......@@ -29,14 +29,35 @@ test_that("Test time/location data structures", {
variable.name = 'Source',
value.name = 'Count'
)
y = Y(data=ss, y = 'Human', type='Type', time = 'Time', location = 'Location')
x = X(data=src, x='Count', type='Type', time='Time', source='Source')
k = Prev(sim_SA_prev, prev='Value', time='Time', source='Source')
list(y=ss[,c('Human','Type','Time','Location')], X=src, prior=priors, prev=sim_SA_prev)
}
test_that("Detect y/X data mismatch", {
dat = testdata()
y = Y(data=dat$y, y = 'Human', type='Type', time = 'Time', location = 'Location')
x = X(data=dat$X, x='Count', type='Type', time='Time', source='Source')
k = Prev(dat$prev, prev='Value', time='Time', source='Source')
expect_silent(HaldDP(y=y, x=x, k=k, priors=dat$prior, a_q = 0.1))
dat$X = dat$X[dat$X$Time == '1',]
x = X(data=dat$X, x='Count', type='Type', time='Time', source='Source')
expect_error(HaldDP(y=y, x=x, k=k, priors=dat$prior, a_q = 0.1), "Times in x and y do not match")
})
test_that("Test time/location data structures", {
dat = testdata()
y = Y(data=dat$y, y = 'Human', type='Type', time = 'Time', location = 'Location')
x = X(data=dat$X, x='Count', type='Type', time='Time', source='Source')
k = Prev(dat$prev, prev='Value', time='Time', source='Source')
model = HaldDP(
y = y,
x = x,
k = k,
priors = priors,
priors = dat$prior,
a_q = 0.1
)
model$mcmc_params(n_iter = 100,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment